Attached is a first attempt to streamline the handling of the
various presentation modes of collapsable insets.

To do still:

1) really remove the Inlined value from the CollapseStatus enum
2) same from the ERT dialog
3) move the drawing of "Conglomerate-style" inset presentation
from CharStyle to Collapsable. These are the SubLabel and 
Corners geometries, the first one with, the second without
label.

The new structure revolves around the geometry() method,
which returns the visual appearance style depending
on a) the stated decoration style or theme, and b) the
collapse-status Open or Collapsed (Inlined will go as
a CollapseStatus, but it returns as a decoration style
and a geometry type.)

There are still two further dynamic parameters, aotoOpen_
and openinlined_, modulating the geometry() output in
some situations. 

I think this will lead to a more unified scheme. This
work is not yet complete. Please comment.

- Martin
Index: insets/InsetCharStyle.h
===================================================================
--- insets/InsetCharStyle.h     (revision 19450)
+++ insets/InsetCharStyle.h     (working copy)
@@ -78,6 +78,9 @@
        ///
        bool forceDefaultParagraphs(idx_type) const { return true; }
        ///
+       virtual Decoration decoration() const { return Conglomerate; }
+
+       ///
        int latex(Buffer const &, odocstream &,
                  OutputParams const &) const;
        ///
Index: insets/InsetCharStyle.cpp
===================================================================
--- insets/InsetCharStyle.cpp   (revision 19450)
+++ insets/InsetCharStyle.cpp   (working copy)
@@ -51,7 +51,6 @@
 
 void InsetCharStyle::init()
 {
-       setInlined();
        setDrawFrame(false);
 }
 
@@ -134,7 +133,6 @@
 {
        params_.read(lex);
        InsetCollapsable::read(buf, lex);
-       setInlined();
 }
 
 
@@ -236,7 +234,6 @@
 
 void InsetCharStyle::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       setInlined();
        switch (cmd.action) {
 
        case LFUN_MOUSE_RELEASE:
Index: insets/InsetCollapsable.cpp
===================================================================
--- insets/InsetCollapsable.cpp (revision 19450)
+++ insets/InsetCollapsable.cpp (working copy)
@@ -45,10 +45,32 @@
 
 InsetCollapsable::CollapseStatus InsetCollapsable::status() const
 {
-       return (autoOpen_ && status_ != Inlined) ? Open : status_;
+       return autoOpen_ ? Open : status_;
 }
 
 
+InsetCollapsable::Geometry InsetCollapsable::geometry() const
+{
+       switch (decoration()) {
+               case Classic:
+                       if (status_ == Open || autoOpen_) {
+                               if (openinlined_)
+                                       return OpenInlined;
+                               else
+                                       return OpenG;
+                       } else
+                               return CollapsedG;
+                       break;
+               case InlinedD:
+                       return InlinedG;
+                       break;
+               case Conglomerate:
+                       return ( status_ == Open ? SubLabel : Corners );
+                       break;
+       }
+}
+
+
 InsetCollapsable::InsetCollapsable
                (BufferParams const & bp, CollapseStatus status)
        : InsetText(bp), label(from_ascii("Label")), status_(status),
@@ -88,9 +110,6 @@
        case Collapsed:
                os << "collapsed";
                break;
-       case Inlined:
-               os << "inlined";
-               break;
        }
        os << "\n";
        text_.write(buf, os);
@@ -107,10 +126,7 @@
                        lex.next();
                        string const tmp_token = lex.getString();
 
