]> git.lyx.org Git - features.git/commitdiff
The mouse box patch for button-style insets
authorMartin Vermeer <martin.vermeer@hut.fi>
Thu, 4 Sep 2003 14:02:05 +0000 (14:02 +0000)
committerMartin Vermeer <martin.vermeer@hut.fi>
Thu, 4 Sep 2003 14:02:05 +0000 (14:02 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7662 a592a061-630c-0410-9148-cb99ea01b6c8

18 files changed:
src/ChangeLog
src/LyXAction.C
src/box.C
src/box.h
src/insets/ChangeLog
src/insets/insetbibtex.C
src/insets/insetbibtex.h
src/insets/insetcommand.h
src/insets/insetfloatlist.C
src/insets/insetfloatlist.h
src/insets/insetinclude.C
src/insets/insetinclude.h
src/insets/insettoc.C
src/insets/insettoc.h
src/insets/renderers.h
src/lfuns.h
src/lyxfunc.C
src/text3.C

index 79d7f54bf75831bafa1b434f7bef499b479c8099..37e4989ef8fd203d8acd3cd367cacfb011db935b 100644 (file)
@@ -1,3 +1,15 @@
+2003-09-03  Martin Vermeer  <martin.vermeer@hut.fi>
+
+       * LyXAction.C:
+       * box.[Ch]:
+       * lfuns.h:
+       * lyxfunc.C:
+       * text3.C: Restricts the mouse click functionality
+       of insets like bibtex, include, toc and floatlist to the visible
+       button, and allows the use of LFUN_INSET_SHOW_DIALOG to bring
+       up the dialogs. Cursor has to be in front of the inset (i.e.
+       start of row) for this to function.
+
 2003-09-04  Lars Gullik Bjønnes  <larsbj@lyx.org>
 
        * bufferview_funcs.C (currentState): output paragraph position
index 4a5bf1a023cc6c71056ef227dfbd17fdc8f36313..57790a45682f10e6d139c9eb0b28fbe3c8bbc900 100644 (file)
@@ -322,6 +322,7 @@ void LyXAction::init()
                { LFUN_INSET_MODIFY, "", Noop },
                { LFUN_INSET_DIALOG_UPDATE, "", Noop },
                { LFUN_INSET_SETTINGS, "inset-settings", ReadOnly },
+               { LFUN_INSET_DIALOG_SHOW, "inset-dialog-show", Noop },
                { LFUN_PARAGRAPH_APPLY, "paragraph-params-apply", Noop },
                { LFUN_PARAGRAPH_UPDATE, "", Noop },
                { LFUN_EXTERNAL_EDIT, "external-edit", Noop },
index 9c2213ef9315060c87e0ccd702252488475745d6..4ee0b2afb036229096309624d7a3cf6e3416b252 100644 (file)
--- a/src/box.C
+++ b/src/box.C
 using std::ostream;
 
 
-Box::Box(int x1_, int x2_, int y1_, int y2_) :
-       x1(x1_), x2(x2_), y1(y1_), y2(y2_)
+Box::Box(int x1_, int x2_, int y1_, int y2_)
+       x1(x1_), x2(x2_), y1(y1_), y2(y2_)
 {}
 
+Box::Box() 
+       : x1(0), x2(0), y1(0), y2(0)
+{}
 
 bool Box::contains(int x, int y)
 {
index 156833f75acf65eedf7e6d7dfee742b5a8719381..55eb980896bffc0f888a85218f25392aa315018a 100644 (file)
--- a/src/box.h
+++ b/src/box.h
@@ -28,6 +28,8 @@ struct Box {
        int y1;
        int y2;
 
+       /// Zero-initialise the member variables.
+       Box();
        /// Initialise the member variables.
        Box(int x1_, int x2_, int y1_, int y2_);
 
index 2bd75886a1e85680d6d4b1fe68aaa7ac7346fc29..df8d6fafe21901257ea8f819a06161ff56d576c5 100644 (file)
@@ -1,3 +1,15 @@
+2003-09-03  Martin Vermeer  <martin.vermeer@hut.fi>
+
+       * insets/insetbibtex.[Ch]:
+       * insets/insetcommand.h:
+       * insets/insetfloatlist.[Ch]:
+       * insets/insetinclude.[Ch]:
+       * insets/insettoc.[Ch]: Restricts the mouse click functionality
+       of insets like bibtex, include, toc and floatlist to the visible
+       button, and allows the use of LFUN_INSET_SHOW_DIALOG to bring
+       up the dialogs. Cursor has to be in front of the inset (i.e.
+       start of row) for this to function.
+
 2003-09-04  Angus Leeming  <leeming@lyx.org>
 
        * insetgraphics.C: #include "support/os.h"
index 64188f9e03550c14ba4c5024ae36f4844556ff47..3687af8b63ab5d4eaa043496d5b3814c707b62c4 100644 (file)
@@ -58,7 +58,9 @@ std::auto_ptr<InsetBase> InsetBibtex::clone() const
 void InsetBibtex::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        InsetCommand::metrics(mi, dim);
-       center_indent_ = (mi.base.textwidth - dim.wid) / 2;
+       int center_indent = (mi.base.textwidth - dim.wid) / 2;
+       Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
+       button().setBox(b);
        dim.wid = mi.base.textwidth;
        dim_ = dim;
 }
@@ -66,7 +68,7 @@ void InsetBibtex::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetBibtex::draw(PainterInfo & pi, int x, int y) const
 {
-       InsetCommand::draw(pi, x + center_indent_, y);
+       InsetCommand::draw(pi, x + button().box().x1, y);
 }
 
 
@@ -74,9 +76,13 @@ dispatch_result InsetBibtex::localDispatch(FuncRequest const & cmd)
 {
        switch (cmd.action) {
 
-       case LFUN_INSET_EDIT:
+       case LFUN_INSET_DIALOG_SHOW:
                InsetCommandMailer("bibtex", *this).showDialog(cmd.view());
                return DISPATCHED;
+       case LFUN_MOUSE_RELEASE:
+               if (button().box().contains(cmd.x, cmd.y)) 
+                       InsetCommandMailer("bibtex", *this).showDialog(cmd.view());
+               return DISPATCHED;
 
        case LFUN_INSET_MODIFY: {
                InsetCommandParams p;
index 9911bf48a56bae01bc89d6623b4cbca2606a251c..7f1db0de0035929a601e35780df5e6dc466f4a9e 100644 (file)
@@ -50,9 +50,6 @@ public:
        bool addDatabase(string const &);
        ///
        bool delDatabase(string const &);
-private:
-       ///
-       mutable unsigned int center_indent_;
 };
 
 #endif // INSET_BIBTEX_H
index 489c68e7a782ac12a23c4f7ebb641228cffb7b2a..8eb2bc268b6a6e65f61e34164ac76311fe2c8837 100644 (file)
@@ -66,7 +66,9 @@ public:
        void setContents(string const & c) { p_.setContents(c); }
        ///
        string const & getOptions() const { return p_.getOptions(); }
-
+       ///
+       ButtonRenderer & button() const { return button_; }
+       
 protected:
        ///
        string const getCommand() const { return p_.getCommand(); }
index c4abb64f39c3b3f7645e481b82ca14504f02323e..6800c53351a510597b29f4b4464af40ed87c6719 100644 (file)
@@ -103,7 +103,10 @@ void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
 void InsetFloatList::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        InsetCommand::metrics(mi, dim);
-       center_indent_ = (mi.base.textwidth - dim.wid) / 2;
+       int center_indent = (mi.base.textwidth - dim.wid) / 2;
+    Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);      
+       button().setBox(b);
+       
        dim.wid = mi.base.textwidth;
        dim_ = dim;
 }
@@ -111,16 +114,22 @@ void InsetFloatList::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetFloatList::draw(PainterInfo & pi, int x, int y) const
 {
-       InsetCommand::draw(pi, x + center_indent_, y);
+       InsetCommand::draw(pi, x + button().box().x1, y);
 }
 
 
 dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd)
 {
        switch (cmd.action) {
-               case LFUN_INSET_EDIT:
+               case LFUN_MOUSE_RELEASE:
+                       if (button().box().contains(cmd.x, cmd.y))
+                               InsetCommandMailer("toc", *this).showDialog(cmd.view());
+                       return DISPATCHED;
+
+               case LFUN_INSET_DIALOG_SHOW:
                        InsetCommandMailer("toc", *this).showDialog(cmd.view());
                        return DISPATCHED;
+
                default:
                        return InsetCommand::localDispatch(cmd);
        }
index b4d14e035ca316fc8f232af2ac828fc01f1f4625..50d7de189d3111d3d6508fbf61fb96272d52ea32 100644 (file)
@@ -56,9 +56,6 @@ public:
        int ascii(Buffer const &, std::ostream &, int linelen) const;
        ///
        void validate(LaTeXFeatures & features) const;
-private:
-       ///
-       mutable unsigned int center_indent_;
 };
 
 #endif
index 7e1af317bb7dacbda3fa09b1a6df5150e1f5c601..b647952c05df1360e57e5318ac04376366bf8ab1 100644 (file)
@@ -148,7 +148,11 @@ dispatch_result InsetInclude::localDispatch(FuncRequest const & cmd)
                return DISPATCHED;
 
        case LFUN_MOUSE_RELEASE:
-       case LFUN_INSET_EDIT:
+               if (button_.box().contains(cmd.x, cmd.y))
+                       InsetIncludeMailer(*this).showDialog(cmd.view());
+               return DISPATCHED;
+       
+       case LFUN_INSET_DIALOG_SHOW:
                InsetIncludeMailer(*this).showDialog(cmd.view());
                return DISPATCHED;
 
@@ -535,10 +539,11 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
                }
                button_.metrics(mi, dim);
        }
