]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCollapsable.h
Cosmetics
[lyx.git] / src / insets / InsetCollapsable.h
index c14cadfc738d6ed18b748e63e88f671133083f31..4e69f893c3d92c3911d8013f46aea5ed971f36c0 100644 (file)
@@ -5,8 +5,8 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Alejandro Aguilar Sierra
- * \author Jürgen Vigna
- * \author Lars Gullik Bjønnes
+ * \author Jürgen Vigna
+ * \author Lars Gullik Bjønnes
  *
  * Full author contact details are available in file CREDITS.
  */
 #include "InsetText.h"
 
 #include "Box.h"
-#include "LyXFont.h"
-
-#include <string>
+#include "TextClass.h"
 
 namespace lyx {
 
-class LyXText;
-class Paragraph;
 class CursorSlice;
+class InsetLayout;
 
 namespace frontend { class Painter; }
 
@@ -36,34 +33,50 @@ namespace frontend { class Painter; }
 class InsetCollapsable : public InsetText {
 public:
        ///
-       static int const TEXT_TO_TOP_OFFSET = 2;
+       InsetCollapsable(Buffer const &, InsetText::UsePlain = InsetText::PlainLayout);
        ///
-       static int const TEXT_TO_BOTTOM_OFFSET = 2;
+       InsetCollapsable(InsetCollapsable const & rhs);
        ///
-       InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
+       InsetCollapsable * asInsetCollapsable() { return this; }
        ///
-       InsetCollapsable(InsetCollapsable const & rhs);
+       InsetCollapsable const * asInsetCollapsable() const { return this; }
        ///
-       docstring insetName() const { return from_ascii("Collapsable"); }
+       docstring toolTip(BufferView const & bv, int x, int y) const;
        ///
-       void read(Buffer const &, Lexer &);
+       docstring name() const { return from_ascii("Collapsable"); }
        ///
-       void write(Buffer const &, std::ostream &) const;
+       InsetLayout const & getLayout(BufferParams const &) const { return *layout_; }
        ///
-       bool metrics(MetricsInfo &, Dimension &) const;
+       InsetLayout const & getLayout() const { return *layout_; } 
        ///
-       void draw(PainterInfo & pi, int x, int y) const;
+       void setLayout(BufferParams const &);
+       /// (Re-)set the character style parameters from \p tc according
+       /// to name()
+       void setLayout(DocumentClass const * const tc);
+       ///
+       virtual bool usePlainLayout() { return true; }
        ///
-       void drawSelection(PainterInfo & pi, int x, int y) const;
+       void read(Lexer &);
+       ///
+       void write(std::ostream &) const;
+       ///
+       void metrics(MetricsInfo &, Dimension &) const;
+       ///
+       void draw(PainterInfo & pi, int x, int y) const;
+
        /// return x,y of given position relative to the inset's baseline
        void cursorPos(BufferView const & bv, CursorSlice const & sl,
                bool boundary, int & x, int & y) const;
-       ///
+       /// Returns true if (mouse) action is over the inset's button.
+       /// Always returns false when the inset does not have a
+       /// button.
        bool hitButton(FuncRequest const &) const;
        ///
        docstring const getNewLabel(docstring const & l) const;
        ///
-       EDITABLE editable() const;
+       bool editable() const;
+       ///
+       bool hasSettings() const { return true; }
        /// can we go further down on mouse click?
        bool descendable() const;
        ///
@@ -71,65 +84,125 @@ public:
        ///
        virtual void setButtonLabel() {}
        ///
-       void setLabelFont(LyXFont & f);
-       ///
-       bool isOpen() const { return status_ == Open || status_ == Inlined; }
-       ///
-       bool inlined() const { return status_ == Inlined; }
-       ///
-       CollapseStatus status() const;
-       ///
-       bool allowSpellCheck() const { return true; }
+       virtual docstring const buttonLabel(BufferView const &) const
+               { return labelstring_; }
+       ///
+       bool isOpen(BufferView const & bv) const 
+               { return geometry(bv) != ButtonOnly; }
+       ///
+       CollapseStatus status(BufferView const & bv) 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      | *) TopButton, <--x) ButtonOnly
+        *                | LeftButton
+        *   Minimalistic | NoButton            ButtonOnly
+        *   Conglomerate | SubLabel            Corners
+        *   ---------------------------------------------
+        *   *) toggled by openinlined_
+        *   x) toggled by auto_open_
+        */
+
+       /// Default looks
+       virtual InsetLayout::InsetDecoration decoration() const;
+       ///
+       enum Geometry {
+               TopButton,
+               ButtonOnly,
+               NoButton,
+               LeftButton,
+               SubLabel,
+               Corners
+       };
+       /// Returns the geometry based on CollapseStatus
+       /// (status_), auto_open_[BufferView] and openinlined_,
+       /// and of course decoration().
+       Geometry geometry(BufferView const & bv) const;
+       /// Returns the geometry disregarding auto_open_
+       Geometry geometry() const;
+       /// Allow spellchecking, except for insets with latex_language
+       bool allowSpellCheck() const { return !forceLTR(); }
+       ///
+       bool allowMultiPar() const;
        ///
        bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
        ///
        void setStatus(Cursor & cur, CollapseStatus st);
        ///
        bool setMouseHover(bool mouse_hover);
