]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcollapsable.C
ws changes only
[lyx.git] / src / insets / insetcollapsable.C
index b70653314a0246dfc7b2c73d2ced2202912f58a2..c54f763e4f6276e70768b281545467d9ba0fb6fa 100644 (file)
@@ -7,68 +7,60 @@
  * \author Jürgen Vigna
  * \author Lars Gullik Bjønnes
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
 #include "insetcollapsable.h"
-#include "insettext.h"
 
+#include "buffer.h"
 #include "BufferView.h"
 #include "debug.h"
-#include "dimension.h"
-#include "gettext.h"
-#include "lyxfont.h"
+#include "LColor.h"
 #include "lyxlex.h"
-#include "lyxtext.h"
-#include "WordLangTuple.h"
 #include "funcrequest.h"
-#include "buffer.h"
 #include "metricsinfo.h"
+#include "paragraph.h"
+#include "WordLangTuple.h"
 
 #include "frontends/font_metrics.h"
 #include "frontends/Painter.h"
 #include "frontends/LyXView.h"
 
-#include "support/LAssert.h"
-#include "support/LOstream.h"
 
-using namespace lyx::support;
-using namespace lyx::graphics;
+using lyx::graphics::PreviewLoader;
 
-using std::vector;
-using std::ostream;
 using std::endl;
+using std::string;
 using std::max;
+using std::ostream;
 
 
 InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed)
-       : UpdatableInset(), collapsed_(collapsed), inset(bp),
+       : UpdatableInset(), inset(bp), collapsed_(collapsed),
          button_dim(0, 0, 0, 0), label("Label"),
 #if 0
        autocollapse(false),
 #endif
-         oldWidth(0), in_update(false), first_after_edit(false)
+         in_update(false), first_after_edit(false)
 {
        inset.setOwner(this);
        inset.setAutoBreakRows(true);
-       inset.setDrawFrame(0, InsetText::ALWAYS);
-       inset.setFrameColor(0, LColor::collapsableframe);
+       inset.setDrawFrame(InsetText::ALWAYS);
+       inset.setFrameColor(LColor::collapsableframe);
        setInsetName("Collapsable");
 }
 
 
 InsetCollapsable::InsetCollapsable(InsetCollapsable const & in)
-       : UpdatableInset(in), collapsed_(in.collapsed_),
-         framecolor(in.framecolor), labelfont(in.labelfont), inset(in.inset),
-         button_dim(0, 0, 0, 0), label(in.label),
+       : UpdatableInset(in), inset(in.inset), collapsed_(in.collapsed_),
+         labelfont_(in.labelfont_), button_dim(0, 0, 0, 0), label(in.label),
 #if 0
          autocollapse(in.autocollapse),
 #endif
-         oldWidth(0), in_update(false), first_after_edit(false)
+         in_update(false), first_after_edit(false)
 {
-       inset.init(&(in.inset));
        inset.setOwner(this);
 }
 
@@ -84,14 +76,14 @@ bool InsetCollapsable::insertInset(BufferView * bv, InsetOld * in)
 }
 
 
-void InsetCollapsable::write(Buffer const * buf, ostream & os) const
+void InsetCollapsable::write(Buffer const & buf, ostream & os) const
 {
        os << "collapsed " << (collapsed_ ? "true" : "false") << "\n";
        inset.writeParagraphData(buf, os);
 }
 
 
