]> git.lyx.org Git - lyx.git/blob - src/insets/lyxinset.h
the fstream/iostream changes and some small other things
[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
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. I think
32             the correct would be to let each subclass of Inset declare
33             its own enum code. Actually the notion of an Inset::Code
34             should be avoided, but I am not sure how this could be done
35             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         /// what appears in the minibuffer when opening
95         virtual char const * EditMessage() const {return _("Opened inset");}
96         ///
97         virtual void Edit(int, int);
98         ///
99         virtual unsigned char Editable() const;
100         ///
101         virtual bool AutoDelete() const;
102         ///
103         virtual void Write(ostream &) = 0;
104         ///
105         virtual void Read(LyXLex & lex) = 0;
106         /** returns the number of rows (\n's) of generated tex code.
107          fragile != 0 means, that the inset should take care about
108          fragile commands by adding a \protect before.
109          */
110         virtual int Latex(ostream &, signed char fragile) = 0;
111         ///
112         virtual int Latex(string & file, signed char fragile) = 0;
113         ///
114         virtual int Linuxdoc(string & /*file*/) = 0;
115         ///
116         virtual int DocBook(string & /*file*/) = 0;
117         /// Updates needed features for this inset.
118         virtual void Validate(LaTeXFeatures & features) const;
119         ///
120         virtual bool Deletable() const;
121
122         /// returns LyX code associated with the inset. Used for TOC, ...)
123         virtual Inset::Code LyxCode() const = 0;
124   
125         /// Get the label that appears at screen
126         virtual string getLabel(int) const {
127                 return string();
128         }
129
130         ///
131         virtual Inset * Clone() const = 0;
132
133         /// returns true to override begin and end inset in file
134         virtual bool DirectWrite() const;
135
136         /// Returns true if the inset should be centered alone
137         virtual bool display() const { return false; }  
138         /// Changes the display state of the inset
139         virtual void display(bool) {}  
140         ///
141         virtual int GetNumberOfLabels() const {
142                 return 0;
143         }
144
145 };
146
147
148 //  Updatable Insets. These insets can be locked and receive
149 //  directly user interaction. Currently used only for mathed.
150 //  Note that all pure methods from Inset class are pure here too.
151 //  [Alejandro 080596] 
152
153 /** Extracted from Matthias notes:
154   * 
155   * An inset can simple call LockInset in it's edit call and *ONLY* 
156   * in it's edit call.
157   *
158   * Unlocking is either done by LyX or the inset itself with a 
159   * UnlockInset-call
160   *
161   * During the lock, all button and keyboard events will be modified
162   * and send to the inset through the following inset-features. Note that
163   * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
164   * to contain the code for restoring the menus and things like this.
165   * 
166   * If a inset wishes any redraw and/or update it just has to call
167   * UpdateInset(this).
168   * 
169   * It's is completly irrelevant, where the inset is. UpdateInset will
170   * find it in any paragraph in any buffer. 
171   * Of course the_locking_inset and the insets in the current paragraph/buffer
172   *  are checked first, so no performance problem should occur.
173   */
174 class UpdatableInset: public Inset {
175 public:
176         ///
177         //virtual ~UpdatableInset() {}
178         ///
179         virtual unsigned char Editable() const;
180    
181         /// may call ToggleLockedInsetCursor
182         virtual void ToggleInsetCursor();
183         ///
184         virtual void GetCursorPos(int &, int &) const {}
185         ///
186         virtual void InsetButtonPress(int x, int y, int button);
187         ///
188         virtual void InsetButtonRelease(int x, int y, int button);
189         
190         ///
191         virtual void InsetKeyPress(XKeyEvent * ev);
192         ///
193         virtual void InsetMotionNotify(int x, int y, int state);
194         ///
195         virtual void InsetUnlock();
196    
197         ///  An updatable inset could handle lyx editing commands
198         virtual bool LocalDispatch(int, char const *) { return false; };
199         //
200         bool isCursorVisible() const { return cursor_visible; }
201 protected:
202         ///
203         bool cursor_visible;
204 };
205 #endif