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