2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-1999 the LyX Team.
10 * ====================================================== */
29 #define USE_OSTREAM_ONLY 1
34 /** This is not quite the correct place for this enum. I think
35 the correct would be to let each subclass of Inset declare
36 its own enum code. Actually the notion of an Inset::Code
37 should be avoided, but I am not sure how this could be done
43 TOC_CODE, // do these insets really need a code? (ale)
101 virtual int ascent(Painter &, LyXFont const &) const = 0;
103 virtual int descent(Painter &, LyXFont const &) const = 0;
105 virtual int width(Painter &, LyXFont const &) const = 0;
107 virtual void draw(Painter &, LyXFont const &,
108 int baseline, float & x) const = 0;
110 virtual LyXFont ConvertFont(LyXFont font);
111 /// what appears in the minibuffer when opening
112 virtual const char * EditMessage() const {return _("Opened inset");}
114 virtual void Edit(BufferView *, int x, int y, unsigned int button);
116 virtual EDITABLE Editable() const;
118 virtual bool AutoDelete() const;
120 virtual void Write(ostream &) const = 0;
122 virtual void Read(LyXLex & lex) = 0;
123 /** returns the number of rows (\n's) of generated tex code.
124 fragile != 0 means, that the inset should take care about
125 fragile commands by adding a \protect before.
127 virtual int Latex(ostream &, signed char fragile) const = 0;
128 #ifndef USE_OSTREAM_ONLY
130 virtual int Latex(string & file, signed char fragile) const = 0;
132 virtual int Linuxdoc(string & /*file*/) const = 0;
134 virtual int DocBook(string & /*file*/) const = 0;
137 virtual int Linuxdoc(ostream &) const = 0;
139 virtual int DocBook(ostream &) const = 0;
141 /// Updates needed features for this inset.
142 virtual void Validate(LaTeXFeatures & features) const;
144 virtual bool Deletable() const;
146 /// returns LyX code associated with the inset. Used for TOC, ...)
147 virtual Inset::Code LyxCode() const = 0;
149 /// Get the label that appears at screen
150 virtual string getLabel(int) const {
155 virtual Inset * Clone() const = 0;
157 /// returns true to override begin and end inset in file
158 virtual bool DirectWrite() const;
160 /// Returns true if the inset should be centered alone
161 virtual bool display() const { return false; }
162 /// Changes the display state of the inset
163 virtual void display(bool) {}
165 virtual int GetNumberOfLabels() const {
169 virtual void init(BufferView *) {}
174 // Updatable Insets. These insets can be locked and receive
175 // directly user interaction. Currently used only for mathed.
176 // Note that all pure methods from Inset class are pure here too.
177 // [Alejandro 080596]
179 /** Extracted from Matthias notes:
181 * An inset can simple call LockInset in it's edit call and *ONLY*
184 * Unlocking is either done by LyX or the inset itself with a
187 * During the lock, all button and keyboard events will be modified
188 * and send to the inset through the following inset-features. Note that
189 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
190 * to contain the code for restoring the menus and things like this.
192 * If a inset wishes any redraw and/or update it just has to call
195 * It's is completly irrelevant, where the inset is. UpdateInset will
196 * find it in any paragraph in any buffer.
197 * Of course the_locking_inset and the insets in the current paragraph/buffer
198 * are checked first, so no performance problem should occur.
200 class UpdatableInset: public Inset {
202 /** Dispatch result codes
203 Now that nested updatable insets are allowed, the local dispatch
204 becomes a bit complex, just two possible results (boolean)
207 DISPATCHED = the inset catched the action
208 FINISHED = the inset must be unlocked as a result
210 UNDISPATCHED = the action was not catched, it should be
211 dispatched by lower level insets
219 /// To convert old binary dispatch results
220 RESULT DISPATCH_RESULT(bool b) {
221 return b ? DISPATCHED : FINISHED;
230 //virtual ~UpdatableInset() {}
232 virtual EDITABLE Editable() const;
234 /// may call ToggleLockedInsetCursor
235 virtual void ToggleInsetCursor(BufferView *);
237 virtual void GetCursorPos(int &, int &) const {}
239 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
241 virtual void InsetButtonRelease(BufferView *,
242 int x, int y, int button);
244 virtual void InsetKeyPress(XKeyEvent * ev);
246 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
248 virtual void InsetUnlock(BufferView *);
250 virtual void Edit(BufferView *, int x, int y, unsigned int button);
252 virtual void draw(Painter &, LyXFont const &,
253 int baseline, float & x) const;
255 virtual void SetFont(BufferView *, LyXFont const &,
256 bool toggleall = false);
258 virtual bool InsertInset(BufferView *, Inset *) { return false; }
260 virtual UpdatableInset * GetLockingInset() { return this; }
262 virtual int InsetInInsetY() { return 0; }
264 virtual bool UpdateInsetInInset(BufferView *, Inset *)
267 virtual bool UnlockInsetInInset(BufferView *, Inset *,
270 /// An updatable inset could handle lyx editing commands
271 virtual RESULT LocalDispatch(BufferView *, int, string const &);
273 virtual bool isCursorVisible() const { return cursor_visible; }
275 virtual int getMaxWidth(Painter & pain) const;
277 virtual void setOwner(UpdatableInset * inset) { owner_ = inset; }
279 virtual UpdatableInset * owner() { return owner_; }
283 // virtual void UpdateLocal(bool flag=true);
286 mutable int top_baseline;
287 mutable bool cursor_visible;
294 UpdatableInset * owner_;