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