]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
prepare for 1.1.6pre2
[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(Buffer const &) 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     unsigned 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 &,
95               bool fragile, bool free_spc) const;
96     ///
97     int Ascii(Buffer const *, std::ostream &, int) const { return 0; }
98     ///
99     int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
100     ///
101     int DocBook(Buffer const *, std::ostream &) const { return 0; }
102     ///
103     void Validate(LaTeXFeatures & features) const;
104     ///
105     void GetCursorPos(BufferView *, int & x, int & y) const;
106     ///
107     void ToggleInsetCursor(BufferView *);
108     ///
109     UpdatableInset * GetLockingInset();
110     ///
111     UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
112     ///
113     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
114     ///
115     void setLabel(string const & l) { label = l; }
116     ///
117     void setLabelFont(LyXFont & f) { labelfont = f; }
118     ///
119     void setAutoCollapse(bool f) { autocollapse = f; }
120     ///
121     int getMaxWidth(Painter & pain, UpdatableInset const *) const;
122     ///
123     LyXText * getLyXText(BufferView *) const;
124     ///
125     void deleteLyXText(BufferView *, bool recursive=true) const;
126     ///
127     void resizeLyXText(BufferView *) const;
128
129 protected:
130     ///
131     int ascent_collapsed(Painter &, LyXFont const &) const;
132     ///
133     int descent_collapsed(Painter &, LyXFont const &) const;
134     ///
135     int width_collapsed(Painter &, LyXFont const & f) const;
136     ///
137     void draw_collapsed(Painter & pain, const LyXFont &, int , float &) const;
138     ///
139     int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
140     
141     ///
142     bool collapsed;
143     ///
144     LColor::color framecolor;
145     ///
146     LyXFont labelfont;
147     ///
148     InsetText * inset;
149     // Instead of making these ints protected we could have a
150     // protected method "clickInButton" (Lgb)
151     ///
152     mutable int
153         button_length, button_top_y, button_bottom_y;
154
155 private:
156     ///
157     string label;
158     ///
159     bool autocollapse;
160     ///
161     int widthCollapsed;
162     ///
163     mutable int oldWidth;
164     ///
165     mutable int topx;
166     mutable int topbaseline;
167     mutable UpdateCodes need_update;
168 };
169
170 #endif