]> git.lyx.org Git - features.git/commitdiff
Fix the fix for bug 4346: http://bugzilla.lyx.org/show_bug.cgi?id=4346.
authorVincent van Ravesteijn <vfr@lyx.org>
Wed, 25 Feb 2009 22:35:41 +0000 (22:35 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Wed, 25 Feb 2009 22:35:41 +0000 (22:35 +0000)
Synchronizing insets asserts with two views open

This finishes the change of http://www.lyx.org/trac/changeset/28587.

Replace the setButtonLabels functions that need a BufferView by buttonLabel functions. These functions modify the label at drawing time.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28610 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetBranch.cpp
src/insets/InsetBranch.h
src/insets/InsetCollapsable.cpp
src/insets/InsetCollapsable.h
src/insets/InsetERT.cpp
src/insets/InsetERT.h
src/insets/InsetListings.cpp
src/insets/InsetListings.h

index 4bc330b3ad59578d61783283dede1a1951e7c0d5..80bfbf41315ffc3762a83db830d2be61a63f2f4e 100644 (file)
@@ -81,7 +81,7 @@ docstring InsetBranch::toolTip(BufferView const &, int, int) const
 }
 
 
-void InsetBranch::setButtonLabel(BufferView const & bv)
+docstring const InsetBranch::buttonLabel(BufferView const & bv) const
 {
        docstring s = _("Branch: ") + params_.branch;
        if (!params_.branch.empty()) {
@@ -91,9 +91,9 @@ void InsetBranch::setButtonLabel(BufferView const & bv)
                        s = _("Undef: ") + s;
        }
        if (decoration() == InsetLayout::CLASSIC)
-               setLabel(isOpen(bv) ? s : getNewLabel(s) );
+               return isOpen(bv) ? s : getNewLabel(s);
        else
-               setLabel(params_.branch + ": " + getNewLabel(s));
+               return params_.branch + ": " + getNewLabel(s);
 }
 
 
index 71591a127a730809bb8d8922e747a5c91f61d83c..607d8cfba224ac4a7a783d04e48cc5e28214217e 100644 (file)
@@ -62,7 +62,7 @@ private:
        ///
        void read(Lexer & lex);
        ///
-       void setButtonLabel(BufferView const & bv);
+       docstring const buttonLabel(BufferView const & bv) const;
        ///
        ColorCode backgroundColor() const;
        ///
index 6c5a44bbefcc4d3ecd6e8bd5ed8a0da09da4f5af..4928eb073d8ee2c4be91dcd46d4ea03314b93857 100644 (file)
@@ -107,7 +107,7 @@ InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
 
 docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
 {
-       Dimension dim = dimensionCollapsed();
+       Dimension dim = dimensionCollapsed(bv);
        if (geometry(bv) == NoButton)
                return translateIfPossible(layout_->labelstring());
        if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des || isOpen(bv))
@@ -187,12 +187,12 @@ void InsetCollapsable::read(Lexer & lex)
 }
 
 
-Dimension InsetCollapsable::dimensionCollapsed() const
+Dimension InsetCollapsable::dimensionCollapsed(BufferView const & bv) const
 {
        LASSERT(layout_, /**/);
        Dimension dim;
        theFontMetrics(layout_->labelfont()).buttonText(
-               labelstring_, dim.wid, dim.asc, dim.des);
+               buttonLabel(bv), dim.wid, dim.asc, dim.des);
        return dim;
 }
 
@@ -207,7 +207,9 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
        mi.base.font = layout_->font();
        mi.base.font.realize(tmpfont);
 
