This looks reasonable to me, though I haven't tested it. (I'm still obsessing over BibTeX stuff.)

One suggestion: I think CharStyles should by default have an unobtrusive presentation, NOT with the label showing. The default presentation now (or previously?) gets particularly ugly if you try to nest them. Making them nest nicely is critical, it seems to me, to any attempt to replace the Text Settings dialog with CharStyles, which we are pretty much on the verge of doing now. (I think it's really just the menu that needs sorting out for that, as we'd need too many CharStyles to just list them all.) Anyway, the crucial thing, I think, is that in the "less intrusive" form, it shouldn't significantly change the line height. At present, the "corners" version seems to do so more than it needs to: The semi-box is drawn lower in this version than when the label is present. And I'd go a bit further, too, and suggest that maybe the unintrusive version should be REALLY unintrusive and maybe not have any distinctive appearance at all, except the font. Yes, I suppose it would be possible to lose one, but then you can always Open All Insets to find it. Or maybe there should be three displays possible here: Labeled, Corners, and None, with maybe Corners being default?

Anyway, thoughts....

Richard

Martin Vermeer wrote:
On Sat, Aug 18, 2007 at 12:09:18PM -0400, Richard Heck wrote:
 Martin Vermeer wrote:
Steady progress, see patch.
 I tried but failed.

 rh


Ok, let's try again ;-/

("must have been good-looking cause he's so hard to see")

- Martin
------------------------------------------------------------------------

Index: InsetCharStyle.h
===================================================================
--- InsetCharStyle.h    (revision 19610)
+++ InsetCharStyle.h    (working copy)
@@ -38,8 +38,6 @@
        Font font;
        ///
        Font labelfont;
-       ///
-       bool show_label;
 };
Index: InsetCharStyle.cpp
===================================================================
--- InsetCharStyle.cpp  (revision 19621)
+++ InsetCharStyle.cpp  (working copy)
@@ -50,9 +50,7 @@
void InsetCharStyle::init()
-{
-       setDrawFrame(false);
-}
+{}
InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s)
@@ -101,7 +99,6 @@
        params_.font = Font(Font::ALL_INHERIT);
        params_.labelfont = Font(Font::ALL_INHERIT);
        params_.labelfont.setColor(Color::error);
-       params_.show_label = true;
 }
@@ -112,7 +109,6 @@
        params_.latexparam = cs->latexparam;
        params_.font = cs->font;
        params_.labelfont = cs->labelfont;
-       params_.show_label = true;
 }
@@ -145,7 +141,7 @@
        mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
        InsetText::metrics(mi, dim);
        mi.base.font = tmpfont;