-
-protected:
        ///
-       virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
+       ColorCode backgroundColor() const { return layout_->bgcolor(); }
        ///
-       Dimension dimensionCollapsed() const;
+       int latex(odocstream &, OutputParams const &) const;
        ///
-       Box const & buttonDim() const;
+       int docbook(odocstream &, OutputParams const &) const;
        ///
-       void edit(Cursor & cur, bool left);
-       ///
-       Inset * editXY(Cursor & cur, int x, int y);
+       int xhtml(odocstream &, OutputParams const &) const;
        ///
-       void setInlined() { status_ = Inlined; }
+       void validate(LaTeXFeatures &) const;
        ///
-       docstring floatName(std::string const & type, BufferParams const &) const;
+       InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
 
+       /// Allow multiple blanks
+       virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
+       /// Don't eliminate empty paragraphs
+       virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
+       /// Force inset into LTR environment if surroundings are RTL?
+       virtual bool forceLTR() const { return layout_->isForceLtr(); }
+       ///
+       virtual bool usePlainLayout() const { return true; }
+       /// Is this inset's layout defined in the document's textclass?
+       /// May be wrong after textclass change or paste from another document
+       bool undefined() const;
+       /// the string that is passed to the TOC
+       void tocString(odocstream &) const;
+       ///
+       virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
 protected:
        ///
-       LyXFont labelfont_;
+       void doDispatch(Cursor & cur, FuncRequest & cmd);
        ///
-       mutable Box button_dim;
+       void edit(Cursor & cur, bool front, 
+               EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
+       ///
+       Inset * editXY(Cursor & cur, int x, int y);
        ///
-       mutable int topx;
+       docstring floatName(std::string const & type, BufferParams const &) const;
        ///
-       mutable int topbaseline;
+       virtual void resetParagraphsFont();
        ///
-       mutable docstring label;
+       mutable CollapseStatus status_;
 private:
+       /// cache for the layout_. Make sure it is in sync with the document class!
+       InsetLayout const * layout_;
        ///
-       mutable CollapseStatus status_;
+       Dimension dimensionCollapsed(BufferView const & bv) const;
+       ///
+       /// should paragraphs be forced to use the empty layout?
+       virtual bool forcePlainLayout(idx_type = 0) const 
+               { return getLayout().forcePlainLayout(); }
+       /// should the user be allowed to customize alignment, etc.?
+       virtual bool allowParagraphCustomization(idx_type = 0) const 
+               { return getLayout().allowParagraphCustomization(); }
+       docstring labelstring_;
+       ///
+       mutable Box button_dim;
        /// a substatus of the Open status, determined automatically in metrics
        mutable bool openinlined_;
-       /// the inset will automatically open when the cursor is inside
-       mutable bool autoOpen_;
-       ///
-       mutable Dimension textdim_;
+       /// the inset will automatically open when the cursor is inside. This is
+       /// dependent on the bufferview, compare with MathMacro::editing_.
+       mutable std::map<BufferView const *, bool> auto_open_;
        /// changes color when mouse enters/leaves this inset
        bool mouse_hover_;
 };
 
-// A helper function that pushes the cursor out of the inset.
-void leaveInset(Cursor & cur, Inset const & in);
-
 } // namespace lyx
 
 #endif