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