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