On Fri, Dec 05, 2003 at 12:02:19AM +0200, Martin Vermeer spake thusly:
> 
> I tightened up the thing a little bit. The patch is attached.  
> 
> I think this is such a clear improvement on what we had, that this
> should go in as it stands, despite small quirks (which I am not even
> sure have to do with the patch). I think we have at least the right
> visual model now.
> 
> - Martin

Here's a slightly improved patch. Less quirks (And this time I
remembered the .h file :-)

- Martin

Index: insetcharstyle.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcharstyle.C,v
retrieving revision 1.7
diff -u -p -r1.7 insetcharstyle.C
--- insetcharstyle.C    1 Dec 2003 16:01:50 -0000       1.7
+++ insetcharstyle.C    5 Dec 2003 07:01:30 -0000
@@ -25,6 +25,8 @@
 #include "metricsinfo.h"
 #include "paragraph.h"
 
+#include "frontends/font_metrics.h"
+#include "frontends/Painter.h"
 #include "support/std_sstream.h"
 
 
@@ -38,13 +40,13 @@ using std::ostringstream;
 void InsetCharStyle::init()
 {
        setInsetName("CharStyle");
-       setButtonLabel();
+       setStatus(Inlined);
 }
 
 
 InsetCharStyle::InsetCharStyle(BufferParams const & bp,
                                CharStyles::iterator cs)
-       : InsetCollapsable(bp)
+       : InsetCollapsable(bp), has_label_(true)
 {
        params_.type = cs->name;
        params_.latextype = cs->latextype;
@@ -57,7 +59,7 @@ InsetCharStyle::InsetCharStyle(BufferPar
 
 
 InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
-       : InsetCollapsable(in), params_(in.params_)
+       : InsetCollapsable(in), params_(in.params_), has_label_(true)
 {
        init();
 }
@@ -85,24 +87,41 @@ void InsetCharStyle::write(Buffer const 
 void InsetCharStyle::read(Buffer const & buf, LyXLex & lex)
 {
        InsetCollapsable::read(buf, lex);
-       setButtonLabel();
+       setStatus(Inlined);
 }
 
 
-void InsetCharStyle::setButtonLabel()
+void InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       LyXFont font(params_.labelfont);
-       font.realize(LyXFont(LyXFont::ALL_SANE));
-       string const s = "Style: " + params_.type;
-       setLabel(isOpen() ? s : getNewLabel(s) );
-       setLabelFont(font);
+       InsetCollapsable::metrics(mi, dim);
+       dim_ = dim;
+       if (has_label_)
+               dim_.des += ascent();
 }
 
 
-void InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
+void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
 {
-       InsetCollapsable::metrics(mi, dim);
-       dim_ = dim;
+       xo_ = x;
+       yo_ = y;
+
+       status_ = Inlined;
+       inset.draw(pi, x, y);
+       if (has_label_) {
+               if (!owner())
+                       x += scroll();
+       LyXFont font;
+       font.setColor(LColor::blue);
+       font.realize(LyXFont(LyXFont::ALL_SANE));
+       font.decSize();
+       font.decSize();
+       int w = 0;
+       int a = 0;
+       int d = 0;
+       font_metrics::rectText(params_.type, font, w, a, d);
+       pi.pain.rectText(x + 0.5 * (dim_.wid - w), y + inset.descent() + a,
+               params_.type, font, LColor::none, LColor::none);
+       }
 }
 
 
@@ -116,9 +135,19 @@ DispatchResult
 InsetCharStyle::priv_dispatch(FuncRequest const & cmd,
                        idx_type & idx, pos_type & pos)
 {
-       DispatchResult dr = InsetCollapsable::priv_dispatch(cmd, idx, pos);
-       setButtonLabel();
-       return dr;
+       setStatus(Inlined);
+       switch (cmd.action) {
+               case LFUN_MOUSE_PRESS:
+                       if (cmd.button() == mouse_button::button3) {
+                               has_label_ = !has_label_;
+                               return DispatchResult(true);
+                       }
+                       inset.dispatch(cmd);
+                       return DispatchResult(true, true);
+                       break;
+               default:
+                       return InsetCollapsable::priv_dispatch(cmd, idx, pos);
+       }
 }
 
 
Index: insetcharstyle.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcharstyle.h,v
retrieving revision 1.2
diff -u -p -r1.2 insetcharstyle.h
--- insetcharstyle.h    1 Dec 2003 16:01:50 -0000       1.2
+++ insetcharstyle.h    5 Dec 2003 07:01:30 -0000
@@ -60,10 +60,10 @@ public:
        ///
        void read(Buffer const & buf, LyXLex & lex);
        ///
-       void setButtonLabel();
-       ///
        void metrics(MetricsInfo &, Dimension &) const;
        ///
+       void draw(PainterInfo &, int, int) const;
+       ///
        void getDrawFont(LyXFont &) const;
        ///
        int latex(Buffer const &, std::ostream &,
@@ -96,6 +96,8 @@ private:
        void init();
        ///
        InsetCharStyleParams params_;
+       ///
+       bool has_label_;
 };
 
 #endif

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to