]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
3d8dd7e21028e31b5b63e5457655523058e6298f
[lyx.git] / src / insets / insetcollapsable.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000 The LyX Team.
8  *
9  *======================================================
10  */
11
12
13 #ifndef INSETCOLLAPSABLE_H
14 #define INSETCOLLAPSABLE_H
15
16 #ifdef __GNUG__
17 #pragma interface
18 #endif
19
20 #include "lyxinset.h"
21 #include "lyxfont.h"
22 #include "LColor.h"
23
24
25 class Painter;
26 class InsetText;
27 class LyXText;
28
29 /** A colapsable text inset
30   
31 */
32 class InsetCollapsable : public UpdatableInset {
33 public:
34     ///
35     enum UpdateCodes {
36         NONE = 0,
37         FULL
38     };
39     ///
40     static int const TEXT_TO_TOP_OFFSET = 2;
41     ///
42     static int const TEXT_TO_BOTTOM_OFFSET = 2;
43     ///
44     InsetCollapsable();
45     ///
46     Inset * Clone() const;
47     ///
48     void Read(Buffer const *, LyXLex &);
49     ///
50     void Write(Buffer const *, std::ostream &) const;
51     ///
52     int ascent(BufferView *, LyXFont const &) const;
53     ///
54     int descent(BufferView *, LyXFont const &) const;
55     ///
56     int width(BufferView *, LyXFont const & f) const;
57     ///
58     void draw(BufferView *, const LyXFont &, int , float &, bool) const;
59     ///
60     void update(BufferView *, LyXFont const &, bool =false); 
61     ///
62     void Edit(BufferView *, int, int, unsigned int);
63     ///
64     EDITABLE Editable() const;
65     ///
66     bool InsertInset(BufferView *, Inset * inset);
67     ///
68     bool IsTextInset() const { return true; }
69     ///
70     bool doClearArea() const;
71     ///
72     void InsetUnlock(BufferView *);
73     ///
74     bool needFullRow() const { return !collapsed; }
75     ///
76     bool LockInsetInInset(BufferView *, UpdatableInset *);
77     ///
78     bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
79     ///
80     bool UpdateInsetInInset(BufferView *, Inset *);
81     ///
82     int InsetInInsetY();
83     ///
84     void InsetButtonRelease(BufferView *, int, int, int);
85     ///
86     void InsetButtonPress(BufferView *, int, int, int);
87     ///
88     void InsetMotionNotify(BufferView *, int, int, int);
89     ///
90     void InsetKeyPress(XKeyEvent *);
91     ///
92     UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
93     ///
94     int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
95     ///
96     int Ascii(Buffer const *, std::ostream &) const { return 0; }
97     ///
98     int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
99     ///
100     int DocBook(Buffer const *, std::ostream &) const { return 0; }
101     ///
102     void Validate(LaTeXFeatures & features) const;
103     ///
104     void GetCursorPos(BufferView *, int & x, int & y) const;
105     ///
106     void ToggleInsetCursor(BufferView *);
107     ///
108     UpdatableInset * GetLockingInset();
109     ///
110     UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
111     ///
112     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
113     ///
114     void setLabel(string const & l) { label = l; }
115     ///
116     void setLabelFont(LyXFont & f) { labelfont = f; }
117     ///
118     void setAutoCollapse(bool f) { autocollapse = f; }
119     ///
120     int getMaxWidth(Painter & pain, UpdatableInset const *) const;
121     ///
122     LyXText * getLyXText(BufferView *) const;
123     void deleteLyXText(BufferView *) const;
124
125 protected:
126     ///
127     int ascent_collapsed(Painter &, LyXFont const &) const;
128     ///
129     int descent_collapsed(Painter &, LyXFont const &) const;
130     ///
131     int width_collapsed(Painter &, LyXFont const & f) const;
132     ///
133     void draw_collapsed(Painter & pain, const LyXFont &, int , float &) const;
134     ///
135     int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
136     
137     ///
138     bool collapsed;
139     ///
140     LColor::color framecolor;
141     ///
142     LyXFont labelfont;
143     ///
144     InsetText * inset;
145     // Instead of making these ints protected we could have a
146     // protected method "clickInButton" (Lgb)
147     ///
148     mutable int
149         button_length, button_top_y, button_bottom_y;
150
151 private:
152     ///
153     string label;
154     ///
155     bool autocollapse;
156     ///
157     int widthCollapsed;
158     ///
159     int oldWidth;
160     ///
161     mutable int topx;
162     mutable int topbaseline;
163     mutable UpdateCodes need_update;
164 };
165
166 #endif