]> git.lyx.org Git - lyx.git/blob - src/insets/lyxinset.h
some small updates to Painter, and make the new painter the default.
[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 #define USE_PAINTER 1
20
21 #include "gettext.h"
22 #include "lyxfont.h"
23 #include "lyxlex.h"
24 #include "lyxscreen.h"
25
26 //#define USE_PAINTER 1
27
28 #ifdef USE_PAINTER
29 class Painter;
30 #endif
31
32 class Buffer;
33 struct LaTeXFeatures;
34
35 /// Insets
36 class Inset {
37 public:
38         /** This is not quite the correct place for this enum. I think
39             the correct would be to let each subclass of Inset declare
40             its own enum code. Actually the notion of an Inset::Code
41             should be avoided, but I am not sure how this could be done
42             in a cleaner way. */
43         enum Code {
44                 ///
45                 NO_CODE,
46                 ///
47                 TOC_CODE,  // do these insets really need a code? (ale)
48                 ///
49                 LOF_CODE,
50                 ///
51                 LOT_CODE,
52                 ///
53                 LOA_CODE,
54                 ///
55                 QUOTE_CODE,
56                 ///
57                 MARK_CODE,
58                 ///
59                 REF_CODE,
60                 ///
61                 URL_CODE,
62                 ///
63                 HTMLURL_CODE,
64                 ///
65                 SEPARATOR_CODE,
66                 ///
67                 ENDING_CODE,
68                 ///
69                 LABEL_CODE,
70                 ///
71                 IGNORE_CODE,
72                 ///
73                 ACCENT_CODE,
74                 ///
75                 MATH_CODE,
76                 ///
77                 INDEX_CODE,
78                 ///
79                 INCLUDE_CODE,
80                 ///
81                 GRAPHICS_CODE,
82                 ///
83                 PARENT_CODE,
84                 ///
85                 BIBTEX_CODE
86         };
87
88         ///
89         virtual ~Inset() {}
90 #ifdef USE_PAINTER
91         ///
92         virtual int ascent(Painter &, LyXFont const &) const = 0;
93         ///
94         virtual int descent(Painter &, LyXFont const &) const = 0;
95         ///
96         virtual int width(Painter &, LyXFont const &) const = 0;
97         ///
98         virtual void draw(Painter &, LyXFont const &,
99                           int baseline, float & x) const = 0;
100 #else
101         ///
102         virtual int Ascent(LyXFont const & font) const = 0;
103         ///
104         virtual int Descent(LyXFont const & font) const = 0;
105         ///
106         virtual int Width(LyXFont const & font) const = 0;
107         ///
108         virtual void Draw(LyXFont font, LyXScreen & scr,
109                           int baseline, float & x) = 0;
110 #endif
111         ///
112         virtual LyXFont ConvertFont(LyXFont font);
113         /// what appears in the minibuffer when opening
114         virtual char const * EditMessage() const {return _("Opened inset");}
115         ///
116         virtual void Edit(int, int);
117         ///
118         virtual unsigned char Editable() const;
119         ///
120         virtual bool AutoDelete() const;
121         ///
122         virtual void Write(ostream &) = 0;
123         ///
124         virtual void Read(LyXLex & lex) = 0;
125         /** returns the number of rows (\n's) of generated tex code.
126          fragile != 0 means, that the inset should take care about
127          fragile commands by adding a \protect before.
128          */
129         virtual int Latex(ostream &, signed char fragile) = 0;
130         ///
131         virtual int Latex(string & file, signed char fragile) = 0;
132         ///
133         virtual int Linuxdoc(string & /*file*/) = 0;
134         ///
135         virtual int DocBook(string & /*file*/) = 0;
136         /// Updates needed features for this inset.
137         virtual void Validate(LaTeXFeatures & features) const;
138         ///
139         virtual bool Deletable() const;
140
141         /// returns LyX code associated with the inset. Used for TOC, ...)
142         virtual Inset::Code LyxCode() const = 0;
143   
144         /// Get the label that appears at screen
145         virtual string getLabel(int) const {
146                 return string();
147         }
148
149         ///
150         virtual Inset * Clone() const = 0;
151
152         /// returns true to override begin and end inset in file
153         virtual bool DirectWrite() const;
154
155         /// Returns true if the inset should be centered alone
156         virtual bool display() const { return false; }  
157         /// Changes the display state of the inset
158         virtual void display(bool) {}  
159         ///
160         virtual int GetNumberOfLabels() const {
161                 return 0;
162         }
163
164 };
165
166
167 //  Updatable Insets. These insets can be locked and receive
168 //  directly user interaction. Currently used only for mathed.
169 //  Note that all pure methods from Inset class are pure here too.
170 //  [Alejandro 080596] 
171
172 /** Extracted from Matthias notes:
173   * 
174   * An inset can simple call LockInset in it's edit call and *ONLY* 
175   * in it's edit call.
176   *
177   * Unlocking is either done by LyX or the inset itself with a 
178   * UnlockInset-call
179   *
180   * During the lock, all button and keyboard events will be modified
181   * and send to the inset through the following inset-features. Note that
182   * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
183   * to contain the code for restoring the menus and things like this.
184   * 
185   * If a inset wishes any redraw and/or update it just has to call
186   * UpdateInset(this).
187   * 
188   * It's is completly irrelevant, where the inset is. UpdateInset will
189   * find it in any paragraph in any buffer. 
190   * Of course the_locking_inset and the insets in the current paragraph/buffer
191   *  are checked first, so no performance problem should occur.
192   */
193 class UpdatableInset: public Inset {
194 public:
195         ///
196         //virtual ~UpdatableInset() {}
197         ///
198         virtual unsigned char Editable() const;
199    
200         /// may call ToggleLockedInsetCursor
201         virtual void ToggleInsetCursor();
202         ///
203         virtual void GetCursorPos(int &, int &) const {}
204         ///
205         virtual void InsetButtonPress(int x, int y, int button);
206         ///
207         virtual void InsetButtonRelease(int x, int y, int button);
208         
209         ///
210         virtual void InsetKeyPress(XKeyEvent * ev);
211         ///
212         virtual void InsetMotionNotify(int x, int y, int state);
213         ///
214         virtual void InsetUnlock();
215    
216         ///  An updatable inset could handle lyx editing commands
217         virtual bool LocalDispatch(int, char const *) { return false; };
218         //
219         bool isCursorVisible() const { return cursor_visible; }
220 protected:
221         ///
222         mutable bool cursor_visible;
223 };
224 #endif