]> git.lyx.org Git - lyx.git/blob - src/insets/lyxinset.h
bf45450c71fed122e1681e55ddc74e84b620fe9c
[lyx.git] / src / insets / lyxinset.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *       
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2000 the LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef LYXINSET_H
13 #define LYXINSET_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "gettext.h"
20 #include "lyxfont.h"
21 #include "lyxlex.h"
22
23 using std::ostream;
24
25 class Painter;
26 class Buffer;
27 class BufferView;
28
29 struct LaTeXFeatures;
30
31
32 /// Insets
33 class Inset {
34 public:
35         /** This is not quite the correct place for this enum. I think
36             the correct would be to let each subclass of Inset declare
37             its own enum code. Actually the notion of an Inset::Code
38             should be avoided, but I am not sure how this could be done
39             in a cleaner way. */
40         enum Code {
41                 ///
42                 NO_CODE,
43                 ///
44                 TOC_CODE,  // do these insets really need a code? (ale)
45                 ///
46                 LOF_CODE,
47                 ///
48                 LOT_CODE,
49                 ///
50                 LOA_CODE,
51                 ///
52                 QUOTE_CODE,
53                 ///
54                 MARK_CODE,
55                 ///
56                 REF_CODE,
57                 ///
58                 URL_CODE,
59                 ///
60                 HTMLURL_CODE,
61                 ///
62                 SEPARATOR_CODE,
63                 ///
64                 ENDING_CODE,
65                 ///
66                 LABEL_CODE,
67                 ///
68                 IGNORE_CODE,
69                 ///
70                 ACCENT_CODE,
71                 ///
72                 MATH_CODE,
73                 ///
74                 INDEX_CODE,
75                 ///
76                 INCLUDE_CODE,
77                 ///
78                 GRAPHICS_CODE,
79                 ///
80                 PARENT_CODE,
81                 ///
82                 BIBTEX_CODE,
83                 ///
84                 TEXT_CODE,
85                 ///
86                 ERT_CODE,
87                 ///
88                 FOOT_CODE,
89                 ///
90                 MARGIN_CODE,
91                 ///
92                 SPECIALCHAR_CODE
93         };
94
95         enum EDITABLE {
96             NOT_EDITABLE = 0,
97             IS_EDITABLE,
98             HIGHLY_EDITABLE
99         };
100
101         ///
102         virtual ~Inset() {}
103         ///
104         virtual int ascent(Painter &, LyXFont const &) const = 0;
105         ///
106         virtual int descent(Painter &, LyXFont const &) const = 0;
107         ///
108         virtual int width(Painter &, LyXFont const &) const = 0;
109         ///
110         virtual void draw(Painter &, LyXFont const &,
111                           int baseline, float & x) const = 0;
112         ///
113         virtual LyXFont ConvertFont(LyXFont font);
114         /// what appears in the minibuffer when opening
115         virtual const char * EditMessage() const {return _("Opened inset");}
116         ///
117         virtual void Edit(BufferView *, int x, int y, unsigned int button);
118         ///
119         virtual EDITABLE Editable() const;
120         ///
121         bool IsTextInset() const;
122         ///
123         virtual bool AutoDelete() const;
124         ///
125         virtual void Write(ostream &) const = 0;
126         ///
127         virtual void Read(LyXLex & lex) = 0;
128         /** returns the number of rows (\n's) of generated tex code.
129          fragile != 0 means, that the inset should take care about
130          fragile commands by adding a \protect before.
131          If the freee_spc (freespacing) variable is set, then this inset
132          is in a free-spacing paragraph.
133          */
134         virtual int Latex(ostream &, signed char fragile,
135                           bool free_spc) const = 0;
136
137         ///
138         virtual int Linuxdoc(ostream &) const = 0;
139         ///
140         virtual int DocBook(ostream &) const = 0;
141         /// Updates needed features for this inset.
142         virtual void Validate(LaTeXFeatures & features) const;
143         ///
144         virtual bool Deletable() const;
145
146         /// returns LyX code associated with the inset. Used for TOC, ...)
147         virtual Inset::Code LyxCode() const { return NO_CODE; }
148   
149         /// Get the label that appears at screen
150         virtual string getLabel(int) const {
151                 return string();
152         }
153
154         ///
155         virtual Inset * Clone() const = 0;
156
157         /// returns true to override begin and end inset in file
158         virtual bool DirectWrite() const;
159
160         /// Returns true if the inset should be centered alone
161         virtual bool display() const { return false; }  
162         /// Changes the display state of the inset
163         virtual void display(bool) {}  
164         ///
165         virtual int GetNumberOfLabels() const {
166                 return 0;
167         }
168         ///
169         virtual void init(BufferView *) {}
170
171 };
172
173
174 //  Updatable Insets. These insets can be locked and receive
175 //  directly user interaction. Currently used only for mathed.
176 //  Note that all pure methods from Inset class are pure here too.
177 //  [Alejandro 080596] 
178
179 /** Extracted from Matthias notes:
180   * 
181   * An inset can simple call LockInset in it's edit call and *ONLY* 
182   * in it's edit call.
183   *
184   * Unlocking is either done by LyX or the inset itself with a 
185   * UnlockInset-call
186   *
187   * During the lock, all button and keyboard events will be modified
188   * and send to the inset through the following inset-features. Note that
189   * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
190   * to contain the code for restoring the menus and things like this.
191   * 
192   * If a inset wishes any redraw and/or update it just has to call
193   * UpdateInset(this).
194   * 
195   * It's is completly irrelevant, where the inset is. UpdateInset will
196   * find it in any paragraph in any buffer. 
197   * Of course the_locking_inset and the insets in the current paragraph/buffer
198   *  are checked first, so no performance problem should occur.
199   */
200 class UpdatableInset: public Inset {
201 public:
202         /** Dispatch result codes
203             Now that nested updatable insets are allowed, the local dispatch
204             becomes a bit complex, just two possible results (boolean)
205             are not enough. 
206          
207             DISPATCHED   = the inset catched the action
208             FINISHED     = the inset must be unlocked as a result
209                            of the action
210             UNDISPATCHED = the action was not catched, it should be
211                            dispatched by lower level insets
212         */ 
213         enum RESULT {
214             UNDISPATCHED = 0,
215             DISPATCHED,
216             FINISHED
217         };
218     
219         /// To convert old binary dispatch results
220         RESULT DISPATCH_RESULT(bool b) {
221                 return b ? DISPATCHED : FINISHED;
222         }
223
224         ///
225         UpdatableInset() {
226             scx = mx_scx = 0;
227             owner_ = 0;
228         }
229         ///
230         //virtual ~UpdatableInset() {}
231         ///
232         virtual EDITABLE Editable() const;
233    
234         /// may call ToggleLockedInsetCursor
235         virtual void ToggleInsetCursor(BufferView *);
236         ///
237         virtual void GetCursorPos(int &, int &) const {}
238         ///
239         virtual void InsetButtonPress(BufferView *, int x, int y, int button);
240         ///
241         virtual void InsetButtonRelease(BufferView *,
242                                         int x, int y, int button);
243         ///
244         virtual void InsetKeyPress(XKeyEvent * ev);
245         ///
246         virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
247         ///
248         virtual void InsetUnlock(BufferView *);
249         ///
250         virtual void Edit(BufferView *, int x, int y, unsigned int button);
251         ///
252         virtual void draw(Painter &, LyXFont const &,
253                           int baseline, float & x) const;
254         ///
255         virtual void SetFont(BufferView *, LyXFont const &,
256                              bool toggleall = false);
257         ///
258         virtual bool InsertInset(BufferView *, Inset *) { return false; }
259         ///
260         virtual UpdatableInset * GetLockingInset() { return this; }
261         ///
262         virtual int InsetInInsetY() { return 0; }
263         ///
264         virtual bool UpdateInsetInInset(BufferView *, Inset *)
265                 { return false; }
266         ///
267         virtual bool UnlockInsetInInset(BufferView *, Inset *,
268                                         bool /*lr*/ = false)
269                 { return false; }
270         ///  An updatable inset could handle lyx editing commands
271         virtual RESULT LocalDispatch(BufferView *, int, string const &);
272         ///
273         virtual bool isCursorVisible() const { return cursor_visible; }
274         ///
275         virtual int getMaxWidth(Painter & pain) const;
276         ///
277         virtual void setOwner(UpdatableInset * inset) { owner_ = inset; }
278         ///
279         virtual UpdatableInset * owner() { return owner_; }
280
281 protected:
282         ///
283         // virtual void UpdateLocal(bool flag=true);
284         ///
285         mutable int top_x;
286         mutable int top_baseline;
287         mutable bool cursor_visible;
288
289 private:
290         ///
291         int mx_scx;
292         mutable int scx;
293         ///
294         UpdatableInset * owner_;
295
296 };
297 #endif