X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fbuffer.C;h=67ddc7672e3990fc07672b5c4c44491a1a8254db;hb=98c966c64594611e469313314abd1e59524adb4a;hp=edefcb7cdd168348e9ce7785b71377d703278696;hpb=f38f4b1deef51e27c07fb859a1b4f2737455ac7e;p=lyx.git
diff --git a/src/buffer.C b/src/buffer.C
index edefcb7cdd..67ddc7672e 100644
--- a/src/buffer.C
+++ b/src/buffer.C
@@ -1,6 +1,6 @@
/* This file is part of
- * ======================================================
- *
+ * ======================================================
+ *
* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
@@ -9,29 +9,11 @@
* This file is Copyright 1996-2001
* Lars Gullik Bjønnes
*
- * ======================================================
+ * ======================================================
*/
#include
-#include
-#include
-#include
";
+ ofs << "";
}
sgmlOpenTag(ofs, depth, style.latexname());
break;
case LATEX_COMMAND:
if (depth!= 0)
- linuxDocError(par, 0,
- _("Error : Wrong depth for"
- " LatexType Command.\n"));
+ sgmlError(par, 0,
+ _("Error : Wrong depth for"
+ " LatexType Command.\n"));
- if (!environment_stack[depth].empty()){
+ if (!environment_stack[depth].empty()) {
sgmlCloseTag(ofs, depth,
environment_stack[depth]);
ofs << "";
@@ -2632,7 +2753,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
case LATEX_ENVIRONMENT:
case LATEX_ITEM_ENVIRONMENT:
- if (depth == par->params().depth()
+ if (depth == par->params().depth()
&& environment_stack[depth] != style.latexname()) {
sgmlCloseTag(ofs, depth,
environment_stack[depth]);
@@ -2689,10 +2810,10 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
break;
}
}
-
+
// Close open tags
for (int i=depth; i >= 0; --i)
- sgmlCloseTag(ofs, depth, environment_stack[i]);
+ sgmlCloseTag(ofs, depth, environment_stack[i]);
if (!body_only) {
ofs << "\n\n";
@@ -2701,6 +2822,9 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
ofs.close();
// How to check for successful close
+
+ // we want this to be true outside previews (for insetexternal)
+ niceFile = true;
}
@@ -2708,7 +2832,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
// writes newline, if necessary.
namespace {
-void linux_doc_line_break(ostream & os, string::size_type & colcount,
+void sgmlLineBreak(ostream & os, string::size_type & colcount,
string::size_type newcol)
{
colcount += newcol;
@@ -2746,27 +2870,27 @@ string tag_name(PAR_TAG const & pt) {
inline
void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
{
- p1 = static_cast(p1 | p2);
+ p1 = static_cast(p1 | p2);
}
inline
void reset(PAR_TAG & p1, PAR_TAG const & p2)
{
- p1 = static_cast( p1 & ~p2);
+ p1 = static_cast(p1 & ~p2);
}
-} // namespace anon
+} // anon
// Handle internal paragraph parsing -- layout already processed.
void Buffer::simpleLinuxDocOnePar(ostream & os,
- Paragraph * par,
- Paragraph::depth_type /*depth*/)
+ Paragraph * par,
+ Paragraph::depth_type /*depth*/)
{
- LyXLayout const & style = textclasslist.Style(params.textclass,
- par->getLayout());
- string::size_type char_line_count = 5; // Heuristic choice ;-)
+ LyXLayout const & style =
+ textclasslist[params.textclass][par->layout()];
+ string::size_type char_line_count = 5; // Heuristic choice ;-)
// gets paragraph main font
LyXFont font_old;
@@ -2786,7 +2910,7 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
stack tag_state;
// parsing main loop
- for (Paragraph::size_type i = 0; i < par->size(); ++i) {
+ for (pos_type i = 0; i < par->size(); ++i) {
PAR_TAG tag_close = NONE;
list < PAR_TAG > tag_open;
@@ -2878,7 +3002,7 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
}
list < PAR_TAG > temp;
- while(!tag_state.empty() && tag_close ) {
+ while (!tag_state.empty() && tag_close) {
PAR_TAG k = tag_state.top();
tag_state.pop();
os << "" << tag_name(k) << ">";
@@ -2916,18 +3040,19 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
++char_line_count;
} else {
string sgml_string;
- if (par->linuxDocConvertChar(c, sgml_string)
- && !style.free_spacing) {
+ if (par->sgmlConvertChar(c, sgml_string)
+ && !style.free_spacing && !par->isFreeSpacing())
+ {
// in freespacing mode, spaces are
// non-breaking characters
if (desc_on) {// if char is ' ' then...
++char_line_count;
- linux_doc_line_break(os, char_line_count, 6);
+ sgmlLineBreak(os, char_line_count, 6);
os << "";
desc_on = false;
} else {
- linux_doc_line_break(os, char_line_count, 1);
+ sgmlLineBreak(os, char_line_count, 1);
os << c;
}
} else {
@@ -2946,19 +3071,28 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
// resets description flag correctly
if (desc_on) {
// not closed...
- linux_doc_line_break(os, char_line_count, 6);
+ sgmlLineBreak(os, char_line_count, 6);
os << "";
}
}
// Print an error message.
-void Buffer::linuxDocError(Paragraph * par, int pos,
- string const & message)
+void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
+ string const & /*message*/) const
{
+#warning This is wrong we cannot insert an inset like this!!!
+ // I guess this was Jose' so I explain you more or less why this
+ // is wrong. This way you insert something in the paragraph and
+ // don't tell it to LyXText (row rebreaking and undo handling!!!)
+ // I deactivate this code, have a look at BufferView::insertErrors
+ // how you should do this correctly! (Jug 20020315)
+#if 0
// insert an error marker in text
InsetError * new_inset = new InsetError(message);
- par->insertInset(pos, new_inset);
+ par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
+ params.language));
+#endif
}
@@ -2966,7 +3100,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
{
ofstream ofs(fname.c_str());
if (!ofs) {
- WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
+ Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
return;
}
@@ -2974,22 +3108,22 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
niceFile = nice; // this will be used by Insetincludes.
- LyXTextClass const & tclass =
- textclasslist.TextClass(params.textclass);
-
- LaTeXFeatures features(params, tclass.numLayouts());
+ LaTeXFeatures features(params);
validate(features);
-
+
texrow.reset();
- string top_element = textclasslist.LatexnameOfClass(params.textclass);
+ LyXTextClass const & tclass = textclasslist[params.textclass];
+ string top_element = tclass.latexname();
if (!only_body) {
ofs << "\n\n";
}
- string top = top_element;
+ string top = top_element;
top += " lang=\"";
top += params.language->code();
top += "\"";
@@ -3022,7 +3156,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
Paragraph::depth_type cmd_depth = 0;
Paragraph::depth_type depth = 0; // paragraph depth
- string item_name;
+ string item_name;
string command_name;
while (par) {
@@ -3031,9 +3165,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
string c_params;
int desc_on = 0; // description mode
- LyXLayout const & style =
- textclasslist.Style(params.textclass,
- par->layout);
+ LyXLayout const & style = tclass[par->layout()];
// environment tag closing
for (; depth > par->params().depth(); --depth) {
@@ -3063,13 +3195,13 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
depth + command_depth,
environment_inner[depth]);
}
-
+
sgmlCloseTag(ofs, depth + command_depth,
environment_stack[depth]);
-
+
environment_stack[depth].erase();
environment_inner[depth].erase();
- }
+ }
// Write opening SGML tags.
switch (style.latextype) {
@@ -3080,17 +3212,17 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
case LATEX_COMMAND:
if (depth != 0)
- linuxDocError(par, 0,
- _("Error : Wrong depth for "
- "LatexType Command.\n"));
-
+ sgmlError(par, 0,
+ _("Error : Wrong depth for "
+ "LatexType Command.\n"));
+
command_name = style.latexname();
-
+
sgmlparam = style.latexparam();
c_params = split(sgmlparam, c_depth,'|');
-
+
cmd_depth = lyx::atoi(c_depth);
-
+
if (command_flag) {
if (cmd_depth < command_base) {
for (Paragraph::depth_type j = command_depth; j >= command_base; --j)
@@ -3112,10 +3244,12 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
// treat label as a special case for
// more WYSIWYM handling.
- if (par->getChar(0) == Paragraph::META_INSET) {
- Inset * inset = par->getInset(0);
+ // This is a hack while paragraphs can't have
+ // attributes, like id in this case.
+ if (par->isInset(0)) {
+ Inset * inset = par->getInset(0);
Inset::Code lyx_code = inset->lyxCode();
- if (lyx_code == Inset::LABEL_CODE){
+ if (lyx_code == Inset::LABEL_CODE) {
command_name += " id=\"";
command_name += (static_cast(inset))->getContents();
command_name += "\"";
@@ -3139,7 +3273,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
if (environment_stack[depth] != style.latexname()) {
- if(environment_stack.size() == depth + 1) {
+ if (environment_stack.size() == depth + 1) {
environment_stack.push_back("!-- --");
environment_inner.push_back("!-- --");
}
@@ -3159,10 +3293,10 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
environment_inner[depth]);
}
}
-
+
if (style.latextype == LATEX_ENVIRONMENT) {
if (!style.latexparam().empty()) {
- if(style.latexparam() == "CDATA")
+ if (style.latexparam() == "CDATA")
ofs << "next();
string end_tag;
@@ -3214,7 +3346,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
break;
case LATEX_ENVIRONMENT:
if (!style.latexparam().empty()) {
- if(style.latexparam() == "CDATA")
+ if (style.latexparam() == "CDATA")
ofs << "]]>";
else
sgmlCloseTag(ofs, depth + command_depth,
@@ -3242,16 +3374,16 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
item_name = "listitem";
sgmlCloseTag(ofs, command_depth + depth,
item_name);
- if (environment_inner[depth] == "varlistentry")
+ if (environment_inner[depth] == "varlistentry")
sgmlCloseTag(ofs, depth + command_depth,
environment_inner[depth]);
}
-
+
sgmlCloseTag(ofs, depth + command_depth,
environment_stack[depth]);
}
}
-
+
for (int j = command_depth; j >= 0 ; --j)
if (!command_stack[j].empty())
sgmlCloseTag(ofs, j, command_stack[j]);
@@ -3261,17 +3393,20 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
ofs.close();
// How to check for successful close
+
+ // we want this to be true outside previews (for insetexternal)
+ niceFile = true;
}
-void Buffer::simpleDocBookOnePar(ostream & os, string & extra,
+void Buffer::simpleDocBookOnePar(ostream & os,
Paragraph * par, int & desc_on,
Paragraph::depth_type depth) const
{
bool emph_flag = false;
- LyXLayout const & style = textclasslist.Style(params.textclass,
- par->getLayout());
+ LyXLayout const & style =
+ textclasslist[params.textclass][par->layout()];
LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
@@ -3280,8 +3415,7 @@ void Buffer::simpleDocBookOnePar(ostream & os, string & extra,
// os << string(depth,' ');
// parsing main loop
- for (Paragraph::size_type i = 0;
- i < par->size(); ++i) {
+ for (pos_type i = 0; i < par->size(); ++i) {
LyXFont font = par->getFont(params, i);
// handle tag
@@ -3289,47 +3423,31 @@ void Buffer::simpleDocBookOnePar(ostream & os, string & extra,
if (font.emph() == LyXFont::ON) {
os << "";
emph_flag = true;
- }else if(i) {
+ } else if (i) {
os << "";
emph_flag = false;
}
}
-
- char c = par->getChar(i);
- if (c == Paragraph::META_INSET) {
- Inset * inset = par->getInset(i);
- ostringstream ost;
- inset->docbook(this, ost);
- string tmp_out = ost.str().c_str();
- //
- // This code needs some explanation:
- // Two insets are treated specially
- // label if it is the first element in a command paragraph
- // desc_on == 3
- // graphics inside tables or figure floats can't go on
- // title (the equivalente in latex for this case is caption
- // and title should come first
- // desc_on == 4
- //
- if (desc_on!= 3 || i!= 0) {
- if (!tmp_out.empty() && tmp_out[0] == '@') {
- if (desc_on == 4)
- extra += frontStrip(tmp_out, '@');
- else
- os << frontStrip(tmp_out, '@');
- }
- else
- os << tmp_out;
+ if (par->isInset(i)) {
+ Inset * inset = par->getInset(i);
+ // don't print the inset in position 0 if desc_on == 3 (label)
+ if ( i || desc_on != 3) {
+ if(style.latexparam() == "CDATA")
+ os << "]]>";
+ inset->docbook(this, os);
+ if(style.latexparam() == "CDATA")
+ os << "getChar(i);
string sgml_string;
- par->linuxDocConvertChar(c, sgml_string);
+ par->sgmlConvertChar(c, sgml_string);
if (style.pass_thru) {
os << c;
- } else if(style.free_spacing || c != ' ') {
+ } else if (style.free_spacing || par->isFreeSpacing() || c != ' ') {
os << sgml_string;
} else if (desc_on ==1) {
++char_line_count;
@@ -3345,13 +3463,13 @@ void Buffer::simpleDocBookOnePar(ostream & os, string & extra,
if (emph_flag) {
os << "";
}
-
+
// resets description flag correctly
if (desc_on == 1) {
// not closed...
- os << "";
+ os << "\n ";
}
- if(style.free_spacing) os << '\n';
+ if (style.free_spacing) os << '\n';
}
@@ -3366,11 +3484,11 @@ int Buffer::runChktex()
// get LaTeX-Filename
string const name = getLatexName();
- string path = OnlyPath(filename);
+ string path = filePath();
string const org_path = path;
if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
- path = tmppath;
+ path = tmppath;
}
Path p(path); // path to LaTeX file
@@ -3383,11 +3501,11 @@ int Buffer::runChktex()
makeLaTeXFile(name, org_path, false);
TeXErrors terr;
- Chktex chktex(lyxrc.chktex_command, name, filepath);
+ Chktex chktex(lyxrc.chktex_command, name, filePath());
int res = chktex.run(terr); // run chktex
if (res == -1) {
- WriteAlert(_("chktex did not work!"),
+ Alert::alert(_("chktex did not work!"),
_("Could not run with file:"), name);
} else if (res > 0) {
// Insert all errors as errors boxes
@@ -3396,7 +3514,7 @@ int Buffer::runChktex()
// if we removed error insets before we ran chktex or if we inserted
// error insets after we ran chktex, this must be run:
- if (removedErrorInsets || res){
+ if (removedErrorInsets || res) {
users->redraw();
users->fitCursor();
}
@@ -3409,13 +3527,12 @@ int Buffer::runChktex()
void Buffer::validate(LaTeXFeatures & features) const
{
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));
-
+ LyXTextClass const & tclass = textclasslist[params.textclass];
+
+ // AMS Style is at document level
+ if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
+ features.require("amsmath");
+
while (par) {
// We don't use "lyxerr.debug" because of speed. (Asger)
if (lyxerr.debugging(Debug::LATEX))
@@ -3443,16 +3560,16 @@ void Buffer::validate(LaTeXFeatures & features) const
|| c == 25
|| c == 26
|| c == 31) {
- features.latexsym = true;
+ features.require("latexsym");
}
} else if (font == 1) {
- features.amssymb = true;
+ features.require("amssymb");
} else if ((font >= 2 && font <= 5)) {
- features.pifont = true;
+ features.require("pifont");
}
}
}
-
+
if (lyxerr.debugging(Debug::LATEX)) {
features.showStruct();
}
@@ -3466,7 +3583,7 @@ string const Buffer::getIncludeonlyList(char delim)
for (inset_iterator it = inset_iterator_begin();
it != inset_iterator_end(); ++it) {
if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
- InsetInclude * insetinc =
+ InsetInclude * insetinc =
static_cast(*it);
if (insetinc->isIncludeOnly()) {
if (!lst.empty())
@@ -3506,57 +3623,44 @@ Buffer::Lists const Buffer::getLists() const
Lists l;
Paragraph * par = paragraph;
-#if 1
- std::pair const tmp =
- textclasslist.NumberOfLayout(params.textclass, "Caption");
- bool const found = tmp.first;
- LyXTextClassList::size_type const cap = tmp.second;
-
-#else
- // This is the prefered way to to this, but boost::tie can break
- // some compilers
- bool found;
- LyXTextClassList::size_type cap;
- boost::tie(found, cap) = textclasslist
- .NumberOfLayout(params.textclass, "Caption");
-#endif
+ LyXTextClass const & textclass = textclasslist[params.textclass];
+ bool found = textclass.hasLayout("Caption");
+ string const layout("Caption");
while (par) {
- char const labeltype =
- textclasslist.Style(params.textclass,
- par->getLayout()).labeltype;
-
+ char const labeltype = textclass[par->layout()].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());
+ labeltype -
+ 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();
-
+
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) {
+ if (tmp->layout() == layout) {
SingleList & item = l[type];
string const str =
tostr(item.size()+1) + ". " + tmp->asString(this, false);
@@ -3567,9 +3671,9 @@ Buffer::Lists const Buffer::getLists() const
}
}
} else {
- lyxerr << "caption not found" << endl;
+ lyxerr << "Caption not found" << endl;
}
-
+
par = par->next();
}
return l;
@@ -3581,7 +3685,7 @@ vector > const Buffer::getBibkeyList()
{
/// if this is a child document and the parent is already loaded
/// Use the parent's list instead [ale990412]
- if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
+ if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
Buffer * tmp = bufferlist.getBuffer(params.parentname);
if (tmp)
return tmp->getBibkeyList();
@@ -3612,7 +3716,7 @@ vector > const Buffer::getBibkeyList()
}
}
}
-
+
return keys;
}
@@ -3665,7 +3769,7 @@ bool Buffer::dispatch(int action, string const & argument)
{
bool dispatched = true;
switch (action) {
- case LFUN_EXPORT:
+ case LFUN_EXPORT:
Exporter::Export(this, argument, false);
break;
@@ -3688,8 +3792,8 @@ void Buffer::resizeInsets(BufferView * bv)
void Buffer::redraw()
{
- users->redraw();
- users->fitCursor();
+ users->redraw();
+ users->fitCursor();
}
@@ -3713,8 +3817,7 @@ bool Buffer::isMultiLingual()
}
-Buffer::inset_iterator::inset_iterator(Paragraph * paragraph,
- Paragraph::size_type pos)
+Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
: par(paragraph)
{
it = par->InsetIterator(pos);
@@ -3773,11 +3876,11 @@ Paragraph * Buffer::getParFromID(int id) const
ParIterator Buffer::par_iterator_begin()
{
- return ParIterator(paragraph);
+ return ParIterator(paragraph);
}
ParIterator Buffer::par_iterator_end()
{
- return ParIterator();
+ return ParIterator();
}