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