X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fbuffer.C;h=331c336463b27a1f5c9c5f04851d2deaad42d4b3;hb=dbd7a961fc46bb10c85bdd8c7fb6626477ae63d8;hp=3701b7768301e033e35fd04db72f5353d9aee5df;hpb=bf6257967e48709d375d5b8aa1cdd66c7f7bc25a;p=lyx.git
diff --git a/src/buffer.C b/src/buffer.C
index 3701b77683..331c336463 100644
--- a/src/buffer.C
+++ b/src/buffer.C
@@ -14,24 +14,6 @@
#include
-#include
-#include
-#include
";
@@ -2721,35 +2781,11 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
}
-void Buffer::docBookHandleCaption(ostream & os, string & inner_tag,
- Paragraph::depth_type depth, int desc_on,
- Paragraph * & par)
-{
- Paragraph * tpar = par;
- while (tpar
- && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
- "Caption").second))
- tpar = tpar->next();
-
- if (tpar &&
- tpar->layout == textclasslist.NumberOfLayout(params.textclass,
- "Caption").second) {
- sgmlOpenTag(os, depth + 1, inner_tag);
- string extra_par;
- simpleDocBookOnePar(os, extra_par, tpar,
- desc_on, depth + 2);
- sgmlCloseTag(os, depth+1, inner_tag);
- if (!extra_par.empty())
- os << extra_par;
- }
-}
-
-
// checks, if newcol chars should be put into this line
// 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;
@@ -2794,22 +2830,20 @@ void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
inline
void reset(PAR_TAG & p1, PAR_TAG const & p2)
{
- p1 = static_cast( p1 & ~p2);
+ p1 = static_cast(p1 & ~p2);
}
} // namespace anon
-
-
// Handle internal paragraph parsing -- layout already processed.
void Buffer::simpleLinuxDocOnePar(ostream & os,
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;
@@ -2827,9 +2861,9 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
bool is_em = false;
- stack < PAR_TAG > tag_state;
+ 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;
@@ -2921,7 +2955,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) << ">";
@@ -2952,29 +2986,26 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
continue;
}
- if (
-#ifndef NO_LATEX
- font.latex() == LyXFont::ON ||
-#endif
- style.latexparam() == "CDATA") {
+ if (style.latexparam() == "CDATA") {
// "TeX"-Mode on == > SGML-Mode on.
if (c != '\0')
os << c;
++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 {
@@ -2993,19 +3024,20 @@ 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
{
// 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));
}
@@ -3013,7 +3045,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;
}
@@ -3022,26 +3054,27 @@ 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);
+ textclasslist[params.textclass];
- LaTeXFeatures features(params, tclass.numLayouts());
+ LaTeXFeatures features(params, tclass.size());
validate(features);
texrow.reset();
- string top_element = textclasslist.LatexnameOfClass(params.textclass);
+ string top_element = textclasslist[params.textclass].latexname();
if (!only_body) {
- string sgml_includedfiles = features.getIncludedFiles(fname);
+ ofs << "\n\n";
- else
- ofs << "\n [ " << params.preamble
- << sgml_includedfiles << " \n]>\n\n";
+ if (!preamble.empty()) {
+ ofs << "\n [ " << preamble << " ]";
+ }
+ ofs << ">\n\n";
}
string top = top_element;
@@ -3055,7 +3088,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
sgmlOpenTag(ofs, 0, top);
- ofs << "\n";
vector environment_stack(10);
@@ -3078,8 +3111,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
int desc_on = 0; // description mode
LyXLayout const & style =
- textclasslist.Style(params.textclass,
- par->layout);
+ textclasslist[params.textclass][par->layout()];
// environment tag closing
for (; depth > par->params().depth(); --depth) {
@@ -3126,9 +3158,9 @@ 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();
@@ -3158,10 +3190,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) {
+ // 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 += "\"";
@@ -3185,7 +3219,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("!-- --");
}
@@ -3208,7 +3242,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")
+ if (style.latexparam() == "CDATA")
ofs << "next();
string end_tag;
@@ -3260,7 +3292,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,
@@ -3310,14 +3342,14 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
-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;
@@ -3326,8 +3358,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
@@ -3335,63 +3366,38 @@ 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) {
+ if (par->isInset(i)) {
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;
+ // 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 << " SGML-Mode on.
- if (c != '\0')
- os << c;
- ++char_line_count;
-#endif
} else {
+ char c = par->getChar(i);
string sgml_string;
- if (par->linuxDocConvertChar(c, sgml_string)
- && !style.free_spacing) { // in freespacing
- // mode, spaces are
- // non-breaking characters
- // char is ' '
- if (desc_on == 1) {
- ++char_line_count;
- os << "\n";
- desc_on = 2;
- } else {
- os << c;
- }
+ par->sgmlConvertChar(c, sgml_string);
+
+ if (style.pass_thru) {
+ os << c;
+ } else if (style.free_spacing || par->isFreeSpacing() || c != ' ') {
+ os << sgml_string;
+ } else if (desc_on ==1) {
+ ++char_line_count;
+ os << "\n";
+ desc_on = 2;
} else {
- os << sgml_string;
+ os << ' ';
}
}
font_old = font;
@@ -3406,7 +3412,7 @@ void Buffer::simpleDocBookOnePar(ostream & os, string & extra,
// not closed...
os << "";
}
- if(style.free_spacing) os << '\n';
+ if (style.free_spacing) os << '\n';
}
@@ -3421,10 +3427,10 @@ 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) < 1)) {
+ if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
path = tmppath;
}
@@ -3438,11 +3444,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
@@ -3451,9 +3457,9 @@ 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(users->text);
+ users->fitCursor();
}
users->owner()->allowInput();
@@ -3464,12 +3470,11 @@ int Buffer::runChktex()
void Buffer::validate(LaTeXFeatures & features) const
{
Paragraph * par = paragraph;
- LyXTextClass const & tclass =
- textclasslist.TextClass(params.textclass);
+ LyXTextClass const & tclass = textclasslist[params.textclass];
// AMS Style is at document level
- features.amsstyle = (params.use_amsmath ||
- tclass.provides(LyXTextClass::amsmath));
+ if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
+ features.require("amsmath");
while (par) {
// We don't use "lyxerr.debug" because of speed. (Asger)
@@ -3498,12 +3503,12 @@ 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");
}
}
}
@@ -3514,33 +3519,6 @@ void Buffer::validate(LaTeXFeatures & features) const
}
-void Buffer::setPaperStuff()
-{
- params.papersize = BufferParams::PAPER_DEFAULT;
- char const c1 = params.paperpackage;
- if (c1 == BufferParams::PACKAGE_NONE) {
- char const c2 = params.papersize2;
- if (c2 == BufferParams::VM_PAPER_USLETTER)
- params.papersize = BufferParams::PAPER_USLETTER;
- else if (c2 == BufferParams::VM_PAPER_USLEGAL)
- params.papersize = BufferParams::PAPER_LEGALPAPER;
- else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
- params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
- else if (c2 == BufferParams::VM_PAPER_A3)
- params.papersize = BufferParams::PAPER_A3PAPER;
- else if (c2 == BufferParams::VM_PAPER_A4)
- params.papersize = BufferParams::PAPER_A4PAPER;
- else if (c2 == BufferParams::VM_PAPER_A5)
- params.papersize = BufferParams::PAPER_A5PAPER;
- else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
- (c2 == BufferParams::VM_PAPER_B5))
- params.papersize = BufferParams::PAPER_B5PAPER;
- } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
- (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
- params.papersize = BufferParams::PAPER_A4PAPER;
-}
-
-
// This function should be in Buffer because it's a buffer's property (ale)
string const Buffer::getIncludeonlyList(char delim)
{
@@ -3587,15 +3565,13 @@ Buffer::Lists const Buffer::getLists() const
{
Lists l;
Paragraph * par = paragraph;
- bool found;
- LyXTextClassList::size_type cap;
- boost::tie(found, cap) = textclasslist
- .NumberOfLayout(params.textclass, "Caption");
+
+ 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) {
@@ -3603,7 +3579,7 @@ Buffer::Lists const Buffer::getLists() const
SingleList & item = l["TOC"];
int depth = max(0,
labeltype -
- textclasslist.TextClass(params.textclass).maxcounter());
+ textclass.maxcounter());
item.push_back(TocItem(par, depth, par->asString(this, true)));
}
// For each paragrph, traverse its insets and look for
@@ -3627,7 +3603,7 @@ Buffer::Lists const Buffer::getLists() const
// 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);
@@ -3760,35 +3736,31 @@ void Buffer::resizeInsets(BufferView * bv)
void Buffer::redraw()
{
users->redraw();
- users->fitCursor(users->text);
+ users->fitCursor();
}
void Buffer::changeLanguage(Language const * from, Language const * to)
{
- Paragraph * par = paragraph;
- while (par) {
- par->changeLanguage(params, from, to);
- par = par->next();
- }
+ ParIterator end = par_iterator_end();
+ for (ParIterator it = par_iterator_begin(); it != end; ++it)
+ (*it)->changeLanguage(params, from, to);
}
bool Buffer::isMultiLingual()
{
- Paragraph * par = paragraph;
- while (par) {
- if (par->isMultiLingual(params))
+ ParIterator end = par_iterator_end();
+ for (ParIterator it = par_iterator_begin(); it != end; ++it)
+ if ((*it)->isMultiLingual(params))
return true;
- par = par->next();
- }
+
return false;
}
-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);
@@ -3843,3 +3815,15 @@ Paragraph * Buffer::getParFromID(int id) const
}
return 0;
}
+
+
+ParIterator Buffer::par_iterator_begin()
+{
+ return ParIterator(paragraph);
+}
+
+
+ParIterator Buffer::par_iterator_end()
+{
+ return ParIterator();
+}