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