2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995-2000 the LyX Team.
9 * ====================================================== */
37 /** This is not quite the correct place for this enum. I think
38 the correct would be to let each subclass of Inset declare
39 its own enum code. Actually the notion of an Inset::Code
40 should be avoided, but I am not sure how this could be done
46 TOC_CODE, // do these insets really need a code? (ale)
110 enum { TEXT_TO_INSET_OFFSET = 2 };
119 Inset() { owner_ = 0; top_x = top_baseline = 0; }
123 virtual int ascent(BufferView *, LyXFont const &) const = 0;
125 virtual int descent(BufferView *, LyXFont const &) const = 0;
127 virtual int width(BufferView *, LyXFont const &) const = 0;
129 virtual void draw(BufferView *, LyXFont const &,
130 int baseline, float & x, bool cleared) const = 0;
131 /// update the inset representation
132 virtual void update(BufferView *, LyXFont const &, bool = false)
135 virtual LyXFont ConvertFont(LyXFont const & font) const;
136 /// what appears in the minibuffer when opening
137 virtual const char * EditMessage() const;
139 virtual void Edit(BufferView *, int x, int y, unsigned int button);
141 virtual EDITABLE Editable() const;
142 /// This is called when the user clicks inside an inset
143 virtual void InsetButtonPress(BufferView *, int, int, int) {}
144 /// This is called when the user releases the button inside an inset
145 virtual void InsetButtonRelease(BufferView *, int, int, int) {}
146 /// This is caleld when the user moves the mouse inside an inset
147 virtual void InsetMotionNotify(BufferView *, int , int , int) {}
149 virtual bool IsTextInset() const { return false; }
151 virtual bool doClearArea() const { return true; }
153 virtual bool AutoDelete() const;
155 virtual void Write(Buffer const *, std::ostream &) const = 0;
157 virtual void Read(Buffer const *, LyXLex & lex) = 0;
158 /** returns the number of rows (\n's) of generated tex code.
159 fragile == true means, that the inset should take care about
160 fragile commands by adding a \protect before.
161 If the free_spc (freespacing) variable is set, then this inset
162 is in a free-spacing paragraph.
164 virtual int Latex(Buffer const *, std::ostream &, bool fragile,
165 bool free_spc) const = 0;
167 virtual int Ascii(Buffer const *, std::ostream &) const = 0;
169 virtual int Linuxdoc(Buffer const *, std::ostream &) const = 0;
171 virtual int DocBook(Buffer const *, std::ostream &) const = 0;
172 /// Updates needed features for this inset.
173 virtual void Validate(LaTeXFeatures & features) const;
175 virtual bool Deletable() const;
177 /// returns LyX code associated with the inset. Used for TOC, ...)
178 virtual Inset::Code LyxCode() const { return NO_CODE; }
180 virtual std::vector<string> getLabelList() const {
181 return std::vector<string>();
185 virtual Inset * Clone() const = 0;
187 /// returns true to override begin and end inset in file
188 virtual bool DirectWrite() const;
190 /// Returns true if the inset should be centered alone
191 virtual bool display() const { return false; }
192 /// Changes the display state of the inset
193 virtual void display(bool) {}
195 /// returns true if this inset needs a row on it's own
197 virtual bool needFullRow() const { return false; }
199 virtual bool InsertInsetAllowed(Inset *) const { return false; }
201 virtual void setInsetName(const char * s) { name = s; }
203 virtual string getInsetName() const { return name; }
205 virtual void setOwner(Inset * inset) { owner_ = inset; }
207 virtual Inset * owner() const { return owner_; }
209 int x() const { return top_x; }
211 int y() const { return top_baseline; }
213 /// because we could have fake text insets and have to call this
214 /// inside them without cast!!!
215 virtual LyXText * getLyXText(BufferView *) const;
216 virtual void deleteLyXText(BufferView *, bool =true) const {}
217 virtual void resizeLyXText(BufferView *) const {}
222 mutable int top_baseline;
232 // Updatable Insets. These insets can be locked and receive
233 // directly user interaction. Currently used only for mathed.
234 // Note that all pure methods from Inset class are pure here too.
235 // [Alejandro 080596]
237 /** Extracted from Matthias notes:
239 * An inset can simple call LockInset in it's edit call and *ONLY*
242 * Unlocking is either done by LyX or the inset itself with a
245 * During the lock, all button and keyboard events will be modified
246 * and send to the inset through the following inset-features. Note that
247 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
248 * to contain the code for restoring the menus and things like this.
250 * If a inset wishes any redraw and/or update it just has to call
253 * It's is completly irrelevant, where the inset is. UpdateInset will
254 * find it in any paragraph in any buffer.
255 * Of course the_locking_inset and the insets in the current paragraph/buffer
256 * are checked first, so no performance problem should occur.
258 class UpdatableInset: public Inset {
260 /** Dispatch result codes
261 Now that nested updatable insets are allowed, the local dispatch
262 becomes a bit complex, just two possible results (boolean)
265 DISPATCHED = the inset catched the action
266 DISPATCHED_NOUPDATE = the inset catched the action and no update
267 is needed here to redraw the inset
268 FINISHED = the inset must be unlocked as a result
270 UNDISPATCHED = the action was not catched, it should be
271 dispatched by lower level insets
280 /// To convert old binary dispatch results
281 RESULT DISPATCH_RESULT(bool b) {
282 return b ? DISPATCHED : FINISHED;
286 UpdatableInset() { scx = mx_scx = 0; }
288 virtual EDITABLE Editable() const;
290 /// may call ToggleLockedInsetCursor
291 virtual void ToggleInsetCursor(BufferView *);
293 virtual void ShowInsetCursor(BufferView *);
295 virtual void HideInsetCursor(BufferView *);
297 virtual void GetCursorPos(BufferView *, int &, int &) const {}
299 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
301 virtual void InsetButtonRelease(BufferView *,
302 int x, int y, int button);
304 virtual void InsetKeyPress(XKeyEvent * ev);
306 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
308 virtual void InsetUnlock(BufferView *);
310 virtual void Edit(BufferView *, int x, int y, unsigned int button);
312 virtual void draw(BufferView *, LyXFont const &,
313 int baseline, float & x, bool cleared) const;
315 virtual void SetFont(BufferView *, LyXFont const &,
316 bool toggleall = false);
318 virtual bool InsertInset(BufferView *, Inset *) { return false; }
320 virtual bool InsertInsetAllowed(Inset *) const { return true; }
322 virtual UpdatableInset * GetLockingInset() { return this; }
324 virtual UpdatableInset * GetFirstLockingInsetOfType(Inset::Code c)
325 { return (c == LyxCode()) ? this : 0; }
327 virtual int InsetInInsetY() { return 0; }
329 virtual bool UpdateInsetInInset(BufferView *, Inset *)
332 virtual bool LockInsetInInset(BufferView *, UpdatableInset *)
335 virtual bool UnlockInsetInInset(BufferView *, UpdatableInset *,
338 /// An updatable inset could handle lyx editing commands
339 virtual RESULT LocalDispatch(BufferView *, int, string const &);
341 virtual bool isCursorVisible() const { return cursor_visible; }
343 virtual int getMaxWidth(Painter & pain, UpdatableInset const *) const;
347 mutable bool cursor_visible;