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