]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
Lots of changes for update of TextInsets, still some problems!
[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     explicit
45     InsetCollapsable();
46     ///
47     ~InsetCollapsable() {}
48     ///
49     Inset * Clone() const;
50     ///
51     void Read(Buffer const *, LyXLex &);
52     ///
53     void Write(Buffer const *, std::ostream &) const;
54     ///
55     int ascent(Painter &, LyXFont const &) const;
56     ///
57     int descent(Painter &, LyXFont const &) const;
58     ///
59     int width(Painter &, LyXFont const & f) const;
60     ///
61     void draw(BufferView *, const LyXFont &, int , float &, bool) const;
62     ///
63     void update(BufferView *, LyXFont const &, bool =false); 
64     ///
65     void Edit(BufferView *, int, int, unsigned int);
66     ///
67     EDITABLE Editable() const;
68     ///
69     bool IsTextInset() const { return true; }
70     ///
71     bool doClearArea() const;
72     ///
73     void InsetUnlock(BufferView *);
74     ///
75     bool needFullRow() const { return !collapsed; }
76     ///
77     bool LockInsetInInset(BufferView *, UpdatableInset *);
78     ///
79     bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
80     ///
81     bool UpdateInsetInInset(BufferView *, Inset *);
82     ///
83     int InsetInInsetY();
84     ///
85     void InsetButtonRelease(BufferView *, int, int, int);
86     ///
87     void InsetButtonPress(BufferView *, int, int, int);
88     ///
89     void InsetMotionNotify(BufferView *, int, int, int);
90     ///
91     void InsetKeyPress(XKeyEvent *);
92     ///
93     UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
94     ///
95     int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
96     ///
97     int Ascii(Buffer const *, std::ostream &) 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     void deleteLyXText(BufferView *);
125
126 protected:
127     ///
128     int ascent_collapsed(Painter &, LyXFont const &) const;
129     ///
130     int descent_collapsed(Painter &, LyXFont const &) const;
131     ///
132     int width_collapsed(Painter &, LyXFont const & f) const;
133     ///
134     void draw_collapsed(Painter & pain, const LyXFont &, int , float &) const;
135     ///
136     int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
137     
138     ///
139     bool collapsed;
140     ///
141     LColor::color framecolor;
142     ///
143     LyXFont labelfont;
144     ///
145     InsetText * inset;
146     // Instead of making these ints protected we could have a
147     // protected method "clickInButton" (Lgb)
148     ///
149     mutable int
150         button_length, button_top_y, button_bottom_y;
151
152 private:
153     ///
154     string label;
155     ///
156     bool autocollapse;
157     ///
158     int widthCollapsed;
159     ///
160     int oldWidth;
161     ///
162     mutable int topx;
163     mutable int topbaseline;
164     mutable UpdateCodes need_update;
165 };
166
167 #endif