]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
Fix GRAPHICS_EDIT of InsetGraphics
[lyx.git] / src / insets / InsetCollapsable.h
1 // -*- C++ -*-
2 /**
3  * \file InsetCollapsable.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alejandro Aguilar Sierra
8  * \author Jürgen Vigna
9  * \author Lars Gullik Bjønnes
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef INSETCOLLAPSABLE_H
15 #define INSETCOLLAPSABLE_H
16
17 #include "Inset.h"
18 #include "InsetText.h"
19
20 #include "Box.h"
21 #include "TextClass.h"
22
23 namespace lyx {
24
25 class CursorSlice;
26 class InsetLayout;
27
28 namespace frontend { class Painter; }
29
30 /** A collapsable text inset
31
32 */
33 class InsetCollapsable : public InsetText {
34 public:
35         ///
36         InsetCollapsable(Buffer const &,
37                 CollapseStatus status = Inset::Open, DocumentClass * tc = 0);
38         ///
39         InsetCollapsable(InsetCollapsable const & rhs);
40         ///
41         InsetCollapsable * asInsetCollapsable() { return this; }
42         ///
43         InsetCollapsable const * asInsetCollapsable() const { return this; }
44         ///
45         docstring toolTip(BufferView const & bv, int x, int y) const;
46         ///
47         docstring name() const { return from_ascii("Collapsable"); }
48         ///
49         InsetLayout const & getLayout(BufferParams const &) const { return *layout_; }
50         ///
51         InsetLayout const & getLayout() const { return *layout_; } 
52         ///
53         void setLayout(BufferParams const &);
54         /// (Re-)set the character style parameters from \p tc according
55         /// to name()
56         void setLayout(DocumentClass const * const tc);
57         ///
58         virtual bool useEmptyLayout() { return true; }
59         ///
60         void read(Lexer &);
61         ///
62         void write(std::ostream &) const;
63         ///
64         void metrics(MetricsInfo &, Dimension &) const;
65         ///
66         void draw(PainterInfo & pi, int x, int y) const;
67
68         /// return x,y of given position relative to the inset's baseline
69         void cursorPos(BufferView const & bv, CursorSlice const & sl,
70         ///
71         bool boundary, int & x, int & y) const;
72         ///
73         bool hitButton(FuncRequest const &) const;
74         ///
75         docstring const getNewLabel(docstring const & l) const;
76         ///
77         EDITABLE editable() const;
78         /// can we go further down on mouse click?
79         bool descendable() const;
80         ///
81         void setLabel(docstring const & l);
82         ///
83         virtual void setButtonLabel() {}
84         ///
85         bool isOpen() const { return geometry() != ButtonOnly; }
86         ///
87         CollapseStatus status() const;
88         /** Of the old CollapseStatus we only keep the values  
89          *  Open and Collapsed.
90          * We define a list of possible inset decoration
91          * styles, and a list of possible (concrete, visual)
92          * inset geometries. Relationships between them
93          * (geometries in body of table):
94          *
95          *               \       CollapseStatus:
96          *   Decoration:  \ Open                Collapsed
97          *   -------------+-------------------------------
98          *   Classic      | *) TopButton, <--x) ButtonOnly
99          *                | LeftButton
100          *   Minimalistic | NoButton            ButtonOnly
101          *   Conglomerate | SubLabel            Corners
102          *   ---------------------------------------------
103          *   *) toggled by openinlined_
104          *   x) toggled by autoOpen_
105          */
106
107         /// Default looks
108         virtual InsetLayout::InsetDecoration decoration() const;
109         ///
110         enum Geometry {
111                 TopButton,
112                 ButtonOnly,
113                 NoButton,
114                 LeftButton,
115                 SubLabel,
116                 Corners
117         };
118         /// Returns the geometry based on CollapseStatus
119         /// (status_), autoOpen_ and openinlined_, and of
120         /// course decoration().
121         Geometry geometry() const;
122         ///
123         bool allowSpellCheck() const { return true; }
124         ///
125         bool allowMultiPar() const;
126         ///
127         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
128         ///
129         void setStatus(Cursor & cur, CollapseStatus st);
130         ///
131         bool setMouseHover(bool mouse_hover);
132         ///
133         ColorCode backgroundColor() const { return layout_->bgcolor(); }
134         ///
135         int latex(odocstream &, OutputParams const &) const;
136         ///
137         void validate(LaTeXFeatures &) const;
138         ///
139         InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
140
141         /// Allow multiple blanks
142         virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
143         /// Don't eliminate empty paragraphs
144         virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
145         /// Force inset into LTR environment if surroundings are RTL?
146         virtual bool forceLTR() const { return layout_->isForceLtr(); }
147         ///
148         virtual bool useEmptyLayout() const { return true; }
149         /// Is this inset's layout defined in the document's textclass?
150         /// May be wrong after textclass change or paste from another document
151         bool undefined() const;
152         ///
153         virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
154 protected:
155         ///
156         void doDispatch(Cursor & cur, FuncRequest & cmd);
157         ///
158         void edit(Cursor & cur, bool front, 
159                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
160         ///
161         Inset * editXY(Cursor & cur, int x, int y);
162         ///
163         docstring floatName(std::string const & type, BufferParams const &) const;
164         ///
165         virtual void resetParagraphsFont();
166
167 private:
168         /// cache for the layout_. Make sure it is in sync with the document class!
169         InsetLayout const * layout_;
170         ///
171         Dimension dimensionCollapsed() const;
172         ///
173         docstring labelstring_;
174         ///
175         mutable Box button_dim;
176         ///
177         mutable CollapseStatus status_;
178         /// a substatus of the Open status, determined automatically in metrics
179         mutable bool openinlined_;
180         /// the inset will automatically open when the cursor is inside
181         mutable bool autoOpen_;
182         /// changes color when mouse enters/leaves this inset
183         bool mouse_hover_;
184 };
185
186 } // namespace lyx
187
188 #endif