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