-       if (params_.show_label) {
+       if (status() == Open) {
                // consider width of the inset label
                Font font(params_.labelfont);
                font.realize(Font(Font::ALL_SANE));
@@ -168,7 +164,7 @@
        dim.des += TEXT_TO_INSET_OFFSET;
        dim.wid += 2 * TEXT_TO_INSET_OFFSET;
        mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
-       if (params_.show_label)
+       if (status() == Open)
                dim.des += ascent();
        bool const changed = dim_ != dim;
        dim_ = dim;
@@ -184,11 +180,11 @@
        getDrawFont(pi.base.font);
        // I don't understand why the above .reduce and .realize aren't
        //needed, or even wanted, here. It just works. -- MV 10.04.2005
-       InsetText::draw(pi, x + TEXT_TO_INSET_OFFSET, y);
+       InsetCollapsable::draw(pi, x, y);
        pi.base.font = tmpfont;
int desc = InsetText::descent();
-       if (params_.show_label)
+       if (status() == Open)
                desc -= ascent();
pi.pain.line(x, y + desc - 4, x, y + desc, params_.labelfont.color());
@@ -198,7 +194,7 @@
                params_.labelfont.color());
// the name of the charstyle. Can be toggled.
-       if (params_.show_label) {
+       if (status() == Open) {
                Font font(params_.labelfont);
                font.realize(Font(Font::ALL_SANE));
                font.decSize();
@@ -218,7 +214,7 @@
                        s, font, Color::none, Color::none);
        }
- // a visual clue when the cursor is inside the inset
+       // a visual cue when the cursor is inside the inset
        Cursor & cur = pi.base.bv->cursor();
        if (cur.isInside(this)) {
                y -= ascent();
@@ -244,18 +240,24 @@
case LFUN_MOUSE_RELEASE:
                        if (cmd.button() == mouse_button::button3)
-                               params_.show_label = !params_.show_label;
+                               if (status() == Open)
+                                       setStatus(cur, Collapsed);
+                               else
+                                       setStatus(cur, Open);
                        else
                                InsetCollapsable::doDispatch(cur, cmd);
                        break;
case LFUN_INSET_TOGGLE:
                if (cmd.argument() == "open")
-                       params_.show_label = true;
+                       setStatus(cur, Open);
                else if (cmd.argument() == "close")
-                       params_.show_label = false;
+                       setStatus(cur, Collapsed);
                else if (cmd.argument() == "toggle" || cmd.argument().empty())
-                       params_.show_label = !params_.show_label;
+                       if (status() == Open)
+                               setStatus(cur, Collapsed);
+                       else
+                               setStatus(cur, Open);
                else // if assign or anything else
                        cur.undispatched();
                cur.dispatched();
@@ -351,7 +353,7 @@
 void InsetCharStyleParams::write(ostream & os) const
 {
        os << "CharStyle " << type << "\n";
-       os << "show_label " << convert<string>(show_label) << "\n";
+       os << "show_label true\n";
 }
@@ -366,11 +368,14 @@
                        type = lex.getString();
                }
+ // FIXME get rid of show_label + // altogether (file fmt change)
                else if (token == "show_label") {
                        lex.next();
-                       show_label = lex.getBool();
+                       bool dummy = lex.getBool();
                }
+ // This is handled in Collapsable
                else if (token == "status") {
                        lex.pushToken(token);
                        break;
Index: InsetCollapsable.cpp
===================================================================
--- InsetCollapsable.cpp        (revision 19610)
+++ InsetCollapsable.cpp        (working copy)
@@ -225,43 +225,47 @@
 {
        const int xx = x + TEXT_TO_INSET_OFFSET;
- if (decoration() == Minimalistic) {
-               InsetText::draw(pi, xx, y);
-       } else {
-               Dimension dimc = dimensionCollapsed();
-               int const top  = y - ascent() + TEXT_TO_INSET_OFFSET;
+       // Draw button first -- top, left or only
+       Dimension dimc = dimensionCollapsed();
+       int const top  = y - ascent() + TEXT_TO_INSET_OFFSET;
+       if (decoration() == Classic) {
                button_dim.x1 = xx + 0;
                button_dim.x2 = xx + dimc.width();
                button_dim.y1 = top;
                button_dim.y2 = top + dimc.height();
pi.pain.buttonText(xx, top + dimc.asc, label, layout_.labelfont, mouse_hover_);
+       }
- int textx, texty;
-               switch (geometry()) {
-               case LeftButton:
-                       textx = xx + dimc.width();
-                       texty = top + textdim_.asc;
-                       InsetText::draw(pi, textx, texty);
-                       break;
-               case TopButton:
-                       textx = xx;
-                       texty = top + dimc.height() + textdim_.asc;
-                       InsetText::draw(pi, textx, texty);
-                       break;
-               case ButtonOnly:
-                       break;
-               case NoButton:
-                       textx = xx;
-                       texty = top + textdim_.asc;
-                       InsetText::draw(pi, textx, texty);
-                       break;
-               case SubLabel:
-               case Corners:
-                       // FIXME add handling of SubLabel, Corners
-                       // still in CharStyle
-                       break;
-               }
+       int textx, texty;
+       switch (geometry()) {
+       case LeftButton:
+               textx = xx + dimc.width();
+               texty = top + textdim_.asc;
+               InsetText::draw(pi, textx, texty);
+               break;
+       case TopButton:
+               textx = xx;
+               texty = top + dimc.height() + textdim_.asc;
+               InsetText::draw(pi, textx, texty);
+               break;
+       case ButtonOnly:
+               break;
+       case NoButton:
+               textx = xx;
+               texty = y + textdim_.asc;
+               InsetText::draw(pi, textx, texty);
+               break;
+       case SubLabel:
+       case Corners:
+               // FIXME add handling of SubLabel, Corners
+               // still in CharStyle
+               textx = xx;
+               texty = y + textdim_.asc;
+               const_cast<InsetCollapsable *>(this)->setDrawFrame(false);
+               InsetText::draw(pi, textx, texty);
+               const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
+               break;
        }
        setPosCache(pi, x, y);
 }


--
==================================================================
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==================================================================
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto

Reply via email to