-                       if (tmp_token == "inlined") {
-                               status_ = Inlined;
-                               token_found = true;
-                       } else if (tmp_token == "collapsed") {
+                       if (tmp_token == "collapsed") {
                                status_ = Collapsed;
                                token_found = true;
                        } else if (tmp_token == "open") {
@@ -152,11 +168,11 @@
        autoOpen_ = mi.base.bv->cursor().isInside(this);
        mi.base.textwidth -= (int) (1.5 * TEXT_TO_INSET_OFFSET);
 
-       if (status() == Inlined) {
+       if (decoration() == InlinedD || decoration() == Conglomerate) {
                InsetText::metrics(mi, dim);
        } else {
                dim = dimensionCollapsed();
-               if (status() == Open) {
+               if (geometry() == OpenG || geometry() == OpenInlined) {
                        InsetText::metrics(mi, textdim_);
                        // This expression should not contain mi.base.texwidth
                        openinlined_ = !hasFixedWidth()
@@ -196,7 +212,7 @@
 void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
 {
        const int xx = x + TEXT_TO_INSET_OFFSET;
-       if (status() == Inlined) {
+       if (decoration() == InlinedD)  {
                InsetText::draw(pi, xx, y);
        } else {
                Dimension dimc = dimensionCollapsed();
@@ -208,17 +224,19 @@
 
                pi.pain.buttonText(xx, top + dimc.asc, label, labelfont_, 
mouse_hover_);
 
-               if (status() == Open) {
+               if (geometry() == OpenInlined) {
                        int textx, texty;
-                       if (openinlined_) {
-                               textx = xx + dimc.width();
-                               texty = top + textdim_.asc;
-                       } else {
-                               textx = xx;
-                               texty = top + dimc.height() + textdim_.asc;
-                       }
+                       textx = xx + dimc.width();
+                       texty = top + textdim_.asc;
                        InsetText::draw(pi, textx, texty);
                }
+               if (geometry() == OpenG) {
+                       int textx, texty;
+                       textx = xx;
+                       texty = top + dimc.height() + textdim_.asc;
+                       InsetText::draw(pi, textx, texty);
+               }
+               // FIXME add handling of SubLabel, Corners
        }
        setPosCache(pi, x, y);
 }
@@ -227,13 +245,11 @@
 void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const
 {
        x += TEXT_TO_INSET_OFFSET;
-       if (status() == Open) {
-               if (openinlined_)
-                       x += dimensionCollapsed().wid;
-               else
-                       y += dimensionCollapsed().des + textdim_.asc;
-       }
-       if (status() != Collapsed)
+       if (geometry() == OpenInlined)
+               x += dimensionCollapsed().wid;
+       if (geometry() == OpenG)
+               y += dimensionCollapsed().des + textdim_.asc;
+       if (geometry() != CollapsedG)
                InsetText::drawSelection(pi, x, y);
 }
 
@@ -241,30 +257,28 @@
 void InsetCollapsable::cursorPos(BufferView const & bv,
                CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
-       BOOST_ASSERT(status() != Collapsed);
+       BOOST_ASSERT(geometry() != CollapsedG);
 
        InsetText::cursorPos(bv, sl, boundary, x, y);
 
-       if (status() == Open) {
-               if (openinlined_)
-                       x += dimensionCollapsed().wid;
-               else
-                       y += dimensionCollapsed().height() - ascent()
-                               + TEXT_TO_INSET_OFFSET + textdim_.asc;
-       }
+       if (geometry() == OpenInlined)
+               x += dimensionCollapsed().wid;
+       if (geometry() == OpenG)
+               y += dimensionCollapsed().height() - ascent()
+                       + TEXT_TO_INSET_OFFSET + textdim_.asc;
        x += TEXT_TO_INSET_OFFSET;
 }
 
 
 Inset::EDITABLE InsetCollapsable::editable() const
 {
-       return status() != Collapsed ? HIGHLY_EDITABLE : IS_EDITABLE;
+       return geometry() != CollapsedG ? HIGHLY_EDITABLE : IS_EDITABLE;
 }
 
 
 bool InsetCollapsable::descendable() const
 {
-       return status() != Collapsed;
+       return geometry() != CollapsedG;
 }
 
 
@@ -306,7 +320,7 @@
 Inset * InsetCollapsable::editXY(Cursor & cur, int x, int y)
 {
        //lyxerr << "InsetCollapsable: edit xy" << endl;
-       if (status() == Collapsed || (button_dim.contains(x, y) && status() != 
Inlined))
+       if (geometry() == CollapsedG || (button_dim.contains(x, y) && 
decoration() != InlinedD))
                return this;
        cur.push(*this);
        return InsetText::editXY(cur, x, y);
@@ -320,7 +334,7 @@
 
        switch (cmd.action) {
        case LFUN_MOUSE_PRESS:
-               if (cmd.button() == mouse_button::button1 && hitButton(cmd) && 
status() != Inlined) {
+               if (cmd.button() == mouse_button::button1 && hitButton(cmd) && 
decoration() != InlinedD) {
                        // reset selection if necessary (see bug 3060)
                        if (cur.selection())
                                cur.bv().cursor().clearSelection();
@@ -329,9 +343,9 @@
                        cur.dispatched();
                        break;
                }
-               if (status() == Inlined)
+               if (decoration() == InlinedD)
                        InsetText::doDispatch(cur, cmd);
-               else if (status() == Open && !hitButton(cmd))
+               else if (geometry() != CollapsedG && !hitButton(cmd))
                        InsetText::doDispatch(cur, cmd);
                else
                        cur.undispatched();
@@ -340,9 +354,9 @@
        case LFUN_MOUSE_MOTION:
        case LFUN_MOUSE_DOUBLE:
        case LFUN_MOUSE_TRIPLE:
-               if (status_ == Inlined)
+               if (decoration() == InlinedD)
                        InsetText::doDispatch(cur, cmd);
-               else if (status() && !hitButton(cmd))
+               else if (geometry() != CollapsedG  && !hitButton(cmd))
                        InsetText::doDispatch(cur, cmd);
                else
                        cur.undispatched();
@@ -355,7 +369,7 @@
                        break;
                }
 
-               if (status() == Inlined) {
+               if (decoration() == InlinedD) {
                        // The mouse click has to be within the inset!
                        InsetText::doDispatch(cur, cmd);
                        break;
@@ -370,7 +384,7 @@
                        // toggle the inset visual state.
                        cur.dispatched();
                        cur.updateFlags(Update::Force | Update::FitCursor);
-                       if (status() == Collapsed) {
+                       if (geometry() == CollapsedG) {
                                setStatus(cur, Open);
                                edit(cur, true);
                        }
@@ -382,7 +396,7 @@
                }
 
                // The mouse click is within the opened inset.
-               if (status() == Open)
+               if (geometry() == OpenG || geometry() == OpenInlined)
                        InsetText::doDispatch(cur, cmd);
                break;
 
Index: insets/InsetCollapsable.h
===================================================================
--- insets/InsetCollapsable.h   (revision 19450)
+++ insets/InsetCollapsable.h   (working copy)
@@ -73,12 +73,52 @@
        ///
        void setLabelFont(Font & f);
        ///
-       bool isOpen() const { return status_ == Open || status_ == Inlined; }
+       bool isOpen() const { return geometry() != CollapsedG; }
        ///
-       bool inlined() const { return status_ == Inlined; }
+       bool inlined() const { return decoration() == InlinedD || decoration() 
== Conglomerate; }
        ///
        CollapseStatus status() const;
+       /** Of the old CollapseStatus we only keep the values  
+        *  Open and Collapsed.
+        * We define a list of possible inset decoration
+        * styles, and a list of possible (concrete, visual)
+        * inset geometries. Relationships between them
+        * (geometries in body of table):
+        *
+        *               \       CollapseStatus:
+        *   Decoration:  \ Open          Collapsed
+        *   -------------+---------------------------
+        *   Classic      | *) OpenG, <--x) CollapsedG
+        *                | OpenInlined
+        *   InlinedD     | InlinedG        InlinedG
+        *   Conglomerate | SubLabel        Corners
+        *   -----------------------------------------
+        *   *) toggled by openinlined_
+        *   x) toggled by autoOpen_
+        */
+
        ///
+       enum Decoration {
+               Classic,
+               InlinedD,
+               Conglomerate
+       };
+       /// Default looks
+       virtual Decoration decoration() const { return Classic;  }
+       ///
+       enum Geometry {
+               OpenG,
+               CollapsedG,
+               InlinedG,
+               OpenInlined,
+               SubLabel,
+               Corners
+       };
+       /// Returns the geometry based on CollapseStatus
+       /// (status_), autoOpen_ and openinlined_, and of
+       /// course decoration().
+       Geometry geometry() const;
+       ///
        bool allowSpellCheck() const { return true; }
        ///
        bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
@@ -99,8 +139,6 @@
        ///
        Inset * editXY(Cursor & cur, int x, int y);
        ///
-       void setInlined() { status_ = Inlined; }
-       ///
        docstring floatName(std::string const & type, BufferParams const &) 
const;
 
 protected:

Reply via email to