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