]> git.lyx.org Git - lyx.git/blob - src/insets/lyxinset.h
continue the crusade to get rid of current_view
[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
82         ///
83         virtual ~Inset() {}
84         ///
85         virtual int ascent(Painter &, LyXFont const &) const = 0;
86         ///
87         virtual int descent(Painter &, LyXFont const &) const = 0;
88         ///
89         virtual int width(Painter &, LyXFont const &) const = 0;
90         ///
91         virtual void draw(Painter &, LyXFont const &,
92                           int baseline, float & x) const = 0;
93         ///
94         virtual LyXFont ConvertFont(LyXFont font);
95         /// what appears in the minibuffer when opening
96         virtual char const * EditMessage() const {return _("Opened inset");}
97         ///
98         virtual void Edit(BufferView *, int, int);
99         ///
100         virtual unsigned char Editable() const;
101         ///
102         virtual bool AutoDelete() const;
103         ///
104         virtual void Write(ostream &) const = 0;
105         ///
106         virtual void Read(LyXLex & lex) = 0;
107         /** returns the number of rows (\n's) of generated tex code.
108          fragile != 0 means, that the inset should take care about
109          fragile commands by adding a \protect before.
110          */
111         virtual int Latex(ostream &, signed char fragile) const = 0;
112         ///
113         virtual int Latex(string & file, signed char fragile) const = 0;
114         ///
115         virtual int Linuxdoc(string & /*file*/) const = 0;
116         ///
117         virtual int DocBook(string & /*file*/) const = 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         ///
132         virtual Inset * Clone() const = 0;
133
134         /// returns true to override begin and end inset in file
135         virtual bool DirectWrite() const;
136
137         /// Returns true if the inset should be centered alone
138         virtual bool display() const { return false; }  
139         /// Changes the display state of the inset
140         virtual void display(bool) {}  
141         ///
142         virtual int GetNumberOfLabels() const {
143                 return 0;
144         }
145
146 };
147
148
149 //  Updatable Insets. These insets can be locked and receive
150 //  directly user interaction. Currently used only for mathed.
151 //  Note that all pure methods from Inset class are pure here too.
152 //  [Alejandro 080596] 
153
154 /** Extracted from Matthias notes:
155   * 
156   * An inset can simple call LockInset in it's edit call and *ONLY* 
157   * in it's edit call.
158   *
159   * Unlocking is either done by LyX or the inset itself with a 
160   * UnlockInset-call
161   *
162   * During the lock, all button and keyboard events will be modified
163   * and send to the inset through the following inset-features. Note that
164   * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
165   * to contain the code for restoring the menus and things like this.
166   * 
167   * If a inset wishes any redraw and/or update it just has to call
168   * UpdateInset(this).
169   * 
170   * It's is completly irrelevant, where the inset is. UpdateInset will
171   * find it in any paragraph in any buffer. 
172   * Of course the_locking_inset and the insets in the current paragraph/buffer
173   *  are checked first, so no performance problem should occur.
174   */
175 class UpdatableInset: public Inset {
176 public:
177         ///
178         //virtual ~UpdatableInset() {}
179         ///
180         virtual unsigned char Editable() const;
181    
182         /// may call ToggleLockedInsetCursor
183         virtual void ToggleInsetCursor(BufferView *);
184         ///
185         virtual void GetCursorPos(int &, int &) const {}
186         ///
187         virtual void InsetButtonPress(BufferView *, int x, int y, int button);
188         ///
189         virtual void InsetButtonRelease(BufferView *,
190                                         int x, int y, int button);
191         
192         ///
193         virtual void InsetKeyPress(XKeyEvent * ev);
194         ///
195         virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
196         ///
197         virtual void InsetUnlock(BufferView *);
198    
199         ///  An updatable inset could handle lyx editing commands
200         virtual bool LocalDispatch(BufferView *, int, char const *) { return false; };
201         //
202         bool isCursorVisible() const { return cursor_visible; }
203 protected:
204         ///
205         mutable bool cursor_visible;
206 };
207 #endif