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