X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetCollapsable.cpp;h=d038cfc2813a8a277a2bd713555576c681646885;hb=dae8555234f0e5c8358b91c307d91b219c664617;hp=78de68a9c95c39105ce937052ce851b5dc9374a7;hpb=351808718d3e8bb97487c0d98d0a416d2f265bf0;p=lyx.git diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 78de68a9c9..d038cfc281 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -26,6 +26,7 @@ #include "Lexer.h" #include "MetricsInfo.h" #include "OutputParams.h" +#include "TextClass.h" #include "frontends/FontMetrics.h" #include "frontends/Painter.h" @@ -129,7 +130,7 @@ InsetCollapsable::Geometry InsetCollapsable::geometry() const docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const { - Dimension dim = dimensionCollapsed(bv); + Dimension const dim = dimensionCollapsed(bv); if (geometry(bv) == NoButton) return translateIfPossible(getLayout().labelstring()); if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des || isOpen(bv)) @@ -172,7 +173,9 @@ void InsetCollapsable::read(Lexer & lex) Dimension InsetCollapsable::dimensionCollapsed(BufferView const & bv) const { Dimension dim; - theFontMetrics(getLayout().labelfont()).buttonText( + FontInfo labelfont(getLabelfont()); + labelfont.realize(sane_font); + theFontMetrics(labelfont).buttonText( buttonLabel(bv), dim.wid, dim.asc, dim.des); return dim; } @@ -183,7 +186,7 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const auto_open_[mi.base.bv] = mi.base.bv->cursor().isInside(this); FontInfo tmpfont = mi.base.font; - mi.base.font = getLayout().font(); + mi.base.font = getFont(); mi.base.font.realize(tmpfont); BufferView const & bv = *mi.base.bv; @@ -200,7 +203,7 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const case SubLabel: { InsetText::metrics(mi, dim); // consider width of the inset label - FontInfo font(getLayout().labelfont()); + FontInfo font(getLabelfont()); font.realize(sane_font); font.decSize(); font.decSize(); @@ -238,6 +241,7 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const bool InsetCollapsable::setMouseHover(BufferView const * bv, bool mouse_hover) + const { mouse_hover_[bv] = mouse_hover; return true; @@ -251,7 +255,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const auto_open_[&bv] = bv.cursor().isInside(this); FontInfo tmpfont = pi.base.font; - pi.base.font = getLayout().font(); + pi.base.font = getFont(); pi.base.font.realize(tmpfont); // Draw button first -- top, left or only @@ -265,7 +269,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const button_dim.y1 = y - dimc.asc; button_dim.y2 = y + dimc.des; - FontInfo labelfont = getLayout().labelfont(); + FontInfo labelfont = getLabelfont(); labelfont.setColor(labelColor()); pi.pain.buttonText(x, y, buttonLabel(bv), labelfont, mouse_hover_[&bv]); @@ -313,26 +317,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, - labelColor()); + Color_foreground); if (status_ == Open) pi.pain.line(xx1, y + desc, xx2, y + desc, - labelColor()); + Color_foreground); else { // Make status_ value visible: pi.pain.line(xx1, y + desc, xx1 + 4, y + desc, - labelColor()); + Color_foreground); pi.pain.line(xx2 - 4, y + desc, xx2, y + desc, - labelColor()); + Color_foreground); } pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3, - y + desc - 4, labelColor()); + y + desc - 4, Color_foreground); // the label below the text. Can be toggled. if (geometry(bv) == SubLabel) { - FontInfo font(getLayout().labelfont()); + FontInfo font(getLabelfont()); font.realize(sane_font); font.decSize(); font.decSize(); @@ -351,12 +355,10 @@ 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, labelColor()); - pi.pain.line(xx1 + 4, y, xx1, y, labelColor()); - pi.pain.line(xx2, y + 4, xx2, y, - labelColor()); - pi.pain.line(xx2 - 4, y, xx2, y, - labelColor()); + pi.pain.line(xx1, y + 4, xx1, y, Color_foreground); + pi.pain.line(xx1 + 4, y, xx1, y, Color_foreground); + pi.pain.line(xx2, y + 4, xx2, y, Color_foreground); + pi.pain.line(xx2 - 4, y, xx2, y, Color_foreground); } break; } @@ -412,6 +414,13 @@ bool InsetCollapsable::hitButton(FuncRequest const & cmd) const } +bool InsetCollapsable::clickable(int x, int y) const +{ + FuncRequest cmd(LFUN_NOACTION, x, y, mouse_button::none); + return hitButton(cmd); +} + + docstring const InsetCollapsable::getNewLabel(docstring const & l) const { docstring label; @@ -473,7 +482,7 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd) case mouse_button::button4: case mouse_button::button5: // Nothing to do. - cur.noUpdate(); + cur.noScreenUpdate(); break; } } else if (geometry(cur.bv()) != ButtonOnly) @@ -486,7 +495,7 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd) case LFUN_MOUSE_DOUBLE: case LFUN_MOUSE_TRIPLE: if (hitButton(cmd)) - cur.noUpdate(); + cur.noScreenUpdate(); else if (geometry(cur.bv()) != ButtonOnly) InsetText::doDispatch(cur, cmd); else @@ -504,7 +513,7 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd) } if (cmd.button() != mouse_button::button1) { // Nothing to do. - cur.noUpdate(); + cur.noScreenUpdate(); break; } // if we are selecting, we do not want to @@ -514,7 +523,7 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd) // Left button is clicked, the user asks to // toggle the inset visual state. cur.dispatched(); - cur.updateFlags(Update::Force | Update::FitCursor); + cur.screenUpdateFlags(Update::Force | Update::FitCursor); if (geometry(cur.bv()) == ButtonOnly) { setStatus(cur, Open); edit(cur, true); @@ -530,11 +539,9 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd) else if (cmd.argument() == "close") setStatus(cur, Collapsed); else if (cmd.argument() == "toggle" || cmd.argument().empty()) - if (status_ == Open) { + if (status_ == Open) setStatus(cur, Collapsed); - if (geometry(cur.bv()) == ButtonOnly) - cur.top().forwardPos(); - } else + else setStatus(cur, Open); else // if assign or anything else cur.undispatched(); @@ -578,9 +585,9 @@ void InsetCollapsable::setLabel(docstring const & l) docstring const InsetCollapsable::buttonLabel(BufferView const & bv) const { - docstring const label = labelstring_.empty() ? - translateIfPossible(getLayout().labelstring()) : labelstring_; InsetLayout const & il = getLayout(); + docstring const label = labelstring_.empty() ? + translateIfPossible(il.labelstring()) : labelstring_; if (!il.contentaslabel() || geometry(bv) != ButtonOnly) return label; return getNewLabel(label); @@ -613,20 +620,35 @@ InsetLayout::InsetDecoration InsetCollapsable::decoration() const } -docstring InsetCollapsable::contextMenu(BufferView const & bv, int x, +string InsetCollapsable::contextMenu(BufferView const & bv, int x, int y) const { + string context_menu = contextMenuName(); + string const it_context_menu = InsetText::contextMenuName(); if (decoration() == InsetLayout::CONGLOMERATE) - return from_ascii("context-conglomerate"); + return context_menu + ";" + it_context_menu; + + string const ic_context_menu = InsetCollapsable::contextMenuName(); + if (ic_context_menu != context_menu) + context_menu += ";" + ic_context_menu; if (geometry(bv) == NoButton) - return from_ascii("context-collapsable"); + return context_menu + ";" + it_context_menu; Dimension dim = dimensionCollapsed(bv); if (x < xo(bv) + dim.wid && y < yo(bv) + dim.des) - return from_ascii("context-collapsable"); + return context_menu; + + return it_context_menu; +} - return InsetText::contextMenu(bv, x, y); + +string InsetCollapsable::contextMenuName() const +{ + if (decoration() == InsetLayout::CONGLOMERATE) + return "context-conglomerate"; + else + return "context-collapsable"; } } // namespace lyx