]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCollapsible.cpp
Fix indentation
[lyx.git] / src / insets / InsetCollapsible.cpp
index 755bb6c30b40e7a11de635f20f0d6d41e775678d..d4c3fd3ec73ce96407247cf559d0b705102e124b 100644 (file)
@@ -157,6 +157,28 @@ void InsetCollapsible::read(Lexer & lex)
        setButtonLabel();
 }
 
+int InsetCollapsible::topOffset(BufferView const * bv) const
+{
+       switch (geometry(*bv)) {
+       case Corners:
+       case SubLabel:
+               return 0;
+       default:
+               return InsetText::topOffset(bv);
+       }
+}
+
+int InsetCollapsible::bottomOffset(BufferView const * bv) const
+{
+       switch (geometry(*bv)) {
+       case Corners:
+       case SubLabel:
+               return InsetText::bottomOffset(bv) / 4;
+       default:
+               return InsetText::bottomOffset(bv);
+       }
+}
+
 
 Dimension InsetCollapsible::dimensionCollapsed(BufferView const & bv) const
 {
@@ -164,7 +186,7 @@ Dimension InsetCollapsible::dimensionCollapsed(BufferView const & bv) const
        FontInfo labelfont(getLabelfont());
        labelfont.realize(sane_font);
        theFontMetrics(labelfont).buttonText(
-               buttonLabel(bv), TEXT_TO_INSET_OFFSET, dim.wid, dim.asc, dim.des);
+               buttonLabel(bv), Inset::textOffset(&bv), dim.wid, dim.asc, dim.des);
        return dim;
 }
 
@@ -185,8 +207,6 @@ void InsetCollapsible::metrics(MetricsInfo & mi, Dimension & dim) const
                break;
        case Corners:
                InsetText::metrics(mi, dim);
-               dim.des -= 3;
-               dim.asc -= 1;
                break;
        case SubLabel: {
                InsetText::metrics(mi, dim);
@@ -221,7 +241,7 @@ void InsetCollapsible::metrics(MetricsInfo & mi, Dimension & dim) const
                                dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des);
                                dim.asc = textdim.asc;
                        } else {
-                               dim.des += textdim.height() + TEXT_TO_INSET_OFFSET;
+                               dim.des += textdim.height() + topOffset(mi.base.bv);
                                dim.wid = max(dim.wid, textdim.wid);
                        }
                }
@@ -264,11 +284,11 @@ void InsetCollapsible::draw(PainterInfo & pi, int x, int y) const
                labelfont.realize(pi.base.font);
                pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
                                   view_[&bv].mouse_hover_ ? Color_buttonhoverbg : Color_buttonbg,
-                                  Color_buttonframe, TEXT_TO_INSET_OFFSET);
+                                  Color_buttonframe, Inset::textOffset(pi.base.bv));
                // Draw the change tracking cue on the label, unless RowPainter already
                // takes care of it.
                if (canPaintChange(bv))
-                       pi.change_.paintCue(pi, x, y, x + dimc.width(), labelfont);
+                       pi.change.paintCue(pi, x, y, x + dimc.width(), labelfont);
        } else {
                view_[&bv].button_dim_.x1 = 0;
                view_[&bv].button_dim_.y1 = 0;
@@ -292,8 +312,8 @@ void InsetCollapsible::draw(PainterInfo & pi, int x, int y) const
                }
                // Do not draw the cue for INSERTED -- it is already in the button and
                // that's enough.
-               Changer cdummy = (pi.change_.type == Change::INSERTED)
-                       ? make_change(pi.change_, Change())
+               Changer cdummy = (pi.change.type == Change::INSERTED)
+                       ? make_change(pi.change, Change())
                        : Changer();
                InsetText::draw(pi, textx, texty);
                break;
@@ -312,21 +332,19 @@ void InsetCollapsible::draw(PainterInfo & pi, int x, int y) const
                // We will take care of the frame and the change tracking cue
                // ourselves, below.
                {
-                       Changer cdummy = make_change(pi.change_, Change());
+                       Changer cdummy = make_change(pi.change, Change());
                        const_cast<InsetCollapsible *>(this)->setDrawFrame(false);
                        InsetText::draw(pi, textx, texty);
                        const_cast<InsetCollapsible *>(this)->setDrawFrame(true);
                }
 
                int desc = textdim.descent();
-               if (g == Corners)
-                       desc -= 3;
 
                // Colour the frame according to the change type. (Like for tables.)
-               Color colour = pi.change_.changed() ? pi.change_.color()
+               Color colour = pi.change.changed() ? pi.change.color()
                                                    : Color_foreground;
-               const int xx1 = x + TEXT_TO_INSET_OFFSET - 1;
-               const int xx2 = x + textdim.wid - TEXT_TO_INSET_OFFSET + 1;
+               const int xx1 = x + leftOffset(pi.base.bv) - 1;
+               const int xx2 = x + textdim.wid - rightOffset(pi.base.bv) + 1;
                pi.pain.line(xx1, y + desc - 4,
                             xx1, y + desc, colour);
                if (status_ == Open)
@@ -345,7 +363,7 @@ void InsetCollapsible::draw(PainterInfo & pi, int x, int y) const
                // the label below the text. Can be toggled.
                if (g == SubLabel) {
                        FontInfo font(getLabelfont());
-                       if (pi.change_.changed())
+                       if (pi.change.changed())
                                font.setPaintColor(colour);
                        font.realize(sane_font);
                        font.decSize();
@@ -353,7 +371,7 @@ void InsetCollapsible::draw(PainterInfo & pi, int x, int y) const
                        int w = 0;
                        int a = 0;
                        int d = 0;
-                       Color const col = pi.full_repaint ? Color_none : pi.backgroundColor(this);
+                       Color const col = pi.full_repaint ? Color_none : pi.background_color;
                        theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
                        int const ww = max(textdim.wid, w);
                        pi.pain.rectText(x + (ww - w) / 2, y + desc + a,
@@ -371,8 +389,8 @@ void InsetCollapsible::draw(PainterInfo & pi, int x, int y) const
                }
                // Strike through the inset if deleted and not already handled by
                // RowPainter.
-               if (pi.change_.deleted() && canPaintChange(bv))
-                       pi.change_.paintCue(pi, xx1, y1, xx2, y + desc);
+               if (pi.change.deleted() && canPaintChange(bv))
+                       pi.change.paintCue(pi, xx1, y1, xx2, y + desc);
                break;
        }
 }
@@ -459,8 +477,7 @@ docstring const InsetCollapsible::getNewLabel(docstring const & l) const
        if (paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
                label << "...";
        }
-       docstring const lbl = label.str();
-       return lbl.empty() ? l : lbl;
+       return label.str().empty() ? l : label.str();
 }
 
 
@@ -660,11 +677,15 @@ docstring InsetCollapsible::getLabel() const
 
 docstring const InsetCollapsible::buttonLabel(BufferView const & bv) const
 {
+       // indicate changed content in label (#8645)
+       // ✎ U+270E LOWER RIGHT PENCIL
+       docstring const indicator = (isChanged() && geometry(bv) == ButtonOnly)
+               ? docstring(1, 0x270E) : docstring();
        InsetLayout const & il = getLayout();
        docstring const label = getLabel();
        if (!il.contentaslabel() || geometry(bv) != ButtonOnly)
-               return label;
-       return getNewLabel(label);
+               return indicator + label;
+       return indicator + getNewLabel(label);
 }