]> git.lyx.org Git - features.git/blob - src/insets/lyxinset.h
Fixed the display bug for text-insets we still had and now ERT-insets do
[features.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 #endif
122         ///
123         virtual int Linuxdoc(string & /*file*/) const = 0;
124         ///
125         virtual int DocBook(string & /*file*/) const = 0;
126         /// Updates needed features for this inset.
127         virtual void Validate(LaTeXFeatures & features) const;
128         ///
129         virtual bool Deletable() const;
130
131         /// returns LyX code associated with the inset. Used for TOC, ...)
132         virtual Inset::Code LyxCode() const = 0;
133   
134         /// Get the label that appears at screen
135         virtual string getLabel(int) const {
136                 return string();
137         }
138
139         ///
140         virtual Inset * Clone() const = 0;
141
142         /// returns true to override begin and end inset in file
143         virtual bool DirectWrite() const;
144
145         /// Returns true if the inset should be centered alone
146         virtual bool display() const { return false; }  
147         /// Changes the display state of the inset
148         virtual void display(bool) {}  
149         ///
150         virtual int GetNumberOfLabels() const {
151                 return 0;
152         }
153         ///
154         virtual void init(BufferView *) {}
155
156 };
157
158
159 //  Updatable Insets. These insets can be locked and receive
160 //  directly user interaction. Currently used only for mathed.
161 //  Note that all pure methods from Inset class are pure here too.
162 //  [Alejandro 080596] 
163
164 /** Extracted from Matthias notes:
165   * 
166   * An inset can simple call LockInset in it's edit call and *ONLY* 
167   * in it's edit call.
168   *
169   * Unlocking is either done by LyX or the inset itself with a 
170   * UnlockInset-call
171   *
172   * During the lock, all button and keyboard events will be modified
173   * and send to the inset through the following inset-features. Note that
174   * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
175   * to contain the code for restoring the menus and things like this.
176   * 
177   * If a inset wishes any redraw and/or update it just has to call
178   * UpdateInset(this).
179   * 
180   * It's is completly irrelevant, where the inset is. UpdateInset will
181   * find it in any paragraph in any buffer. 
182   * Of course the_locking_inset and the insets in the current paragraph/buffer
183   *  are checked first, so no performance problem should occur.
184   */
185 class UpdatableInset: public Inset {
186 public:
187         /** Dispatch result codes
188             Now that nested updatable insets are allowed, the local dispatch
189             becomes a bit complex, just two possible results (boolean)
190             are not enough. 
191          
192             DISPATCHED   = the inset catched the action
193             FINISHED     = the inset must be unlocked as a result
194                            of the action
195             UNDISPATCHED = the action was not catched, it should be
196                            dispatched by lower level insets
197         */ 
198         enum RESULT {
199             UNDISPATCHED = 0,
200             DISPATCHED,
201             FINISHED
202         };
203     
204         /// To convert old binary dispatch results
205         RESULT DISPATCH_RESULT(bool b) {
206                 return (b) ? DISPATCHED: FINISHED;
207         }
208
209         ///
210         UpdatableInset() { scx = mx_scx = 0; }
211         ///
212         //virtual ~UpdatableInset() {}
213         ///
214         virtual unsigned char Editable() const;
215    
216         /// may call ToggleLockedInsetCursor
217         virtual void ToggleInsetCursor(BufferView *);
218         ///
219         virtual void GetCursorPos(int &, int &) const {}
220         ///
221         virtual void InsetButtonPress(BufferView *, int x, int y, int button);
222         ///
223         virtual void InsetButtonRelease(BufferView *,
224                                         int x, int y, int button);
225         ///
226         virtual void InsetKeyPress(XKeyEvent * ev);
227         ///
228         virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
229         ///
230         virtual void InsetUnlock(BufferView *);
231         ///
232         virtual void Edit(BufferView *, int x, int y, unsigned int button);
233         ///
234         virtual void draw(Painter &, LyXFont const &,
235                           int baseline, float & x) const;
236         ///
237         virtual void SetFont(BufferView *, LyXFont const &, bool toggleall=false);
238         ///
239         virtual bool InsertInset(BufferView *, Inset *) { return false; }
240         ///
241         virtual UpdatableInset * GetLockingInset() { return this; }
242         ///
243         virtual int InsetInInsetY() { return 0; }
244         ///
245         virtual bool UpdateInsetInInset(BufferView *, Inset *)
246                 { return false; }
247         ///
248         virtual bool UnlockInsetInInset(BufferView *, Inset *,
249                                         bool /*lr*/=false)
250                 { return false; }
251         ///  An updatable inset could handle lyx editing commands
252         virtual RESULT LocalDispatch(BufferView *, int, string const &);
253         ///
254         virtual bool isCursorVisible() const { return cursor_visible; }
255         ///
256         virtual int getMaxWidth(UpdatableInset *) const { return -1; }
257 protected:
258         ///
259         // virtual void UpdateLocal(bool flag=true);
260         ///
261         mutable int top_x;
262         mutable int top_baseline;
263         mutable bool cursor_visible;
264
265 private:
266         ///
267         int mx_scx;
268         mutable int scx;
269 };
270 #endif