On Mon, Sep 01, 2003 at 03:05:57PM +0100, Angus Leeming spake thusly:
> > 
> > First try...

Second try.

...
 
> * insetbibtex.C:
> +       Box b(
> +               center_indent_,
> +               center_indent_ + dim.wid,
> +               -dim.asc,
> +               dim.des
> +       );
> You wan't win any friends for this sort of fancy indentation.

As I value your friendship, advise me :-/

...
 
> -- 
> Angus
> 
- Martin 

Index: box.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/box.C,v
retrieving revision 1.8
diff -u -p -r1.8 box.C
--- box.C       23 Aug 2003 00:16:06 -0000      1.8
+++ box.C       2 Sep 2003 14:05:45 -0000
@@ -23,6 +23,9 @@ Box::Box(int x1_, int x2_, int y1_, int 
        x1(x1_), x2(x2_), y1(y1_), y2(y2_)
 {}
 
+Box::Box() : 
+       x1(0), x2(0), y1(0), y2(0)
+{}
 
 bool Box::contained(int x, int y)
 {
Index: box.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/box.h,v
retrieving revision 1.8
diff -u -p -r1.8 box.h
--- box.h       23 Aug 2003 00:16:06 -0000      1.8
+++ box.h       2 Sep 2003 14:05:45 -0000
@@ -30,7 +30,10 @@ struct Box {
 
        /// Initialise the member variables.
        Box(int x1_, int x2_, int y1_, int y2_);
+       /// Shorter version:
+       Box();
 
+       
        /**
         * Returns true if the given co-ordinates are within
         * the box. Check is exclusive (point on a border
Index: insets/insetbibtex.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbibtex.C,v
retrieving revision 1.21
diff -u -p -r1.21 insetbibtex.C
--- insets/insetbibtex.C        28 Aug 2003 07:41:28 -0000      1.21
+++ insets/insetbibtex.C        2 Sep 2003 14:05:45 -0000
@@ -57,7 +57,14 @@ std::auto_ptr<InsetBase> InsetBibtex::cl
 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
+       );
+       setButtonBox(b);
        dim.wid = mi.base.textwidth;
        dim_ = dim;
 }
@@ -65,7 +72,7 @@ void InsetBibtex::metrics(MetricsInfo & 
 
 void InsetBibtex::draw(PainterInfo & pi, int x, int y) const
 {
-       InsetCommand::draw(pi, x + center_indent_, y);
+       InsetCommand::draw(pi, x + buttonBox().x1, y);
 }
 
 
@@ -73,8 +80,9 @@ dispatch_result InsetBibtex::localDispat
 {
        switch (cmd.action) {
 
-       case LFUN_INSET_EDIT:
-               InsetCommandMailer("bibtex", *this).showDialog(cmd.view());
+       case LFUN_MOUSE_RELEASE:
+               if (buttonBox().contained(cmd.x, cmd.y)) 
+                       InsetCommandMailer("bibtex", *this).showDialog(cmd.view());
                return DISPATCHED;
 
        case LFUN_INSET_MODIFY: {
Index: insets/insetbibtex.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbibtex.h,v
retrieving revision 1.20
diff -u -p -r1.20 insetbibtex.h
--- insets/insetbibtex.h        28 Aug 2003 07:41:28 -0000      1.20
+++ insets/insetbibtex.h        2 Sep 2003 14:05:45 -0000
@@ -50,9 +50,6 @@ public:
        bool addDatabase(string const &);
        ///
        bool delDatabase(string const &);
-private:
-       ///
-       mutable unsigned int center_indent_;
 };
 
 #endif // INSET_BIBTEX_H
Index: insets/insetcommand.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcommand.h,v
retrieving revision 1.69
diff -u -p -r1.69 insetcommand.h
--- insets/insetcommand.h       28 Aug 2003 07:41:29 -0000      1.69
+++ insets/insetcommand.h       2 Sep 2003 14:05:45 -0000
@@ -18,6 +18,7 @@
 #include "insetcommandparams.h"
 #include "renderers.h"
 #include "mailinset.h"
+#include "box.h"
 
 // Created by Alejandro 970222
 /** Used to insert a LaTeX command automatically
@@ -66,7 +67,11 @@ public:
        void setContents(string const & c) { p_.setContents(c); }
        ///
        string const & getOptions() const { return p_.getOptions(); }
-
+       ///
+       Box buttonBox() const { return button_box_; }
+       ///
+       void setButtonBox(Box b) const { button_box_ = b; }
+       
 protected:
        ///
        string const getCommand() const { return p_.getCommand(); }
@@ -88,6 +93,7 @@ private:
        InsetCommandParams p_;
        mutable bool set_label_;
        mutable ButtonRenderer button_;
+       mutable Box button_box_;
 };
 
 
Index: insets/insetfloatlist.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetfloatlist.C,v
retrieving revision 1.39
diff -u -p -r1.39 insetfloatlist.C
--- insets/insetfloatlist.C     28 Aug 2003 07:41:29 -0000      1.39
+++ insets/insetfloatlist.C     2 Sep 2003 14:05:45 -0000
@@ -101,7 +101,15 @@ void InsetFloatList::read(Buffer const &
 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
+       );      
+       setButtonBox(b);
+       
        dim.wid = mi.base.textwidth;
        dim_ = dim;
 }
@@ -109,15 +117,16 @@ void InsetFloatList::metrics(MetricsInfo
 
 void InsetFloatList::draw(PainterInfo & pi, int x, int y) const
 {
-       InsetCommand::draw(pi, x + center_indent_, y);
+       InsetCommand::draw(pi, x + buttonBox().x1, y);
 }
 
 
 dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd)
 {
        switch (cmd.action) {
-               case LFUN_INSET_EDIT:
-                       InsetCommandMailer("toc", *this).showDialog(cmd.view());
+               case LFUN_MOUSE_RELEASE:
+                       if (buttonBox().contained(cmd.x, cmd.y))
+                               InsetCommandMailer("toc", 
*this).showDialog(cmd.view());
                        return DISPATCHED;
                default:
                        return InsetCommand::localDispatch(cmd);
Index: insets/insetfloatlist.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetfloatlist.h,v
retrieving revision 1.29
diff -u -p -r1.29 insetfloatlist.h
--- insets/insetfloatlist.h     28 Aug 2003 07:41:29 -0000      1.29
+++ insets/insetfloatlist.h     2 Sep 2003 14:05:45 -0000
@@ -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: insets/insetinclude.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetinclude.C,v
retrieving revision 1.138
diff -u -p -r1.138 insetinclude.C
--- insets/insetinclude.C       28 Aug 2003 07:41:29 -0000      1.138
+++ insets/insetinclude.C       2 Sep 2003 14:05:45 -0000
@@ -117,7 +117,8 @@ InsetInclude::InsetInclude(InsetInclude 
          params_(other.params_),
          include_label(other.include_label),
          preview_(new PreviewImpl(*this)),
-         set_label_(other.set_label_)
+         set_label_(other.set_label_),
+         button_box_(other.button_box_)
 {}
 
 
@@ -148,8 +149,8 @@ dispatch_result InsetInclude::localDispa
                return DISPATCHED;
 
        case LFUN_MOUSE_RELEASE:
-       case LFUN_INSET_EDIT:
-               InsetIncludeMailer(*this).showDialog(cmd.view());
+               if (button_box_.contained(cmd.x, cmd.y))
+                       InsetIncludeMailer(*this).showDialog(cmd.view());
                return DISPATCHED;
 
        default:
@@ -535,10 +536,19 @@ void InsetInclude::metrics(MetricsInfo &
                }
                button_.metrics(mi, dim);
        }
+       int center_indent_;
        if (params_.flag == INPUT)
                center_indent_ = 0;
        else
                center_indent_ = (mi.base.textwidth - dim.wid) / 2;
+       Box b(
+               center_indent_,
+               center_indent_ + dim.wid,
+               -dim.asc,
+               dim.des
+       );
+       button_box_ = b;
+
        dim.wid = mi.base.textwidth;
        dim_ = dim;
 }
@@ -548,14 +558,14 @@ void InsetInclude::draw(PainterInfo & pi
 {
        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: insets/insetinclude.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetinclude.h,v
retrieving revision 1.79
diff -u -p -r1.79 insetinclude.h
--- insets/insetinclude.h       28 Aug 2003 07:41:29 -0000      1.79
+++ insets/insetinclude.h       2 Sep 2003 14:05:45 -0000
@@ -14,6 +14,7 @@
 
 #include "insetcommand.h"
 #include "dimension.h"
+#include "box.h"
 #include "renderers.h"
 #include <boost/scoped_ptr.hpp>
 
@@ -138,7 +139,7 @@ private:
        /// cache
        mutable bool set_label_;
        mutable ButtonRenderer button_;
-       mutable unsigned int center_indent_;
+       mutable Box button_box_;
 };
 
 
Index: insets/insettoc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettoc.C,v
retrieving revision 1.50
diff -u -p -r1.50 insettoc.C
--- insets/insettoc.C   28 Aug 2003 07:41:30 -0000      1.50
+++ insets/insettoc.C   2 Sep 2003 14:05:45 -0000
@@ -57,7 +57,15 @@ 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
+       );
+       setButtonBox(b);
+
        dim.wid = mi.base.textwidth;
        dim_ = dim;
 }
@@ -65,15 +73,16 @@ void InsetTOC::metrics(MetricsInfo & mi,
 
 void InsetTOC::draw(PainterInfo & pi, int x, int y) const
 {
-       InsetCommand::draw(pi, x + center_indent_, y);
+       InsetCommand::draw(pi, x + buttonBox().x1, y);
 }
 
 
 dispatch_result InsetTOC::localDispatch(FuncRequest const & cmd)
 {
        switch (cmd.action) {
-       case LFUN_INSET_EDIT:
-               InsetCommandMailer("toc", *this).showDialog(cmd.view());
+       case LFUN_MOUSE_RELEASE:
+               if (buttonBox().contained(cmd.x, cmd.y))
+                       InsetCommandMailer("toc", *this).showDialog(cmd.view());
                return DISPATCHED;
        default:
                return InsetCommand::localDispatch(cmd);
Index: insets/insettoc.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettoc.h,v
retrieving revision 1.47
diff -u -p -r1.47 insettoc.h
--- insets/insettoc.h   28 Aug 2003 07:41:30 -0000      1.47
+++ insets/insettoc.h   2 Sep 2003 14:05:45 -0000
@@ -46,9 +46,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

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to