X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetCollapsable.cpp;h=6135a63545e69494301a66ba7928e58729a98007;hb=2c357c1d23b7b83839a9beb8225d4f1ae4f793b4;hp=0780999c2e7bbe4b15961731428a8705b04c5278;hpb=a51525c4162632d77884827909336ba7d88482e6;p=lyx.git diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 0780999c2e..6135a63545 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -22,6 +22,7 @@ #include "DispatchResult.h" #include "FloatList.h" #include "FuncStatus.h" +#include "InsetLayout.h" #include "Language.h" #include "LaTeXFeatures.h" #include "Lexer.h" @@ -51,7 +52,7 @@ InsetCollapsable::CollapseStatus InsetCollapsable::status() const InsetCollapsable::Geometry InsetCollapsable::geometry() const { switch (decoration()) { - case Classic: + case Deco_Classic: if (status() == Open) { if (openinlined_) return LeftButton; @@ -60,11 +61,14 @@ InsetCollapsable::Geometry InsetCollapsable::geometry() const } else return ButtonOnly; - case Minimalistic: + case Deco_Minimalistic: return status() == Open ? NoButton : ButtonOnly ; - case Conglomerate: + case Deco_Conglomerate: return status() == Open ? SubLabel : Corners ; + + case Deco_Default: + break; // this shouldn't happen } // dummy return value to shut down a warning, @@ -105,7 +109,7 @@ docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const { Dimension dim = dimensionCollapsed(); if (geometry() == NoButton) - return layout_->labelstring; + return layout_->labelstring(); else if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des) return docstring(); @@ -130,7 +134,7 @@ void InsetCollapsable::setLayout(TextClassPtr tc) textClass_ = tc; if ( tc.get() != 0 ) { layout_ = &tc->insetlayout(name()); - labelstring_ = layout_->labelstring; + labelstring_ = layout_->labelstring(); } else { layout_ = &TextClass::emptyInsetLayout(); labelstring_ = _("UNDEFINED"); @@ -207,7 +211,7 @@ Dimension InsetCollapsable::dimensionCollapsed() const { BOOST_ASSERT(layout_); Dimension dim; - theFontMetrics(layout_->labelfont).buttonText( + theFontMetrics(layout_->labelfont()).buttonText( labelstring_, dim.wid, dim.asc, dim.des); return dim; } @@ -220,7 +224,7 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const autoOpen_ = mi.base.bv->cursor().isInside(this); FontInfo tmpfont = mi.base.font; - mi.base.font = layout_->font; + mi.base.font = layout_->font(); mi.base.font.realize(tmpfont); switch (geometry()) { @@ -235,7 +239,7 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const case SubLabel: { InsetText::metrics(mi, dim); // consider width of the inset label - FontInfo font(layout_->labelfont); + FontInfo font(layout_->labelfont()); font.realize(sane_font); font.decSize(); font.decSize(); @@ -288,7 +292,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const pi.background_color = backgroundColor(); FontInfo tmpfont = pi.base.font; - pi.base.font = layout_->font; + pi.base.font = layout_->font(); pi.base.font.realize(tmpfont); // Draw button first -- top, left or only @@ -302,7 +306,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const button_dim.y1 = y - dimc.asc; button_dim.y2 = y + dimc.des; - pi.pain.buttonText(x, y, labelstring_, layout_->labelfont, + pi.pain.buttonText(x, y, labelstring_, layout_->labelfont(), mouse_hover_); } else { button_dim.x1 = 0; @@ -348,26 +352,26 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const const int xx2 = x + textdim.wid - TEXT_TO_INSET_OFFSET + 1; pi.pain.line(xx1, y + desc - 4, xx1, y + desc, - layout_->labelfont.color()); + layout_->labelfont().color()); if (status_ == Open) pi.pain.line(xx1, y + desc, xx2, y + desc, - layout_->labelfont.color()); + layout_->labelfont().color()); else { // Make status_ value visible: pi.pain.line(xx1, y + desc, xx1 + 4, y + desc, - layout_->labelfont.color()); + layout_->labelfont().color()); pi.pain.line(xx2 - 4, y + desc, xx2, y + desc, - layout_->labelfont.color()); + layout_->labelfont().color()); } pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3, y + desc - 4, - layout_->labelfont.color()); + layout_->labelfont().color()); // the label below the text. Can be toggled. if (geometry() == SubLabel) { - FontInfo font(layout_->labelfont); + FontInfo font(layout_->labelfont()); font.realize(sane_font); font.decSize(); font.decSize(); @@ -386,12 +390,12 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const if (cur.isInside(this)) { y -= textdim.asc; y += 3; - pi.pain.line(xx1, y + 4, xx1, y, layout_->labelfont.color()); - pi.pain.line(xx1 + 4, y, xx1, y, layout_->labelfont.color()); + pi.pain.line(xx1, y + 4, xx1, y, layout_->labelfont().color()); + pi.pain.line(xx1 + 4, y, xx1, y, layout_->labelfont().color()); pi.pain.line(xx2, y + 4, xx2, y, - layout_->labelfont.color()); + layout_->labelfont().color()); pi.pain.line(xx2 - 4, y, xx2, y, - layout_->labelfont.color()); + layout_->labelfont().color()); } break; } @@ -532,7 +536,7 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd) case LFUN_MOUSE_RELEASE: if (cmd.button() == mouse_button::button3) { // There is no button to right click: - if (decoration() == Minimalistic || + if (decoration() == Deco_Minimalistic || geometry() == Corners || geometry() == SubLabel || geometry() == NoButton @@ -612,7 +616,7 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd) } default: - if (layout_ && layout_->forceltr) { + if (layout_ && layout_->isForceLtr()) { // Force any new text to latex_language // FIXME: This should only be necessary in constructor, but // new paragraphs that are created by pressing enter at the @@ -630,7 +634,7 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd) bool InsetCollapsable::allowMultiPar() const { - return layout_->multipar; + return layout_->isMultiPar(); } @@ -638,9 +642,9 @@ void InsetCollapsable::resetParagraphsFont() { Font font; font.fontInfo() = inherit_font; - if (layout_->forceltr) + if (layout_->isForceLtr()) font.setLanguage(latex_language); - if (layout_->passthru) { + if (layout_->isPassThru()) { ParagraphList::iterator par = paragraphs().begin(); ParagraphList::iterator const end = paragraphs().end(); while (par != end) { @@ -744,7 +748,7 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_TABULAR_INSERT: case LFUN_TOC_INSERT: case LFUN_WRAP_INSERT: - if (layout_->passthru) { + if (layout_->isPassThru()) { flag.enabled(false); return true; } else @@ -759,12 +763,12 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd, return true; case LFUN_LANGUAGE: - flag.enabled(!layout_->forceltr); + flag.enabled(!layout_->isForceLtr()); return InsetText::getStatus(cur, cmd, flag); case LFUN_BREAK_PARAGRAPH: case LFUN_BREAK_PARAGRAPH_SKIP: - flag.enabled(layout_->multipar); + flag.enabled(layout_->isMultiPar()); return true; default: @@ -797,18 +801,23 @@ docstring InsetCollapsable::floatName(string const & type, BufferParams const & } -InsetCollapsable::Decoration InsetCollapsable::decoration() const +InsetDecoration InsetCollapsable::decoration() const { - if (!layout_ || layout_->decoration == "classic") - return Classic; - if (layout_->decoration == "minimalistic") - return Minimalistic; - if (layout_->decoration == "conglomerate") - return Conglomerate; + if (!layout_) + return Deco_Classic; + InsetDecoration const dec = layout_->decoration(); + switch (dec) { + case Deco_Classic: + case Deco_Minimalistic: + case Deco_Conglomerate: + return dec; + case Deco_Default: + break; + } if (lyxCode() == FLEX_CODE) // FIXME: Is this really necessary? - return Conglomerate; - return Classic; + return Deco_Conglomerate; + return Deco_Classic; } @@ -821,7 +830,7 @@ bool InsetCollapsable::isMacroScope(Buffer const &) const // see InsetCollapsable::latex(...) below. In these case // an environment is opened there - if (!layout_->latexname.empty()) + if (!layout_->latexname().empty()) return true; return false; @@ -841,32 +850,32 @@ int InsetCollapsable::latex(Buffer const & buf, odocstream & os, // a collapsable inset, either a command or an environment. Standard // collapsable insets should not redefine this, non-standard ones may // call this. - if (!layout_->latexname.empty()) { - if (layout_->latextype == "command") { + if (!layout_->latexname().empty()) { + if (layout_->latextype() == "command") { // FIXME UNICODE if (runparams.moving_arg) os << "\\protect"; - os << '\\' << from_utf8(layout_->latexname); - if (!layout_->latexparam.empty()) - os << from_utf8(layout_->latexparam); + os << '\\' << from_utf8(layout_->latexname()); + if (!layout_->latexparam().empty()) + os << from_utf8(layout_->latexparam()); os << '{'; - } else if (layout_->latextype == "environment") { - os << "%\n\\begin{" << from_utf8(layout_->latexname) << "}\n"; - if (!layout_->latexparam.empty()) - os << from_utf8(layout_->latexparam); + } else if (layout_->latextype() == "environment") { + os << "%\n\\begin{" << from_utf8(layout_->latexname()) << "}\n"; + if (!layout_->latexparam().empty()) + os << from_utf8(layout_->latexparam()); } } OutputParams rp = runparams; - if (layout_->passthru) + if (layout_->isPassThru()) rp.verbatim = true; - if (layout_->needprotect) + if (layout_->isNeedProtect()) rp.moving_arg = true; int i = InsetText::latex(buf, os, rp); - if (!layout_->latexname.empty()) { - if (layout_->latextype == "command") { + if (!layout_->latexname().empty()) { + if (layout_->latextype() == "command") { os << "}"; - } else if (layout_->latextype == "environment") { - os << "\n\\end{" << from_utf8(layout_->latexname) << "}\n"; + } else if (layout_->latextype() == "environment") { + os << "\n\\end{" << from_utf8(layout_->latexname()) << "}\n"; i += 4; } } @@ -880,15 +889,15 @@ void InsetCollapsable::validate(LaTeXFeatures & features) const return; // Force inclusion of preamble snippet in layout file - features.require(layout_->name); + features.require(to_utf8(layout_->name())); InsetText::validate(features); } bool InsetCollapsable::undefined() const { - std::string const & n = getLayout().name; - return n.empty() || n == TextClass::emptyInsetLayout().name; + docstring const & n = getLayout().name(); + return n.empty() || n == TextClass::emptyInsetLayout().name(); }