From dbd7a961fc46bb10c85bdd8c7fb6626477ae63d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sat, 2 Mar 2002 16:39:54 +0000 Subject: [PATCH] layout as string git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3640 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ChangeLog | 4 + lib/layouts/stdclass.inc | 1 + src/BufferView2.C | 2 +- src/BufferView_pimpl.C | 58 ++++---- src/ChangeLog | 39 ++++++ src/CutAndPaste.C | 29 ++-- src/LaTeXFeatures.C | 25 ++-- src/LaTeXFeatures.h | 7 +- src/LyXView.C | 13 +- src/LyXView.h | 3 +- src/buffer.C | 152 +++++++------------- src/bufferparams.C | 6 +- src/bufferview_funcs.C | 4 +- src/frontends/ChangeLog | 4 + src/frontends/Toolbar.C | 3 +- src/frontends/Toolbar.h | 2 +- src/frontends/qt2/ChangeLog | 4 + src/frontends/qt2/QDocument.C | 2 +- src/frontends/xforms/ChangeLog | 9 ++ src/frontends/xforms/FormDocument.C | 28 ++-- src/frontends/xforms/FormParagraph.C | 9 +- src/frontends/xforms/Toolbar_pimpl.C | 11 +- src/frontends/xforms/Toolbar_pimpl.h | 3 +- src/insets/ChangeLog | 10 ++ src/insets/insetbib.C | 6 +- src/insets/insetert.C | 5 +- src/insets/insetinclude.C | 4 +- src/insets/insettext.C | 40 +++--- src/lyx_cb.C | 10 +- src/lyxlayout.C | 61 ++++++-- src/lyxlayout.h | 11 +- src/lyxtext.h | 11 +- src/lyxtextclass.C | 202 ++++++++++++++++++++++++--- src/lyxtextclass.h | 53 +++---- src/lyxtextclasslist.C | 100 +------------ src/lyxtextclasslist.h | 30 +--- src/paragraph.C | 116 +++++++-------- src/paragraph.h | 15 +- src/paragraph_pimpl.C | 12 +- src/support/ChangeLog | 4 + src/support/types.h | 20 --- src/text.C | 166 ++++++++++------------ src/text2.C | 128 ++++++++--------- 43 files changed, 737 insertions(+), 685 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 1d1570a51e..52b2d89803 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2002-03-02 Lars Gullik Bjønnes + + * layouts/stdclass.inc: add DefaultStyle + 2002-03-01 Jean-Marc Lasgouttes * doc/LaTeXConfig.lyx.in: add entry for svprothb diff --git a/lib/layouts/stdclass.inc b/lib/layouts/stdclass.inc index 06785745dc..17a7498e32 100644 --- a/lib/layouts/stdclass.inc +++ b/lib/layouts/stdclass.inc @@ -11,6 +11,7 @@ Columns 1 Sides 1 SecNumDepth 2 TocDepth 2 +DefaultStyle Standard # This is just to show how to declare the default font. # The defaults are exactly those shown here. diff --git a/src/BufferView2.C b/src/BufferView2.C index 9ed1e8720e..a07916d07e 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -601,7 +601,7 @@ int BufferView::unlockInset(UpdatableInset * inset) inset->insetUnlock(this); theLockingInset(0); // make sure we update the combo ! - owner()->setLayout(getLyXText()->cursor.par()->getLayout()); + owner()->setLayout(getLyXText()->cursor.par()->layout()); finishUndo(); return 0; } else if (inset && theLockingInset() && diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index a90b76067a..a7afbd8b2a 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -73,7 +73,7 @@ #include -extern lyx::layout_type current_layout; +extern string current_layout; using std::vector; using std::find_if; @@ -85,7 +85,6 @@ using std::min; using SigC::slot; using lyx::pos_type; -using lyx::layout_type; using lyx::textclass_type; /* the selection possible is needed, that only motion events are @@ -870,9 +869,7 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y, // Maybe we want to edit a bibitem ale970302 if (bv_->text->cursor.par()->bibkey && x < 20 + - bibitemMaxWidth(bv_, textclasslist. - TextClass(buffer_-> - params.textclass).defaultfont())) { + bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) { bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0); } @@ -1669,34 +1666,34 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) // Derive layout number from given argument (string) // and current buffer's textclass (number). */ textclass_type tclass = buffer_->params.textclass; - pair layout = - textclasslist.NumberOfLayout(tclass, argument); + bool hasLayout = + textclasslist[tclass].hasLayout(argument); + string layout = argument; // If the entry is obsolete, use the new one instead. - if (layout.first) { - string obs = textclasslist.Style(tclass, layout.second) + if (hasLayout) { + string const & obs = textclasslist[tclass][layout] .obsoleted_by(); if (!obs.empty()) - layout = textclasslist.NumberOfLayout(tclass, obs); + layout = obs; } - // see if we found the layout number: - if (!layout.first) { + if (!hasLayout) { owner_->getLyXFunc()->setErrorMessage( string(N_("Layout ")) + argument + N_(" not known")); break; } - if (current_layout != layout.second) { + if (current_layout != layout) { LyXText * lt = bv_->getLyXText(); hideCursor(); - current_layout = layout.second; + current_layout = layout; update(lt, BufferView::SELECT | BufferView::FITCUR); - lt->setLayout(bv_, layout.second); - owner_->setLayout(layout.second); + lt->setLayout(bv_, layout); + owner_->setLayout(layout); update(lt, BufferView::SELECT | BufferView::FITCUR @@ -2341,9 +2338,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - LyXLayout const & style = textclasslist - .Style(buffer_->params.textclass, - lt->cursor.par()->getLayout()); + LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()]; if (style.free_spacing) { lt->insertChar(bv_, ' '); @@ -2879,7 +2874,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) break; case LFUN_GETLAYOUT: - owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout)); + owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout())); break; case LFUN_GETFONT: @@ -3308,8 +3303,8 @@ void BufferView::Pimpl::smartQuote() hideCursor(); - LyXLayout const & style = textclasslist.Style( - bv_->buffer()->params.textclass, par->getLayout()); + LyXLayout const & style = + textclasslist[bv_->buffer()->params.textclass][par->layout()]; if (style.pass_thru || (!insertInset(new InsetQuotes(c, bv_->buffer()->params)))) @@ -3369,17 +3364,20 @@ bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout) update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); } - pair lres = - textclasslist.NumberOfLayout(buffer_->params .textclass, lout); - layout_type lay = 0; - if (lres.first != false) { + string lres = lout; + LyXTextClass const & tclass = + textclasslist[buffer_->params.textclass]; + bool hasLayout = tclass.hasLayout(lres); + string lay = tclass.defaultLayoutName(); + + if (hasLayout != false) { // layout found - lay = lres.second; + lay = lres; } else { - // layout not fount using default "Standard" (0) - lay = 0; + // layout not fount using default + lay = tclass.defaultLayoutName(); } - + bv_->text->setLayout(bv_, lay); bv_->text->setParagraph(bv_, 0, 0, diff --git a/src/ChangeLog b/src/ChangeLog index 4156f3df64..fbd6196de9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,44 @@ 2002-03-02 Lars Gullik Bjønnes + * text2.C: layout as string + + * text.C: layout as string + + * paragraph_pimpl.C: layout as string + + * paragraph.[Ch]: layout as string + + * lyxtextclasslist.[Ch]: layout as string + + * lyxtextclass.[Ch]: layout as string + + * lyxtext.h: layout as string + + * lyxlayout.[Ch]: layout as string + + * lyx_cb.C: layout as string + + * bufferview_funcs.C: layout as string + + * bufferparams.C: layout as string + + * buffer.C: layout as string + + * LyXView.[Ch]: layout as string + + * LaTeXFeatures.[Ch]: layout as string + + * CutAndPaste.C (SwitchLayoutsBetweenClasses): layout as string + + * BufferView_pimpl.C: change current_layout to string, remove + lyx::layout_type. + (Dispatch): + (smartQuote): + (insertInset): + (workAreaButtonRelease): layout as string + + * BufferView2.C (unlockInset): adjust + * vspace.C (asLatexCommand): use an explict temp variable. 2002-03-01 John Levon diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 2eab33a685..0ad7fe6162 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -26,7 +26,6 @@ using std::pair; using lyx::pos_type; -using lyx::layout_type; using lyx::textclass_type; extern BufferView * current_view; @@ -380,26 +379,28 @@ int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1, ParIterator end = ParIterator(); for (ParIterator it = ParIterator(par); it != end; ++it) { par = *it; - string const name = textclasslist.NameOfLayout(c1, par->layout); - int lay = 0; - pair pp = - textclasslist.NumberOfLayout(c2, name); - if (pp.first) { - lay = pp.second; + string const name = par->layout(); + LyXTextClass const & tclass = textclasslist[c2]; + + bool hasLayout = tclass.hasLayout(name); + + string lay = tclass.defaultLayoutName(); + if (hasLayout) { + lay = name; } else { - // not found: use default layout "Standard" (0) - lay = 0; + // not found: use default layout + lay = tclass.defaultLayoutName(); } - par->layout = lay; + par->layout(lay); - if (name != textclasslist.NameOfLayout(c2, par->layout)) { + if (name != par->layout()) { ++ret; string const s = _("Layout had to be changed from\n") + name + _(" to ") - + textclasslist.NameOfLayout(c2, par->layout) + + par->layout() + _("\nbecause of class conversion from\n") - + textclasslist.NameOfClass(c1) + _(" to ") - + textclasslist.NameOfClass(c2); + + textclasslist[c1].name() + _(" to ") + + textclasslist[c2].name(); InsetError * new_inset = new InsetError(s); par->insertInset(0, new_inset, LyXFont(LyXFont::ALL_INHERIT, diff --git a/src/LaTeXFeatures.C b/src/LaTeXFeatures.C index 15102ef3c2..cf8cec1380 100644 --- a/src/LaTeXFeatures.C +++ b/src/LaTeXFeatures.C @@ -28,7 +28,6 @@ #include "support/filetools.h" #include "support/lstrings.h" -using lyx::layout_type; using lyx::textclass_type; using std::endl; @@ -38,8 +37,8 @@ using std::find; using std::ostream; -LaTeXFeatures::LaTeXFeatures(BufferParams const & p, layout_type n) - : layout(n, false), params(p) +LaTeXFeatures::LaTeXFeatures(BufferParams const & p) + : params(p) {} @@ -52,9 +51,9 @@ void LaTeXFeatures::require(string const & name) } -void LaTeXFeatures::useLayout(vector::size_type const & idx) +void LaTeXFeatures::useLayout(string const & lyt) { - layout[idx] = true; + layout.insert(lyt); } @@ -152,8 +151,7 @@ const int nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *); string const LaTeXFeatures::getPackages() const { ostringstream packages; - LyXTextClass const & tclass = - textclasslist.TextClass(params.textclass); + LyXTextClass const & tclass = textclasslist[params.textclass]; /** @@ -325,17 +323,17 @@ string const LaTeXFeatures::getMacros() const string const LaTeXFeatures::getTClassPreamble() const { // the text class specific preamble - LyXTextClass const & tclass = textclasslist.TextClass(params.textclass); + LyXTextClass const & tclass = textclasslist[params.textclass]; ostringstream tcpreamble; tcpreamble << tclass.preamble(); - for (layout_type i = 0; i < tclass.numLayouts(); ++i) { - if (layout[i]) { - tcpreamble << tclass[i].preamble(); - } + set::const_iterator cit = layout.begin(); + set::const_iterator end = layout.end(); + for (; cit != end; ++cit) { + tcpreamble << tclass[*cit].preamble(); } - + return tcpreamble.str().c_str(); } @@ -383,6 +381,7 @@ BufferParams const & LaTeXFeatures::bufferParams() const return params; } + void LaTeXFeatures::getFloatDefinitions(ostream & os) const { // Here we will output the code to create the needed float styles. diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h index 6b884de02d..f70d8286ea 100644 --- a/src/LaTeXFeatures.h +++ b/src/LaTeXFeatures.h @@ -45,7 +45,7 @@ struct Language; class LaTeXFeatures { public: /// - LaTeXFeatures(BufferParams const &, lyx::layout_type n) ; + LaTeXFeatures(BufferParams const &); /// The packages needed by the document string const getPackages() const; /// The macros definitions needed by the document @@ -79,8 +79,7 @@ public: /// std::set getEncodingSet(string const & doc_encoding); /// - /// - void useLayout(std::vector::size_type const & idx); + void useLayout(string const & lyt); /// BufferParams const & bufferParams() const; /// @@ -88,7 +87,7 @@ public: private: string externalPreambles; - std::vector layout; + std::set layout; /// Static preamble bits from the external material insets diff --git a/src/LyXView.C b/src/LyXView.C index 386fb03195..e1510008b7 100644 --- a/src/LyXView.C +++ b/src/LyXView.C @@ -28,6 +28,7 @@ #include "gettext.h" #include "lyxfunc.h" #include "BufferView.h" +#include "lyxtextclasslist.h" #include "frontends/Dialogs.h" #include "frontends/Toolbar.h" @@ -40,12 +41,11 @@ #include using std::endl; -using lyx::layout_type; extern void AutoSave(BufferView *); extern void QuitLyX(); -layout_type current_layout = 0; +string current_layout; LyXView::LyXView() @@ -104,7 +104,7 @@ Toolbar * LyXView::getToolbar() const } -void LyXView::setLayout(layout_type layout) +void LyXView::setLayout(string const & layout) { toolbar->setLayout(layout); } @@ -205,12 +205,13 @@ void LyXView::updateLayoutChoice() if (last_textclass != int(buffer()->params.textclass)) { toolbar->updateLayoutList(true); last_textclass = int(buffer()->params.textclass); - current_layout = 0; + current_layout = textclasslist[last_textclass].defaultLayoutName(); } else { toolbar->updateLayoutList(false); } - - layout_type layout = bufferview->getLyXText()->cursor.par()->getLayout(); + + string const & layout = + bufferview->getLyXText()->cursor.par()->layout(); if (layout != current_layout) { toolbar->setLayout(layout); diff --git a/src/LyXView.h b/src/LyXView.h index dafacd8956..cb2465781f 100644 --- a/src/LyXView.h +++ b/src/LyXView.h @@ -53,8 +53,7 @@ public: Toolbar * getToolbar() const; /// sets the layout in the toolbar layout combox - void setLayout(lyx::layout_type layout); - + void setLayout(string const & layout); /// update the toolbar void updateToolbar(); diff --git a/src/buffer.C b/src/buffer.C index b815c87a07..331c336463 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -128,7 +128,6 @@ using std::stack; using std::list; using lyx::pos_type; -using lyx::layout_type; using lyx::textclass_type; // all these externs should eventually be removed. @@ -466,9 +465,6 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, string const layoutname = lex.getString(); //lyxerr << "Looking for layout '" // << layoutname << "'!" << endl; - - pair pp - = textclasslist.NumberOfLayout(params.textclass, layoutname); //lyxerr << "Result: " << pp.first << "/" << pp.second << endl; @@ -537,37 +533,12 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, par = new Paragraph(par); } pos = 0; - if (pp.first) { - par->layout = pp.second; -#ifndef NO_COMPABILITY - } else if (ert_comp.active) { - par->layout = 0; -#endif - } else { - // layout not found - // use default layout "Standard" (0) - //lyxerr << "Layout '" << layoutname - // << "' was not found!" << endl; - - par->layout = 0; - ++unknown_layouts; - string const s = _("Layout had to be changed from\n") - + layoutname + _(" to ") - + textclasslist.NameOfLayout(params.textclass, par->layout); - InsetError * new_inset = new InsetError(s); - par->insertInset(0, new_inset, - LyXFont(LyXFont::ALL_INHERIT, - params.language)); - } + par->layout(layoutname); // Test whether the layout is obsolete. LyXLayout const & layout = - textclasslist.Style(params.textclass, - par->layout); + textclasslist[params.textclass][par->layout()]; if (!layout.obsoleted_by().empty()) - par->layout = textclasslist - .NumberOfLayout(params.textclass, - layout.obsoleted_by()) - .second; + par->layout(layout.obsoleted_by()); par->params().depth(depth); font = LyXFont(LyXFont::ALL_INHERIT, params.language); if (file_format < 216 @@ -696,7 +667,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, string(_("LyX will not be able to produce output correctly."))); params.textclass = 0; } - if (!textclasslist.Load(params.textclass)) { + if (!textclasslist[params.textclass].load()) { // if the textclass wasn't loaded properly // we need to either substitute another // or stop loading the file. @@ -704,7 +675,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, // stop loading... ideas?? ARRae980418 Alert::alert(_("Textclass Loading Error!"), string(_("Can't load textclass ")) + - textclasslist.NameOfClass(params.textclass), + textclasslist[params.textclass].name(), _("-- substituting default")); params.textclass = 0; } @@ -1098,8 +1069,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, #endif } else if (token == "\\SpecialChar") { LyXLayout const & layout = - textclasslist.Style(params.textclass, - par->getLayout()); + textclasslist[params.textclass][par->layout()]; // Insets don't make sense in a free-spacing context! ---Kayvan if (layout.free_spacing || par->isFreeSpacing()) { @@ -1157,8 +1127,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, // Remove it later some time...introduced with fileformat // 2.16. (Lgb) LyXLayout const & layout = - textclasslist.Style(params.textclass, - par->getLayout()); + textclasslist[params.textclass][par->layout()]; if (layout.free_spacing || par->isFreeSpacing()) { par->insertChar(pos, ' ', font); @@ -1249,8 +1218,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, if (checkminipage && (call_depth == 1)) { checkminipage = false; if (minipar && (minipar != par) && - (par->params().pextraType()==Paragraph::PEXTRA_MINIPAGE)) - { + (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) { lyxerr << "minipages in a row" << endl; if (par->params().pextraStartMinipage()) { lyxerr << "start new minipage" << endl; @@ -1271,10 +1239,10 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, // create a new paragraph to insert the // minipages in the following case if (par->params().pextraStartMinipage() && - !par->params().pextraHfill()) - { + !par->params().pextraHfill()) { Paragraph * p = new Paragraph; - p->layout = 0; + p->layout(textclasslist[params.textclass].defaultLayoutName()); + p->previous(parBeforeMinipage); parBeforeMinipage->next(p); p->next(0); @@ -1348,7 +1316,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, // a sequence of minipages // in its own paragraph. Paragraph * p = new Paragraph; - p->layout = 0; + p->layout(textclasslist[params.textclass].defaultLayoutName()); p->previous(par->previous()); p->next(0); p->params().depth(depth); @@ -1392,11 +1360,11 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par, void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos, LyXFont const & fn,string const & str) const { - LyXLayout const & layout = textclasslist.Style(params.textclass, - par->getLayout()); + LyXLayout const & layout = + textclasslist[params.textclass][par->layout()]; LyXFont font = fn; - (void)par->checkInsertChar(font); + par->checkInsertChar(font); // insert the string, don't insert doublespace bool space_inserted = true; for(string::const_iterator cit = str.begin(); @@ -1824,11 +1792,11 @@ string const Buffer::asciiParagraph(Paragraph const * par, #endif // First write the layout - string const tmp = textclasslist.NameOfLayout(params.textclass, par->layout); - if (tmp == "Itemize") { + string const & tmp = lowercase(par->layout()); + if (tmp == "itemize") { ltype = 1; ltype_depth = depth + 1; - } else if (tmp == "Enumerate") { + } else if (tmp == "enumerate") { ltype = 2; ltype_depth = depth + 1; } else if (contains(tmp, "ection")) { @@ -1837,13 +1805,13 @@ string const Buffer::asciiParagraph(Paragraph const * par, } else if (contains(tmp, "aragraph")) { ltype = 4; ltype_depth = depth + 1; - } else if (tmp == "Description") { + } else if (tmp == "description") { ltype = 5; ltype_depth = depth + 1; - } else if (tmp == "Abstract") { + } else if (tmp == "abstract") { ltype = 6; ltype_depth = 0; - } else if (tmp == "Bibliography") { + } else if (tmp == "bibliography") { ltype = 7; ltype_depth = 0; } else { @@ -2048,7 +2016,7 @@ void Buffer::makeLaTeXFile(string const & fname, tex_code_break_column = lyxrc.ascii_linelen; LyXTextClass const & tclass = - textclasslist.TextClass(params.textclass); + textclasslist[params.textclass]; ofstream ofs(fname.c_str()); if (!ofs) { @@ -2058,7 +2026,7 @@ void Buffer::makeLaTeXFile(string const & fname, // validate the buffer. lyxerr[Debug::LATEX] << " Validating buffer..." << endl; - LaTeXFeatures features(params, tclass.numLayouts()); + LaTeXFeatures features(params, tclass.size()); validate(features); lyxerr[Debug::LATEX] << " Buffer validation done." << endl; @@ -2191,7 +2159,7 @@ void Buffer::makeLaTeXFile(string const & fname, } ofs << '{' - << textclasslist.LatexnameOfClass(params.textclass) + << textclasslist[params.textclass].latexname() << "}\n"; texrow.newline(); // end of \documentclass defs @@ -2549,7 +2517,7 @@ void Buffer::latexParagraphs(ostream & ofs, Paragraph * par, // any environment other then "Standard" to be valid! if ((in == 0) || !in->forceDefaultParagraphs(in)) { LyXLayout const & layout = - textclasslist.Style(params.textclass, par->layout); + textclasslist[params.textclass][par->layout()]; if (layout.intitle) { if (already_title) { @@ -2584,32 +2552,34 @@ void Buffer::latexParagraphs(ostream & ofs, Paragraph * par, bool Buffer::isLatex() const { - return textclasslist.TextClass(params.textclass).outputType() == LATEX; + return textclasslist[params.textclass].outputType() == LATEX; } bool Buffer::isLinuxDoc() const { - return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC; + return textclasslist[params.textclass].outputType() == LINUXDOC; } bool Buffer::isLiterate() const { - return textclasslist.TextClass(params.textclass).outputType() == LITERATE; + return textclasslist[params.textclass].outputType() == LITERATE; } bool Buffer::isDocBook() const { - return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK; + return textclasslist[params.textclass].outputType() == DOCBOOK; } bool Buffer::isSGML() const { - return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC || - textclasslist.TextClass(params.textclass).outputType() == DOCBOOK; + LyXTextClass const & tclass = textclasslist[params.textclass]; + + return tclass.outputType() == LINUXDOC || + tclass.outputType() == DOCBOOK; } @@ -2642,15 +2612,15 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) niceFile = nice; // this will be used by included files. - LyXTextClass const & tclass = - textclasslist.TextClass(params.textclass); + LyXTextClass const & tclass = 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 (!body_only) { ofs << "layout); + textclasslist[params.textclass][par->layout()]; // treat as a special case for compatibility with old code if (par->isInset(0)) { @@ -2872,8 +2841,8 @@ void Buffer::simpleLinuxDocOnePar(ostream & os, Paragraph * par, Paragraph::depth_type /*depth*/) { - LyXLayout const & style = textclasslist.Style(params.textclass, - par->getLayout()); + LyXLayout const & style = + textclasslist[params.textclass][par->layout()]; string::size_type char_line_count = 5; // Heuristic choice ;-) // gets paragraph main font @@ -3085,14 +3054,14 @@ 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) { ofs << "layout); + textclasslist[params.textclass][par->layout()]; // environment tag closing for (; depth > par->params().depth(); --depth) { @@ -3380,8 +3348,8 @@ void Buffer::simpleDocBookOnePar(ostream & os, { 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; @@ -3502,8 +3470,7 @@ 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 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath)) @@ -3599,25 +3566,12 @@ 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; - textclass_type const cap = tmp.second; - -#else - // This is the prefered way to to this, but boost::tie can break - // some compilers - bool found; - textclass_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) { @@ -3625,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 @@ -3649,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); diff --git a/src/bufferparams.C b/src/bufferparams.C index 6aa67adfc1..179d26604b 100644 --- a/src/bufferparams.C +++ b/src/bufferparams.C @@ -75,7 +75,7 @@ void BufferParams::writeFile(ostream & os) const // Prints out the buffer info into the .lyx file given by file // the textclass - os << "\\textclass " << textclasslist.NameOfClass(textclass) << '\n'; + os << "\\textclass " << textclasslist[textclass].name() << '\n'; // then the the preamble if (!preamble.empty()) { @@ -209,7 +209,7 @@ void BufferParams::setPaperStuff() void BufferParams::useClassDefaults() { - LyXTextClass const & tclass = textclasslist.TextClass(textclass); + LyXTextClass const & tclass = textclasslist[textclass]; sides = tclass.sides(); columns = tclass.columns(); @@ -222,7 +222,7 @@ void BufferParams::useClassDefaults() bool BufferParams::hasClassDefaults() const { - LyXTextClass const & tclass = textclasslist.TextClass(textclass); + LyXTextClass const & tclass = textclasslist[textclass]; return (sides == tclass.sides() && columns == tclass.columns() diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 1331407e33..308c4dc796 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -159,9 +159,7 @@ string const currentState(BufferView * bv) Buffer * buffer = bv->buffer(); LyXFont font = text->real_current_font; LyXFont const & defaultfont = - textclasslist - .TextClass(buffer->params.textclass) - .defaultfont(); + textclasslist[buffer->params.textclass].defaultfont(); font.reduce(defaultfont); state << _("Font:") << ' ' diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 57517b4bb5..7807eaa48d 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,7 @@ +2002-03-02 Lars Gullik Bjønnes + + * Toolbar.[Ch] (setLayout): layout as string + 2002-02-28 Angus Leeming * Dialogs.h (initialiseGraphics): a new static method. diff --git a/src/frontends/Toolbar.C b/src/frontends/Toolbar.C index 68abc6b466..dc1237a6f7 100644 --- a/src/frontends/Toolbar.C +++ b/src/frontends/Toolbar.C @@ -75,7 +75,8 @@ void Toolbar::update() } -void Toolbar::setLayout(int layout) + +void Toolbar::setLayout(string const & layout) { pimpl_->setLayout(layout); } diff --git a/src/frontends/Toolbar.h b/src/frontends/Toolbar.h index bee96e3ee5..b4e398ef6c 100644 --- a/src/frontends/Toolbar.h +++ b/src/frontends/Toolbar.h @@ -54,7 +54,7 @@ public: void update(); /// update the layout combox - void setLayout(int layout); + void setLayout(string const & layout); /// Populate the layout combox; re-do everything if force is true. void updateLayoutList(bool force); /// Drop down the layout list diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 76d059a7c8..f27f6af2b5 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,7 @@ +2002-03-02 Lars Gullik Bjønnes + + * QDocument.C (class_update): layout as string + 2002-03-01 John Levon * Makefile.am: diff --git a/src/frontends/qt2/QDocument.C b/src/frontends/qt2/QDocument.C index 0f1885d8b5..610fd74393 100644 --- a/src/frontends/qt2/QDocument.C +++ b/src/frontends/qt2/QDocument.C @@ -566,7 +566,7 @@ void QDocument::class_update(BufferParams const & params) if (!class_.get()) return; - LyXTextClass const & tclass = textclasslist.TextClass(params.textclass); + LyXTextClass const & tclass = textclasslist[params.textclass]; combo_doc_class->select_text( textclasslist.DescOfClass(params.textclass)); diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index ba9365dfc0..7ec907ed72 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,12 @@ +2002-03-02 Lars Gullik Bjønnes + + * Toolbar_pimpl.[Ch]: layout as string + + * FormParagraph.C: layout as string + + * FormDocument.C (build): use remove_if and contains_functor + layout as string + 2002-03-01 Martin Vermeer * FormMathsBitmap.[Ch]: diff --git a/src/frontends/xforms/FormDocument.C b/src/frontends/xforms/FormDocument.C index 7e91036be9..f37303d53b 100644 --- a/src/frontends/xforms/FormDocument.C +++ b/src/frontends/xforms/FormDocument.C @@ -48,8 +48,13 @@ #include "support/filetools.h" #include "support/lstrings.h" +#include + +using std::bind2nd; + using Liason::setMinibuffer; using SigC::slot; +using std::vector; FormDocument::FormDocument(LyXView * lv, Dialogs * d) : FormBaseBD(lv, d, _("Document Layout")), @@ -122,12 +127,20 @@ void FormDocument::build() // Create the contents of the unit choices // Don't include the "%" terms... - std::vector units_vec = getLatexUnits(); - for (std::vector::iterator it = units_vec.begin(); + vector units_vec = getLatexUnits(); +#if 0 + for (vector::iterator it = units_vec.begin(); it != units_vec.end(); ++it) { if (contains(*it, "%")) it = units_vec.erase(it, it+1) - 1; } +#else + vector::iterator ret = + remove_if(units_vec.begin(), + units_vec.end(), + bind2nd(contains_functor(), "%")); + units_vec.erase(ret, units_vec.end()); +#endif string units = getStringFromVector(units_vec, "|"); fl_addto_choice(paper_->choice_custom_width_units, units.c_str()); @@ -724,7 +737,7 @@ bool FormDocument::class_apply() if (params.textclass != old_class) { // try to load new_class - if (textclasslist.Load(params.textclass)) { + if (textclasslist[params.textclass].load()) { // successfully loaded redo = true; setMinibuffer(lv_, _("Converting document to new document class...")); @@ -734,7 +747,7 @@ bool FormDocument::class_apply() lv_->buffer()->params); if (ret) { string s; - if (ret==1) { + if (ret == 1) { s = _("One paragraph couldn't be converted"); } else { s += tostr(ret); @@ -932,10 +945,9 @@ void FormDocument::class_update(BufferParams const & params) if (!class_.get()) return; - LyXTextClass const & tclass = textclasslist.TextClass(params.textclass); + LyXTextClass const & tclass = textclasslist[params.textclass]; - combo_doc_class->select( - textclasslist.DescOfClass(params.textclass)); + combo_doc_class->select(tclass.description()); fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str()); fl_clear_choice(class_->choice_doc_fontsize); fl_addto_choice(class_->choice_doc_fontsize, "default"); @@ -1416,7 +1428,7 @@ void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long) lv_->prohibitInput(); unsigned int tc = combo_doc_class->get() - 1; - if (textclasslist.Load(tc)) { + if (textclasslist[tc].load()) { // we use a copy of the bufferparams because we do not // want to modify them yet. BufferParams params = lv_->buffer()->params; diff --git a/src/frontends/xforms/FormParagraph.C b/src/frontends/xforms/FormParagraph.C index ee44289c94..648114776a 100644 --- a/src/frontends/xforms/FormParagraph.C +++ b/src/frontends/xforms/FormParagraph.C @@ -331,10 +331,11 @@ void FormParagraph::update() fl_set_button(dialog_->radio_align_center, 0); fl_set_button(dialog_->radio_align_block, 0); + LyXTextClass const & tclass = textclasslist[buf->params.textclass]; + int align = par_->getAlign(); if (align == LYX_ALIGN_LAYOUT) - align = textclasslist.Style(buf->params.textclass, - par_->getLayout()).align; + align = tclass[par_->layout()].align; switch (align) { case LYX_ALIGN_RIGHT: @@ -351,9 +352,7 @@ void FormParagraph::update() break; } - LyXAlignment alignpos = - textclasslist.Style(buf->params.textclass, - par_->getLayout()).alignpossible; + LyXAlignment alignpos = tclass[par_->layout()].alignpossible; setEnabled(dialog_->radio_align_block, bool(alignpos & LYX_ALIGN_BLOCK)); setEnabled(dialog_->radio_align_center, bool(alignpos & LYX_ALIGN_CENTER)); diff --git a/src/frontends/xforms/Toolbar_pimpl.C b/src/frontends/xforms/Toolbar_pimpl.C index 6bf013398c..3785955688 100644 --- a/src/frontends/xforms/Toolbar_pimpl.C +++ b/src/frontends/xforms/Toolbar_pimpl.C @@ -234,8 +234,7 @@ void Toolbar::Pimpl::layoutSelected() { string const & layoutguiname = combox->getline(); LyXTextClass const & tc = - textclasslist.TextClass(owner->buffer()-> - params.textclass); + textclasslist[owner->buffer()->params.textclass]; LyXTextClass::const_iterator end = tc.end(); for (LyXTextClass::const_iterator cit = tc.begin(); @@ -250,12 +249,11 @@ void Toolbar::Pimpl::layoutSelected() } -void Toolbar::Pimpl::setLayout(int layout) +void Toolbar::Pimpl::setLayout(string const & layout) { if (combox) { LyXTextClass const & tc = - textclasslist.TextClass(owner->buffer()-> - params.textclass); + textclasslist[owner->buffer()->params.textclass]; combox->select(_(tc[layout].name())); } } @@ -270,8 +268,7 @@ void Toolbar::Pimpl::updateLayoutList(bool force) if (combox->empty() || force) { combox->clear(); LyXTextClass const & tc = - textclasslist.TextClass(owner->buffer()-> - params.textclass); + textclasslist[owner->buffer()->params.textclass]; LyXTextClass::const_iterator end = tc.end(); for (LyXTextClass::const_iterator cit = tc.begin(); cit != end; ++cit) { diff --git a/src/frontends/xforms/Toolbar_pimpl.h b/src/frontends/xforms/Toolbar_pimpl.h index 6eea76f594..5bdaba476b 100644 --- a/src/frontends/xforms/Toolbar_pimpl.h +++ b/src/frontends/xforms/Toolbar_pimpl.h @@ -61,9 +61,8 @@ public: /// update the state of the icons void update(); - /// select the right layout in the combox - void setLayout(int layout); + void setLayout(string const & layout); /// Populate the layout combox; re-do everything if force is true. void updateLayoutList(bool force); /// Drop down the layout list diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 9b5e4ffa7c..1a1e7e2eeb 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,13 @@ +2002-03-02 Lars Gullik Bjønnes + + * insettext.C: layout as string + + * insetinclude.C: layout as string + + * insetert.C: layout as string + + * insetbib.C: layout as string + 2002-02-28 Angus Leeming * insetert.C: diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index d314ad7013..03f020b745 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -145,7 +145,7 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os, // 1. \bibliographystyle{style} // 2. \addcontentsline{...} - if option bibtotoc set // 3. \bibliography{database} - string adb, db_out; + string adb; string db_in = getContents(); db_in = split(db_in, adb, ','); @@ -174,7 +174,8 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os, // part of its name, because it's than book. // For the "official" lyx-layouts it's no problem to support // all well - if (!contains(textclasslist.NameOfClass(buffer->params.textclass),"art")) { + if (!contains(textclasslist[buffer->params.textclass].name(), + "art")) { if (buffer->params.sides == LyXTextClass::OneSide) { // oneside os << "\\clearpage"; @@ -196,6 +197,7 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os, // If we generate in a temp dir, we might need to give an // absolute path there. This is a bit complicated since we can // have a comma-separated list of bibliographies + string db_out; while (!adb.empty()) { if (!buffer->niceFile && IsFileReadable(MakeAbsPath(adb, buffer->filePath())+".bib")) diff --git a/src/insets/insetert.C b/src/insets/insetert.C index e02c92b616..53ada70eb0 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -199,8 +199,7 @@ void InsetERT::write(Buffer const * buf, ostream & os) const << "status "<< st << "\n"; //inset.writeParagraphData(buf, os); - string const layout = - textclasslist.NameOfLayout(buf->params.textclass, 0); + string const layout(textclasslist[buf->params.textclass].defaultLayoutName()); Paragraph * par = inset.paragraph(); while (par) { os << "\n\\layout " << layout << "\n"; @@ -453,7 +452,7 @@ InsetERT::localDispatch(BufferView * bv, kb_action action, string const & arg) switch (action) { case LFUN_LAYOUT: - bv->owner()->setLayout(inset.paragraph()->getLayout()); + bv->owner()->setLayout(inset.paragraph()->layout()); break; default: result = InsetCollapsable::localDispatch(bv, action, arg); diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 2e3e062714..f2e598dffc 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -242,9 +242,9 @@ int InsetInclude::latex(Buffer const * buffer, ostream & os, lyxerr << "WARNING: Included file `" << MakeDisplayPath(getFileName()) << "' has textclass `" - << textclasslist.NameOfClass(tmp->params.textclass) + << textclasslist[tmp->params.textclass].name() << "' while parent file has textclass `" - << textclasslist.NameOfClass(buffer->params.textclass) + << textclasslist[buffer->params.textclass].name() << "'." << endl; //return 0; } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 55f7759411..f22c7cf84e 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -65,7 +65,6 @@ using std::vector; using std::pair; using lyx::pos_type; -using lyx::layout_type; using lyx::textclass_type; extern unsigned char getCurrentTextClass(Buffer *); @@ -620,7 +619,7 @@ void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const bv->owner()->updateMenubar(); bv->owner()->updateToolbar(); if (old_par != cpar(bv)) { - bv->owner()->setLayout(cpar(bv)->getLayout()); + bv->owner()->setLayout(cpar(bv)->layout()); old_par = cpar(bv); } } @@ -749,9 +748,9 @@ void InsetText::insetUnlock(BufferView * bv) code = FULL; } else if (owner()) { bv->owner()->setLayout(owner()->getLyXText(bv) - ->cursor.par()->getLayout()); + ->cursor.par()->layout()); } else - bv->owner()->setLayout(bv->text->cursor.par()->getLayout()); + bv->owner()->setLayout(bv->text->cursor.par()->layout()); // hack for deleteEmptyParMech if (par->size()) { lt->setCursor(bv, par, 0); @@ -975,7 +974,7 @@ void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button) lt = 0; updateLocal(bv, CURSOR, false); } - bv->owner()->setLayout(cpar(bv)->getLayout()); + bv->owner()->setLayout(cpar(bv)->layout()); old_par = cpar(bv); // Insert primary selection with middle mouse // if there is a local selection in the current buffer, @@ -1320,39 +1319,40 @@ InsetText::localDispatch(BufferView * bv, case LFUN_LAYOUT: // do not set layouts on non breakable textinsets if (autoBreakRows) { - layout_type cur_layout = cpar(bv)->layout; + string cur_layout = cpar(bv)->layout(); // Derive layout number from given argument (string) // and current buffer's textclass (number). */ textclass_type tclass = bv->buffer()->params.textclass; - pair layout = - textclasslist.NumberOfLayout(tclass, arg); + string layout = lowercase(arg); + bool hasLayout = textclasslist[tclass].hasLayout(layout); // If the entry is obsolete, use the new one instead. - if (layout.first) { - string obs = textclasslist.Style(tclass,layout.second). + if (hasLayout) { + string const & obs = + textclasslist[tclass][layout]. obsoleted_by(); if (!obs.empty()) - layout = textclasslist.NumberOfLayout(tclass, obs); + layout = lowercase(obs); } // see if we found the layout number: - if (!layout.first) { + if (!hasLayout) { string const msg = string(N_("Layout ")) + arg + N_(" not known"); bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg); break; } - if (cur_layout != layout.second) { - cur_layout = layout.second; - lt->setLayout(bv, layout.second); - bv->owner()->setLayout(cpar(bv)->getLayout()); + if (cur_layout != layout) { + cur_layout = layout; + lt->setLayout(bv, layout); + bv->owner()->setLayout(cpar(bv)->layout()); updwhat = CURSOR_PAR; updflag = true; } } else { // reset the layout box - bv->owner()->setLayout(cpar(bv)->getLayout()); + bv->owner()->setLayout(cpar(bv)->layout()); } break; case LFUN_PARAGRAPH_SPACING: @@ -1469,8 +1469,7 @@ int InsetText::docbook(Buffer const * buf, ostream & os) const int desc_on = 0; // description mode LyXLayout const & style = - textclasslist.Style(buf->params.textclass, - p->layout); + textclasslist[buf->params.textclass][p->layout()]; // environment tag closing for (; depth > p->params().depth(); --depth) { @@ -1650,8 +1649,7 @@ void InsetText::validate(LaTeXFeatures & features) const int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const { - if (textclasslist.Style(buf->params.textclass, - p->getLayout()).labeltype != LABEL_MANUAL) + if (textclasslist[buf->params.textclass][p->layout()].labeltype != LABEL_MANUAL) return 0; else return p->beginningOfMainBody(); diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 7a1325803b..cc172ae59d 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -421,15 +421,13 @@ void MenuInsertLabel(BufferView * bv, string const & arg) bv->owner()->prohibitInput(); if (label.empty()) { Paragraph * par = bv->getLyXText()->cursor.par(); - LyXLayout const * layout = - &textclasslist.Style(bv->buffer()->params.textclass, - par->getLayout()); + LyXTextClass const & tclass = + textclasslist[bv->buffer()->params.textclass]; + LyXLayout const * layout = &tclass[par->layout()]; if (layout->latextype == LATEX_PARAGRAPH && par->previous()) { Paragraph * par2 = par->previous(); - LyXLayout const * layout2 = - &textclasslist.Style(bv->buffer()->params.textclass, - par2->getLayout()); + LyXLayout const * layout2 = &tclass[par2->layout()]; if (layout2->latextype != LATEX_PARAGRAPH) { par = par2; layout = layout2; diff --git a/src/lyxlayout.C b/src/lyxlayout.C index 0a35e05979..55e2cf0622 100644 --- a/src/lyxlayout.C +++ b/src/lyxlayout.C @@ -180,29 +180,44 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass) case LT_COPYSTYLE: // initialize with a known style if (lexrc.next()) { - if (tclass.hasLayout(lexrc.getString())) { - string const tmpname = name_; - this->operator= (tclass.GetLayout(lexrc.getString())); - name_ = tmpname; + string const style = lowercase(lexrc.getString()); + + if (tclass.hasLayout(style)) { + string const tmpname = lowercase(name_); + this->operator=(tclass[style]); + name_ = lowercase(tmpname); } else { - lexrc.printError("Cannot copy known " - "style `$$Token'"); + lyxerr << "Cannot copy unknown style `" << style << "'" << endl; + LyXTextClass::const_iterator it = tclass.begin(); + LyXTextClass::const_iterator end = tclass.end(); + lyxerr << "All layouts so far:" << endl; + for (; it != end; ++it) { + //lyxerr << it->name() << endl; + fprintf(stderr, "%s\n", it->name().c_str()); + } + + //lexrc.printError("Cannot copy known " + // "style `$$Token'"); } } break; case LT_OBSOLETEDBY: // replace with a known style if (lexrc.next()) { - if (tclass.hasLayout(lexrc.getString())) { + string const style = lowercase(lexrc.getString()); + + if (tclass.hasLayout(style)) { string const tmpname = name_; - this->operator= (tclass.GetLayout(lexrc.getString())); + this->operator=(tclass[style]); name_ = tmpname; if (obsoleted_by().empty()) - obsoleted_by_ = lexrc.getString(); + obsoleted_by_ = style; } else { - lexrc.printError("Cannot replace with" - " unknown style " - "`$$Token'"); + lyxerr << "Cannot replace with unknown style `" << style << "'" << endl; + + //lexrc.printError("Cannot replace with" + // " unknown style " + // "`$$Token'"); } } break; @@ -718,3 +733,25 @@ void LyXLayout::readSpacing(LyXLex & lexrc) break; } } + + +string const & LyXLayout::name() const +{ + static string name_t; + name_t = lowercase(name_); + return name_t; +} + + +void LyXLayout::setName(string const & n) +{ + name_ = lowercase(n); +} + + +string const & LyXLayout::obsoleted_by() const +{ + static string obsoleted_by_t; + obsoleted_by_t = lowercase(obsoleted_by_); + return obsoleted_by_t; +} diff --git a/src/lyxlayout.h b/src/lyxlayout.h index ef8dcbadf4..d0f79c7b96 100644 --- a/src/lyxlayout.h +++ b/src/lyxlayout.h @@ -28,10 +28,9 @@ class LyXTextClass; class LyXLayout { public: /// - LyXLayout (); - + LyXLayout(); /// - bool Read (LyXLex &, LyXTextClass const &); + bool Read(LyXLex &, LyXTextClass const &); /// void readAlign(LyXLex &); /// @@ -47,11 +46,11 @@ public: /// void readSpacing(LyXLex &); /// - string const & name() const { return name_; } + string const & name() const; /// - void setName(string const & n) { name_ = n; } + void setName(string const & n); /// - string const & obsoleted_by() const { return obsoleted_by_; } + string const & obsoleted_by() const; /// string const & latexname() const { return latexname_; } /// diff --git a/src/lyxtext.h b/src/lyxtext.h index b7da0fe71e..89ffc10999 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -115,11 +115,11 @@ public: those paragraphs */ Paragraph * setLayout(BufferView *, LyXCursor & actual_cursor, - LyXCursor & selection_start, - LyXCursor & selection_end, - lyx::layout_type layout); + LyXCursor & selection_start, + LyXCursor & selection_end, + string const & layout); /// - void setLayout(BufferView *, lyx::layout_type layout); + void setLayout(BufferView *, string const & layout); /// used in setlayout void makeFontEntriesLayoutSpecific(Buffer const *, Paragraph * par); @@ -514,8 +514,7 @@ private: Asger has learned that this should be a buffer-property instead Lgb has learned that 'char' is a lousy type for non-characters */ - lyx::layout_type copylayouttype; - + string copylayouttype; /** inserts a new row behind the specified row, increments the touched counters */ void insertRow(Row * row, Paragraph * par, lyx::pos_type pos) const; diff --git a/src/lyxtextclass.C b/src/lyxtextclass.C index e449feaa66..cefc00a93b 100644 --- a/src/lyxtextclass.C +++ b/src/lyxtextclass.C @@ -79,6 +79,7 @@ enum TextClassTags { TC_OUTPUTTYPE = 1, TC_INPUT, TC_STYLE, + TC_DEFAULTSTYLE, TC_NOSTYLE, TC_COLUMNS, TC_SIDES, @@ -104,6 +105,7 @@ bool LyXTextClass::Read(string const & filename, bool merge) { "classoptions", TC_CLASSOPTIONS }, { "columns", TC_COLUMNS }, { "defaultfont", TC_DEFAULTFONT }, + { "defaultstyle", TC_DEFAULTSTYLE }, { "input", TC_INPUT }, { "leftmargin", TC_LEFTMARGIN }, { "maxcounter", TC_MAXCOUNTER }, @@ -168,12 +170,19 @@ bool LyXTextClass::Read(string const & filename, bool merge) } break; + case TC_DEFAULTSTYLE: + if (lexrc.next()) { + string const name = subst(lowercase(lexrc.getString()), '_', ' '); + defaultlayout_ = name; + } + break; + case TC_STYLE: if (lexrc.next()) { - string name = subst(lexrc.getString(), + string const name = subst(lowercase(lexrc.getString()), '_', ' '); if (hasLayout(name)) { - LyXLayout & lay = GetLayout(name); + LyXLayout & lay = operator[](name); error = do_readStyle(lexrc, lay); } else { LyXLayout lay; @@ -190,11 +199,12 @@ bool LyXTextClass::Read(string const & filename, bool merge) case TC_NOSTYLE: if (lexrc.next()) { - string const style = subst(lexrc.getString(), + string const style = subst(lowercase(lexrc.getString()), '_', ' '); if (!delete_layout(style)) - lexrc.printError("Cannot delete style" - " `$$Token'"); + lyxerr << "Cannot delete style `" << style << "'" << endl; +// lexrc.printError("Cannot delete style" +// " `$$Token'"); } break; @@ -291,6 +301,11 @@ bool LyXTextClass::Read(string const & filename, bool merge) lyxerr[Debug::TCLASS] << "Finished reading textclass " << MakeDisplayPath(filename) << endl; + if (defaultlayout_.empty()) { + lyxerr << "Error: Textclass '" << name_ + << "' is missing a defaultstyle." << endl; + error = true; + } } else lyxerr[Debug::TCLASS] << "Finished reading input file " << MakeDisplayPath(filename) @@ -470,38 +485,73 @@ string const & LyXTextClass::rightmargin() const } -bool LyXTextClass::hasLayout(string const & name) const +bool LyXTextClass::hasLayout(string const & n) const { + string const name = (n.empty() ? defaultLayoutName() : lowercase(n)); + return find_if(layoutlist.begin(), layoutlist.end(), lyx::compare_memfun(&LyXLayout::name, name)) != layoutlist.end(); } -LyXLayout const & LyXTextClass::GetLayout (string const & name) const +LyXLayout const & LyXTextClass::operator[](string const & n) const { + if (n.empty()) + lyxerr << "Operator[] called with empty n" << endl; + + string const name = (n.empty() ? defaultLayoutName() : lowercase(n)); + LayoutList::const_iterator cit = find_if(layoutlist.begin(), layoutlist.end(), lyx::compare_memfun(&LyXLayout::name, name)); - lyx::Assert(cit != layoutlist.end()); // we require the name to exist - return (*cit); + + if (cit == layoutlist.end()) { + lyxerr << "We failed to find the layout '" << name + << "' in the layout list. You MUST investigate!" + << endl; + + // we require the name to exist + lyx::Assert(false); + } + + return *cit; } -LyXLayout & LyXTextClass::GetLayout(string const & name) +LyXLayout & LyXTextClass::operator[](string const & n) { + if (n.empty()) + lyxerr << "Operator[] called with empty n" << endl; + + string const name = (n.empty() ? defaultLayoutName() : lowercase(n)); + LayoutList::iterator it = find_if(layoutlist.begin(), layoutlist.end(), lyx::compare_memfun(&LyXLayout::name, name)); - lyx::Assert(it != layoutlist.end()); // we require the name to exist - return (*it); + + if (it == layoutlist.end()) { + lyxerr << "We failed to find the layout '" << name + << "' in the layout list. You MUST investigate!" + << endl; + + // we require the name to exist + lyx::Assert(false); + } + + return *it; } -bool LyXTextClass::delete_layout(string const & name) +bool LyXTextClass::delete_layout(string const & n) { + string const name = lowercase(n); + + if (name == defaultLayoutName()) + return false; + LayoutList::iterator it = remove_if(layoutlist.begin(), layoutlist.end(), lyx::compare_memfun(&LyXLayout::name, name)); @@ -513,21 +563,141 @@ bool LyXTextClass::delete_layout(string const & name) // Load textclass info if not loaded yet -void LyXTextClass::load() +bool LyXTextClass::load() const { - if (loaded) return; + if (loaded) + return true; // Read style-file string const real_file = LibFileSearch("layouts", name_, "layout"); - if (Read(real_file)) { + if (const_cast(this)->Read(real_file)) { lyxerr << "Error reading `" << MakeDisplayPath(real_file) << "'\n(Check `" << name_ << "')\nCheck your installation and " "try Options/Reconfigure..." << endl; + loaded = false; } loaded = true; + return loaded; + +} + + +string const LyXTextClass::defaultLayoutName() const +{ + // This really should come from the actual layout... (Lgb) + return defaultlayout_; +} + + +LyXLayout const & LyXTextClass::defaultLayout() const +{ + return operator[](defaultLayoutName()); +} + + +LyXLayout & LyXTextClass::defaultLayout() +{ + return operator[](defaultLayoutName()); +} + + +string const & LyXTextClass::name() const +{ + return name_; +} + + +string const & LyXTextClass::latexname() const +{ + const_cast(this)->load(); + return latexname_; +} + + +string const & LyXTextClass::description() const +{ + return description_; +} + + +string const & LyXTextClass::opt_fontsize() const +{ + return opt_fontsize_; +} + + +string const & LyXTextClass::opt_pagestyle() const +{ + return opt_pagestyle_; +} + + +string const & LyXTextClass::options() const +{ + return options_; +} + + +string const & LyXTextClass::pagestyle() const +{ + return pagestyle_; +} + + +string const & LyXTextClass::preamble() const +{ + return preamble_; +} + + +LyXTextClass::PageSides LyXTextClass::sides() const +{ + return sides_; +} + + +int LyXTextClass::secnumdepth() const +{ + return secnumdepth_; +} + + +int LyXTextClass::tocdepth() const +{ + return tocdepth_; +} + + +OutputType LyXTextClass::outputType() const +{ + return outputType_; +} + + +bool LyXTextClass::provides(LyXTextClass::Provides p) const +{ + return provides_ & p; +} + + +unsigned int LyXTextClass::columns() const +{ + return columns_; +} + + +int LyXTextClass::maxcounter() const +{ + return maxcounter_; +} + + +int LyXTextClass::size() const +{ + return layoutlist.size(); } diff --git a/src/lyxtextclass.h b/src/lyxtextclass.h index 1053fa805f..c5fddbec37 100644 --- a/src/lyxtextclass.h +++ b/src/lyxtextclass.h @@ -58,30 +58,36 @@ public: bool hasLayout(string const & name) const; /// - LyXLayout const & GetLayout(string const & vname) const; + LyXLayout const & operator[](string const & vname) const; /// - LyXLayout & GetLayout(string const & vname); + LyXLayout & operator[](string const & vname); /// Sees to that the textclass structure has been loaded - void load(); + bool load() const; /// - string const & name() const { return name_; } + string const defaultLayoutName() const; /// - string const & latexname() const { return latexname_; } + LyXLayout const & defaultLayout() const; /// - string const & description() const { return description_; } + LyXLayout & defaultLayout(); /// - string const & opt_fontsize() const { return opt_fontsize_; } + string const & name() const; /// - string const & opt_pagestyle() const { return opt_pagestyle_; } + string const & latexname() const; /// - string const & options() const { return options_; } + string const & description() const; /// - string const & pagestyle() const { return pagestyle_; } + string const & opt_fontsize() const; /// - string const & preamble() const { return preamble_; } + string const & opt_pagestyle() const; + /// + string const & options() const; + /// + string const & pagestyle() const; + /// + string const & preamble() const; /// Packages that are already loaded by the class enum Provides { @@ -95,10 +101,10 @@ public: url = 4 }; /// - bool provides(Provides p) const { return provides_ & p; } + bool provides(Provides p) const; /// - unsigned int columns() const { return columns_; } + unsigned int columns() const; /// enum PageSides { /// @@ -107,14 +113,14 @@ public: TwoSides }; /// - PageSides sides() const { return sides_; } + PageSides sides() const; /// - int secnumdepth() const { return secnumdepth_; } + int secnumdepth() const; /// - int tocdepth() const { return tocdepth_; } + int tocdepth() const; /// - OutputType outputType() const { return outputType_; } + OutputType outputType() const; /// LyXFont const & defaultfont() const; @@ -125,13 +131,9 @@ public: /// Text that dictates how wide the right margin is on the screen string const & rightmargin() const; /// - int maxcounter() const { return maxcounter_; } + int maxcounter() const; /// - lyx::layout_type numLayouts() const { return layoutlist.size(); } - /// - LyXLayout const & operator[](lyx::layout_type i) const { - return layoutlist[i]; - } + int size() const; private: /// bool delete_layout(string const &); @@ -152,6 +154,8 @@ private: /// string pagestyle_; /// + string defaultlayout_; + /// string preamble_; /// Provides provides_; @@ -183,9 +187,10 @@ private: LayoutList layoutlist; /// Has this layout file been loaded yet? - bool loaded; + mutable bool loaded; }; + /// inline void operator|=(LyXTextClass::Provides & p1, LyXTextClass::Provides p2) diff --git a/src/lyxtextclasslist.C b/src/lyxtextclasslist.C index 9c1c447d1b..79f0c3b117 100644 --- a/src/lyxtextclasslist.C +++ b/src/lyxtextclasslist.C @@ -29,7 +29,6 @@ #include -using lyx::layout_type; using lyx::textclass_type; using std::pair; using std::make_pair; @@ -51,88 +50,9 @@ LyXTextClassList::NumberOfClass(string const & textclass) const } -// Gets layout structure from style number and textclass number -LyXLayout const & -LyXTextClassList::Style(textclass_type textclass, - layout_type layout) const -{ - classlist[textclass].load(); - if (layout < classlist[textclass].numLayouts()) - return classlist[textclass][layout]; - return classlist[textclass][0]; -} - - -// Gets layout number from name and textclass number -pair const -LyXTextClassList::NumberOfLayout(textclass_type textclass, - string const & name) const -{ - classlist[textclass].load(); - for (unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) { - if (classlist[textclass][i].name() == name) - return make_pair(true, i); - } - return make_pair(false, layout_type(0)); // not found -} - - -// Gets a layout (style) name from layout number and textclass number -string const & -LyXTextClassList::NameOfLayout(textclass_type textclass, - layout_type layout) const -{ - static string const dummy("dummy"); - classlist[textclass].load(); - if (layout < classlist[textclass].numLayouts()) - return classlist[textclass][layout].name(); - return dummy; -} - - -// Gets a textclass name from number -string const & -LyXTextClassList::NameOfClass(textclass_type number) const -{ - static string const dummy("dummy"); - if (classlist.empty()) { - return dummy; - } - lyx::Assert(number < classlist.size()); - return classlist[number].name(); -} - - -// Gets a textclass latexname from number -string const & -LyXTextClassList::LatexnameOfClass(textclass_type number) const -{ - static string const dummy("dummy"); - classlist[number].load(); - if (classlist.empty()) { - return dummy; - } - lyx::Assert(number < classlist.size()); - return classlist[number].latexname(); -} - - -// Gets a textclass description from number -string const & -LyXTextClassList::DescOfClass(textclass_type number) const -{ - static string const dummy("dummy"); - if (classlist.empty()) { - return dummy; - } - lyx::Assert(number < classlist.size()); - return classlist[number].description(); -} - - // Gets a textclass structure from number LyXTextClass const & -LyXTextClassList::TextClass(textclass_type textclass) const +LyXTextClassList::operator[](textclass_type textclass) const { classlist[textclass].load(); if (textclass < classlist.size()) @@ -244,24 +164,6 @@ bool LyXTextClassList::Read () return true; } - -/* Load textclass - Returns false if this fails -*/ -bool LyXTextClassList::Load(textclass_type number) const -{ - bool result = true; - if (number < classlist.size()) { - classlist[number].load(); - if (classlist[number].numLayouts() == 0) { - result = false; - } - } else { - result = false; - } - return result; -} - // Global variable: textclass table. LyXTextClassList textclasslist; diff --git a/src/lyxtextclasslist.h b/src/lyxtextclasslist.h index 015bdda5cc..0865670745 100644 --- a/src/lyxtextclasslist.h +++ b/src/lyxtextclasslist.h @@ -41,18 +41,6 @@ public: const_iterator begin() const { return classlist.begin(); } /// const_iterator end() const { return classlist.end(); } - - /// Gets layout structure from layout number and textclass number - LyXLayout const & Style(lyx::textclass_type textclass, - lyx::layout_type layout) const; - - /// Gets layout number from textclass number and layout name - std::pair const - NumberOfLayout(lyx::textclass_type textclass, string const & name) const; - - /// Gets a layout name from layout number and textclass number - string const & - NameOfLayout(lyx::textclass_type textclass, lyx::layout_type layout) const; /** Gets textclass number from name. Returns -1 if textclass name does not exist @@ -61,31 +49,17 @@ public: NumberOfClass(string const & textclass) const; /// - string const & NameOfClass(lyx::textclass_type number) const; - - /// - string const & LatexnameOfClass(lyx::textclass_type number) const; - - /// - string const & DescOfClass(lyx::textclass_type number) const; - - /// - LyXTextClass const & TextClass(lyx::textclass_type textclass) const; + LyXTextClass const & operator[](lyx::textclass_type textclass) const; /** Read textclass list. Returns false if this fails */ bool Read(); - - /** Load textclass. - Returns false if this fails - */ - bool Load(lyx::textclass_type number) const; private: /// mutable ClassList classlist; /// - void Add (LyXTextClass const &); + void Add(LyXTextClass const &); }; /// diff --git a/src/paragraph.C b/src/paragraph.C index 68445688ca..e8fb22e4f3 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -55,7 +55,6 @@ using std::upper_bound; using std::reverse; using lyx::pos_type; -using lyx::layout_type; int tex_code_break_column = 72; // needs non-zero initialization. set later. // this is a bad idea, but how can Paragraph find its buffer to get @@ -78,7 +77,7 @@ extern BufferView * current_view; Paragraph::Paragraph() - : layout(0), pimpl_(new Paragraph::Pimpl(this)) + : pimpl_(new Paragraph::Pimpl(this)) { for (int i = 0; i < 10; ++i) setCounter(i, 0); @@ -93,7 +92,7 @@ Paragraph::Paragraph() // This constructor inserts the new paragraph in a list. Paragraph::Paragraph(Paragraph * par) - : layout(0), pimpl_(new Paragraph::Pimpl(this)) + : pimpl_(new Paragraph::Pimpl(this)) { for (int i = 0; i < 10; ++i) setCounter(i, 0); @@ -115,7 +114,7 @@ Paragraph::Paragraph(Paragraph * par) Paragraph::Paragraph(Paragraph const & lp, bool same_ids) - : layout(0), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids)) + : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids)) { for (int i = 0; i < 10; ++i) setCounter(i, 0); @@ -126,7 +125,7 @@ Paragraph::Paragraph(Paragraph const & lp, bool same_ids) // this is because of the dummy layout of the paragraphs that // follow footnotes - layout = lp.layout; + layout_ = lp.layout(); // ale970302 if (lp.bibkey) { @@ -191,9 +190,7 @@ void Paragraph::writeFile(Buffer const * buf, ostream & os, } // First write the layout - os << "\n\\layout " - << textclasslist.NameOfLayout(bparams.textclass, layout) - << "\n"; + os << "\n\\layout " << layout() << "\n"; // Maybe some vertical spaces. if (params().spaceTop().kind() != VSpace::NONE) @@ -341,7 +338,7 @@ void Paragraph::validate(LaTeXFeatures & features) const features.require("setspace"); // then the layouts - features.useLayout(getLayout()); + features.useLayout(layout()); // then the fonts Language const * doc_language = bparams.language; @@ -388,14 +385,13 @@ void Paragraph::validate(LaTeXFeatures & features) const } // then the insets - LyXLayout const & layout = - textclasslist.Style(bparams.textclass, getLayout()); + LyXLayout const & lout = textclasslist[bparams.textclass][layout()]; for (InsetList::const_iterator cit = insetlist.begin(); cit != insetlist.end(); ++cit) { if (cit->inset) { cit->inset->validate(features); - if (layout.needprotect && + if (lout.needprotect && cit->inset->lyxCode() == Inset::FOOT_CODE) features.require("NeedLyXFootnoteCode"); } @@ -480,8 +476,9 @@ bool Paragraph::insertFromMinibuffer(pos_type pos) void Paragraph::clear() { params().clear(); - - layout = 0; + + layout_.erase(); + bibkey = 0; } @@ -634,18 +631,17 @@ LyXFont const Paragraph::getFont(BufferParams const & bparams, { lyx::Assert(pos >= 0); - LyXLayout const & layout = - textclasslist.Style(bparams.textclass, - getLayout()); + LyXLayout const & lout = + textclasslist[bparams.textclass][layout()]; pos_type main_body = 0; - if (layout.labeltype == LABEL_MANUAL) + if (lout.labeltype == LABEL_MANUAL) main_body = beginningOfMainBody(); LyXFont layoutfont; if (pos < main_body) - layoutfont = layout.labelfont; + layoutfont = lout.labelfont; else - layoutfont = layout.font; + layoutfont = lout.font; LyXFont tmpfont = getFontSettings(bparams, pos); #ifndef INHERIT_LANGUAGE @@ -660,10 +656,10 @@ LyXFont const Paragraph::getFont(BufferParams const & bparams, LyXFont const Paragraph::getLabelFont(BufferParams const & bparams) const { - LyXLayout const & layout = - textclasslist.Style(bparams.textclass, getLayout()); + LyXLayout const & lout = + textclasslist[bparams.textclass][layout()]; - LyXFont tmpfont = layout.labelfont; + LyXFont tmpfont = lout.labelfont; tmpfont.setLanguage(getParLanguage(bparams)); return pimpl_->realizeFont(tmpfont, bparams); @@ -672,11 +668,10 @@ LyXFont const Paragraph::getLabelFont(BufferParams const & bparams) const LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams) const { - LyXLayout const & layout = - textclasslist.Style(bparams.textclass, - getLayout()); + LyXLayout const & lout = + textclasslist[bparams.textclass][layout()]; - LyXFont tmpfont = layout.font; + LyXFont tmpfont = lout.font; tmpfont.setLanguage(getParLanguage(bparams)); return pimpl_->realizeFont(tmpfont, bparams); @@ -872,12 +867,12 @@ void Paragraph::breakParagraph(BufferParams const & bparams, // layout stays the same with latex-environments if (flag) { - tmp->setOnlyLayout(layout); + tmp->layout(layout()); tmp->setLabelWidthString(params().labelWidthString()); } if (size() > pos || !size() || flag == 2) { - tmp->setOnlyLayout(layout); + tmp->layout(layout()); tmp->params().align(params().align()); tmp->setLabelWidthString(params().labelWidthString()); @@ -915,7 +910,7 @@ void Paragraph::breakParagraph(BufferParams const & bparams, clear(); // layout stays the same with latex-environments if (flag) { - setOnlyLayout(tmp->layout); + layout(tmp->layout()); setLabelWidthString(tmp->params().labelWidthString()); params().depth(tmp->params().depth()); } @@ -925,7 +920,7 @@ void Paragraph::breakParagraph(BufferParams const & bparams, void Paragraph::makeSameLayout(Paragraph const * par) { - layout = par->layout; + layout(par->layout()); // move to pimpl? params() = par->params(); } @@ -933,9 +928,8 @@ void Paragraph::makeSameLayout(Paragraph const * par) int Paragraph::stripLeadingSpaces(lyx::textclass_type tclass) { - if (textclasslist.Style(tclass, getLayout()).free_spacing || - isFreeSpacing()) - { + if (textclasslist[tclass][layout()].free_spacing || + isFreeSpacing()) { return 0; } @@ -952,7 +946,7 @@ int Paragraph::stripLeadingSpaces(lyx::textclass_type tclass) bool Paragraph::hasSameLayout(Paragraph const * par) const { return - par->layout == layout && + par->layout() == layout() && params().sameLayout(par->params()); } @@ -1022,10 +1016,9 @@ int Paragraph::getEndLabel(BufferParams const & bparams) const Paragraph const * par = this; depth_type par_depth = getDepth(); while (par) { - layout_type layout = par->getLayout(); + string const & layout = par->layout(); int const endlabeltype = - textclasslist.Style(bparams.textclass, - layout).endlabeltype; + textclasslist[bparams.textclass][layout].endlabeltype; if (endlabeltype != END_LABEL_NO_LABEL) { if (!next_) return endlabeltype; @@ -1033,7 +1026,7 @@ int Paragraph::getEndLabel(BufferParams const & bparams) const depth_type const next_depth = next_->getDepth(); if (par_depth > next_depth || (par_depth == next_depth - && layout != next_->getLayout())) + && layout != next_->layout())) return endlabeltype; break; } @@ -1055,8 +1048,7 @@ Paragraph::depth_type Paragraph::getDepth() const Paragraph::depth_type Paragraph::getMaxDepthAfter(Buffer const * buffer) const { - const bool isenv = textclasslist.Style(buffer->params.textclass, - getLayout()).isEnvironment(); + bool const isenv = textclasslist[buffer->params.textclass][layout()].isEnvironment(); if (isenv) return params().depth() + 1; @@ -1099,15 +1091,9 @@ void Paragraph::setLabelWidthString(string const & s) } -void Paragraph::setOnlyLayout(layout_type new_layout) -{ - layout = new_layout; -} - - -void Paragraph::setLayout(layout_type new_layout) +void Paragraph::applyLayout(string const & new_layout) { - layout = new_layout; + layout(new_layout); params().labelWidthString(string()); params().align(LYX_ALIGN_LAYOUT); params().spaceTop(VSpace(VSpace::NONE)); @@ -1246,7 +1232,7 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf, // any special options in the paragraph and also we don't allow // any environment other then "Standard" to be valid! if ((in == 0) || !in->forceDefaultParagraphs(in)) { - style = textclasslist.Style(bparams.textclass, layout); + style = textclasslist[bparams.textclass][layout()]; if (params().startOfAppendix()) { os << "\\appendix\n"; @@ -1284,7 +1270,7 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf, texrow.newline(); } } else { - style = textclasslist.Style(bparams.textclass, 0); + style = textclasslist[bparams.textclass].defaultLayout(); } Language const * language = getParLanguage(bparams); @@ -1295,7 +1281,7 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf, if (language->babel() != previous_language->babel() // check if we already put language command in TeXEnvironment() && !(style.isEnvironment() - && (!previous() || previous()->layout != layout || + && (!previous() || previous()->layout() != layout() || previous()->params().depth() != params().depth()))) { if (!lyxrc.language_command_end.empty() && @@ -1382,7 +1368,7 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf, // if its the last paragraph of the current environment // skip it otherwise fall through if (next_ - && (next_->layout != layout + && (next_->layout() != layout() || next_->params().depth() != params().depth())) break; // fall through possible @@ -1554,9 +1540,9 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf, (inInset() && inInset()->forceDefaultParagraphs(inInset())); if (asdefault) { - style = textclasslist.Style(bparams.textclass, 0); + style = textclasslist[bparams.textclass].defaultLayout(); } else { - style = textclasslist.Style(bparams.textclass, layout); + style = textclasslist[bparams.textclass][layout()]; } LyXFont basefont; @@ -1805,8 +1791,7 @@ Paragraph * Paragraph::TeXEnvironment(Buffer const * buf, lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl; LyXLayout const & style = - textclasslist.Style(bparams.textclass, - layout); + textclasslist[bparams.textclass][layout()]; Language const * language = getParLanguage(bparams); Language const * doc_language = bparams.language; @@ -1853,8 +1838,7 @@ Paragraph * Paragraph::TeXEnvironment(Buffer const * buf, par = par->TeXOnePar(buf, bparams, os, texrow, false); if (par && par->params().depth() > params().depth()) { - if (textclasslist.Style(bparams.textclass, - par->layout).isParagraph() + if (textclasslist[bparams.textclass][par->layout()].isParagraph() // Thinko! // How to handle this? (Lgb) //&& !suffixIs(os, "\n\n") @@ -1875,7 +1859,7 @@ Paragraph * Paragraph::TeXEnvironment(Buffer const * buf, par = par->pimpl_->TeXDeeper(buf, bparams, os, texrow); } } while (par - && par->layout == layout + && par->layout() == layout() && par->params().depth() == params().depth()); if (style.isEnvironment()) { @@ -2130,9 +2114,15 @@ void Paragraph::id(int id_arg) } -layout_type Paragraph::getLayout() const +string const & Paragraph::layout() const +{ + return layout_; +} + + +void Paragraph::layout(string const & new_layout) { - return layout; + layout_ = new_layout; } @@ -2140,7 +2130,7 @@ bool Paragraph::isFirstInSequence() const { Paragraph const * dhook = depthHook(getDepth()); return (dhook == this - || dhook->getLayout() != getLayout() + || dhook->layout() != layout() || dhook->getDepth() != getDepth()); } diff --git a/src/paragraph.h b/src/paragraph.h index accc89ef35..3a6999528e 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -167,8 +167,10 @@ public: void clearContents(); /// - lyx::layout_type layout; - + string const & layout() const; + /// + void layout(string const & new_layout); + /// void setCounter(int i, int v); /// @@ -218,17 +220,13 @@ public: /// void setLabelWidthString(string const & s); /// - lyx::layout_type getLayout() const; - /// char getAlign() const; /// The nesting depth of a paragraph depth_type getDepth() const; /// The maximal possible depth of a paragraph after this one depth_type getMaxDepthAfter(Buffer const *) const; /// - void setLayout(lyx::layout_type new_layout); - /// - void setOnlyLayout(lyx::layout_type new_layout); + void applyLayout(string const & new_layout); /// int getFirstCounter(int i) const; /// @@ -347,7 +345,8 @@ public: ParagraphParameters & params(); ParagraphParameters const & params() const; private: - + /// + string layout_; /// struct InsetTable { /// diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index aaa4125d38..c223c72785 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -521,8 +521,7 @@ Paragraph * Paragraph::Pimpl::TeXDeeper(Buffer const * buf, Paragraph * par = owner_; while (par && par->params().depth() == owner_->params().depth()) { - if (textclasslist.Style(bparams.textclass, - par->layout).isEnvironment()) { + if (textclasslist[bparams.textclass][par->layout()].isEnvironment()) { par = par->TeXEnvironment(buf, bparams, os, texrow); } else { @@ -557,12 +556,12 @@ LyXFont const Paragraph::Pimpl::realizeFont(LyXFont const & font, // check for environment font information char par_depth = owner_->getDepth(); Paragraph const * par = owner_; + LyXTextClass const & tclass = textclasslist[bparams.textclass]; + while (par && par->getDepth() && !tmpfont.resolved()) { par = par->outerHook(); if (par) { - tmpfont.realize(textclasslist. - Style(bparams.textclass, - par->getLayout()).font + tmpfont.realize(tclass[par->layout()].font #ifdef INHERIT_LANGUAGE , bparams.language #endif @@ -571,8 +570,7 @@ LyXFont const Paragraph::Pimpl::realizeFont(LyXFont const & font, } } - tmpfont.realize(textclasslist.TextClass(bparams.textclass) - .defaultfont() + tmpfont.realize(tclass.defaultfont() #ifdef INHERIT_LANGUAGE , bparams.language #endif diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 72e7b400e7..16adb24bfb 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,7 @@ +2002-03-02 Lars Gullik Bjønnes + + * types.h: remove layout_type + 2002-03-01 Angus Leeming * filetools.C (getExtFromContents): cleanup. diff --git a/src/support/types.h b/src/support/types.h index f7dfad62fe..ad8fe03b62 100644 --- a/src/support/types.h +++ b/src/support/types.h @@ -23,10 +23,6 @@ namespace lyx /// a type for sizes typedef std::vector::size_type size_type; - /// a type used for numbering layouts within a text class - // used to be LyXTextClass::size_type - typedef std::vector::size_type layout_type; - /// a type used for numbering text classes // used to be LyXTextClassList::size_type typedef std::vector::size_type textclass_type; @@ -48,22 +44,6 @@ namespace lyx private: base_type data_; }; - - - struct layout_type { - /// - typedef std::vector::size_type base_type; - /// - layout_type(base_type t) { data_ = t; } - /// - operator base_type() const { return data_; } - /// - void operator++() { ++data_; } - /// - private: - base_type data_; - }; - struct textclass_type { /// diff --git a/src/text.C b/src/text.C index bb38d17522..04152131f3 100644 --- a/src/text.C +++ b/src/text.C @@ -93,8 +93,7 @@ int LyXText::workWidth(BufferView * bview, Inset * inset) const } LyXLayout const & layout = - textclasslist.Style(bview->buffer()->params.textclass, - par->getLayout()); + textclasslist[bview->buffer()->params.textclass][par->layout()]; if (layout.margintype != MARGIN_RIGHT_ADDRESS_BOX) { // Optimization here: in most cases, the real row is @@ -681,8 +680,8 @@ void LyXText::draw(DrawRowParams & p, pos_type & vpos) int LyXText::leftMargin(BufferView * bview, Row const * row) const { LyXTextClass const & tclass = - textclasslist.TextClass(bview->buffer()->params.textclass); - LyXLayout const & layout = tclass[row->par()->getLayout()]; + textclasslist[bview->buffer()->params.textclass]; + LyXLayout const & layout = tclass[row->par()->layout()]; string parindent = layout.parindent; @@ -694,13 +693,13 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const // I have had this idea very late, so it seems to be a // later added hack and this is true if (!row->par()->getDepth()) { - if (!row->par()->getLayout()) { + if (row->par()->layout() == tclass.defaultLayoutName()) { // find the previous same level paragraph if (row->par()->previous()) { Paragraph * newpar = row->par() ->depthHook(row->par()->getDepth()); if (newpar && - tclass[newpar->getLayout()].nextnoindent) + tclass[newpar->layout()].nextnoindent) parindent.erase(); } } @@ -712,9 +711,8 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const // make a corresponding row. Needed to call LeftMargin() - // check wether it is a sufficent paragraph - if (newpar && tclass[newpar->getLayout()].isEnvironment()) - { + // check wether it is a sufficent paragraph + if (newpar && tclass[newpar->layout()].isEnvironment()) { Row dummyrow; dummyrow.par(newpar); dummyrow.pos(newpar->size()); @@ -726,14 +724,13 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const // LeftMargin() is always called row->par()->params().depth(0); } - - if (newpar && !row->par()->getLayout()) { + + if (newpar && row->par()->layout() == tclass.defaultLayoutName()) { if (newpar->params().noindent()) parindent.erase(); else - parindent = tclass[newpar->getLayout()].parindent; + parindent = tclass[newpar->layout()].parindent; } - } LyXFont const labelfont = getLabelFont(bview->buffer(), row->par()); @@ -839,26 +836,26 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const && !row->par()->params().noindent() // in tabulars paragraphs are never indented! && (!row->par()->inInset() || row->par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE) - && (row->par()->layout || + && (row->par()->layout() != tclass.defaultLayoutName() || bview->buffer()->params.paragraph_separation == - BufferParams::PARSEP_INDENT)) + BufferParams::PARSEP_INDENT)) { x += lyxfont::signedWidth(parindent, tclass.defaultfont()); - else if (layout.labeltype == LABEL_BIBLIO) { + } else if (layout.labeltype == LABEL_BIBLIO) { // ale970405 Right width for bibitems x += bibitemMaxWidth(bview, tclass.defaultfont()); } } + return x; } int LyXText::rightMargin(Buffer const * buf, Row const * row) const { - LyXTextClass const & tclass = - textclasslist.TextClass(buf->params.textclass); - LyXLayout const & layout = tclass[row->par()->getLayout()]; - + LyXTextClass const & tclass = textclasslist[buf->params.textclass]; + LyXLayout const & layout = tclass[row->par()->layout()]; + int x = LYX_PAPER_MARGIN + lyxfont::signedWidth(tclass.rightmargin(), tclass.defaultfont()); @@ -879,8 +876,7 @@ int LyXText::rightMargin(Buffer const * buf, Row const * row) const // make a corresponding row. Needed to call LeftMargin() // check wether it is a sufficent paragraph - if (newpar - && tclass[newpar->getLayout()].isEnvironment()) { + if (newpar && tclass[newpar->layout()].isEnvironment()) { Row dummyrow; dummyrow.par(newpar); dummyrow.pos(0); @@ -903,8 +899,7 @@ int LyXText::rightMargin(Buffer const * buf, Row const * row) const int LyXText::labelEnd(BufferView * bview, Row const * row) const { - if (textclasslist.Style(bview->buffer()->params.textclass, - row->par()->getLayout()).margintype + if (textclasslist[bview->buffer()->params.textclass][row->par()->layout()].margintype == MARGIN_MANUAL) { Row tmprow; tmprow = *row; @@ -937,8 +932,7 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const pos_type const main_body = beginningOfMainBody(bview->buffer(), par); LyXLayout const & layout = - textclasslist.Style(bview->buffer()->params.textclass, - par->getLayout()); + textclasslist[bview->buffer()->params.textclass][par->layout()]; pos_type i = pos; if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) { @@ -1057,8 +1051,7 @@ int LyXText::fill(BufferView * bview, Row * row, int paper_width) const pos_type const last = rowLastPrintable(row); // special handling of the right address boxes - if (textclasslist.Style(bview->buffer()->params.textclass, - row->par()->getLayout()).margintype + if (textclasslist[bview->buffer()->params.textclass][row->par()->layout()].margintype == MARGIN_RIGHT_ADDRESS_BOX) { int const tmpfill = row->fill(); @@ -1068,8 +1061,7 @@ int LyXText::fill(BufferView * bview, Row * row, int paper_width) const } else w = leftMargin(bview, row); - LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass, - row->par()->getLayout()); + LyXLayout const & layout = textclasslist[bview->buffer()->params.textclass][row->par()->layout()]; pos_type const main_body = beginningOfMainBody(bview->buffer(), row->par()); pos_type i = row->pos(); @@ -1230,8 +1222,7 @@ bool LyXText::hfillExpansion(Buffer const * buf, Row const * row_ptr, return true; // in some labels it does not count - if (textclasslist.Style(buf->params.textclass, - row_ptr->par()->getLayout()).margintype + if (textclasslist[buf->params.textclass][row_ptr->par()->layout()].margintype != MARGIN_MANUAL && pos < beginningOfMainBody(buf, row_ptr->par())) return false; @@ -1277,8 +1268,7 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const Paragraph * par = row_ptr->par(); Paragraph * firstpar = row_ptr->par(); - LyXLayout const & layout = textclasslist.Style(bview->buffer()->params.textclass, - firstpar->getLayout()); + LyXLayout const & layout = textclasslist[bview->buffer()->params.textclass][firstpar->layout()]; // as max get the first character of this row then it can increes but not // decrees the height. Just some point to start with so we don't have to @@ -1364,9 +1354,7 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const { maxasc += bview->buffer()->params.getDefSkip().inPixels(bview); } else if (firstpar->previous() && - textclasslist.Style(bview->buffer()->params.textclass, - firstpar->previous()-> - getLayout()).isParagraph() && + textclasslist[bview->buffer()->params.textclass][firstpar->previous()->layout()].isParagraph() && firstpar->previous()->getDepth() == 0) { // is it right to use defskip here too? (AS) @@ -1443,7 +1431,7 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const Paragraph * prev = row_ptr->par()->previous(); if (prev) prev = row_ptr->par()->depthHook(row_ptr->par()->getDepth()); - if (prev && prev->getLayout() == firstpar->getLayout() && + if (prev && prev->layout() == firstpar->layout() && prev->getDepth() == firstpar->getDepth() && prev->getLabelWidthString() == firstpar->getLabelWidthString()) { @@ -1452,9 +1440,7 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const tmptop = layout.topsep; if (row_ptr->previous()->par()->getDepth() >= row_ptr->par()->getDepth()) - tmptop -= textclasslist.Style(bview->buffer()->params.textclass, - row_ptr->previous()->par()-> - getLayout()).bottomsep; + tmptop -= textclasslist[bview->buffer()->params.textclass][row_ptr->previous()->par()->layout()].bottomsep; if (tmptop > 0) layoutasc = (tmptop * defaultHeight()); @@ -1467,13 +1453,12 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const prev = row_ptr->par()->outerHook(); if (prev) { - maxasc += int(textclasslist.Style(bview->buffer()->params.textclass, - prev->getLayout()).parsep * defaultHeight()); + maxasc += int(textclasslist[bview->buffer()->params.textclass][prev->layout()].parsep * defaultHeight()); } else { if (firstpar->previous() && firstpar->previous()->getDepth() == 0 && - firstpar->previous()->getLayout() != - firstpar->getLayout()) + firstpar->previous()->layout() != + firstpar->layout()) { // avoid parsep } else if (firstpar->previous()) { @@ -1517,15 +1502,13 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const float unusual = 0; if (comparepar->getDepth() > nextpar->getDepth()) { - usual = (textclasslist.Style(bview->buffer()->params.textclass, - comparepar->getLayout()).bottomsep * defaultHeight()); + usual = (textclasslist[bview->buffer()->params.textclass][comparepar->layout()].bottomsep * defaultHeight()); comparepar = comparepar->depthHook(nextpar->getDepth()); - if (comparepar->getLayout()!= nextpar->getLayout() + if (comparepar->layout()!= nextpar->layout() || nextpar->getLabelWidthString() != comparepar->getLabelWidthString()) { - unusual = (textclasslist.Style(bview->buffer()->params.textclass, - comparepar->getLayout()).bottomsep * defaultHeight()); + unusual = (textclasslist[bview->buffer()->params.textclass][comparepar->layout()].bottomsep * defaultHeight()); } if (unusual > usual) layoutdesc = unusual; @@ -1533,11 +1516,10 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const layoutdesc = usual; } else if (comparepar->getDepth() == nextpar->getDepth()) { - if (comparepar->getLayout()!= nextpar->getLayout() + if (comparepar->layout() != nextpar->layout() || nextpar->getLabelWidthString() != comparepar->getLabelWidthString()) - layoutdesc = int(textclasslist.Style(bview->buffer()->params.textclass, - comparepar->getLayout()).bottomsep * defaultHeight()); + layoutdesc = int(textclasslist[bview->buffer()->params.textclass][comparepar->layout()].bottomsep * defaultHeight()); } } } @@ -1698,8 +1680,7 @@ void LyXText::breakAgainOneRow(BufferView * bview, Row * row) void LyXText::breakParagraph(BufferView * bview, char keep_layout) { LyXLayout const & layout = - textclasslist.Style(bview->buffer()->params.textclass, - cursor.par()->getLayout()); + textclasslist[bview->buffer()->params.textclass][cursor.par()->layout()]; // this is only allowed, if the current paragraph is not empty or caption if ((cursor.par()->size() <= 0) @@ -1728,10 +1709,10 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout) if (layout.labeltype == LABEL_SENSITIVE) { if (!cursor.pos()) // set to standard-layout - cursor.par()->setLayout(0); + cursor.par()->applyLayout(0); else // set to standard-layout - cursor.par()->next()->setLayout(0); + cursor.par()->next()->applyLayout(0); } /* if the cursor is at the beginning of a row without prior newline, @@ -1804,8 +1785,7 @@ void LyXText::insertChar(BufferView * bview, char c) // disable the double-space checking bool const freeSpacing = - textclasslist.Style(bview->buffer()->params.textclass, - cursor.row()->par()->getLayout()).free_spacing || + textclasslist[bview->buffer()->params.textclass][cursor.row()->par()->layout()].free_spacing || cursor.row()->par()->isFreeSpacing(); @@ -2048,8 +2028,7 @@ void LyXText::insertChar(BufferView * bview, char c) redoHeightOfParagraph(bview, cursor); } else { // now the special right address boxes - if (textclasslist.Style(bview->buffer()->params.textclass, - cursor.par()->getLayout()).margintype + if (textclasslist[bview->buffer()->params.textclass][cursor.par()->layout()].margintype == MARGIN_RIGHT_ADDRESS_BOX) { redoDrawingOfParagraph(bview, cursor); } @@ -2098,12 +2077,12 @@ void LyXText::prepareToPrint(BufferView * bview, x = (workWidth(bview) > 0) ? leftMargin(bview, row) : 0; // is there a manual margin with a manual label - if (textclasslist.Style(bview->buffer()->params.textclass, - row->par()->getLayout()).margintype == MARGIN_MANUAL - && textclasslist.Style(bview->buffer()->params.textclass, - row->par()->getLayout()).labeltype == LABEL_MANUAL) { - - /* one more since labels are left aligned */ + LyXTextClass const & tclass = textclasslist[bview->buffer()->params.textclass]; + LyXLayout const & layout = tclass[row->par()->layout()]; + + if (layout.margintype == MARGIN_MANUAL + && layout.labeltype == LABEL_MANUAL) { + // one more since labels are left aligned nlh = numberOfLabelHfills(bview->buffer(), row) + 1; if (nlh && !row->par()->getLabelWidthString().empty()) { fill_label_hfill = labelFill(bview, row) / nlh; @@ -2124,7 +2103,7 @@ void LyXText::prepareToPrint(BufferView * bview, // set x how you need it int align; if (row->par()->params().align() == LYX_ALIGN_LAYOUT) { - align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->getLayout()).align; + align = layout.align; } else { align = row->par()->params().align(); } @@ -2170,14 +2149,11 @@ void LyXText::prepareToPrint(BufferView * bview, pos_type last = rowLast(row); if (main_body > 0 && - (main_body-1 > last || - !row->par()->isLineSeparator(main_body-1))) { - LyXLayout const & layout = - textclasslist.Style(bview->buffer()->params.textclass, - row->par()->getLayout()); + (main_body - 1 > last || + !row->par()->isLineSeparator(main_body - 1))) { x += lyxfont::width(layout.labelsep, getLabelFont(bview->buffer(), row->par())); - if (main_body-1 <= last) + if (main_body - 1 <= last) x += fill_label_hfill; } } @@ -2691,7 +2667,7 @@ void LyXText::backspace(BufferView * bview) if (cursor.par()->previous()) { Paragraph * tmppar = cursor.par()->previous(); - if (cursor.par()->getLayout() == tmppar->getLayout() + if (cursor.par()->layout() == tmppar->layout() && cursor.par()->getAlign() == tmppar->getAlign()) { // Inherit bottom DTD from the paragraph below. // (the one we are deleting) @@ -2743,11 +2719,12 @@ void LyXText::backspace(BufferView * bview) Correction: Pasting is always allowed with standard-layout */ + LyXTextClass const & tclass = textclasslist[bview->buffer()->params.textclass]; + if (cursor.par() != tmppar - && (cursor.par()->getLayout() == tmppar->getLayout() - || tmppar->getLayout() == 0 /*standard*/) - && cursor.par()->getAlign() == tmppar->getAlign()) - { + && (cursor.par()->layout() == tmppar->layout() + || tmppar->layout() == tclass.defaultLayoutName()) + && cursor.par()->getAlign() == tmppar->getAlign()) { removeParagraph(tmprow); removeRow(tmprow); cursor.par()->pasteParagraph(bview->buffer()->params); @@ -2977,8 +2954,9 @@ void LyXText::backspace(BufferView * bview) redoHeightOfParagraph(bview, cursor); } else { // now the special right address boxes - if (textclasslist.Style(bview->buffer()->params.textclass, - cursor.par()->getLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) { + if (textclasslist + [bview->buffer()->params.textclass] + [cursor.par()->layout()].margintype == MARGIN_RIGHT_ADDRESS_BOX) { redoDrawingOfParagraph(bview, cursor); } } @@ -3111,8 +3089,10 @@ void LyXText::paintRowSelection(DrawRowParams & p) pos_type pos = vis2log(vpos); float const old_tmpx = tmpx; if (main_body > 0 && pos == main_body - 1) { - LyXLayout const & layout = textclasslist.Style(buffer->params.textclass, - par->getLayout()); + LyXLayout const & layout = + textclasslist + [buffer->params.textclass] + [par->layout()]; LyXFont const lfont = getLabelFont(buffer, par); @@ -3332,9 +3312,9 @@ void LyXText::paintFirstRow(DrawRowParams & p) parparams.spaceTop(), p.yo + y_top); Buffer const * buffer = p.bv->buffer(); - - LyXLayout const & layout = - textclasslist.Style(buffer->params.textclass, par->getLayout()); + + LyXTextClass const & tclass = textclasslist[buffer->params.textclass]; + LyXLayout const & layout = tclass[par->layout()]; // think about the parskip // some parskips VERY EASY IMPLEMENTATION @@ -3345,8 +3325,7 @@ void LyXText::paintFirstRow(DrawRowParams & p) y_top += buffer->params.getDefSkip().inPixels(p.bv); } else { LyXLayout const & playout = - textclasslist.Style(buffer->params.textclass, - par->previous()->getLayout()); + tclass[par->previous()->layout()]; if (playout.latextype == LATEX_PARAGRAPH && !par->previous()->getDepth()) { // is it right to use defskip here, too? (AS) @@ -3561,9 +3540,8 @@ void LyXText::paintLastRow(DrawRowParams & p) case END_LABEL_STATIC: { LyXFont font(LyXFont::ALL_SANE); - LyXTextClass::LayoutList::size_type layout = par->getLayout(); - string const str = textclasslist. - Style(buffer->params.textclass, layout).endlabelstring(); + string const & layout = par->layout(); + string const str = textclasslist[buffer->params.textclass][layout].endlabelstring(); font = getLabelFont(buffer, par); int const x = is_rtl ? int(p.x) - lyxfont::width(str, font) @@ -3591,7 +3569,7 @@ void LyXText::paintRowText(DrawRowParams & p) } LyXLayout const & layout = - textclasslist.Style(buffer->params.textclass, par->getLayout()); + textclasslist[buffer->params.textclass][par->layout()]; pos_type vpos = p.row->pos(); while (vpos <= last) { @@ -3728,8 +3706,8 @@ LyXText::getColumnNearX(BufferView * bview, Row * row, int & x, pos_type last = rowLastPrintable(row); pos_type c = 0; LyXLayout const & layout = - textclasslist.Style(bview->buffer()->params.textclass, - row->par()->getLayout()); + textclasslist[bview->buffer()->params.textclass][ + row->par()->layout()]; bool left_side = false; pos_type main_body = beginningOfMainBody(bview->buffer(), row->par()); diff --git a/src/text2.C b/src/text2.C index e6cfd1f417..fab6665f65 100644 --- a/src/text2.C +++ b/src/text2.C @@ -58,8 +58,7 @@ LyXText::LyXText(BufferView * bv) : number_of_rows(0), height(0), width(0), first(0), bv_owner(bv), inset_owner(0), the_locking_inset(0), need_break_row(0), refresh_y(0), refresh_row(0), - status_(LyXText::UNCHANGED), firstrow(0), lastrow(0), - copylayouttype(0) + status_(LyXText::UNCHANGED), firstrow(0), lastrow(0) {} @@ -67,10 +66,10 @@ LyXText::LyXText(InsetText * inset) : number_of_rows(0), height(0), width(0), first(0), bv_owner(0), inset_owner(inset), the_locking_inset(0), need_break_row(0), refresh_y(0), refresh_row(0), - status_(LyXText::UNCHANGED), firstrow(0), lastrow(0), - copylayouttype(0) + status_(LyXText::UNCHANGED), firstrow(0), lastrow(0) {} + void LyXText::init(BufferView * bview, bool reinit) { if (reinit) { @@ -82,7 +81,8 @@ void LyXText::init(BufferView * bview, bool reinit) firstrow = tmprow; } lastrow = refresh_row = need_break_row = 0; - width = height = copylayouttype = 0; + width = height = 0; + copylayouttype.erase(); number_of_rows = first = refresh_y = 0; status_ = LyXText::UNCHANGED; } else if (firstrow) @@ -125,13 +125,12 @@ LyXFont const realizeFont(LyXFont const & font, par = par->outerHook(); if (par) { #ifndef INHERIT_LANGUAGE - tmpfont.realize(textclasslist. - Style(buf->params.textclass, - par->getLayout()).font); + tmpfont.realize(textclasslist[buf->params.textclass][ + par->layout()].font); #else tmpfont.realize(textclasslist. Style(buf->params.textclass, - par->getLayout()).font, + par->layout()).font, buf->params.language); #endif par_depth = par->getDepth(); @@ -139,9 +138,9 @@ LyXFont const realizeFont(LyXFont const & font, } #ifndef INHERIT_LANGUAGE - tmpfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont()); + tmpfont.realize(textclasslist[buf->params.textclass].defaultfont()); #else - tmpfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont(), + tmpfont.realize(textclasslist[buf->params.textclass].defaultfont(), buf->params.language); #endif @@ -164,7 +163,7 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par, lyx::Assert(pos >= 0); LyXLayout const & layout = - textclasslist.Style(buf->params.textclass, par->getLayout()); + textclasslist[buf->params.textclass][par->layout()]; Paragraph::depth_type par_depth = par->getDepth(); // We specialize the 95% common case: @@ -220,7 +219,7 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par, LyXFont const LyXText::getLayoutFont(Buffer const * buf, Paragraph * par) const { LyXLayout const & layout = - textclasslist.Style(buf->params.textclass, par->getLayout()); + textclasslist[buf->params.textclass][par->layout()]; Paragraph::depth_type par_depth = par->getDepth(); @@ -235,7 +234,7 @@ LyXFont const LyXText::getLayoutFont(Buffer const * buf, Paragraph * par) const LyXFont const LyXText::getLabelFont(Buffer const * buf, Paragraph * par) const { LyXLayout const & layout = - textclasslist.Style(buf->params.textclass, par->getLayout()); + textclasslist[buf->params.textclass][par->layout()]; Paragraph::depth_type par_depth = par->getDepth(); @@ -266,7 +265,6 @@ void LyXText::setCharFont(BufferView * bv, Paragraph * par, // Plug thru to version below: setCharFont(buf, par, pos, font); - } @@ -275,9 +273,8 @@ void LyXText::setCharFont(Buffer const * buf, Paragraph * par, { LyXFont font(fnt); - LyXLayout const & layout = - textclasslist.Style(buf->params.textclass, - par->getLayout()); + LyXTextClass const & tclass = textclasslist[buf->params.textclass]; + LyXLayout const & layout = tclass[par->layout()]; // Get concrete layout font to reduce against LyXFont layoutfont; @@ -294,23 +291,20 @@ void LyXText::setCharFont(Buffer const * buf, Paragraph * par, tp = tp->outerHook(); if (tp) #ifndef INHERIT_LANGUAGE - layoutfont.realize(textclasslist. - Style(buf->params.textclass, - tp->getLayout()).font); + layoutfont.realize(tclass[tp->layout()].font); #else layoutfont.realize(textclasslist. Style(buf->params.textclass, - tp->getLayout()).font, + tp->layout()).font, buf->params.language); #endif } } #ifndef INHERIT_LANGUAGE - layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont()); + layoutfont.realize(tclass.defaultfont()); #else - layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont(), - buf->params.language); + layoutfont.realize(tclass.defaultfont(), buf->params.language); #endif // Now, reduce font against full layout font @@ -464,7 +458,7 @@ void LyXText::makeFontEntriesLayoutSpecific(Buffer const * buf, Paragraph * par) { LyXLayout const & layout = - textclasslist.Style(buf->params.textclass, par->getLayout()); + textclasslist[buf->params.textclass][par->layout()]; LyXFont layoutfont; for (pos_type pos = 0; pos < par->size(); ++pos) { @@ -483,7 +477,7 @@ void LyXText::makeFontEntriesLayoutSpecific(Buffer const * buf, Paragraph * LyXText::setLayout(BufferView * bview, LyXCursor & cur, LyXCursor & sstart_cur, LyXCursor & send_cur, - lyx::layout_type layout) + string const & layout) { Paragraph * endpar = send_cur.par()->next(); Paragraph * undoendpar = endpar; @@ -503,12 +497,12 @@ Paragraph * LyXText::setLayout(BufferView * bview, // ok we have a selection. This is always between sstart_cur // and sel_end cursor cur = sstart_cur; - + LyXLayout const & lyxlayout = - textclasslist.Style(bview->buffer()->params.textclass, layout); + textclasslist[bview->buffer()->params.textclass][layout]; do { - cur.par()->setLayout(layout); + cur.par()->applyLayout(layout); makeFontEntriesLayoutSpecific(bview->buffer(), cur.par()); Paragraph * fppar = cur.par(); fppar->params().spaceTop(lyxlayout.fill_top ? @@ -527,13 +521,13 @@ Paragraph * LyXText::setLayout(BufferView * bview, if (cur.par() != send_cur.par()) cur.par(cur.par()->next()); } while (cur.par() != send_cur.par()); - + return endpar; } // set layout over selection and make a total rebreak of those paragraphs -void LyXText::setLayout(BufferView * bview, lyx::layout_type layout) +void LyXText::setLayout(BufferView * bview, string const & layout) { LyXCursor tmpcursor = cursor; /* store the current cursor */ @@ -595,10 +589,12 @@ void LyXText::incDepth(BufferView * bview) bool anything_changed = false; + LyXTextClass const & tclass = + textclasslist[bview->buffer()->params.textclass]; + while (true) { // NOTE: you can't change the depth of a bibliography entry - if (textclasslist.Style(bview->buffer()->params.textclass, - cursor.par()->getLayout()).labeltype != LABEL_BIBLIO) { + if (tclass[cursor.par()->layout()].labeltype != LABEL_BIBLIO) { Paragraph * prev = cursor.par()->previous(); if (prev) { @@ -1138,8 +1134,8 @@ string LyXText::getStringToIndex(BufferView * bview) pos_type LyXText::beginningOfMainBody(Buffer const * buf, Paragraph const * par) const { - if (textclasslist.Style(buf->params.textclass, - par->getLayout()).labeltype != LABEL_MANUAL) + if (textclasslist[buf->params.textclass][ + par->layout()].labeltype != LABEL_MANUAL) return 0; else return par->beginningOfMainBody(); @@ -1187,6 +1183,9 @@ void LyXText::setParagraph(BufferView * bview, Paragraph * tmppar = selection.end.par(); + LyXTextClass const & tclass = + textclasslist[bview->buffer()->params.textclass]; + while (tmppar != selection.start.par()->previous()) { setCursor(bview, tmppar, 0); status(bview, LyXText::NEED_MORE_REFRESH); @@ -1200,16 +1199,12 @@ void LyXText::setParagraph(BufferView * bview, cursor.par()->params().spaceBottom(space_bottom); cursor.par()->params().spacing(spacing); // does the layout allow the new alignment? + LyXLayout const & layout = tclass[cursor.par()->layout()]; + if (align == LYX_ALIGN_LAYOUT) - align = textclasslist - .Style(bview->buffer()->params.textclass, - cursor.par()->getLayout()).align; - if (align & textclasslist - .Style(bview->buffer()->params.textclass, - cursor.par()->getLayout()).alignpossible) { - if (align == textclasslist - .Style(bview->buffer()->params.textclass, - cursor.par()->getLayout()).align) + align = layout.align; + if (align & layout.alignpossible) { + if (align == layout.align) cursor.par()->params().align(LYX_ALIGN_LAYOUT); else cursor.par()->params().align(align); @@ -1289,12 +1284,9 @@ string const romanCounter(int n) // set the counter of a paragraph. This includes the labels void LyXText::setCounter(Buffer const * buf, Paragraph * par) const { - LyXLayout const & layout = - textclasslist.Style(buf->params.textclass, - par->getLayout()); + LyXTextClass const & textclass = textclasslist[buf->params.textclass]; + LyXLayout const & layout = textclass[par->layout()]; - LyXTextClass const & textclass = - textclasslist.TextClass(buf->params.textclass); // copy the prev-counters to this one, // unless this is the first paragraph @@ -1329,9 +1321,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const */ if (par->previous() && par->previous()->getDepth() < par->getDepth() - && textclasslist.Style(buf->params.textclass, - par->previous()->getLayout() - ).labeltype == LABEL_COUNTER_ENUMI + && textclass[par->previous()->layout()].labeltype == LABEL_COUNTER_ENUMI && par->enumdepth < 3 && layout.labeltype != LABEL_BIBLIO) { par->enumdepth++; @@ -1632,11 +1622,12 @@ void LyXText::updateCounters(BufferView * bview, Row * row) const // now check for the headline layouts. remember that they // have a dynamic left margin - if ((textclasslist.Style(bview->buffer()->params.textclass, - par->layout).margintype == MARGIN_DYNAMIC - || textclasslist.Style(bview->buffer()->params.textclass, - par->layout).labeltype == LABEL_SENSITIVE)) { - + LyXTextClass const & tclass = + textclasslist[bview->buffer()->params.textclass]; + LyXLayout const & layout = tclass[par->layout()]; + + if (layout.margintype == MARGIN_DYNAMIC + || layout.labeltype == LABEL_SENSITIVE) { // Rebreak the paragraph removeParagraph(row); appendParagraph(bview, row); @@ -1671,7 +1662,7 @@ void LyXText::insertInset(BufferView * bview, Inset * inset) void LyXText::copyEnvironmentType() { - copylayouttype = cursor.par()->getLayout(); + copylayouttype = cursor.par()->layout(); } @@ -1976,8 +1967,8 @@ void LyXText::checkParagraph(BufferView * bview, Paragraph * par, status(bview, LyXText::NEED_MORE_REFRESH); // check the special right address boxes - if (textclasslist.Style(bview->buffer()->params.textclass, - par->getLayout()).margintype + if (textclasslist[bview->buffer()->params.textclass][ + par->layout()].margintype == MARGIN_RIGHT_ADDRESS_BOX) { tmpcursor.par(par); @@ -2116,9 +2107,9 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par, pos = vis2log(vpos); if (main_body > 0 && pos == main_body - 1) { x += fill_label_hfill + - lyxfont::width(textclasslist.Style( - bview->buffer()->params.textclass, - row->par()->getLayout()) + lyxfont::width(textclasslist[ + bview->buffer()->params.textclass][ + row->par()->layout()] .labelsep, getLabelFont(bview->buffer(), row->par())); if (row->par()->isLineSeparator(main_body-1)) @@ -2334,8 +2325,8 @@ bool LyXText::deleteEmptyParagraphMechanism(BufferView * bview, if (selection.set()) return false; // We allow all kinds of "mumbo-jumbo" when freespacing. - if (textclasslist.Style(bview->buffer()->params.textclass, - old_cursor.par()->getLayout()).free_spacing + if (textclasslist[bview->buffer()->params.textclass][ + old_cursor.par()->layout()].free_spacing || old_cursor.par()->isFreeSpacing()) { return false; @@ -2403,8 +2394,9 @@ bool LyXText::deleteEmptyParagraphMechanism(BufferView * bview, return false; // Do not delete empty paragraphs with keepempty set. - if ((textclasslist.Style(bview->buffer()->params.textclass, - old_cursor.par()->getLayout())).keepempty) + if (textclasslist + [bview->buffer()->params.textclass] + [old_cursor.par()->layout()].keepempty) return false; // only do our magic if we changed paragraph -- 2.39.2