X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fbuffer.C;h=67d895c460b4c7c1058202fdde62755e360440dd;hb=00d24ec87650e4ac7db77ad54cb4aa2f688100f3;hp=58ebb34d8f0435146a0a46dba7549c6319989ad7;hpb=9356012089091a9c47b51ced9c27c516bf766637;p=lyx.git
diff --git a/src/buffer.C b/src/buffer.C
index 58ebb34d8f..67d895c460 100644
--- a/src/buffer.C
+++ b/src/buffer.C
@@ -4,9 +4,9 @@
* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
- * Copyright 1995-2000 The LyX Team.
+ * Copyright 1995-2001 The LyX Team.
*
- * This file is Copyright 1996-1999
+ * This file is Copyright 1996-2001
* Lars Gullik Bjønnes
*
* ======================================================
@@ -17,6 +17,8 @@
#include
#include
#include
");
- break;
}
}
// Print an error message.
-void Buffer::LinuxDocError(LyXParagraph * par, int pos,
+void Buffer::linuxDocError(Paragraph * par, int pos,
string const & message)
{
// insert an error marker in text
InsetError * new_inset = new InsetError(message);
- par->InsertInset(pos, new_inset);
+ par->insertInset(pos, new_inset);
}
-// This constant defines the maximum number of
-// environment layouts that can be nesteded.
-// The same applies for command layouts.
-// These values should be more than enough.
-// José Matos (1999/07/22)
-
-enum { MAX_NEST_LEVEL = 25};
void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
{
- LyXParagraph * par = paragraph;
-
- niceFile = nice; // this will be used by Insetincludes.
+ ofstream ofs(fname.c_str());
+ if (!ofs) {
+ WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
+ return;
+ }
- string top_element= textclasslist.LatexnameOfClass(params.textclass);
- // Please use a real stack.
- string environment_stack[MAX_NEST_LEVEL];
- string environment_inner[MAX_NEST_LEVEL];
- // Please use a real stack.
- string command_stack[MAX_NEST_LEVEL];
- bool command_flag= false;
- int command_depth= 0, command_base= 0, cmd_depth= 0;
+ Paragraph * par = paragraph;
- string item_name, command_name;
- string c_depth, c_params, tmps;
+ niceFile = nice; // this will be used by Insetincludes.
- int depth = 0; // paragraph depth
LyXTextClass const & tclass =
textclasslist.TextClass(params.textclass);
LaTeXFeatures features(params, tclass.numLayouts());
validate(features);
-
- //if (nice)
- tex_code_break_column = lyxrc.ascii_linelen;
- //else
- //tex_code_break_column = 0;
-
- ofstream ofs(fname.c_str());
- if (!ofs) {
- WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
- return;
- }
texrow.reset();
+ string top_element = textclasslist.LatexnameOfClass(params.textclass);
+
if (!only_body) {
- string sgml_includedfiles=features.getIncludedFiles(fname);
+ string sgml_includedfiles = features.getIncludedFiles(fname);
ofs << "\n";
+ vector environment_stack(10);
+ vector environment_inner(10);
+ vector command_stack(10);
+
+ bool command_flag = false;
+ Paragraph::depth_type command_depth = 0;
+ Paragraph::depth_type command_base = 0;
+ Paragraph::depth_type cmd_depth = 0;
+ Paragraph::depth_type depth = 0; // paragraph depth
+
+ string item_name;
+ string command_name;
+
while (par) {
+ string sgmlparam;
+ string c_depth;
+ string c_params;
int desc_on = 0; // description mode
+
LyXLayout const & style =
textclasslist.Style(params.textclass,
par->layout);
// environment tag closing
- for (; depth > par->params.depth(); --depth) {
+ for (; depth > par->params().depth(); --depth) {
if (environment_inner[depth] != "!-- --") {
- item_name= "listitem";
+ item_name = "listitem";
sgmlCloseTag(ofs, command_depth + depth,
item_name);
if (environment_inner[depth] == "varlistentry")
@@ -3089,7 +3090,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
environment_inner[depth].erase();
}
- if (depth == par->params.depth()
+ if (depth == par->params().depth()
&& environment_stack[depth] != style.latexname()
&& !environment_stack[depth].empty()) {
if (environment_inner[depth] != "!-- --") {
@@ -3112,49 +3113,47 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
// Write opening SGML tags.
switch (style.latextype) {
case LATEX_PARAGRAPH:
- sgmlOpenTag(ofs, depth+command_depth, style.latexname());
+ sgmlOpenTag(ofs, depth + command_depth,
+ style.latexname());
break;
case LATEX_COMMAND:
- if (depth!= 0)
- LinuxDocError(par, 0,
+ if (depth != 0)
+ linuxDocError(par, 0,
_("Error : Wrong depth for "
"LatexType Command.\n"));
command_name = style.latexname();
- tmps = style.latexparam();
- c_params = split(tmps, c_depth,'|');
+ sgmlparam = style.latexparam();
+ c_params = split(sgmlparam, c_depth,'|');
- cmd_depth= lyx::atoi(c_depth);
+ cmd_depth = lyx::atoi(c_depth);
if (command_flag) {
- if (cmd_depth= command_base; --j)
- if (!command_stack[j].empty())
- sgmlCloseTag(ofs, j, command_stack[j]);
- command_depth= command_base= cmd_depth;
+ if (cmd_depth < command_base) {
+ for (Paragraph::depth_type j = command_depth; j >= command_base; --j)
+ sgmlCloseTag(ofs, j, command_stack[j]);
+ command_depth = command_base = cmd_depth;
} else if (cmd_depth <= command_depth) {
- for (int j = command_depth;
- j >= cmd_depth; --j)
-
- if (!command_stack[j].empty())
- sgmlCloseTag(ofs, j, command_stack[j]);
- command_depth= cmd_depth;
+ for (int j = command_depth; j >= int(cmd_depth); --j)
+ sgmlCloseTag(ofs, j, command_stack[j]);
+ command_depth = cmd_depth;
} else
- command_depth= cmd_depth;
+ command_depth = cmd_depth;
} else {
command_depth = command_base = cmd_depth;
command_flag = true;
}
- command_stack[command_depth]= command_name;
+ if (command_stack.size() == command_depth + 1)
+ command_stack.push_back(string());
+ command_stack[command_depth] = command_name;
// treat label as a special case for
// more WYSIWYM handling.
- if (par->GetChar(0) == LyXParagraph::META_INSET) {
- Inset * inset = par->GetInset(0);
- Inset::Code lyx_code = inset->LyxCode();
+ if (par->getChar(0) == Paragraph::META_INSET) {
+ Inset * inset = par->getInset(0);
+ Inset::Code lyx_code = inset->lyxCode();
if (lyx_code == Inset::LABEL_CODE){
command_name += " id=\"";
command_name += (static_cast(inset))->getContents();
@@ -3173,12 +3172,16 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
case LATEX_ENVIRONMENT:
case LATEX_ITEM_ENVIRONMENT:
- if (depth < par->params.depth()) {
- depth = par->params.depth();
+ if (depth < par->params().depth()) {
+ depth = par->params().depth();
environment_stack[depth].erase();
}
if (environment_stack[depth] != style.latexname()) {
+ if(environment_stack.size() == depth + 1) {
+ environment_stack.push_back("!-- --");
+ environment_inner.push_back("!-- --");
+ }
environment_stack[depth] = style.latexname();
environment_inner[depth] = "!-- --";
sgmlOpenTag(ofs, depth + command_depth,
@@ -3199,7 +3202,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
if (style.latextype == LATEX_ENVIRONMENT) {
if (!style.latexparam().empty()) {
if(style.latexparam() == "CDATA")
- ofs << "next_;
- DocBookHandleFootnote(ofs, par,
- depth + 1 + command_depth);
- } while(par && par->IsDummy());
-#else
string extra_par;
- SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
+ simpleDocBookOnePar(ofs, extra_par, par, desc_on,
depth + 1 + command_depth);
par = par->next();
-#endif
+
string end_tag;
// write closing SGML tags
switch (style.latextype) {
@@ -3282,10 +3275,10 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
// Close open tags
- for (; depth >= 0; --depth) {
+ for (int d = depth; d >= 0; --d) {
if (!environment_stack[depth].empty()) {
if (environment_inner[depth] != "!-- --") {
- item_name= "listitem";
+ item_name = "listitem";
sgmlCloseTag(ofs, command_depth + depth,
item_name);
if (environment_inner[depth] == "varlistentry")
@@ -3298,7 +3291,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
}
- for (int j = command_depth; j >= command_base; --j)
+ for (int j = command_depth; j >= 0 ; --j)
if (!command_stack[j].empty())
sgmlCloseTag(ofs, j, command_stack[j]);
@@ -3310,51 +3303,43 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
-void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
- LyXParagraph * par, int & desc_on,
- int depth) const
+void Buffer::simpleDocBookOnePar(ostream & os, string & extra,
+ Paragraph * par, int & desc_on,
+ Paragraph::depth_type depth) const
{
bool emph_flag = false;
LyXLayout const & style = textclasslist.Style(params.textclass,
- par->GetLayout());
+ par->getLayout());
- LyXParagraph::size_type main_body;
- if (style.labeltype != LABEL_MANUAL)
- main_body = 0;
- else
- main_body = par->BeginningOfMainBody();
+ LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
- // gets paragraph main font
- LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
-
int char_line_count = depth;
- if (!style.free_spacing)
- for (int j = 0; j < depth; ++j)
- os << ' ';
+ //if (!style.free_spacing)
+ // os << string(depth,' ');
// parsing main loop
- for (LyXParagraph::size_type i = 0;
+ for (Paragraph::size_type i = 0;
i < par->size(); ++i) {
- LyXFont font2 = par->getFont(params, i);
+ LyXFont font = par->getFont(params, i);
// handle tag
- if (font1.emph() != font2.emph() && i) {
- if (font2.emph() == LyXFont::ON) {
+ if (font_old.emph() != font.emph()) {
+ if (font.emph() == LyXFont::ON) {
os << "";
emph_flag = true;
- }else {
+ }else if(i) {
os << "";
emph_flag = false;
}
}
- char c = par->GetChar(i);
+ char c = par->getChar(i);
- if (c == LyXParagraph::META_INSET) {
- Inset * inset = par->GetInset(i);
- std::ostringstream ost;
- inset->DocBook(this, ost);
+ if (c == Paragraph::META_INSET) {
+ Inset * inset = par->getInset(i);
+ ostringstream ost;
+ inset->docBook(this, ost);
string tmp_out = ost.str().c_str();
//
@@ -3377,11 +3362,6 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
else
os << tmp_out;
}
- } else if (font2.latex() == LyXFont::ON) {
- // "TeX"-Mode on ==> SGML-Mode on.
- if (c != '\0')
- os << c;
- ++char_line_count;
} else {
string sgml_string;
if (par->linuxDocConvertChar(c, sgml_string)
@@ -3400,25 +3380,19 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
os << sgml_string;
}
}
- font1 = font2;
+ font_old = font;
}
- // needed if there is an optional argument but no contents
- if (main_body > 0 && main_body == par->size()) {
- font1 = style.font;
- }
if (emph_flag) {
os << "";
}
// resets description flag correctly
- switch (desc_on){
- case 1:
+ if (desc_on == 1) {
// not closed...
os << "";
- break;
}
- os << '\n';
+ if(style.free_spacing) os << '\n';
}
@@ -3429,19 +3403,19 @@ int Buffer::runChktex()
{
if (!users->text) return 0;
- ProhibitInput(users);
+ users->owner()->prohibitInput();
// get LaTeX-Filename
string const name = getLatexName();
string path = OnlyPath(filename);
string const org_path = path;
- if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
+ if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
path = tmppath;
}
Path p(path); // path to LaTeX file
- users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
+ users->owner()->message(_("Running chktex..."));
// Remove all error insets
bool const removedErrorInsets = users->removeAutoInsets();
@@ -3465,9 +3439,9 @@ int Buffer::runChktex()
// error insets after we ran chktex, this must be run:
if (removedErrorInsets || res){
users->redraw();
- users->fitCursor(users->text);
+ users->fitCursor();
}
- AllowInput(users);
+ users->owner()->allowInput();
return res;
}
@@ -3475,12 +3449,11 @@ int Buffer::runChktex()
void Buffer::validate(LaTeXFeatures & features) const
{
- LyXParagraph * par = paragraph;
+ Paragraph * par = paragraph;
LyXTextClass const & tclass =
textclasslist.TextClass(params.textclass);
// AMS Style is at document level
-
features.amsstyle = (params.use_amsmath ||
tclass.provides(LyXTextClass::amsmath));
@@ -3494,11 +3467,7 @@ void Buffer::validate(LaTeXFeatures & features) const
par->validate(features);
// and then the next paragraph
-#ifndef NEW_INSETS
- par = par->next_;
-#else
par = par->next();
-#endif
}
// the bullet shapes are buffer level not paragraph level
@@ -3564,7 +3533,7 @@ string const Buffer::getIncludeonlyList(char delim)
string lst;
for (inset_iterator it = inset_iterator_begin();
it != inset_iterator_end(); ++it) {
- if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
+ if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
InsetInclude * insetinc =
static_cast(*it);
if (insetinc->isIncludeOnly()) {
@@ -3574,7 +3543,7 @@ string const Buffer::getIncludeonlyList(char delim)
}
}
}
- lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
+ lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
return lst;
}
@@ -3603,101 +3572,62 @@ vector const Buffer::getLabelList()
Buffer::Lists const Buffer::getLists() const
{
Lists l;
- LyXParagraph * par = paragraph;
-#ifdef NEW_INSETS
+ Paragraph * par = paragraph;
bool found;
LyXTextClassList::size_type cap;
- tie(found, cap) = textclasslist.NumberOfLayout(params.textclass, "Caption");
-#endif
+ boost::tie(found, cap) = textclasslist
+ .NumberOfLayout(params.textclass, "Caption");
while (par) {
-#ifndef NEW_INSETS
- if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
- if (textclasslist.Style(params.textclass,
- par->GetLayout()).labeltype
- == LABEL_SENSITIVE) {
- string type;
- switch (par->footnotekind) {
- case LyXParagraph::FIG:
- case LyXParagraph::WIDE_FIG:
- type = "LOF";
- break;
- case LyXParagraph::TAB:
- case LyXParagraph::WIDE_TAB:
- type = "LOT";
- break;
- case LyXParagraph::ALGORITHM:
- type = "LOA";
- break;
- case LyXParagraph::FOOTNOTE:
- case LyXParagraph::MARGIN:
- break;
- }
- if (!type.empty()) {
- SingleList & item = l[type];
- string const str =
- tostr(item.size()+1) + ". " + par->String(this, false);
- item.push_back(TocItem(par, 0, str));
- }
- }
- } else if (!par->IsDummy()) {
-#endif
- char const labeltype =
- textclasslist.Style(params.textclass,
- par->GetLayout()).labeltype;
-
- if (labeltype >= LABEL_COUNTER_CHAPTER
- && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
+ char const labeltype =
+ textclasslist.Style(params.textclass,
+ par->getLayout()).labeltype;
+
+ if (labeltype >= LABEL_COUNTER_CHAPTER
+ && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
// insert this into the table of contents
- SingleList & item = l["TOC"];
- int depth = max(0,
- labeltype -
- textclasslist.TextClass(params.textclass).maxcounter());
- item.push_back(TocItem(par, depth, par->String(this, true)));
- }
-#ifdef NEW_INSETS
- // For each paragrph, traverse its insets and look for
- // FLOAT_CODE
+ SingleList & item = l["TOC"];
+ int depth = max(0,
+ labeltype -
+ textclasslist.TextClass(params.textclass).maxcounter());
+ item.push_back(TocItem(par, depth, par->asString(this, true)));
+ }
+ // For each paragrph, traverse its insets and look for
+ // FLOAT_CODE
+
+ if (found) {
+ Paragraph::inset_iterator it =
+ par->inset_iterator_begin();
+ Paragraph::inset_iterator end =
+ par->inset_iterator_end();
- if (found) {
- LyXParagraph::inset_iterator it =
- par->inset_iterator_begin();
- LyXParagraph::inset_iterator end =
- par->inset_iterator_end();
-
- for (; it != end; ++it) {
- if ((*it)->LyxCode() == Inset::FLOAT_CODE) {
- InsetFloat * il =
- static_cast(*it);
-
- string const type = il->type();
-
- // Now find the caption in the float...
- // We now tranverse the paragraphs of
- // the inset...
- LyXParagraph * tmp = il->inset->par;
- while (tmp) {
- if (tmp->layout == cap) {
- SingleList & item = l[type];
- string const str =
- tostr(item.size()+1) + ". " + tmp->String(this, false);
- item.push_back(TocItem(tmp, 0 , str));
- }
- tmp = tmp->next();
+ for (; it != end; ++it) {
+ if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
+ InsetFloat * il =
+ static_cast(*it);
+
+ string const type = il->type();
+
+ // Now find the caption in the float...
+ // We now tranverse the paragraphs of
+ // the inset...
+ Paragraph * tmp = il->inset.paragraph();
+ while (tmp) {
+ if (tmp->layout == cap) {
+ SingleList & item = l[type];
+ string const str =
+ tostr(item.size()+1) + ". " + tmp->asString(this, false);
+ item.push_back(TocItem(tmp, 0 , str));
}
+ tmp = tmp->next();
}
}
- } else {
- lyxerr << "caption not found" << endl;
}
-
-#endif
-#ifndef NEW_INSETS
+ } else {
+ lyxerr << "caption not found" << endl;
}
- par = par->next_;
-#else
+
par = par->next();
-#endif
}
return l;
}
@@ -3715,16 +3645,12 @@ vector > const Buffer::getBibkeyList()
}
vector > keys;
- LyXParagraph * par = paragraph;
+ Paragraph * par = paragraph;
while (par) {
if (par->bibkey)
keys.push_back(pair(par->bibkey->getContents(),
- par->String(this, false)));
-#ifndef NEW_INSETS
- par = par->next_;
-#else
+ par->asString(this, false)));
par = par->next();
-#endif
}
// Might be either using bibtex or a child has bibliography
@@ -3732,11 +3658,11 @@ vector > const Buffer::getBibkeyList()
for (inset_iterator it = inset_iterator_begin();
it != inset_iterator_end(); ++it) {
// Search for Bibtex or Include inset
- if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
+ if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
vector > tmp =
static_cast(*it)->getKeys(this);
keys.insert(keys.end(), tmp.begin(), tmp.end());
- } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
+ } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
vector > const tmp =
static_cast(*it)->getKeys();
keys.insert(keys.end(), tmp.begin(), tmp.end());
@@ -3781,18 +3707,18 @@ void Buffer::markDepClean(string const & name)
}
-bool Buffer::Dispatch(string const & command)
+bool Buffer::dispatch(string const & command)
{
// Split command string into command and argument
string cmd;
string line = frontStrip(command);
string const arg = strip(frontStrip(split(line, cmd, ' ')));
- return Dispatch(lyxaction.LookupFunc(cmd), arg);
+ return dispatch(lyxaction.LookupFunc(cmd), arg);
}
-bool Buffer::Dispatch(int action, string const & argument)
+bool Buffer::dispatch(int action, string const & argument)
{
bool dispatched = true;
switch (action) {
@@ -3807,89 +3733,99 @@ bool Buffer::Dispatch(int action, string const & argument)
}
-void Buffer::resize()
-{
- /// resize the BufferViews!
- if (users)
- users->resize();
-}
-
-
void Buffer::resizeInsets(BufferView * bv)
{
/// then remove all LyXText in text-insets
- LyXParagraph * par = paragraph;
-#ifndef NEW_INSETS
- for (; par; par = par->next_) {
- par->resizeInsetsLyXText(bv);
- }
-#else
+ Paragraph * par = paragraph;
for (; par; par = par->next()) {
par->resizeInsetsLyXText(bv);
}
-#endif
}
-void Buffer::ChangeLanguage(Language const * from, Language const * to)
+void Buffer::redraw()
{
+ users->redraw();
+ users->fitCursor();
+}
- LyXParagraph * par = paragraph;
+
+void Buffer::changeLanguage(Language const * from, Language const * to)
+{
+
+ Paragraph * par = paragraph;
while (par) {
- par->ChangeLanguage(params, from, to);
-#ifndef NEW_INSETS
- par = par->next_;
-#else
+ par->changeLanguage(params, from, to);
par = par->next();
-#endif
}
}
bool Buffer::isMultiLingual()
{
- LyXParagraph * par = paragraph;
+ Paragraph * par = paragraph;
while (par) {
if (par->isMultiLingual(params))
return true;
-#ifndef NEW_INSETS
- par = par->next_;
-#else
par = par->next();
-#endif
}
return false;
}
-Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
- LyXParagraph::size_type pos)
+Buffer::inset_iterator::inset_iterator(Paragraph * paragraph,
+ Paragraph::size_type pos)
: par(paragraph)
{
it = par->InsetIterator(pos);
if (it == par->inset_iterator_end()) {
-#ifndef NEW_INSETS
- par = par->next_;
-#else
par = par->next();
-#endif
- SetParagraph();
+ setParagraph();
}
}
-void Buffer::inset_iterator::SetParagraph()
+void Buffer::inset_iterator::setParagraph()
{
while (par) {
it = par->inset_iterator_begin();
if (it != par->inset_iterator_end())
return;
-#ifndef NEW_INSETS
- par = par->next_;
-#else
par = par->next();
-#endif
}
//it = 0;
// We maintain an invariant that whenever par = 0 then it = 0
}
+
+
+Inset * Buffer::getInsetFromID(int id_arg) const
+{
+ for (inset_iterator it = inset_const_iterator_begin();
+ it != inset_const_iterator_end(); ++it)
+ {
+ if ((*it)->id() == id_arg)
+ return *it;
+ Inset * in = (*it)->getInsetFromID(id_arg);
+ if (in)
+ return in;
+ }
+ return 0;
+}
+
+
+Paragraph * Buffer::getParFromID(int id) const
+{
+ if (id < 0) return 0;
+ Paragraph * par = paragraph;
+ while (par) {
+ if (par->id() == id) {
+ return par;
+ }
+ Paragraph * tmp = par->getParFromID(id);
+ if (tmp) {
+ return tmp;
+ }
+ par = par->next();
+ }
+ return 0;
+}