-void InsetCollapsable::read(Buffer const * buf, LyXLex & lex)
+void InsetCollapsable::read(Buffer const & buf, LyXLex & lex)
 {
        if (lex.isOK()) {
                lex.next();
@@ -112,21 +104,21 @@ void InsetCollapsable::read(Buffer const * buf, LyXLex & lex)
 
 void InsetCollapsable::dimension_collapsed(Dimension & dim) const
 {
-       font_metrics::buttonText(label, labelfont, dim.wid, dim.asc, dim.des);
+       font_metrics::buttonText(label, labelfont_, dim.wid, dim.asc, dim.des);
 }
 
 
 int InsetCollapsable::height_collapsed() const
 {
        Dimension dim;
-       font_metrics::buttonText(label, labelfont, dim.wid, dim.asc, dim.des);
+       font_metrics::buttonText(label, labelfont_, dim.wid, dim.asc, dim.des);
        return dim.asc + dim.des;
 }
 
 
 void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       //lyxerr << "InsetCollapsable::metrics:  width: " << mi.base.textwidth << "\n";
+       //lyxerr << "InsetCollapsable::metrics:  width: " << mi.base.textwidth << endl;
        dimension_collapsed(dim);
        if (!collapsed_) {
                Dimension insetdim;
@@ -140,15 +132,12 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetCollapsable::draw_collapsed(PainterInfo & pi, int x, int y) const
 {
-       pi.pain.buttonText(x, y, label, labelfont);
+       pi.pain.buttonText(x, y, label, labelfont_);
 }
 
 
 void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const
 {
-       Assert(pi.base.bv);
-       cache(pi.base.bv);
-
        Dimension dim_collapsed;
        dimension_collapsed(dim_collapsed);
 
@@ -229,53 +218,48 @@ void InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd)
 
        if (collapsed_ && cmd.button() != mouse_button::button3) {
                collapsed_ = false;
-               inset.setUpdateStatus(InsetText::FULL);
                bv->updateInset(this);
                bv->buffer()->markDirty();
                return;
        }
 
-       if (cmd.button() != mouse_button::button3 && hitButton(cmd))
-       {
+       if (cmd.button() != mouse_button::button3 && hitButton(cmd)) {
                if (collapsed_) {
                        collapsed_ = false;
-                       inset.setUpdateStatus(InsetText::FULL);
-                       bv->updateInset(this);
-                       bv->buffer()->markDirty();
                } else {
                        collapsed_ = true;
                        bv->unlockInset(this);
-                       bv->updateInset(this);
-                       bv->buffer()->markDirty();
                }
-       } else if (!collapsed_ && (cmd.y > button_dim.y2)) {
-               ret = (inset.localDispatch(adjustCommand(cmd)) == DISPATCHED);
+               bv->updateInset(this);
+               bv->buffer()->markDirty();
+       } else if (!collapsed_ && cmd.y > button_dim.y2) {
+               ret = inset.localDispatch(adjustCommand(cmd)) == DISPATCHED;
        }
        if (cmd.button() == mouse_button::button3 && !ret)
                showInsetDialog(bv);
 }
 
 
-int InsetCollapsable::latex(Buffer const * buf, ostream & os,
+int InsetCollapsable::latex(Buffer const & buf, ostream & os,
                            LatexRunParams const & runparams) const
 {
        return inset.latex(buf, os, runparams);
 }
 
 
-int InsetCollapsable::ascii(Buffer const * buf, 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, ostream & os) const
+int InsetCollapsable::linuxdoc(Buffer const & buf, ostream & os) const
 {
        return inset.linuxdoc(buf, os);
 }
 
 
-int InsetCollapsable::docbook(Buffer const * buf, ostream & os, bool mixcont) const
+int InsetCollapsable::docbook(Buffer const & buf, ostream & os, bool mixcont) const
 {
        return inset.docbook(buf, os, mixcont);
 }
@@ -283,31 +267,30 @@ int InsetCollapsable::docbook(Buffer const * buf, ostream & os, bool mixcont) co
 
 bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
 {
-       return button_dim.contained(cmd.x, cmd.y);
+       return button_dim.contains(cmd.x, cmd.y);
 }
 
 
-InsetOld::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd)
+dispatch_result InsetCollapsable::localDispatch(FuncRequest const & cmd)
 {
-       lyxerr << "InsetCollapsable::localDispatch: "
-               << cmd.action << " '" << cmd.argument << "'\n";
+       //lyxerr << "InsetCollapsable::localDispatch: "
+       //      << cmd.action << " '" << cmd.argument << "'\n";
        BufferView * bv = cmd.view();
        switch (cmd.action) {
                case LFUN_INSET_EDIT: {
                        if (!cmd.argument.empty()) {
                                UpdatableInset::localDispatch(cmd);
                                if (collapsed_) {
-                                       lyxerr << "branch collapsed_\n";
+                                       lyxerr << "branch collapsed_" << endl;
                                        collapsed_ = false;
                                        if (bv->lockInset(this)) {
-                                               inset.setUpdateStatus(InsetText::FULL);
                                                bv->updateInset(this);
                                                bv->buffer()->markDirty();
                                                inset.localDispatch(cmd);
                                                first_after_edit = true;
                                        }
                                } else {
-                                       lyxerr << "branch not collapsed_\n";
+                                       lyxerr << "branch not collapsed_" << endl;
                                        if (bv->lockInset(this))
                                                inset.localDispatch(cmd);
                                }
@@ -333,15 +316,14 @@ InsetOld::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd)
                                bv->buffer()->markDirty();
                                inset.localDispatch(cmd);
                        } else {
-                               FuncRequest cmd1 = cmd;
                                if (!bv->lockInset(this))
                                        return DISPATCHED;
                                if (cmd.y <= button_dim.y2) {
+                                       FuncRequest cmd1 = cmd;
                                        cmd1.y = 0;
-                               } else {
-                                       cmd1.y = ascent() + cmd.y - (height_collapsed() + inset.ascent());
-                               }
-                               inset.localDispatch(cmd);
+                                       inset.localDispatch(cmd1);
+                               } else
+                                       inset.localDispatch(adjustCommand(cmd));
                        }
                        return DISPATCHED;
                }
@@ -361,7 +343,7 @@ InsetOld::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd)
                        return DISPATCHED;
 
                default:
-                       UpdatableInset::RESULT result = inset.localDispatch(cmd);
+                       dispatch_result result = inset.localDispatch(cmd);
                        if (result >= FINISHED)
                                bv->unlockInset(this);
                        first_after_edit = false;
@@ -389,14 +371,6 @@ bool InsetCollapsable::unlockInsetInInset(BufferView * bv, UpdatableInset * in,
 }
 
 
-bool InsetCollapsable::updateInsetInInset(BufferView * bv, InsetOld *in)
-{
-       if (in == this)
-               return true;
-       return inset.updateInsetInInset(bv, in);
-}
-
-
 int InsetCollapsable::insetInInsetY() const
 {
        return inset.insetInInsetY() - (top_baseline - inset.y());
@@ -458,16 +432,10 @@ void InsetCollapsable::deleteLyXText(BufferView * bv, bool recursive) const
 }
 
 
-void InsetCollapsable::resizeLyXText(BufferView * bv, bool force) const
+void InsetCollapsable::getLabelList(Buffer const & buffer,
+                                   std::vector<string> & list) const
 {
-       inset.resizeLyXText(bv, force);
-       oldWidth = width();
-}
-
-
-void InsetCollapsable::getLabelList(std::vector<string> & list) const
-{
-       inset.getLabelList(list);
+       inset.getLabelList(buffer, list);
 }
 
 
@@ -504,7 +472,8 @@ InsetOld * InsetCollapsable::getInsetFromID(int id_arg) const
 
 void InsetCollapsable::open(BufferView * bv)
 {
-       if (!collapsed_) return;
+       if (!collapsed_)
+               return;
 
        collapsed_ = false;
        bv->updateInset(this);
@@ -517,7 +486,7 @@ void InsetCollapsable::close(BufferView * bv) const
                return;
 
        collapsed_ = true;
-       bv->updateInset(const_cast<InsetCollapsable *>(this));
+       bv->updateInset(this);
 }
 
 
@@ -527,6 +496,12 @@ void InsetCollapsable::setLabel(string const & l) const
 }
 
 
+void InsetCollapsable::setCollapsed(bool c) const
+{
+       collapsed_ = c;
+}
+
+
 void InsetCollapsable::markErased()
 {
        inset.markErased();
@@ -584,15 +559,3 @@ void InsetCollapsable::addPreview(PreviewLoader & loader) const
 {
        inset.addPreview(loader);
 }
-
-
-void InsetCollapsable::cache(BufferView * bv) const
-{
-       view_ = bv->owner()->view();
-}
-
-
-BufferView * InsetCollapsable::view() const
-{
-       return view_.lock().get();
-}