]> git.lyx.org Git - lyx.git/blob - src/insets/lyxinset.h
0e7cfce93daccda5835f96a7d660f3b999625a8a
[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 "definitions.h"
20 #include "gettext.h"
21 #include "lyxfont.h"
22 #include "lyxlex.h"
23 #include "lyxscreen.h"
24
25 class Buffer;
26 struct LaTeXFeatures;
27
28 /// Insets
29 class Inset {
30 public:
31         /** This is not quite the correct place for this enum, but it is
32           better than definitions.h. I think the correct would be to let
33           each subclass of Inset declare its own enum code. Actually the
34           notion of an Inset::Code should be avoided, but I am not sure how
35           this could be done in a cleaner way. */
36         enum Code {
37                 ///
38                 NO_CODE,
39                 ///
40                 TOC_CODE,  // do these insets really need a code? (ale)
41                 ///
42                 LOF_CODE,
43                 ///
44                 LOT_CODE,
45                 ///
46                 LOA_CODE,
47                 ///
48                 QUOTE_CODE,
49                 ///
50                 MARK_CODE,
51                 ///
52                 REF_CODE,
53                 ///
54                 URL_CODE,
55                 ///
56                 HTMLURL_CODE,
57                 ///
58                 SEPARATOR_CODE,
59                 ///
60                 ENDING_CODE,
61                 ///
62                 LABEL_CODE,
63                 ///
64                 IGNORE_CODE,
65                 ///
66                 ACCENT_CODE,
67                 ///
68                 MATH_CODE,
69                 ///
70                 INDEX_CODE,
71                 ///
72                 INCLUDE_CODE,
73                 ///
74                 GRAPHICS_CODE,
75                 ///
76                 PARENT_CODE,
77                 ///
78                 BIBTEX_CODE
79         };
80
81         ///
82         virtual ~Inset() {}
83         ///
84         virtual int Ascent(LyXFont const & font) const = 0;
85         ///
86         virtual int Descent(LyXFont const & font) const = 0;
87         ///
88         virtual int Width(LyXFont const & font) const = 0;
89         ///
90         virtual LyXFont ConvertFont(LyXFont font);
91         ///
92         virtual void Draw(LyXFont font, LyXScreen & scr,
93                           int baseline, float & x) = 0;
94         ///
95         //virtual void setBuffer(Buffer const&) {;}
96         /// what appears in the minibuffer when opening
97         virtual char const * EditMessage() {return _("Opened inset");}
98         ///
99         virtual void Edit(int, int);
100         ///
101         virtual unsigned char Editable() const;
102         ///
103         virtual bool AutoDelete() const;
104         ///
105         virtual void Write(FILE * file)=0;
106         ///
107         virtual void Read(LyXLex & lex)=0;
108         /** returns the number of rows (\n's) of generated tex code.
109          fragile != 0 means, that the inset should take care about
110          fragile commands by adding a \protect before.
111          */
112         virtual int Latex(FILE * file, signed char fragile) = 0;
113         virtual int Latex(string & file, signed char fragile) = 0;
114         ///
115         virtual int Linuxdoc(string &/*file*/) = 0;
116         ///
117         virtual int DocBook(string &/*file*/) = 0;
118         /// Updates needed features for this inset.
119         virtual void Validate(LaTeXFeatures & features) const;
120         ///
121         virtual bool Deletable() const;
122
123         /// returns LyX code associated with the inset. Used for TOC, ...)
124         virtual Inset::Code LyxCode() const = 0;
125   
126         /// Get the label that appears at screen
127         virtual string getLabel(int) const {
128                 return string();
129         }
130
131         /// used for autocorrection
132         virtual bool IsEqual(Inset * /*other*/){
133                 return false;
134         }
135
136         ///
137         virtual Inset * Clone() = 0;
138
139         /// returns true to override begin and end inset in file
140         virtual bool DirectWrite() const;
141
142         /// Returns true if the inset should be centered alone
143         virtual bool Display() const { return false; }  
144  
145         /// Changes the display state of the inset
146         virtual void SetDisplay(bool) {  }  
147         ///
148         virtual int GetNumberOfLabels() const {
149                 return 0;
150         }
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         ///
184         virtual ~UpdatableInset() {}
185         ///
186         virtual unsigned char Editable() const;
187    
188         /// may call ToggleLockedInsetCursor
189         virtual void ToggleInsetCursor();
190         ///
191         virtual void GetCursorPos(int &, int &) {}
192         ///
193         virtual void InsetButtonPress(int x, int y, int button);
194         ///
195         virtual void InsetButtonRelease(int x, int y, int button);
196         
197         ///
198         virtual void InsetKeyPress(XKeyEvent * ev);
199         ///
200         virtual void InsetMotionNotify(int x, int y, int state);
201         ///
202         virtual void InsetUnlock();
203    
204         ///  An updatable inset could handle lyx editing commands
205         virtual bool LocalDispatch(int, char const *) { return false; };
206         //
207         bool isCursorVisible() const { return cursor_visible; }
208 protected:
209         ///
210         bool cursor_visible;
211 };
212 #endif