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