-       switch (geometry(*mi.base.bv)) {
+       BufferView const & bv = *mi.base.bv;
+
+       switch (geometry(bv)) {
        case NoButton:
                InsetText::metrics(mi, dim);
                break;
@@ -226,16 +228,16 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
                int w = 0;
                int a = 0;
                int d = 0;
-               theFontMetrics(font).rectText(labelstring_, w, a, d);
+               theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
                dim.des += a + d;
                break;
                }
        case TopButton:
        case LeftButton:
        case ButtonOnly:
-               dim = dimensionCollapsed();
-               if (geometry(*mi.base.bv) == TopButton 
-                         || geometry(*mi.base.bv) == LeftButton) {
+               dim = dimensionCollapsed(bv);
+               if (geometry(bv) == TopButton 
+                         || geometry(bv) == LeftButton) {
                        Dimension textdim;
                        InsetText::metrics(mi, textdim);
                        openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth;
@@ -266,15 +268,16 @@ bool InsetCollapsable::setMouseHover(bool mouse_hover)
 void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
 {
        LASSERT(layout_, /**/);
+       BufferView const & bv = *pi.base.bv;
 
-       auto_open_[pi.base.bv] =  pi.base.bv->cursor().isInside(this);
+       auto_open_[&bv] =  bv.cursor().isInside(this);
 
        FontInfo tmpfont = pi.base.font;
        pi.base.font = layout_->font();
        pi.base.font.realize(tmpfont);
 
        // Draw button first -- top, left or only
-       Dimension dimc = dimensionCollapsed();
+       Dimension dimc = dimensionCollapsed(bv);
 
        if (geometry(*pi.base.bv) == TopButton ||
            geometry(*pi.base.bv) == LeftButton ||
@@ -284,7 +287,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, buttonLabel(bv), layout_->labelfont(),
                        mouse_hover_);
        } else {
                button_dim.x1 = 0;
@@ -293,10 +296,10 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
                button_dim.y2 = 0;
        }
 
-       Dimension const textdim = InsetText::dimension(*pi.base.bv);
+       Dimension const textdim = InsetText::dimension(bv);
        int const baseline = y;
        int textx, texty;
-       switch (geometry(*pi.base.bv)) {
+       switch (geometry(bv)) {
        case LeftButton:
                textx = x + dimc.width();
                texty = baseline;
@@ -323,7 +326,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
                const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
 
                int desc = textdim.descent();
-               if (geometry(*pi.base.bv) == Corners)
+               if (geometry(bv) == Corners)
                        desc -= 3;
 
                const int xx1 = x + TEXT_TO_INSET_OFFSET - 1;
@@ -348,7 +351,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
                        y + desc - 4, layout_->labelfont().color());
 
                // the label below the text. Can be toggled.
-               if (geometry(*pi.base.bv) == SubLabel) {
+               if (geometry(bv) == SubLabel) {
                        FontInfo font(layout_->labelfont());
                        font.realize(sane_font);
                        font.decSize();
@@ -356,15 +359,15 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
                        int w = 0;
                        int a = 0;
                        int d = 0;
-                       theFontMetrics(font).rectText(labelstring_, w, a, d);
+                       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,
-                               labelstring_, font, Color_none, Color_none);
+                               buttonLabel(bv), font, Color_none, Color_none);
                        desc += d;
                }
 
                // a visual cue when the cursor is inside the inset
-               Cursor & cur = pi.base.bv->cursor();
+               Cursor const & cur = bv.cursor();
                if (cur.isInside(this)) {
                        y -= textdim.asc;
                        y += 3;
@@ -394,10 +397,10 @@ void InsetCollapsable::cursorPos(BufferView const & bv,
 
        switch (geometry(bv)) {
        case LeftButton:
-               x += dimensionCollapsed().wid;
+               x += dimensionCollapsed(bv).wid;
                break;
        case TopButton: {
-               y += dimensionCollapsed().des + textdim.asc;
+               y += dimensionCollapsed(bv).des + textdim.asc;
                break;
        }
        case NoButton:
@@ -871,7 +874,7 @@ docstring InsetCollapsable::contextMenu(BufferView const & bv, int x,
        if (geometry(bv) == NoButton)
                return from_ascii("context-collapsable");
 
-       Dimension dim = dimensionCollapsed();
+       Dimension dim = dimensionCollapsed(bv);
        if (x < xo(bv) + dim.wid && y < yo(bv) + dim.des)
                return from_ascii("context-collapsable");
 
index 88055b4ba00f7e7cab46f241b8e6859b4a125946..2308ae753f385c89f41396939109bb46dad2764f 100644 (file)
@@ -69,8 +69,7 @@ public:
 
        /// return x,y of given position relative to the inset's baseline
        void cursorPos(BufferView const & bv, CursorSlice const & sl,
-       ///
-       bool boundary, int & x, int & y) const;
+               bool boundary, int & x, int & y) const;
        /// Returns true if (mouse) action is over the inset's button.
        /// Always returns false when the inset does not have a
        /// button.
@@ -86,6 +85,9 @@ public:
        ///
        virtual void setButtonLabel() {}
        ///
+       virtual docstring const buttonLabel(BufferView const & bv) const
+               { return labelstring_; }
+       ///
        bool isOpen(BufferView const & bv) const 
                { return geometry(bv) != ButtonOnly; }
        ///
@@ -178,7 +180,7 @@ private:
        /// cache for the layout_. Make sure it is in sync with the document class!
        InsetLayout const * layout_;
        ///
-       Dimension dimensionCollapsed() const;
+       Dimension dimensionCollapsed(BufferView const & bv) const;
        ///
        /// should paragraphs be forced to use the empty layout?
        virtual bool forcePlainLayout(idx_type = 0) const 
index de911557c72ad1c964353f9c7a9b790b44132b82..95cda7e7ca12f10dc628415ad65be3c0619a14d7 100644 (file)
@@ -162,12 +162,12 @@ bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-void InsetERT::setButtonLabel(BufferView const & bv)
+docstring const InsetERT::buttonLabel(BufferView const & bv) const
 {
        if (decoration() == InsetLayout::CLASSIC)
-               setLabel(isOpen(bv) ? _("ERT") : getNewLabel(_("ERT")));
+               return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"));
        else
-               setLabel(getNewLabel(_("ERT")));
+               return getNewLabel(_("ERT"));
 }
 
 
index 2df001b3e0972615b10418bb6f67fa2c78425ef3..1015e2f8ce1f9da8597fe47c32e9f3669f27836e 100644 (file)
@@ -69,7 +69,7 @@ private:
        ///
        Inset * clone() const { return new InsetERT(*this); }
        ///
-       void setButtonLabel(BufferView const & bv);
+       docstring const buttonLabel(BufferView const & bv) const;
        ///
        bool allowSpellCheck() const { return false; }
 };
index 035da731f22714c46c6ccdcab5d13c7295a7a29f..15471f353f74969fbc2f4d7d15893c1cbf5dfccf 100644 (file)
@@ -397,13 +397,12 @@ bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-void InsetListings::setButtonLabel(BufferView const & bv)
+docstring const InsetListings::buttonLabel(BufferView const & bv) const
 {
-       // FIXME UNICODE
        if (decoration() == InsetLayout::CLASSIC)
-               setLabel(isOpen(bv) ?  _("Listing") : getNewLabel(_("Listing")));
+               return isOpen(bv) ? _("Listing") : getNewLabel(_("Listing"));
        else
-               setLabel(getNewLabel(_("Listing")));
+               return getNewLabel(_("Listing"));
 }
 
 
index 09d1ac73000f837939ede43789e6e2fc51c6f24d..5396b7d0e1f0140a48808034dffeaa2f659faa48 100644 (file)
@@ -73,7 +73,7 @@ private:
        ///
        Inset * clone() const { return new InsetListings(*this); }
        ///
-       void setButtonLabel(BufferView const & bv);
+       docstring const buttonLabel(BufferView const & bv) const;
        ///
        docstring getCaption(OutputParams const &) const;