]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcollapsable.C
hopefully fix tex2lyx linking.
[lyx.git] / src / insets / insetcollapsable.C
index 5c2b3dee169dceeed6fe8c5e2f2aa1b34eefd23d..3d4434aa79e138ec868fac88b959d75115e279f8 100644 (file)
 #include "insetcollapsable.h"
 
 #include "buffer.h"
+#include "bufferparams.h"
 #include "BufferView.h"
 #include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
+#include "FloatList.h"
 #include "FuncStatus.h"
+#include "gettext.h"
 #include "LColor.h"
 #include "lyxlex.h"
 #include "funcrequest.h"
 #include "metricsinfo.h"
 #include "paragraph.h"
 
-#include "frontends/font_metrics.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
-#include "frontends/LyXView.h"
 
 
-using lyx::graphics::PreviewLoader;
+namespace lyx {
+
+using graphics::PreviewLoader;
 
 using std::endl;
 using std::string;
@@ -48,13 +52,13 @@ InsetCollapsable::CollapseStatus InsetCollapsable::status() const
 
 InsetCollapsable::InsetCollapsable
                (BufferParams const & bp, CollapseStatus status)
-       : InsetText(bp), label("Label"), status_(status),
+       : InsetText(bp), label(from_ascii("Label")), status_(status),
          openinlined_(false), autoOpen_(false)
 {
        setAutoBreakRows(true);
        setDrawFrame(true);
        setFrameColor(LColor::collapsableframe);
-       setInsetName("Collapsable");
+       setInsetName(from_ascii("Collapsable"));
        setButtonLabel();
 }
 
@@ -122,7 +126,8 @@ void InsetCollapsable::read(Buffer const & buf, LyXLex & lex)
 Dimension InsetCollapsable::dimensionCollapsed() const
 {
        Dimension dim;
-       font_metrics::buttonText(label, labelfont_, dim.wid, dim.asc, dim.des);
+       theFontMetrics(labelfont_).buttonText(
+               label, dim.wid, dim.asc, dim.des);
        return dim;
 }
 
@@ -206,12 +211,12 @@ void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const
 }
 
 
-void InsetCollapsable::cursorPos
-       (CursorSlice const & sl, bool boundary, int & x, int & y) const
+void InsetCollapsable::cursorPos(BufferView const & bv, 
+               CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
        BOOST_ASSERT(status() != Collapsed);
 
-       InsetText::cursorPos(sl, boundary, x, y);
+       InsetText::cursorPos(bv, sl, boundary, x, y);
 
        if (status() == Open) {
                if (openinlined_)
@@ -242,9 +247,9 @@ bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
 }
 
 
-string const InsetCollapsable::getNewLabel(string const & l) const
+docstring const InsetCollapsable::getNewLabel(docstring const & l) const
 {
-       string label;
+       docstring label;
        pos_type const max_length = 15;
        pos_type const p_siz = paragraphs().begin()->size();
        pos_type const n = min(max_length, p_siz);
@@ -288,6 +293,11 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
 
        switch (cmd.action) {
        case LFUN_MOUSE_PRESS:
+               if (cmd.button() == mouse_button::button1 && hitButton(cmd)) {
+                       cur.dispatched();
+                       cur.noUpdate();
+                       break;
+               }
                if (status() == Inlined)
                        InsetText::doDispatch(cur, cmd);
                else if (status() == Open && !hitButton(cmd))
@@ -309,44 +319,43 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
 
        case LFUN_MOUSE_RELEASE:
                if (cmd.button() == mouse_button::button3) {
+                       // Open the Inset configuration dialog
                        showInsetDialog(&cur.bv());
                        break;
                }
 
-               switch (status()) {
-
-               case Collapsed:
-                       //lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
-                       setStatus(cur, Open);
-                       edit(cur, true);
-                       cur.bv().cursor() = cur;
+               if (status() == Inlined) {
+                       // The mouse click has to be within the inset!
+                       InsetText::doDispatch(cur, cmd);
                        break;
+               }
 
-               case Open: {
-                       if (hitButton(cmd)) {
-                               //lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
+               if (cmd.button() == mouse_button::button1 && hitButton(cmd)) {
+                       // Left button is clicked, the user asks to toggle the inset
+                       // visual state.
+                       cur.dispatched();
+                       cur.updateFlags(Update::Force | Update::FitCursor);
+                       if (status() == Collapsed) {
+                               setStatus(cur, Open);
+                               edit(cur, true);
+                       }
+                       else {
                                setStatus(cur, Collapsed);
-                               cur.bv().cursor() = cur;
-                       } else {
-                               //lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
-                               InsetText::doDispatch(cur, cmd);
                        }
+                       cur.bv().cursor() = cur;
                        break;
                }
 
-               case Inlined:
-                       //lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
-                       InsetText::doDispatch(cur, cmd);
-                       break;
-               }
+               // The mouse click is within the opened inset.
+               InsetText::doDispatch(cur, cmd);
                break;
 
        case LFUN_INSET_TOGGLE:
-               if (cmd.argument == "open")
+               if (cmd.argument() == "open")
                        setStatus(cur, Open);
-               else if (cmd.argument == "close")
+               else if (cmd.argument() == "close")
                        setStatus(cur, Collapsed);
-               else if (cmd.argument == "toggle" || cmd.argument.empty())
+               else if (cmd.argument() == "toggle" || cmd.argument().empty())
                        if (isOpen()) {
                                setStatus(cur, Collapsed);
                                cur.forwardPosNoDescend();
@@ -371,8 +380,8 @@ bool InsetCollapsable::getStatus(LCursor & cur, FuncRequest const & cmd,
        switch (cmd.action) {
 
        case LFUN_INSET_TOGGLE:
-               if (cmd.argument == "open" || cmd.argument == "close" ||
-                   cmd.argument == "toggle")
+               if (cmd.argument() == "open" || cmd.argument() == "close" ||
+                   cmd.argument() == "toggle")
                        flag.enabled(true);
                else
                        flag.enabled(false);
@@ -384,7 +393,7 @@ bool InsetCollapsable::getStatus(LCursor & cur, FuncRequest const & cmd,
 }
 
 
-void InsetCollapsable::setLabel(string const & l)
+void InsetCollapsable::setLabel(docstring const & l)
 {
        label = l;
 }
@@ -403,3 +412,14 @@ void InsetCollapsable::setLabelFont(LyXFont & font)
 {
        labelfont_ = font;
 }
+
+docstring InsetCollapsable::floatName(string const & type, BufferParams const & bp)
+{
+       FloatList const & floats = bp.getLyXTextClass().floats();
+       FloatList::const_iterator it = floats[type];
+       // FIXME UNICODE
+       return (it == floats.end()) ? from_ascii(type) : _(it->second.name());
+}
+
+
+} // namespace lyx