-       if (params_.flag == INPUT)
-               center_indent_ = 0;
-       else
-               center_indent_ = (mi.base.textwidth - dim.wid) / 2;
+       int center_indent = (params_.flag == INPUT ? 0 : 
+               (mi.base.textwidth - dim.wid) / 2);
+       Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
+       button_.setBox(b);
+
        dim.wid = mi.base.textwidth;
        dim_ = dim;
 }
@@ -548,14 +553,14 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
 {
        cache(pi.base.bv);
        if (!preview_->previewReady()) {
-               button_.draw(pi, x + center_indent_, y);
+               button_.draw(pi, x + button_.box().x1, y);
                return;
        }
 
        if (!preview_->monitoring())
                preview_->startMonitoring();
 
-       pi.pain.image(x + center_indent_, y - dim_.asc, dim_.wid, dim_.height(),
+       pi.pain.image(x + button_.box().x1, y - dim_.asc, dim_.wid, dim_.height(),
                            *(preview_->pimage()->image()));
 }
 
index 4e90013fddb0424aeebdfa50652a605b341a1796..7e0ee9fdd3885f164e26cd4193dfa087867345e7 100644 (file)
@@ -138,7 +138,6 @@ private:
        /// cache
        mutable bool set_label_;
        mutable ButtonRenderer button_;
-       mutable unsigned int center_indent_;
 };
 
 
