On Fri, Dec 05, 2003 at 10:19:29AM +0100, Jean-Marc Lasgouttes spake thusly: > Isn't it possible to have this code in InsetCollapsable? My though is > that we should try to limit the number of possible appearance of > insets rather than have each inset invent something. > > I think that all insets in inline mode would benefit from this > representation (think of ERT). > > JMarc
Good idea actually. Especially ERT. Only I don't feel like doing that right now. I slightly improved again the patch; now the frame has been replaced by a blue underline to be less conspicuous. Otherwise the same. Patch attached. As I haven't heard any real objections (just blue-sky ideas building on it) I'll commit later today. - 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 10:37:43 -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,48 @@ 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.setDrawFrame(InsetText::NEVER); + inset.draw(pi, x, y); + + pi.pain.line(x + 2, y + inset.descent(), x + dim_.wid - 2, + y + inset.descent(), LColor::blue); + + 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 +142,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 10:37:43 -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
pgp00000.pgp
Description: PGP signature