]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcollapsable.C
quick fix for commented out figures
[lyx.git] / src / insets / insetcollapsable.C
index ce43acc582135c7dfc603ace9d0a760c7e93a5fe..53e97c3f4204a38023d39ba4dfed43677d9dc15c 100644 (file)
@@ -1,8 +1,8 @@
 /* This file is part of
  * ======================================================
- * 
+ *
  *           LyX, The Document Processor
- *      
+ *
  *          Copyright 1998-2001 The LyX Team.
  *
  * ======================================================
 #include "lyxfont.h"
 #include "BufferView.h"
 #include "Painter.h"
-#include "insets/insettext.h"
-#include "support/LOstream.h"
-#include "support/lstrings.h"
 #include "debug.h"
 #include "lyxtext.h"
 #include "font.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
@@ -52,8 +56,8 @@ 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
@@ -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);
@@ -195,7 +199,6 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
 
        if (!isOpen()) {
                draw_collapsed(pain, baseline, x);
-               x += TEXT_TO_INSET_OFFSET;
                return;
        }
 
@@ -205,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!
@@ -221,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))
@@ -232,7 +235,7 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
 
 
 void InsetCollapsable::edit(BufferView * bv, int xp, int yp,
-                            unsigned int button)
+                           unsigned int button)
 {
        UpdatableInset::edit(bv, xp, yp, button);
 
@@ -243,7 +246,7 @@ void InsetCollapsable::edit(BufferView * bv, int xp, int yp,
                first_after_edit = true;
                if (!bv->lockInset(this))
                        return;
-               bv->updateInset(this, true);
+               bv->updateInset(this, false);
                inset.edit(bv);
        } else {
                if (!bv->lockInset(this))
@@ -271,7 +274,7 @@ void InsetCollapsable::edit(BufferView * bv, bool front)
                if (!bv->lockInset(this))
                        return;
                inset.setUpdateStatus(bv, InsetText::FULL);
-               bv->updateInset(this, true);
+               bv->updateInset(this, false);
                inset.edit(bv, front);
        } else {
                if (!bv->lockInset(this))
@@ -310,7 +313,7 @@ void InsetCollapsable::insetUnlock(BufferView * bv)
 
 
 void InsetCollapsable::insetButtonPress(BufferView * bv,
-                                        int x, int y, int button)
+                                       int x, int y, int button)
 {
        if (!collapsed_ && (y > button_bottom_y)) {
                LyXFont font(LyXFont::ALL_SANE);
@@ -323,10 +326,11 @@ void InsetCollapsable::insetButtonPress(BufferView * bv,
 }
 
 
-void InsetCollapsable::insetButtonRelease(BufferView * bv,
-                                          int x, int y, int button)
+bool InsetCollapsable::insetButtonRelease(BufferView * bv,
+                                         int x, int y, int button)
 {
-       if ((x >= 0)  && (x < button_length) &&
+       bool ret = false;
+       if ((button != 3) && (x >= 0)  && (x < button_length) &&
            (y >= button_top_y) &&  (y <= button_bottom_y))
        {
                if (collapsed_) {
@@ -334,11 +338,11 @@ void InsetCollapsable::insetButtonRelease(BufferView * bv,
 // should not be called on inset open!
 //                     inset.insetButtonRelease(bv, 0, 0, button);
                        inset.setUpdateStatus(bv, InsetText::FULL);
-                       bv->updateInset(this, true);
+                       bv->updateInset(this, false);
                } else {
                        collapsed_ = true;
                        bv->unlockInset(this);
-                       bv->updateInset(this, true);
+                       bv->updateInset(this, false);
                }
        } else if (!collapsed_ && (y > button_bottom_y)) {
                LyXFont font(LyXFont::ALL_SANE);
@@ -346,13 +350,17 @@ void InsetCollapsable::insetButtonRelease(BufferView * bv,
                    (ascent_collapsed() +
                     descent_collapsed() +
                     inset.ascent(bv, font));
-               inset.insetButtonRelease(bv, x, yy, button);
+               ret = inset.insetButtonRelease(bv, x, yy, button);
        }
+       if ((button == 3) && !ret) {
+               return showInsetDialog(bv);
+       }
+       return false;
 }
 
 
 void InsetCollapsable::insetMotionNotify(BufferView * bv,
-                                         int x, int y, int state)
+                                        int x, int y, int state)
 {
        if (y > button_bottom_y) {
                LyXFont font(LyXFont::ALL_SANE);
@@ -372,14 +380,32 @@ void InsetCollapsable::insetKeyPress(XKeyEvent * 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, ostream & os, int ll) const
+{
+       return inset.ascii(buf, os, ll);
+}
+
+
+int InsetCollapsable::linuxdoc(Buffer const * buf, ostream & os) const
+{
+       return inset.linuxdoc(buf, os);
+}
+
+
+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);
@@ -395,10 +421,11 @@ int InsetCollapsable::getMaxWidth(BufferView * bv,
        return UpdatableInset::getMaxWidth(bv, in);
 #endif
 }
+#endif
 
 
 void InsetCollapsable::update(BufferView * bv, LyXFont const & font,
-                              bool reinit)
+                             bool reinit)
 {
        if (in_update) {
                if (reinit && owner()) {
@@ -420,7 +447,7 @@ InsetCollapsable::localDispatch(BufferView * bv, kb_action action,
                                string const & arg)
 {
        UpdatableInset::RESULT result = inset.localDispatch(bv, action, arg);
-       if (result == FINISHED)
+       if (result >= FINISHED)
                bv->unlockInset(this);
        first_after_edit = false;
        return result;
@@ -448,7 +475,7 @@ bool InsetCollapsable::unlockInsetInInset(BufferView * bv, UpdatableInset * in,
 
 bool InsetCollapsable::updateInsetInInset(BufferView * bv, Inset *in)
 {
-       if (&inset == in)
+       if (in == this)
                return true;
        return inset.updateInsetInInset(bv, in);
 }
@@ -508,7 +535,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);
 }
@@ -541,7 +568,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();
 }
@@ -552,7 +579,7 @@ bool InsetCollapsable::nodraw() const
        return inset.nodraw();
 }
 
+
 int InsetCollapsable::scroll(bool recursive) const
 {
        int sx = UpdatableInset::scroll(false);
@@ -577,6 +604,12 @@ Paragraph * InsetCollapsable::firstParagraph() const
 }
 
 
+Paragraph * InsetCollapsable::getFirstParagraph(int i) const
+{
+       return inset.getFirstParagraph(i);
+}
+
+
 LyXCursor const & InsetCollapsable::cursor(BufferView * bv) const
 {
        return inset.cursor(bv);
@@ -594,9 +627,9 @@ Inset * InsetCollapsable::getInsetFromID(int id_arg) const
 void InsetCollapsable::open(BufferView * bv)
 {
        if (!collapsed_) return;
-       
+
        collapsed_ = false;
-       bv->updateInset(this, true);
+       bv->updateInset(this, false);
 }
 
 
@@ -604,9 +637,9 @@ void InsetCollapsable::close(BufferView * bv) const
 {
        if (collapsed_)
                return;
-       
+
        collapsed_ = true;
-       bv->updateInset(const_cast<InsetCollapsable *>(this), true);
+       bv->updateInset(const_cast<InsetCollapsable *>(this), false);
 }
 
 
@@ -617,7 +650,7 @@ void InsetCollapsable::setLabel(string const & l) const
 
 
 bool InsetCollapsable::searchForward(BufferView * bv, string const & str,
-                                     bool const & cs, bool const & mw)
+                                    bool cs, bool mw)
 {
        bool found = inset.searchForward(bv, str, cs, mw);
        if (first_after_edit && !found)
@@ -625,8 +658,10 @@ bool InsetCollapsable::searchForward(BufferView * bv, string const & str,
        first_after_edit = false;
        return found;
 }
+
+
 bool InsetCollapsable::searchBackward(BufferView * bv, string const & str,
-                                      bool const & cs, bool const & mw)
+                                     bool cs, bool mw)
 {
        bool found = inset.searchBackward(bv, str, cs, mw);
        if (first_after_edit && !found)
@@ -636,9 +671,10 @@ bool InsetCollapsable::searchBackward(BufferView * bv, string const & str,
 }
 
 
-string const InsetCollapsable::selectNextWord(BufferView * bv, float & value) const
+string const InsetCollapsable::selectNextWordToSpellcheck(BufferView * bv,
+                                             float & value) const
 {
-       string str = inset.selectNextWord(bv, value);
+       string const str = inset.selectNextWordToSpellcheck(bv, value);
        if (first_after_edit && str.empty())
                close(bv);
        first_after_edit = false;