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