index f68649a009befbb9f9b00624e686dc66ad1a7ef0..74273ce85eed42cdef56655633b0493fe5a2b42c 100644 (file)
@@ -59,7 +59,10 @@ InsetOld::Code InsetTOC::lyxCode() const
 void InsetTOC::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        InsetCommand::metrics(mi, dim);
-       center_indent_ = (mi.base.textwidth - dim.wid) / 2;
+       int center_indent = (mi.base.textwidth - dim.wid) / 2;
+       Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
+       button().setBox(b);
+
        dim.wid = mi.base.textwidth;
        dim_ = dim;
 }
@@ -67,16 +70,22 @@ void InsetTOC::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetTOC::draw(PainterInfo & pi, int x, int y) const
 {
-       InsetCommand::draw(pi, x + center_indent_, y);
+       InsetCommand::draw(pi, x + button().box().x1, y);
 }
 
 
 dispatch_result InsetTOC::localDispatch(FuncRequest const & cmd)
 {
        switch (cmd.action) {
-       case LFUN_INSET_EDIT:
+       case LFUN_MOUSE_RELEASE:
+               if (button().box().contains(cmd.x, cmd.y))
+                       InsetCommandMailer("toc", *this).showDialog(cmd.view());
+               return DISPATCHED;
+
+       case LFUN_INSET_DIALOG_SHOW:
                InsetCommandMailer("toc", *this).showDialog(cmd.view());
                return DISPATCHED;
+
        default:
                return InsetCommand::localDispatch(cmd);
        }
index 81a1aaa75ab3208533a9df43a9927826e3049e44..b53a5501815c14a0092462c019a73ac5bbd4cab2 100644 (file)
@@ -48,9 +48,6 @@ public:
        int linuxdoc(Buffer const &, std::ostream &) const;
        ///
        int docbook(Buffer const &, std::ostream &, bool mixcont) const;
-private:
-       ///
-       mutable unsigned int center_indent_;
 };
 
 #endif
