]> git.lyx.org Git - lyx.git/blob - src/insets/lyxinset.h
Added a preliminary NOT working insettabular. Lot's of fixes for the text
[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 Buffer;
26 class BufferView;
27
28 struct LaTeXFeatures;
29
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                 NUMBER_CODE,
95                 ///
96                 TABULAR_CODE
97         };
98
99         enum EDITABLE {
100             NOT_EDITABLE = 0,
101             IS_EDITABLE,
102             HIGHLY_EDITABLE
103         };
104
105         ///
106         Inset() { owner_ = 0; }
107         ///
108         virtual ~Inset() {}
109         ///
110         virtual int ascent(Painter &, LyXFont const &) const = 0;
111         ///
112         virtual int descent(Painter &, LyXFont const &) const = 0;
113         ///
114         virtual int width(Painter &, LyXFont const &) const = 0;
115         ///
116         virtual void draw(Painter &, LyXFont const &,
117                           int baseline, float & x) const = 0;
118         ///
119         virtual LyXFont ConvertFont(LyXFont font);
120         /// what appears in the minibuffer when opening
121         virtual const char * EditMessage() const;
122         ///
123         virtual void Edit(BufferView *, int x, int y, unsigned int button);
124         ///
125         virtual EDITABLE Editable() const;
126         ///
127         virtual void InsetButtonPress(BufferView *, int, int, int) {}
128         ///
129         virtual void InsetButtonRelease(BufferView *, int, int, int) {}
130         ///
131         virtual void InsetMotionNotify(BufferView *, int , int , int) {}
132         ///
133         bool IsTextInset() const;
134         ///
135         virtual bool AutoDelete() const;
136         ///
137         virtual void Write(std::ostream &) const = 0;
138         ///
139         virtual void Read(LyXLex & lex) = 0;
140         /** returns the number of rows (\n's) of generated tex code.
141          fragile == true means, that the inset should take care about
142          fragile commands by adding a \protect before.
143          If the free_spc (freespacing) variable is set, then this inset
144          is in a free-spacing paragraph.
145          */
146         virtual int Latex(std::ostream &, bool fragile,
147                           bool free_spc) const = 0;
148
149         ///
150         virtual int Linuxdoc(std::ostream &) const = 0;
151         ///
152         virtual int DocBook(std::ostream &) const = 0;
153         /// Updates needed features for this inset.
154         virtual void Validate(LaTeXFeatures & features) const;
155         ///
156         virtual bool Deletable() const;
157
158         /// returns LyX code associated with the inset. Used for TOC, ...)
159         virtual Inset::Code LyxCode() const { return NO_CODE; }
160   
161         /// Get the label that appears at screen
162         virtual string getLabel(int) const {
163                 return string();
164         }
165
166         ///
167         virtual Inset * Clone() const = 0;
168
169         /// returns true to override begin and end inset in file
170         virtual bool DirectWrite() const;
171
172         /// Returns true if the inset should be centered alone
173         virtual bool display() const { return false; }  
174         /// Changes the display state of the inset
175         virtual void display(bool) {}  
176         ///
177         virtual int GetNumberOfLabels() const {
178                 return 0;
179         }
180         ///
181         virtual void init(BufferView *) {}
182         ///
183         virtual bool InsertInsetAllowed(Inset *) const { return false; }
184         ///
185         virtual void setInsetName(const char * s) { name = s; }
186         ///
187         virtual string getInsetName() const { return name; }
188         ///
189         virtual void setOwner(Inset * inset) { owner_ = inset; }
190         ///
191         virtual Inset * owner() const { return owner_; }
192         ///
193 private:
194         ///
195         Inset * owner_;
196         ///
197         string name;
198 };
199
200
201 //  Updatable Insets. These insets can be locked and receive
202 //  directly user interaction. Currently used only for mathed.
203 //  Note that all pure methods from Inset class are pure here too.
204 //  [Alejandro 080596] 
205
206 /** Extracted from Matthias notes:
207   * 
208   * An inset can simple call LockInset in it's edit call and *ONLY* 
209   * in it's edit call.
210   *
211   * Unlocking is either done by LyX or the inset itself with a 
212   * UnlockInset-call
213   *
214   * During the lock, all button and keyboard events will be modified
215   * and send to the inset through the following inset-features. Note that
216   * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
217   * to contain the code for restoring the menus and things like this.
218   * 
219   * If a inset wishes any redraw and/or update it just has to call
220   * UpdateInset(this).
221   * 
222   * It's is completly irrelevant, where the inset is. UpdateInset will
223   * find it in any paragraph in any buffer. 
224   * Of course the_locking_inset and the insets in the current paragraph/buffer
225   *  are checked first, so no performance problem should occur.
226   */
227 class UpdatableInset: public Inset {
228 public:
229         /** Dispatch result codes
230             Now that nested updatable insets are allowed, the local dispatch
231             becomes a bit complex, just two possible results (boolean)
232             are not enough. 
233          
234             DISPATCHED   = the inset catched the action
235             DISPATCHED_NOUPDATE = the inset catched the action and no update
236                                   is needed here to redraw the inset
237             FINISHED     = the inset must be unlocked as a result
238                            of the action
239             UNDISPATCHED = the action was not catched, it should be
240                            dispatched by lower level insets
241         */ 
242         enum RESULT {
243             UNDISPATCHED = 0,
244             DISPATCHED,
245             DISPATCHED_NOUPDATE,
246             FINISHED
247         };
248     
249         /// To convert old binary dispatch results
250         RESULT DISPATCH_RESULT(bool b) {
251                 return b ? DISPATCHED : FINISHED;
252         }
253
254         ///
255         UpdatableInset() { scx = mx_scx = 0; }
256         ///
257         //virtual ~UpdatableInset() {}
258         ///
259         virtual EDITABLE Editable() const;
260    
261         /// may call ToggleLockedInsetCursor
262         virtual void ToggleInsetCursor(BufferView *);
263         ///
264         virtual void ShowInsetCursor(BufferView *);
265         ///
266         virtual void HideInsetCursor(BufferView *);
267         ///
268         virtual void GetCursorPos(int &, int &) const {}
269         ///
270         virtual void InsetButtonPress(BufferView *, int x, int y, int button);
271         ///
272         virtual void InsetButtonRelease(BufferView *,
273                                         int x, int y, int button);
274         ///
275         virtual void InsetKeyPress(XKeyEvent * ev);
276         ///
277         virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
278         ///
279         virtual void InsetUnlock(BufferView *);
280         ///
281         virtual void Edit(BufferView *, int x, int y, unsigned int button);
282         ///
283         virtual void draw(Painter &, LyXFont const &,
284                           int baseline, float & x) const;
285         ///
286         virtual void SetFont(BufferView *, LyXFont const &,
287                              bool toggleall = false);
288         ///
289         virtual bool InsertInset(BufferView *, Inset *) { return false; }
290         ///
291         virtual bool InsertInsetAllowed(Inset *) const { return true; }
292         ///
293         virtual UpdatableInset * GetLockingInset() { return this; }
294         ///
295         virtual int InsetInInsetY() { return 0; }
296         ///
297         virtual bool UpdateInsetInInset(BufferView *, Inset *)
298                 { return false; }
299         ///
300         virtual bool LockInsetInInset(BufferView *, UpdatableInset *)
301                 { return false; }
302         ///
303         virtual bool UnlockInsetInInset(BufferView *, UpdatableInset *,
304                                         bool /*lr*/ = false)
305                 { return false; }
306         ///  An updatable inset could handle lyx editing commands
307         virtual RESULT LocalDispatch(BufferView *, int, string const &);
308         ///
309         virtual bool isCursorVisible() const { return cursor_visible; }
310         ///
311         virtual int getMaxWidth(Painter & pain, UpdatableInset const *) const;
312
313 protected:
314         ///
315         // virtual void UpdateLocal(bool flag=true);
316         ///
317         mutable int top_x;
318         mutable int top_baseline;
319         mutable bool cursor_visible;
320
321 private:
322         ///
323         int mx_scx;
324         mutable int scx;
325 };
326 #endif