1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * This file is Copyright 1996-2001
12 * ======================================================
18 #include "bufferlist.h"
19 #include "LyXAction.h"
22 #include "tex-strings.h"
24 #include "bufferview_funcs.h"
30 #include "LaTeXFeatures.h"
37 #include "BufferView.h"
38 #include "ParagraphParameters.h"
39 #include "iterators.h"
40 #include "lyxtextclasslist.h"
42 #include "paragraph_funcs.h"
45 #include "frontends/LyXView.h"
47 #include "mathed/formulamacro.h"
48 #include "mathed/formula.h"
50 #include "insets/inseterror.h"
51 #include "insets/insetbibitem.h"
52 #include "insets/insetbibtex.h"
53 #include "insets/insetinclude.h"
54 #include "insets/insettext.h"
56 #include "frontends/Dialogs.h"
57 #include "frontends/Alert.h"
59 #include "graphics/Previews.h"
61 #include "support/textutils.h"
62 #include "support/filetools.h"
63 #include "support/path.h"
64 #include "support/os.h"
65 #include "support/lyxlib.h"
66 #include "support/FileInfo.h"
67 #include "support/lyxmanip.h"
68 #include "support/lyxtime.h"
70 #include <boost/bind.hpp>
71 #include <boost/tuple/tuple.hpp>
72 #include "BoostFormat.h"
84 #include <sys/types.h>
91 #ifndef CXX_GLOBAL_CSTD
103 using std::make_pair;
111 using lyx::textclass_type;
113 // all these externs should eventually be removed.
114 extern BufferList bufferlist;
118 const int LYX_FORMAT = 222;
122 Buffer::Buffer(string const & file, bool ronly)
123 : niceFile(true), lyx_clean(true), bak_clean(true),
124 unnamed(false), read_only(ronly),
125 filename_(file), users(0)
127 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
128 filepath_ = OnlyPath(file);
130 if (read_only || lyxrc.use_tempdir) {
131 tmppath = CreateBufferTmpDir();
136 // set initial author
137 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
143 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
144 // here the buffer should take care that it is
145 // saved properly, before it goes into the void.
147 // make sure that views using this buffer
152 if (!tmppath.empty()) {
153 DestroyBufferTmpDir(tmppath);
158 // Remove any previewed LaTeX snippets assocoated with this buffer.
159 grfx::Previews::get().removeLoader(this);
163 string const Buffer::getLatexName(bool no_path) const
165 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
167 return OnlyFilename(name);
173 pair<Buffer::LogType, string> const Buffer::getLogName() const
175 string const filename = getLatexName(false);
177 if (filename.empty())
178 return make_pair(Buffer::latexlog, string());
180 string path = OnlyPath(filename);
182 if (lyxrc.use_tempdir || !IsDirWriteable(path))
185 string const fname = AddName(path,
186 OnlyFilename(ChangeExtension(filename,
189 AddName(path, OnlyFilename(
190 ChangeExtension(filename,
191 formats.extension("literate") + ".out")));
193 // If no Latex log or Build log is newer, show Build log
195 FileInfo const f_fi(fname);
196 FileInfo const b_fi(bname);
199 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
200 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
201 return make_pair(Buffer::buildlog, bname);
203 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
204 return make_pair(Buffer::latexlog, fname);
208 void Buffer::setReadonly(bool flag)
210 if (read_only != flag) {
213 users->owner()->getDialogs().updateBufferDependent(false);
218 AuthorList & Buffer::authors()
220 return params.authorlist;
224 /// Update window titles of all users
225 // Should work on a list
226 void Buffer::updateTitles() const
229 users->owner()->updateWindowTitle();
233 /// Reset autosave timer of all users
234 // Should work on a list
235 void Buffer::resetAutosaveTimers() const
238 users->owner()->resetAutosaveTimer();
242 void Buffer::setFileName(string const & newfile)
244 filename_ = MakeAbsPath(newfile);
245 filepath_ = OnlyPath(filename_);
246 setReadonly(IsFileWriteable(filename_) == 0);
251 // We'll remove this later. (Lgb)
255 #warning this is never set to != 0 !!! - remove ?
259 void unknownClass(string const & unknown)
263 boost::io::str(boost::format(
264 _("The document uses an unknown textclass \"%1$s\".")) % unknown)
265 + _("-- substituting default.");
267 _("The document uses an unknown textclass ")
268 + unknown + _("-- substituting default.");
270 Alert::alert(_("Textclass error"), msg);
275 int Buffer::readHeader(LyXLex & lex)
277 int unknown_tokens = 0;
281 string const token = lex.getString();
286 if (token == "\\end_header")
289 lyxerr[Debug::PARSER] << "Handling header token: `"
290 << token << '\'' << endl;
292 string unknown = params.readToken(lex, token);
293 if (!unknown.empty()) {
294 if (unknown[0] != '\\') {
295 unknownClass(unknown);
301 return unknown_tokens;
305 // candidate for move to BufferView
306 // (at least some parts in the beginning of the func)
309 // changed to be public and have one parameter
310 // if par = 0 normal behavior
311 // else insert behavior
312 // Returns false if "\the_end" is not read (Asger)
313 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
316 int unknown_tokens = 0;
318 Paragraph::depth_type depth = 0;
319 bool the_end_read = false;
321 if (paragraphs.empty()) {
322 unknown_tokens += readHeader(lex);
324 if (!params.getLyXTextClass().load()) {
326 Alert::alert(_("Textclass Loading Error!"),
327 boost::io::str(boost::format(_("Can't load textclass %1$s")) %
328 params.getLyXTextClass().name()),
329 _("-- substituting default."));
331 Alert::alert(_("Textclass Loading Error!"),
332 _("Can't load textclass ")
333 + params.getLyXTextClass().name(),
334 _("-- substituting default."));
336 params.textclass = 0;
339 // We are inserting into an existing document
340 users->text->breakParagraph(users, paragraphs);
343 // We don't want to adopt the parameters from the
344 // document we insert, so read them into a temporary buffer
345 // and then discard it
347 Buffer tmpbuf("", false);
348 tmpbuf.readHeader(lex);
353 string const token = lex.getString();
358 lyxerr[Debug::PARSER] << "Handling token: `"
359 << token << '\'' << endl;
361 if (token == "\\the_end") {
366 unknown_tokens += readParagraph(lex, token, paragraphs, pit, depth);
369 if (unknown_layouts > 0) {
370 string s = _("Couldn't set the layout for ");
371 if (unknown_layouts == 1) {
372 s += _("one paragraph");
374 s += tostr(unknown_layouts);
375 s += _(" paragraphs");
378 Alert::alert(_("Textclass Loading Error!"), s,
379 boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
381 Alert::alert(_("Textclass Loading Error!"), s,
382 _("When reading ") + fileName());
386 if (unknown_tokens > 0) {
387 string s = _("Encountered ");
388 if (unknown_tokens == 1) {
389 s += _("one unknown token");
391 s += tostr(unknown_tokens);
392 s += _(" unknown tokens");
395 Alert::alert(_("Textclass Loading Error!"), s,
396 boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
398 Alert::alert(_("Textclass Loading Error!"), s,
399 _("When reading ") + fileName());
408 Buffer::readParagraph(LyXLex & lex, string const & token,
409 ParagraphList & pars, ParagraphList::iterator & pit,
410 Paragraph::depth_type & depth)
412 static Change current_change;
415 if (token == "\\layout") {
416 lex.pushToken(token);
418 Paragraph * par = new Paragraph();
419 par->params().depth(depth);
420 if (params.tracking_changes)
422 LyXFont f(LyXFont::ALL_INHERIT, params.language);
425 // FIXME: goddamn InsetTabular makes us pass a Buffer
427 unknown += ::readParagraph(*this, *par, lex);
430 if (pit != pars.end())
432 pit = pars.insert(pit, par);
433 } else if (token == "\\begin_deeper") {
435 } else if (token == "\\end_deeper") {
437 lex.printError("\\end_deeper: " "depth is already null");
448 // needed to insert the selection
449 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
450 LyXFont const & fn,string const & str)
452 LyXLayout_ptr const & layout = par->layout();
456 par->checkInsertChar(font);
457 // insert the string, don't insert doublespace
458 bool space_inserted = true;
459 bool autobreakrows = !par->inInset() ||
460 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
461 for(string::const_iterator cit = str.begin();
462 cit != str.end(); ++cit) {
464 if (autobreakrows && (!par->empty() || layout->keepempty)) {
465 breakParagraph(params, paragraphs, par, pos,
466 layout->isEnvironment());
469 space_inserted = true;
473 // do not insert consecutive spaces if !free_spacing
474 } else if ((*cit == ' ' || *cit == '\t') &&
475 space_inserted && !layout->free_spacing &&
476 !par->isFreeSpacing())
479 } else if (*cit == '\t') {
480 if (!layout->free_spacing && !par->isFreeSpacing()) {
481 // tabs are like spaces here
482 par->insertChar(pos, ' ', font);
484 space_inserted = true;
486 const pos_type nb = 8 - pos % 8;
487 for (pos_type a = 0; a < nb ; ++a) {
488 par->insertChar(pos, ' ', font);
491 space_inserted = true;
493 } else if (!IsPrintable(*cit)) {
494 // Ignore unprintables
497 // just insert the character
498 par->insertChar(pos, *cit, font);
500 space_inserted = (*cit == ' ');
507 bool Buffer::readFile(LyXLex & lex, string const & filename)
509 return readFile(lex, filename, paragraphs.begin());
513 bool Buffer::readFile(LyXLex & lex, string const & filename, ParagraphList::iterator pit)
517 string const token(lex.getString());
518 if (token == "\\lyxformat") { // the first token _must_ be...
520 string tmp_format = lex.getString();
521 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
522 // if present remove ".," from string.
523 string::size_type dot = tmp_format.find_first_of(".,");
524 //lyxerr << " dot found at " << dot << endl;
525 if (dot != string::npos)
526 tmp_format.erase(dot, 1);
527 file_format = strToInt(tmp_format);
528 //lyxerr << "format: " << file_format << endl;
529 if (file_format == LYX_FORMAT) {
531 } else if (file_format > LYX_FORMAT) {
533 Alert::alert(_("Warning!"),
534 _("The file was created with a newer version of "
535 "LyX. This is likely to cause problems."));
537 } else if (file_format < LYX_FORMAT) {
539 if (file_format < 200) {
540 Alert::alert(_("ERROR!"),
541 _("Old LyX file format found. "
542 "Use LyX 0.10.x to read this!"));
544 } else if (!filename.empty()) {
546 LibFileSearch("lyx2lyx", "lyx2lyx");
547 if (command.empty()) {
548 Alert::alert(_("ERROR!"),
549 _("Can't find conversion script."));
553 +tostr(LYX_FORMAT) + ' '
554 + QuoteName(filename);
555 lyxerr[Debug::INFO] << "Running '"
558 cmd_ret const ret = RunCommand(command);
560 Alert::alert(_("ERROR!"),
561 _("An error occured while "
562 "running the conversion script."));
565 istringstream is(STRCONV(ret.second));
567 tmplex.setStream(is);
568 return readFile(tmplex, string(), pit);
570 // This code is reached if lyx2lyx failed (for
571 // some reason) to change the file format of
577 bool the_end = readBody(lex, pit);
578 params.setPaperStuff();
581 Alert::alert(_("Warning!"),
582 _("Reading of document is not complete"),
583 _("Maybe the document is truncated"));
586 } else { // "\\lyxformat" not found
587 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
590 Alert::alert(_("ERROR!"), _("Unable to read file!"));
595 // Should probably be moved to somewhere else: BufferView? LyXView?
596 bool Buffer::save() const
598 // We don't need autosaves in the immediate future. (Asger)
599 resetAutosaveTimers();
603 if (lyxrc.make_backup) {
604 s = fileName() + '~';
605 if (!lyxrc.backupdir_path.empty())
606 s = AddName(lyxrc.backupdir_path,
607 subst(os::slashify_path(s),'/','!'));
609 // Rename is the wrong way of making a backup,
610 // this is the correct way.
611 /* truss cp fil fil2:
612 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
613 stat("LyXVC.lyx", 0xEFFFF688) = 0
614 open("LyXVC.lyx", O_RDONLY) = 3
615 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
616 fstat(4, 0xEFFFF508) = 0
617 fstat(3, 0xEFFFF508) = 0
618 read(3, " # T h i s f i l e w".., 8192) = 5579
619 write(4, " # T h i s f i l e w".., 5579) = 5579
620 read(3, 0xEFFFD4A0, 8192) = 0
623 chmod("LyXVC3.lyx", 0100644) = 0
624 lseek(0, 0, SEEK_CUR) = 46440
628 // Should probably have some more error checking here.
629 // Doing it this way, also makes the inodes stay the same.
630 // This is still not a very good solution, in particular we
631 // might loose the owner of the backup.
632 FileInfo finfo(fileName());
634 mode_t fmode = finfo.getMode();
635 struct utimbuf times = {
636 finfo.getAccessTime(),
637 finfo.getModificationTime() };
639 ifstream ifs(fileName().c_str());
640 ofstream ofs(s.c_str(), ios::out|ios::trunc);
645 ::chmod(s.c_str(), fmode);
647 if (::utime(s.c_str(), ×)) {
648 lyxerr << "utime error." << endl;
651 lyxerr << "LyX was not able to make "
652 "backup copy. Beware." << endl;
657 if (writeFile(fileName())) {
659 removeAutosaveFile(fileName());
661 // Saving failed, so backup is not backup
662 if (lyxrc.make_backup) {
663 lyx::rename(s, fileName());
671 bool Buffer::writeFile(string const & fname) const
673 if (read_only && (fname == fileName())) {
677 FileInfo finfo(fname);
678 if (finfo.exist() && !finfo.writable()) {
682 ofstream ofs(fname.c_str());
688 // Use the standard "C" locale for file output.
689 ofs.imbue(std::locale::classic());
692 // The top of the file should not be written by params.
694 // write out a comment in the top of the file
695 ofs << '#' << lyx_docversion
696 << " created this file. For more info see http://www.lyx.org/\n"
697 << "\\lyxformat " << LYX_FORMAT << "\n";
699 // now write out the buffer paramters.
700 params.writeFile(ofs);
702 ofs << "\\end_header\n";
704 Paragraph::depth_type depth = 0;
706 // this will write out all the paragraphs
707 // using recursive descent.
708 ParagraphList::iterator pit = paragraphs.begin();
709 ParagraphList::iterator pend = paragraphs.end();
710 for (; pit != pend; ++pit)
711 pit->write(this, ofs, params, depth);
713 // Write marker that shows file is complete
714 ofs << "\n\\the_end" << endl;
718 // how to check if close went ok?
719 // Following is an attempt... (BE 20001011)
721 // good() returns false if any error occured, including some
723 // bad() returns true if something bad happened in the buffer,
724 // which should include file system full errors.
731 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
733 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
745 pair<int, string> const addDepth(int depth, int ldepth)
749 d += (ldepth - depth) * 2;
750 return make_pair(d, string(d, ' '));
756 string const Buffer::asciiParagraph(Paragraph const & par,
757 unsigned int linelen,
758 bool noparbreak) const
760 ostringstream buffer;
761 Paragraph::depth_type depth = 0;
763 Paragraph::depth_type ltype_depth = 0;
764 bool ref_printed = false;
765 // if (!par->previous()) {
767 // begins or ends a deeper area ?
768 if (depth != par->params().depth()) {
769 if (par->params().depth() > depth) {
770 while (par->params().depth() > depth) {
774 while (par->params().depth() < depth) {
780 depth = par.params().depth();
783 // First write the layout
784 string const & tmp = par.layout()->name();
785 if (compare_no_case(tmp, "itemize") == 0) {
787 ltype_depth = depth + 1;
788 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
790 ltype_depth = depth + 1;
791 } else if (contains(ascii_lowercase(tmp), "ection")) {
793 ltype_depth = depth + 1;
794 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
796 ltype_depth = depth + 1;
797 } else if (compare_ascii_no_case(tmp, "description") == 0) {
799 ltype_depth = depth + 1;
800 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
803 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
811 /* maybe some vertical spaces */
813 /* the labelwidthstring used in lists */
817 /* some pagebreaks? */
821 /* what about the alignment */
823 // lyxerr << "Should this ever happen?" << endl;
826 // linelen <= 0 is special and means we don't have paragraph breaks
828 string::size_type currlinelen = 0;
834 buffer << string(depth * 2, ' ');
835 currlinelen += depth * 2;
838 // we should probably change to the paragraph language in the
839 // gettext here (if possible) so that strings are outputted in
840 // the correct language! (20012712 Jug)
844 case 4: // (Sub)Paragraph
845 case 5: // Description
849 buffer << _("Abstract") << "\n\n";
852 string const abst = _("Abstract: ");
854 currlinelen += abst.length();
857 case 7: // Bibliography
860 buffer << _("References") << "\n\n";
863 string const refs = _("References: ");
865 currlinelen += refs.length();
873 string const parlab = par.params().labelString();
874 buffer << parlab << ' ';
875 currlinelen += parlab.length() + 1;
883 pair<int, string> p = addDepth(depth, ltype_depth);
885 currlinelen += p.first;
888 // this is to change the linebreak to do it by word a bit more
889 // intelligent hopefully! (only in the case where we have a
890 // max linelength!) (Jug)
894 for (pos_type i = 0; i < par.size(); ++i) {
895 char c = par.getUChar(params, i);
897 case Paragraph::META_INSET:
899 Inset const * inset = par.getInset(i);
903 currlinelen += word.length();
906 if (inset->ascii(this, buffer, linelen)) {
907 // to be sure it breaks paragraph
908 currlinelen += linelen;
914 case Paragraph::META_NEWLINE:
916 buffer << word << "\n";
919 pair<int, string> p = addDepth(depth,
922 currlinelen = p.first;
929 currlinelen + word.length() > linelen - 10) {
931 pair<int, string> p = addDepth(depth, ltype_depth);
933 currlinelen = p.first;
936 buffer << word << ' ';
937 currlinelen += word.length() + 1;
944 lyxerr[Debug::INFO] <<
945 "writeAsciiFile: NULL char in structure." << endl;
948 (currlinelen + word.length()) > linelen)
952 pair<int, string> p =
953 addDepth(depth, ltype_depth);
955 currlinelen = p.first;
962 return STRCONV(buffer.str());
966 void Buffer::writeFileAscii(string const & fname, int linelen)
968 ofstream ofs(fname.c_str());
970 Alert::err_alert(_("Error: Cannot write file:"), fname);
973 writeFileAscii(ofs, linelen);
977 void Buffer::writeFileAscii(ostream & os, int linelen)
979 ParagraphList::iterator beg = paragraphs.begin();
980 ParagraphList::iterator end = paragraphs.end();
981 ParagraphList::iterator it = beg;
982 for (; it != end; ++it) {
983 os << asciiParagraph(*it, linelen, it == beg);
990 void Buffer::makeLaTeXFile(string const & fname,
991 string const & original_path,
992 bool nice, bool only_body, bool only_preamble)
994 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
996 ofstream ofs(fname.c_str());
998 Alert::err_alert(_("Error: Cannot open file: "), fname);
1002 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
1006 lyxerr << "File was not closed properly." << endl;
1011 void Buffer::makeLaTeXFile(ostream & os,
1012 string const & original_path,
1013 bool nice, bool only_body, bool only_preamble)
1015 niceFile = nice; // this will be used by Insetincludes.
1017 // validate the buffer.
1018 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1019 LaTeXFeatures features(params);
1021 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1024 // The starting paragraph of the coming rows is the
1025 // first paragraph of the document. (Asger)
1026 texrow.start(&*(paragraphs.begin()), 0);
1028 if (!only_body && nice) {
1029 os << "%% " << lyx_docversion << " created this file. "
1030 "For more info, see http://www.lyx.org/.\n"
1031 "%% Do not edit unless you really know what "
1036 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1037 // There are a few differences between nice LaTeX and usual files:
1038 // usual is \batchmode and has a
1039 // special input@path to allow the including of figures
1040 // with either \input or \includegraphics (what figinsets do).
1041 // input@path is set when the actual parameter
1042 // original_path is set. This is done for usual tex-file, but not
1043 // for nice-latex-file. (Matthias 250696)
1046 // code for usual, NOT nice-latex-file
1047 os << "\\batchmode\n"; // changed
1048 // from \nonstopmode
1051 if (!original_path.empty()) {
1052 string inputpath = os::external_path(original_path);
1053 subst(inputpath, "~", "\\string~");
1054 os << "\\makeatletter\n"
1055 << "\\def\\input@path{{"
1056 << inputpath << "/}}\n"
1057 << "\\makeatother\n";
1063 // Write the preamble
1064 params.writeLaTeX(os, features, texrow);
1070 os << "\\begin{document}\n";
1073 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1075 if (!lyxrc.language_auto_begin) {
1076 os << subst(lyxrc.language_command_begin, "$$lang",
1077 params.language->babel())
1082 latexParagraphs(this, paragraphs, paragraphs.begin(), paragraphs.end(), os, texrow);
1084 // add this just in case after all the paragraphs
1088 if (!lyxrc.language_auto_end) {
1089 os << subst(lyxrc.language_command_end, "$$lang",
1090 params.language->babel())
1096 os << "\\end{document}\n";
1099 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1101 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1105 // Just to be sure. (Asger)
1108 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1109 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1112 // we want this to be true outside previews (for insetexternal)
1117 bool Buffer::isLatex() const
1119 return params.getLyXTextClass().outputType() == LATEX;
1123 bool Buffer::isLinuxDoc() const
1125 return params.getLyXTextClass().outputType() == LINUXDOC;
1129 bool Buffer::isLiterate() const
1131 return params.getLyXTextClass().outputType() == LITERATE;
1135 bool Buffer::isDocBook() const
1137 return params.getLyXTextClass().outputType() == DOCBOOK;
1141 bool Buffer::isSGML() const
1143 LyXTextClass const & tclass = params.getLyXTextClass();
1145 return tclass.outputType() == LINUXDOC ||
1146 tclass.outputType() == DOCBOOK;
1150 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1152 ofstream ofs(fname.c_str());
1155 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
1159 niceFile = nice; // this will be used by included files.
1161 LaTeXFeatures features(params);
1167 LyXTextClass const & tclass = params.getLyXTextClass();
1169 string top_element = tclass.latexname();
1172 ofs << "<!doctype linuxdoc system";
1174 string preamble = params.preamble;
1175 const string name = nice ? ChangeExtension(filename_, ".sgml")
1177 preamble += features.getIncludedFiles(name);
1178 preamble += features.getLyXSGMLEntities();
1180 if (!preamble.empty()) {
1181 ofs << " [ " << preamble << " ]";
1185 if (params.options.empty())
1186 sgml::openTag(ofs, 0, false, top_element);
1188 string top = top_element;
1190 top += params.options;
1191 sgml::openTag(ofs, 0, false, top);
1195 ofs << "<!-- " << lyx_docversion
1196 << " created this file. For more info see http://www.lyx.org/"
1199 Paragraph::depth_type depth = 0; // paragraph depth
1200 Paragraph * par = &*(paragraphs.begin());
1202 vector<string> environment_stack(5);
1205 LyXLayout_ptr const & style = par->layout();
1206 // treat <toc> as a special case for compatibility with old code
1207 if (par->isInset(0)) {
1208 Inset * inset = par->getInset(0);
1209 Inset::Code lyx_code = inset->lyxCode();
1210 if (lyx_code == Inset::TOC_CODE) {
1211 string const temp = "toc";
1212 sgml::openTag(ofs, depth, false, temp);
1219 // environment tag closing
1220 for (; depth > par->params().depth(); --depth) {
1221 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1222 environment_stack[depth].erase();
1225 // write opening SGML tags
1226 switch (style->latextype) {
1227 case LATEX_PARAGRAPH:
1228 if (depth == par->params().depth()
1229 && !environment_stack[depth].empty()) {
1230 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1231 environment_stack[depth].erase();
1237 sgml::openTag(ofs, depth, false, style->latexname());
1243 _("Error: Wrong depth for LatexType Command.\n"));
1245 if (!environment_stack[depth].empty()) {
1246 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1250 environment_stack[depth].erase();
1251 sgml::openTag(ofs, depth, false, style->latexname());
1254 case LATEX_ENVIRONMENT:
1255 case LATEX_ITEM_ENVIRONMENT:
1256 case LATEX_BIB_ENVIRONMENT:
1258 string const & latexname = style->latexname();
1260 if (depth == par->params().depth()
1261 && environment_stack[depth] != latexname) {
1262 sgml::closeTag(ofs, depth, false,
1263 environment_stack[depth]);
1264 environment_stack[depth].erase();
1266 if (depth < par->params().depth()) {
1267 depth = par->params().depth();
1268 environment_stack[depth].erase();
1270 if (environment_stack[depth] != latexname) {
1272 sgml::openTag(ofs, depth, false, "p");
1274 sgml::openTag(ofs, depth, false, latexname);
1276 if (environment_stack.size() == depth + 1)
1277 environment_stack.push_back("!-- --");
1278 environment_stack[depth] = latexname;
1281 if (style->latexparam() == "CDATA")
1284 if (style->latextype == LATEX_ENVIRONMENT) break;
1286 if (style->labeltype == LABEL_MANUAL)
1291 sgml::openTag(ofs, depth + 1, false, item_name);
1296 sgml::openTag(ofs, depth, false, style->latexname());
1300 simpleLinuxDocOnePar(ofs, par, depth);
1305 // write closing SGML tags
1306 switch (style->latextype) {
1309 case LATEX_ENVIRONMENT:
1310 case LATEX_ITEM_ENVIRONMENT:
1311 case LATEX_BIB_ENVIRONMENT:
1312 if (style->latexparam() == "CDATA")
1316 sgml::closeTag(ofs, depth, false, style->latexname());
1322 for (int i = depth; i >= 0; --i)
1323 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1327 sgml::closeTag(ofs, 0, false, top_element);
1331 // How to check for successful close
1333 // we want this to be true outside previews (for insetexternal)
1338 // checks, if newcol chars should be put into this line
1339 // writes newline, if necessary.
1342 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1343 string::size_type newcol)
1346 if (colcount > lyxrc.ascii_linelen) {
1348 colcount = newcol; // assume write after this call
1363 string tag_name(PAR_TAG const & pt) {
1365 case NONE: return "!-- --";
1366 case TT: return "tt";
1367 case SF: return "sf";
1368 case BF: return "bf";
1369 case IT: return "it";
1370 case SL: return "sl";
1371 case EM: return "em";
1378 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1380 p1 = static_cast<PAR_TAG>(p1 | p2);
1385 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1387 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1393 // Handle internal paragraph parsing -- layout already processed.
1394 void Buffer::simpleLinuxDocOnePar(ostream & os,
1396 Paragraph::depth_type /*depth*/)
1398 LyXLayout_ptr const & style = par->layout();
1400 string::size_type char_line_count = 5; // Heuristic choice ;-)
1402 // gets paragraph main font
1405 if (style->labeltype == LABEL_MANUAL) {
1406 font_old = style->labelfont;
1409 font_old = style->font;
1413 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1414 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1415 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1418 stack<PAR_TAG> tag_state;
1419 // parsing main loop
1420 for (pos_type i = 0; i < par->size(); ++i) {
1422 PAR_TAG tag_close = NONE;
1423 list < PAR_TAG > tag_open;
1425 LyXFont const font = par->getFont(params, i);
1427 if (font_old.family() != font.family()) {
1428 switch (family_type) {
1429 case LyXFont::SANS_FAMILY:
1432 case LyXFont::TYPEWRITER_FAMILY:
1439 family_type = font.family();
1441 switch (family_type) {
1442 case LyXFont::SANS_FAMILY:
1443 tag_open.push_back(SF);
1445 case LyXFont::TYPEWRITER_FAMILY:
1446 tag_open.push_back(TT);
1453 if (font_old.series() != font.series()) {
1454 switch (series_type) {
1455 case LyXFont::BOLD_SERIES:
1462 series_type = font.series();
1464 switch (series_type) {
1465 case LyXFont::BOLD_SERIES:
1466 tag_open.push_back(BF);
1474 if (font_old.shape() != font.shape()) {
1475 switch (shape_type) {
1476 case LyXFont::ITALIC_SHAPE:
1479 case LyXFont::SLANTED_SHAPE:
1486 shape_type = font.shape();
1488 switch (shape_type) {
1489 case LyXFont::ITALIC_SHAPE:
1490 tag_open.push_back(IT);
1492 case LyXFont::SLANTED_SHAPE:
1493 tag_open.push_back(SL);
1500 if (font_old.emph() != font.emph()) {
1501 if (font.emph() == LyXFont::ON) {
1502 tag_open.push_back(EM);
1511 list < PAR_TAG > temp;
1512 while (!tag_state.empty() && tag_close) {
1513 PAR_TAG k = tag_state.top();
1515 os << "</" << tag_name(k) << '>';
1522 for(list< PAR_TAG >::const_iterator j = temp.begin();
1523 j != temp.end(); ++j) {
1525 os << '<' << tag_name(*j) << '>';
1528 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1529 j != tag_open.end(); ++j) {
1531 os << '<' << tag_name(*j) << '>';
1534 char c = par->getChar(i);
1536 if (c == Paragraph::META_INSET) {
1537 Inset * inset = par->getInset(i);
1538 inset->linuxdoc(this, os);
1543 if (style->latexparam() == "CDATA") {
1544 // "TeX"-Mode on == > SGML-Mode on.
1551 boost::tie(ws, str) = sgml::escapeChar(c);
1552 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
1553 // in freespacing mode, spaces are
1554 // non-breaking characters
1555 if (desc_on) {// if char is ' ' then...
1558 sgmlLineBreak(os, char_line_count, 6);
1562 sgmlLineBreak(os, char_line_count, 1);
1567 char_line_count += str.length();
1573 while (!tag_state.empty()) {
1574 os << "</" << tag_name(tag_state.top()) << '>';
1578 // resets description flag correctly
1580 // <tag> not closed...
1581 sgmlLineBreak(os, char_line_count, 6);
1587 // Print an error message.
1588 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
1589 string const & /*message*/) const
1591 #ifdef WITH_WARNINGS
1592 #warning This is wrong we cannot insert an inset like this!!!
1593 // I guess this was Jose' so I explain you more or less why this
1594 // is wrong. This way you insert something in the paragraph and
1595 // don't tell it to LyXText (row rebreaking and undo handling!!!)
1596 // I deactivate this code, have a look at BufferView::insertErrors
1597 // how you should do this correctly! (Jug 20020315)
1600 // insert an error marker in text
1601 InsetError * new_inset = new InsetError(message);
1602 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1608 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1610 ofstream ofs(fname.c_str());
1612 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
1616 Paragraph * par = &*(paragraphs.begin());
1618 niceFile = nice; // this will be used by Insetincludes.
1620 LaTeXFeatures features(params);
1625 LyXTextClass const & tclass = params.getLyXTextClass();
1626 string top_element = tclass.latexname();
1629 ofs << "<!DOCTYPE " << top_element
1630 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1632 string preamble = params.preamble;
1633 const string name = nice ? ChangeExtension(filename_, ".sgml")
1635 preamble += features.getIncludedFiles(name);
1636 preamble += features.getLyXSGMLEntities();
1638 if (!preamble.empty()) {
1639 ofs << "\n [ " << preamble << " ]";
1644 string top = top_element;
1646 top += params.language->code();
1649 if (!params.options.empty()) {
1651 top += params.options;
1653 sgml::openTag(ofs, 0, false, top);
1655 ofs << "<!-- DocBook file was created by " << lyx_docversion
1656 << "\n See http://www.lyx.org/ for more information -->\n";
1658 vector<string> environment_stack(10);
1659 vector<string> environment_inner(10);
1660 vector<string> command_stack(10);
1662 bool command_flag = false;
1663 Paragraph::depth_type command_depth = 0;
1664 Paragraph::depth_type command_base = 0;
1665 Paragraph::depth_type cmd_depth = 0;
1666 Paragraph::depth_type depth = 0; // paragraph depth
1669 string command_name;
1675 int desc_on = 0; // description mode
1677 LyXLayout_ptr const & style = par->layout();
1679 // environment tag closing
1680 for (; depth > par->params().depth(); --depth) {
1681 if (environment_inner[depth] != "!-- --") {
1682 item_name = "listitem";
1683 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1684 if (environment_inner[depth] == "varlistentry")
1685 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1687 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1688 environment_stack[depth].erase();
1689 environment_inner[depth].erase();
1692 if (depth == par->params().depth()
1693 && environment_stack[depth] != style->latexname()
1694 && !environment_stack[depth].empty()) {
1695 if (environment_inner[depth] != "!-- --") {
1696 item_name= "listitem";
1697 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1698 if (environment_inner[depth] == "varlistentry")
1699 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1702 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1704 environment_stack[depth].erase();
1705 environment_inner[depth].erase();
1708 // Write opening SGML tags.
1709 switch (style->latextype) {
1710 case LATEX_PARAGRAPH:
1711 sgml::openTag(ofs, depth + command_depth,
1712 false, style->latexname());
1718 _("Error: Wrong depth for LatexType Command.\n"));
1720 command_name = style->latexname();
1722 sgmlparam = style->latexparam();
1723 c_params = split(sgmlparam, c_depth,'|');
1725 cmd_depth = lyx::atoi(c_depth);
1728 if (cmd_depth < command_base) {
1729 for (Paragraph::depth_type j = command_depth;
1730 j >= command_base; --j) {
1731 sgml::closeTag(ofs, j, false, command_stack[j]);
1734 command_depth = command_base = cmd_depth;
1735 } else if (cmd_depth <= command_depth) {
1736 for (int j = command_depth;
1737 j >= int(cmd_depth); --j) {
1738 sgml::closeTag(ofs, j, false, command_stack[j]);
1741 command_depth = cmd_depth;
1743 command_depth = cmd_depth;
1745 command_depth = command_base = cmd_depth;
1746 command_flag = true;
1748 if (command_stack.size() == command_depth + 1)
1749 command_stack.push_back(string());
1750 command_stack[command_depth] = command_name;
1752 // treat label as a special case for
1753 // more WYSIWYM handling.
1754 // This is a hack while paragraphs can't have
1755 // attributes, like id in this case.
1756 if (par->isInset(0)) {
1757 Inset * inset = par->getInset(0);
1758 Inset::Code lyx_code = inset->lyxCode();
1759 if (lyx_code == Inset::LABEL_CODE) {
1760 command_name += " id=\"";
1761 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1762 command_name += '"';
1767 sgml::openTag(ofs, depth + command_depth, false, command_name);
1769 item_name = c_params.empty() ? "title" : c_params;
1770 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1773 case LATEX_ENVIRONMENT:
1774 case LATEX_ITEM_ENVIRONMENT:
1775 if (depth < par->params().depth()) {
1776 depth = par->params().depth();
1777 environment_stack[depth].erase();
1780 if (environment_stack[depth] != style->latexname()) {
1781 if (environment_stack.size() == depth + 1) {
1782 environment_stack.push_back("!-- --");
1783 environment_inner.push_back("!-- --");
1785 environment_stack[depth] = style->latexname();
1786 environment_inner[depth] = "!-- --";
1787 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1789 if (environment_inner[depth] != "!-- --") {
1790 item_name= "listitem";
1791 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1792 if (environment_inner[depth] == "varlistentry")
1793 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1797 if (style->latextype == LATEX_ENVIRONMENT) {
1798 if (!style->latexparam().empty()) {
1799 if (style->latexparam() == "CDATA")
1802 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1807 desc_on = (style->labeltype == LABEL_MANUAL);
1809 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1810 sgml::openTag(ofs, depth + 1 + command_depth,
1811 false, environment_inner[depth]);
1813 item_name = desc_on ? "term" : "para";
1814 sgml::openTag(ofs, depth + 1 + command_depth,
1818 sgml::openTag(ofs, depth + command_depth,
1819 false, style->latexname());
1823 simpleDocBookOnePar(ofs, par, desc_on,
1824 depth + 1 + command_depth);
1828 // write closing SGML tags
1829 switch (style->latextype) {
1831 end_tag = c_params.empty() ? "title" : c_params;
1832 sgml::closeTag(ofs, depth + command_depth,
1835 case LATEX_ENVIRONMENT:
1836 if (!style->latexparam().empty()) {
1837 if (style->latexparam() == "CDATA")
1840 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1843 case LATEX_ITEM_ENVIRONMENT:
1844 if (desc_on == 1) break;
1846 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1848 case LATEX_PARAGRAPH:
1849 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1852 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1858 for (int d = depth; d >= 0; --d) {
1859 if (!environment_stack[depth].empty()) {
1860 if (environment_inner[depth] != "!-- --") {
1861 item_name = "listitem";
1862 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1863 if (environment_inner[depth] == "varlistentry")
1864 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1867 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1871 for (int j = command_depth; j >= 0 ; --j)
1872 if (!command_stack[j].empty()) {
1873 sgml::closeTag(ofs, j, false, command_stack[j]);
1878 sgml::closeTag(ofs, 0, false, top_element);
1881 // How to check for successful close
1883 // we want this to be true outside previews (for insetexternal)
1888 void Buffer::simpleDocBookOnePar(ostream & os,
1889 Paragraph * par, int & desc_on,
1890 Paragraph::depth_type depth) const
1892 bool emph_flag = false;
1894 LyXLayout_ptr const & style = par->layout();
1896 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1898 int char_line_count = depth;
1899 //if (!style.free_spacing)
1900 // os << string(depth,' ');
1902 // parsing main loop
1903 for (pos_type i = 0; i < par->size(); ++i) {
1904 LyXFont font = par->getFont(params, i);
1906 // handle <emphasis> tag
1907 if (font_old.emph() != font.emph()) {
1908 if (font.emph() == LyXFont::ON) {
1909 if (style->latexparam() == "CDATA")
1912 if (style->latexparam() == "CDATA")
1916 if (style->latexparam() == "CDATA")
1918 os << "</emphasis>";
1919 if (style->latexparam() == "CDATA")
1926 if (par->isInset(i)) {
1927 Inset * inset = par->getInset(i);
1928 // don't print the inset in position 0 if desc_on == 3 (label)
1929 if (i || desc_on != 3) {
1930 if (style->latexparam() == "CDATA")
1932 inset->docbook(this, os, false);
1933 if (style->latexparam() == "CDATA")
1937 char c = par->getChar(i);
1940 boost::tie(ws, str) = sgml::escapeChar(c);
1942 if (style->pass_thru) {
1944 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
1946 } else if (desc_on ==1) {
1948 os << "\n</term><listitem><para>";
1958 if (style->latexparam() == "CDATA")
1960 os << "</emphasis>";
1961 if (style->latexparam() == "CDATA")
1965 // resets description flag correctly
1967 // <term> not closed...
1968 os << "</term>\n<listitem><para> </para>";
1970 if (style->free_spacing)
1975 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1976 // Other flags: -wall -v0 -x
1977 int Buffer::runChktex()
1979 if (!users->text) return 0;
1981 users->owner()->busy(true);
1983 // get LaTeX-Filename
1984 string const name = getLatexName();
1985 string path = filePath();
1987 string const org_path = path;
1988 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1992 Path p(path); // path to LaTeX file
1993 users->owner()->message(_("Running chktex..."));
1995 // Remove all error insets
1996 bool const removedErrorInsets = users->removeAutoInsets();
1998 // Generate the LaTeX file if neccessary
1999 makeLaTeXFile(name, org_path, false);
2002 Chktex chktex(lyxrc.chktex_command, name, filePath());
2003 int res = chktex.run(terr); // run chktex
2006 Alert::alert(_("chktex did not work!"),
2007 _("Could not run with file:"), name);
2008 } else if (res > 0) {
2009 // Insert all errors as errors boxes
2010 users->insertErrors(terr);
2013 // if we removed error insets before we ran chktex or if we inserted
2014 // error insets after we ran chktex, this must be run:
2015 if (removedErrorInsets || res) {
2016 #warning repaint needed here, or do you mean update() ?
2020 users->owner()->busy(false);
2026 void Buffer::validate(LaTeXFeatures & features) const
2028 LyXTextClass const & tclass = params.getLyXTextClass();
2030 if (params.tracking_changes) {
2031 features.require("dvipost");
2032 features.require("color");
2035 // AMS Style is at document level
2036 if (params.use_amsmath == BufferParams::AMS_ON
2037 || tclass.provides(LyXTextClass::amsmath))
2038 features.require("amsmath");
2040 for_each(paragraphs.begin(), paragraphs.end(),
2041 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
2043 // the bullet shapes are buffer level not paragraph level
2044 // so they are tested here
2045 for (int i = 0; i < 4; ++i) {
2046 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2047 int const font = params.user_defined_bullets[i].getFont();
2049 int const c = params
2050 .user_defined_bullets[i]
2057 features.require("latexsym");
2059 } else if (font == 1) {
2060 features.require("amssymb");
2061 } else if ((font >= 2 && font <= 5)) {
2062 features.require("pifont");
2067 if (lyxerr.debugging(Debug::LATEX)) {
2068 features.showStruct();
2073 vector<string> const Buffer::getLabelList() const
2075 /// if this is a child document and the parent is already loaded
2076 /// Use the parent's list instead [ale990407]
2077 if (!params.parentname.empty()
2078 && bufferlist.exists(params.parentname)) {
2079 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2081 return tmp->getLabelList();
2084 vector<string> label_list;
2085 for (inset_iterator it = inset_const_iterator_begin();
2086 it != inset_const_iterator_end(); ++it) {
2087 vector<string> const l = it->getLabelList();
2088 label_list.insert(label_list.end(), l.begin(), l.end());
2094 // This is also a buffer property (ale)
2095 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
2097 /// if this is a child document and the parent is already loaded
2098 /// use the parent's list instead [ale990412]
2099 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2100 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2102 tmp->fillWithBibKeys(keys);
2107 for (inset_iterator it = inset_const_iterator_begin();
2108 it != inset_const_iterator_end(); ++it) {
2109 if (it->lyxCode() == Inset::BIBTEX_CODE)
2110 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2111 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2112 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2113 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2114 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2115 string const key = bib.getContents();
2116 string const opt = bib.getOptions();
2117 string const ref; // = pit->asString(this, false);
2118 string const info = opt + "TheBibliographyRef" + ref;
2119 keys.push_back(pair<string, string>(key, info));
2125 bool Buffer::isDepClean(string const & name) const
2127 DepClean::const_iterator it = dep_clean_.find(name);
2128 if (it == dep_clean_.end())
2134 void Buffer::markDepClean(string const & name)
2136 dep_clean_[name] = true;
2140 bool Buffer::dispatch(string const & command, bool * result)
2142 // Split command string into command and argument
2144 string line = ltrim(command);
2145 string const arg = trim(split(line, cmd, ' '));
2147 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2151 bool Buffer::dispatch(int action, string const & argument, bool * result)
2153 bool dispatched = true;
2157 bool const tmp = Exporter::Export(this, argument, false);
2170 void Buffer::resizeInsets(BufferView * bv)
2172 /// then remove all LyXText in text-insets
2173 for_each(paragraphs.begin(), paragraphs.end(),
2174 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2178 void Buffer::redraw()
2180 #warning repaint needed here, or do you mean update() ?
2186 void Buffer::changeLanguage(Language const * from, Language const * to)
2189 ParIterator end = par_iterator_end();
2190 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2191 (*it)->changeLanguage(params, from, to);
2195 bool Buffer::isMultiLingual()
2197 ParIterator end = par_iterator_end();
2198 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2199 if ((*it)->isMultiLingual(params))
2206 void Buffer::inset_iterator::setParagraph()
2208 while (pit != pend) {
2209 it = pit->insetlist.begin();
2210 if (it != pit->insetlist.end())
2217 Inset * Buffer::getInsetFromID(int id_arg) const
2219 for (inset_iterator it = inset_const_iterator_begin();
2220 it != inset_const_iterator_end(); ++it)
2222 if (it->id() == id_arg)
2224 Inset * in = it->getInsetFromID(id_arg);
2232 Paragraph * Buffer::getParFromID(int id) const
2237 // why should we allow < 0 ??
2238 //lyx::Assert(id >= 0);
2240 ParConstIterator it(par_iterator_begin());
2241 ParConstIterator end(par_iterator_end());
2243 for (; it != end; ++it) {
2244 // go on then, show me how to remove
2246 if ((*it)->id() == id) {
2247 return const_cast<Paragraph*>(*it);
2255 ParIterator Buffer::par_iterator_begin()
2257 return ParIterator(&*(paragraphs.begin()));
2261 ParIterator Buffer::par_iterator_end()
2263 return ParIterator();
2266 ParConstIterator Buffer::par_iterator_begin() const
2268 return ParConstIterator(&*(paragraphs.begin()));
2272 ParConstIterator Buffer::par_iterator_end() const
2274 return ParConstIterator();
2279 void Buffer::addUser(BufferView * u)
2285 void Buffer::delUser(BufferView *)
2291 Language const * Buffer::getLanguage() const
2293 return params.language;
2297 bool Buffer::isClean() const
2303 bool Buffer::isBakClean() const
2309 void Buffer::markClean() const
2315 // if the .lyx file has been saved, we don't need an
2321 void Buffer::markBakClean()
2327 void Buffer::setUnnamed(bool flag)
2333 bool Buffer::isUnnamed()
2339 void Buffer::markDirty()
2347 DepClean::iterator it = dep_clean_.begin();
2348 DepClean::const_iterator const end = dep_clean_.end();
2350 for (; it != end; ++it) {
2356 string const & Buffer::fileName() const
2362 string const & Buffer::filePath() const
2368 bool Buffer::isReadonly() const
2374 BufferView * Buffer::getUser() const
2380 void Buffer::setParentName(string const & name)
2382 params.parentname = name;
2386 Buffer::inset_iterator::inset_iterator()
2391 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2398 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2402 if (it == pit->insetlist.end()) {
2411 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2413 inset_iterator tmp = *this;
2419 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2421 return *it.getInset();
2425 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2427 return it.getInset();
2431 Paragraph * Buffer::inset_iterator::getPar()
2437 lyx::pos_type Buffer::inset_iterator::getPos() const
2443 bool operator==(Buffer::inset_iterator const & iter1,
2444 Buffer::inset_iterator const & iter2)
2446 return iter1.pit == iter2.pit
2447 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2451 bool operator!=(Buffer::inset_iterator const & iter1,
2452 Buffer::inset_iterator const & iter2)
2454 return !(iter1 == iter2);