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