index fd23de1d17b11042ff5ec74d95496e0d4a04c64c..e74f7ca491e4eac503aa9148c60aa23d5db5a60e 100644 (file)
@@ -13,6 +13,7 @@
 #define RENDERERS_H
 
 #include "dimension.h"
+#include "box.h"
 
 #include "graphics/GraphicsLoader.h"
 #include "graphics/GraphicsParams.h"
@@ -68,10 +69,16 @@ public:
        /// draw inset and update (xo, yo)-cache
        virtual void draw(PainterInfo & pi, int x, int y) const;
 
+       /// The "sensitive area" box, i.e., the button area
+       Box box() const { return button_box_; }
+       ///
+       void setBox(Box b) { button_box_ = b; }
+       
 private:
        /// The stored data.
        string text_;
        bool editable_;
+       Box button_box_;
 };
 
 
index c06047b7e1f75d523113d1471131c12324701274..8dab45e776c1f6d0cb3c1e23e6caa188516368b4 100644 (file)
@@ -322,6 +322,7 @@ enum kb_action {
        LFUN_EXTERNAL_EDIT,
        // 245
        LFUN_INSERT_BRANCH,
+       LFUN_INSET_DIALOG_SHOW,
        
        LFUN_LASTACTION                  // end of the table
 };
index c7de612436e78f1250562b8b7e2998f0cfdaf9b1..e2eb5b683dcbaacd64dd604e7c7826e17692c271 100644 (file)
@@ -691,6 +691,20 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                if (!mathcursor)
                        code = InsetOld::SPACE_CODE;
                break;
+       case LFUN_INSET_DIALOG_SHOW: {
+                       LyXText * lt = view()->getLyXText();
+                       InsetOld * inset = lt->getInset();
+                       disable = !inset;
+                       if (!disable) {
+                               code = inset->lyxCode();
+                               if (!(code == InsetOld::INCLUDE_CODE 
+                                       || code == InsetOld::BIBTEX_CODE 
+                                       || code == InsetOld::FLOAT_LIST_CODE 
+                                       || code == InsetOld::TOC_CODE))
+                                       disable = true;
+                       }
+               }
+               break;
        default:
                break;
        }
@@ -1462,6 +1476,16 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
        }
        break;
 
+       case LFUN_INSET_DIALOG_SHOW: {
+               LyXText * lt = view()->getLyXText();
+               InsetOld * inset = lt->getInset();
+               if (inset) {
+                       FuncRequest cmd(view(), LFUN_INSET_DIALOG_SHOW);
+                       inset->localDispatch(cmd);
+               }
+       }
+       break;                                                   
+       
        case LFUN_DIALOG_UPDATE: {
                string const & name = argument;
                // Can only update a dialog connected to an existing inset
index 2203305b57043c42851a1ad68b8790623b97fa30..14c40bd71fed3409c0bd5d996aec2550ecfc6a55 100644 (file)
@@ -388,8 +388,9 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd,
 
 InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 {
-       lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
-                             <<"] arg[" << cmd.argument << ']' << endl;
+       lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
+                             <<"] arg[" << cmd.argument << ']' << "xy[" <<
+                                 cmd.x << ',' << cmd.y << ']' << endl;
 
        BufferView * bv = cmd.view();