]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcollapsable.C
Switch from SigC signals to boost::signals
[lyx.git] / src / insets / insetcollapsable.C
index d05f943ba2b0cb38be9fc61640b08856d81d5047..00b3e869ec6c3ce989ecb5b63d41ecf05bcfa110 100644 (file)
@@ -1,8 +1,8 @@
 /* This file is part of
  * ======================================================
- * 
+ *
  *           LyX, The Document Processor
- *      
+ *
  *          Copyright 1998-2001 The LyX Team.
  *
  * ======================================================
 #include "gettext.h"
 #include "lyxfont.h"
 #include "BufferView.h"
-#include "Painter.h"
-#include "insets/insettext.h"
-#include "support/LOstream.h"
-#include "support/lstrings.h"
+#include "frontends/Painter.h"
 #include "debug.h"
 #include "lyxtext.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "lyxlex.h"
 
-class LyXText;
+#include "insets/insettext.h"
+
+#include "support/LOstream.h"
+#include "support/lstrings.h"
 
+using std::vector;
 using std::ostream;
 using std::endl;
 using std::max;
 
 
-InsetCollapsable::InsetCollapsable(bool collapsed)
-       : UpdatableInset(), collapsed_(collapsed), 
+class LyXText;
+
+
+InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed)
+       : UpdatableInset(), collapsed_(collapsed), inset(bp),
          button_length(0), button_top_y(0), button_bottom_y(0),
          need_update(NONE), label("Label"),
 #if 0
        autocollapse(false),
 #endif
-         oldWidth(0), in_update(false)
+         oldWidth(0), in_update(false), first_after_edit(false)
 {
        inset.setOwner(this);
        inset.setAutoBreakRows(true);
@@ -52,14 +56,14 @@ InsetCollapsable::InsetCollapsable(bool collapsed)
 
 
 InsetCollapsable::InsetCollapsable(InsetCollapsable const & in, bool same_id)
-       : UpdatableInset(in, same_id), collapsed_(in.collapsed_), 
-         framecolor(in.framecolor), labelfont(in.labelfont),
+       : UpdatableInset(in, same_id), collapsed_(in.collapsed_),
+         framecolor(in.framecolor), labelfont(in.labelfont), inset(in.inset),
          button_length(0), button_top_y(0), button_bottom_y(0),
          need_update(NONE), label(in.label),
 #if 0
          autocollapse(in.autocollapse),
 #endif
-         oldWidth(0), in_update(false)
+         oldWidth(0), in_update(false), first_after_edit(false)
 {
        inset.init(&(in.inset), same_id);
        inset.setOwner(this);
@@ -109,7 +113,7 @@ int InsetCollapsable::ascent_collapsed() const
        int width = 0;
        int ascent = 0;
        int descent = 0;
-       lyxfont::buttonText(label, labelfont, width, ascent, descent);
+       font_metrics::buttonText(label, labelfont, width, ascent, descent);
        return ascent;
 }
 
@@ -119,7 +123,7 @@ int InsetCollapsable::descent_collapsed() const
        int width = 0;
        int ascent = 0;
        int descent = 0;
-       lyxfont::buttonText(label, labelfont, width, ascent, descent);
+       font_metrics::buttonText(label, labelfont, width, ascent, descent);
        return descent;
 }
 
@@ -130,7 +134,7 @@ int InsetCollapsable::width_collapsed() const
        int width;
        int ascent;
        int descent;
-       lyxfont::buttonText(label, labelfont, width, ascent, descent);
+       font_metrics::buttonText(label, labelfont, width, ascent, descent);
        return width + (2*TEXT_TO_INSET_OFFSET);
 }
 
@@ -143,7 +147,7 @@ int InsetCollapsable::ascent(BufferView * /*bv*/, LyXFont const &) const
 
 int InsetCollapsable::descent(BufferView * bv, LyXFont const & font) const
 {
-       if (collapsed_) 
+       if (collapsed_)
                return descent_collapsed();
 
        return descent_collapsed()
@@ -155,7 +159,7 @@ int InsetCollapsable::descent(BufferView * bv, LyXFont const & font) const
 
 int InsetCollapsable::width(BufferView * bv, LyXFont const & font) const
 {
-       if (collapsed_) 
+       if (collapsed_)
                return width_collapsed();
 
        int widthCollapsed = width_collapsed();
@@ -174,8 +178,8 @@ void InsetCollapsable::draw_collapsed(Painter & pain,
 }
 
 
-void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, 
-                            int baseline, float & x, bool cleared) const
+void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
+                           int baseline, float & x, bool cleared) const
 {
        if (need_update != NONE) {
                const_cast<InsetText *>(&inset)->update(bv, f, true);
@@ -204,9 +208,9 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
                x += static_cast<float>(scroll());
 
        if (!cleared && (inset.need_update == InsetText::FULL ||
-                        inset.need_update == InsetText::INIT ||
-                        top_x != int(x) ||
-                        top_baseline != baseline))
+                        inset.need_update == InsetText::INIT ||
+                        top_x != int(x) ||
+                        top_baseline != baseline))
        {
                // we don't need anymore to clear here we just have to tell
                // the underlying LyXText that it should do the RowClear!
@@ -220,9 +224,9 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
        top_baseline = baseline;
 
        int const bl = baseline - ascent(bv, f) + ascent_collapsed();
-       
+
        draw_collapsed(pain, bl, old_x);
-       inset.draw(bv, f, 
+       inset.draw(bv, f,
                           bl + descent_collapsed() + inset.ascent(bv, f),
                           x, cleared);
        if (x < (top_x + button_length + TEXT_TO_INSET_OFFSET))
@@ -231,7 +235,7 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
 
 
 void InsetCollapsable::edit(BufferView * bv, int xp, int yp,
-                            unsigned int button)
+                            mouse_button::state button)
 {
        UpdatableInset::edit(bv, xp, yp, button);
 
@@ -248,7 +252,7 @@ void InsetCollapsable::edit(BufferView * bv, int xp, int yp,
                if (!bv->lockInset(this))
                        return;
                if (yp <= button_bottom_y) {
-                       inset.edit(bv);
+                       inset.edit(bv, xp, 0, button);
                } else {
                        LyXFont font(LyXFont::ALL_SANE);
                        int yy = ascent(bv, font) + yp -
@@ -272,12 +276,12 @@ void InsetCollapsable::edit(BufferView * bv, bool front)
                inset.setUpdateStatus(bv, InsetText::FULL);
                bv->updateInset(this, false);
                inset.edit(bv, front);
+               first_after_edit = true;
        } else {
                if (!bv->lockInset(this))
                        return;
                inset.edit(bv, front);
        }
-       first_after_edit = true;
 }
 
 
@@ -309,7 +313,7 @@ void InsetCollapsable::insetUnlock(BufferView * bv)
 
 
 void InsetCollapsable::insetButtonPress(BufferView * bv,
-                                        int x, int y, int button)
+       int x, int y, mouse_button::state button)
 {
        if (!collapsed_ && (y > button_bottom_y)) {
                LyXFont font(LyXFont::ALL_SANE);
@@ -323,10 +327,10 @@ void InsetCollapsable::insetButtonPress(BufferView * bv,
 
 
 bool InsetCollapsable::insetButtonRelease(BufferView * bv,
-                                          int x, int y, int button)
+       int x, int y, mouse_button::state button)
 {
        bool ret = false;
-       if ((button != 3) && (x >= 0)  && (x < button_length) &&
+       if ((button != mouse_button::button3) && (x < button_length) &&
            (y >= button_top_y) &&  (y <= button_bottom_y))
        {
                if (collapsed_) {
@@ -348,15 +352,15 @@ bool InsetCollapsable::insetButtonRelease(BufferView * bv,
                     inset.ascent(bv, font));
                ret = inset.insetButtonRelease(bv, x, yy, button);
        }
-       if ((button == 3) && !ret) {
+       if ((button == mouse_button::button3) && !ret) {
                return showInsetDialog(bv);
        }
-       return false;
+       return ret;
 }
 
 
 void InsetCollapsable::insetMotionNotify(BufferView * bv,
-                                         int x, int y, int state)
+       int x, int y, mouse_button::state state)
 {
        if (y > button_bottom_y) {
                LyXFont font(LyXFont::ALL_SANE);
@@ -369,39 +373,33 @@ void InsetCollapsable::insetMotionNotify(BufferView * bv,
 }
 
 
-void InsetCollapsable::insetKeyPress(XKeyEvent * xke)
-{
-       inset.insetKeyPress(xke);
-}
-
-
 int InsetCollapsable::latex(Buffer const * buf, ostream & os,
-                            bool fragile, bool free_spc) const
+                           bool fragile, bool free_spc) const
 {
        return inset.latex(buf, os, fragile, free_spc);
 }
 
 
-int InsetCollapsable::ascii(Buffer const *buf, std::ostream & os, int ll) const
+int InsetCollapsable::ascii(Buffer const * buf, ostream & os, int ll) const
 {
        return inset.ascii(buf, os, ll);
 }
 
 
-int InsetCollapsable::linuxdoc(Buffer const *buf, std::ostream & os) const
+int InsetCollapsable::linuxdoc(Buffer const * buf, ostream & os) const
 {
        return inset.linuxdoc(buf, os);
 }
 
 
-int InsetCollapsable::docbook(Buffer const *buf, std::ostream & os) const
+int InsetCollapsable::docbook(Buffer const * buf, ostream & os) const
 {
        return inset.docbook(buf, os);
 }
 
 #if 0
 int InsetCollapsable::getMaxWidth(BufferView * bv,
-                                  UpdatableInset const * in) const
+                                 UpdatableInset const * in) const
 {
 #if 0
        int const w = UpdatableInset::getMaxWidth(bv, in);
@@ -421,7 +419,7 @@ int InsetCollapsable::getMaxWidth(BufferView * bv,
 
 
 void InsetCollapsable::update(BufferView * bv, LyXFont const & font,
-                              bool reinit)
+                             bool reinit)
 {
        if (in_update) {
                if (reinit && owner()) {
@@ -440,7 +438,7 @@ void InsetCollapsable::update(BufferView * bv, LyXFont const & font,
 
 UpdatableInset::RESULT
 InsetCollapsable::localDispatch(BufferView * bv, kb_action action,
-                                string const & arg)
+                               string const & arg)
 {
        UpdatableInset::RESULT result = inset.localDispatch(bv, action, arg);
        if (result >= FINISHED)
@@ -459,7 +457,7 @@ bool InsetCollapsable::lockInsetInInset(BufferView * bv, UpdatableInset * in)
 
 
 bool InsetCollapsable::unlockInsetInInset(BufferView * bv, UpdatableInset * in,
-                                          bool lr)
+                                         bool lr)
 {
        if (&inset == in) {
                bv->unlockInset(this);
@@ -477,7 +475,7 @@ bool InsetCollapsable::updateInsetInInset(BufferView * bv, Inset *in)
 }
 
 
-unsigned int InsetCollapsable::insetInInsetY()
+int InsetCollapsable::insetInInsetY() const
 {
        return inset.insetInInsetY() - (top_baseline - inset.y());
 }
@@ -531,7 +529,7 @@ UpdatableInset * InsetCollapsable::getFirstLockingInsetOfType(Inset::Code c)
 
 
 void InsetCollapsable::setFont(BufferView * bv, LyXFont const & font,
-                               bool toggleall, bool selectall)
+                              bool toggleall, bool selectall)
 {
        inset.setFont(bv, font, toggleall, selectall);
 }
@@ -564,7 +562,7 @@ void InsetCollapsable::resizeLyXText(BufferView * bv, bool force) const
 }
 
 
-std::vector<string> const InsetCollapsable::getLabelList() const
+vector<string> const InsetCollapsable::getLabelList() const
 {
        return inset.getLabelList();
 }
@@ -575,7 +573,7 @@ bool InsetCollapsable::nodraw() const
        return inset.nodraw();
 }
 
+
 int InsetCollapsable::scroll(bool recursive) const
 {
        int sx = UpdatableInset::scroll(false);
@@ -623,7 +621,7 @@ Inset * InsetCollapsable::getInsetFromID(int id_arg) const
 void InsetCollapsable::open(BufferView * bv)
 {
        if (!collapsed_) return;
-       
+
        collapsed_ = false;
        bv->updateInset(this, false);
 }
@@ -633,7 +631,7 @@ void InsetCollapsable::close(BufferView * bv) const
 {
        if (collapsed_)
                return;
-       
+
        collapsed_ = true;
        bv->updateInset(const_cast<InsetCollapsable *>(this), false);
 }
@@ -646,7 +644,7 @@ void InsetCollapsable::setLabel(string const & l) const
 
 
 bool InsetCollapsable::searchForward(BufferView * bv, string const & str,
-                                     bool cs, bool mw)
+                                    bool cs, bool mw)
 {
        bool found = inset.searchForward(bv, str, cs, mw);
        if (first_after_edit && !found)
@@ -657,7 +655,7 @@ bool InsetCollapsable::searchForward(BufferView * bv, string const & str,
 
 
 bool InsetCollapsable::searchBackward(BufferView * bv, string const & str,
-                                      bool cs, bool mw)
+                                     bool cs, bool mw)
 {
        bool found = inset.searchBackward(bv, str, cs, mw);
        if (first_after_edit && !found)