]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsible.h
Fix text direction issue for InsetInfo in RTL context
[lyx.git] / src / insets / InsetCollapsible.h
1 // -*- C++ -*-
2 /**
3  * \file InsetCollapsible.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 INSETCOLLAPSIBLE_H
15 #define INSETCOLLAPSIBLE_H
16
17 #include "InsetText.h"
18
19 #include "Box.h"
20
21 #include <map>
22
23 namespace lyx {
24
25 class CursorSlice;
26 class InsetLayout;
27
28 namespace frontend { class Painter; }
29
30 /** A collapsible text inset
31
32 */
33 class InsetCollapsible : public InsetText {
34 public:
35         ///
36         InsetCollapsible(Buffer *, InsetText::UsePlain = InsetText::PlainLayout);
37         ///
38         InsetCollapsible(InsetCollapsible const & rhs);
39         ///
40         virtual ~InsetCollapsible();
41         ///
42         InsetCollapsible * asInsetCollapsible() { return this; }
43         ///
44         InsetCollapsible const * asInsetCollapsible() const { return this; }
45         ///
46         docstring toolTip(BufferView const & bv, int x, int y) const;
47         ///
48         docstring layoutName() const { return from_ascii("Collapsible"); }
49         ///
50         void read(Lexer &);
51         ///
52         void write(std::ostream &) const;
53         ///
54         void metrics(MetricsInfo &, Dimension &) const;
55         ///
56         void draw(PainterInfo & pi, int x, int y) const;
57         ///
58         virtual void drawBackground(PainterInfo &, int, int) const {}
59
60         /// return x,y of given position relative to the inset's baseline
61         void cursorPos(BufferView const & bv, CursorSlice const & sl,
62                 bool boundary, int & x, int & y) const;
63         ///
64         docstring const getNewLabel(docstring const & l) const;
65         ///
66         bool editable() const;
67         ///
68         bool hasSettings() const { return true; }
69         /// Returns true if coordinates are over the inset's button.
70         /// Always returns false when the inset does not have a
71         /// button.
72         bool clickable(BufferView const & bv, int x, int y) const;
73         /// can we go further down on mouse click?
74         bool descendable(BufferView const & bv) const;
75         ///
76         void setLabel(docstring const & l);
77         ///
78         docstring getLabel() const;
79         ///
80         virtual void setButtonLabel() {}
81         ///
82         virtual docstring const buttonLabel(BufferView const &) const;
83         ///
84         bool isOpen(BufferView const & bv) const
85                 { return geometry(bv) != ButtonOnly; }
86         ///
87         enum CollapseStatus {
88                 Collapsed,
89                 Open
90         };
91         ///
92         virtual void setStatus(Cursor & cur, CollapseStatus st);
93         ///
94         CollapseStatus status(BufferView const & bv) const;
95         /** Of the old CollapseStatus we only keep the values
96          *  Open and Collapsed.
97          * We define a list of possible inset decoration
98          * styles, and a list of possible (concrete, visual)
99          * inset geometries. Relationships between them
100          * (geometries in body of table):
101          *
102          *               \       CollapseStatus:
103          *   Decoration:  \ Open                Collapsed
104          *   -------------+-------------------------------
105          *   Classic      | *) TopButton, <--x) ButtonOnly
106          *                | LeftButton
107          *   Minimalistic | NoButton            ButtonOnly
108          *   Conglomerate | SubLabel            Corners
109          *   ---------------------------------------------
110          *   *) toggled by openinlined_
111          *   x) toggled by auto_open_
112          */
113
114         /// Default looks
115         virtual InsetLayout::InsetDecoration decoration() const;
116         /// Inset font
117         virtual FontInfo getFont() const { return getLayout().font(); }
118         /// Label font
119         virtual FontInfo getLabelfont() const { return getLayout().labelfont(); }
120         ///
121         enum Geometry {
122                 TopButton,
123                 ButtonOnly,
124                 NoButton,
125                 LeftButton,
126                 SubLabel,
127                 Corners
128         };
129         /// Returns the geometry based on CollapseStatus
130         /// (status_), auto_open_[BufferView] and openinlined_,
131         /// and of course decoration().
132         Geometry geometry(BufferView const & bv) const;
133         ///
134         bool canPaintChange(BufferView const & bv) const;
135         ///
136         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
137         ///
138         bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
139         ///
140         ColorCode backgroundColor(PainterInfo const &) const
141                 { return getLayout().bgcolor(); }
142         ///
143         ColorCode labelColor() const { return getLayout().labelfont().color(); }
144         ///
145         InsetCode lyxCode() const { return COLLAPSIBLE_CODE; }
146
147         ///
148         virtual bool usePlainLayout() const { return true; }
149         ///
150         std::string contextMenu(BufferView const & bv, int x, int y) const;
151         ///
152         std::string contextMenuName() const;
153         ///
154         void addToToc(DocIterator const & dit, bool output_active,
155                       UpdateType utype, TocBackend & backend) const; //override
156
157 protected:
158         ///
159         void doDispatch(Cursor & cur, FuncRequest & cmd);
160         ///
161         void edit(Cursor & cur, bool front,
162                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
163         ///
164         Inset * editXY(Cursor & cur, int x, int y);
165         ///
166         mutable CollapseStatus status_;
167 private:
168         ///
169         Dimension dimensionCollapsed(BufferView const & bv) const;
170         ///
171         docstring labelstring_;
172
173         // These variables depend of the view in which the inset is displayed
174         struct View
175         {
176                 /// The dimension of the inset button
177                 Box button_dim_;
178                 /// a substatus of the Open status, determined automatically in metrics
179                 bool openinlined_;
180                 /// the inset will automatically open when the cursor is inside. This is
181                 /// dependent on the bufferview, compare with InsetMathMacro::editing_.
182                 bool auto_open_;
183                 /// changes color when mouse enters/leaves this inset
184                 bool mouse_hover_;
185         };
186
187         ///
188         mutable std::map<BufferView const *, View> view_;
189 };
190
191 } // namespace lyx
192
193 #endif