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