2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995-2000 the LyX Team.
9 * ====================================================== */
25 #include "commandtags.h"
38 /** This is not quite the correct place for this enum. I think
39 the correct would be to let each subclass of Inset declare
40 its own enum code. Actually the notion of an Inset::Code
41 should be avoided, but I am not sure how this could be done
47 TOC_CODE, // do these insets really need a code? (ale)
119 TEXT_TO_INSET_OFFSET = 2
133 Inset() : top_x(0), top_baseline(0), scx(0), owner_(0) {}
137 virtual int ascent(BufferView *, LyXFont const &) const = 0;
139 virtual int descent(BufferView *, LyXFont const &) const = 0;
141 virtual int width(BufferView *, LyXFont const &) const = 0;
143 virtual void draw(BufferView *, LyXFont const &,
144 int baseline, float & x, bool cleared) const = 0;
145 /// update the inset representation
146 virtual void update(BufferView *, LyXFont const &, bool = false)
149 virtual LyXFont const ConvertFont(LyXFont const & font) const;
150 /// what appears in the minibuffer when opening
151 virtual string const EditMessage() const;
153 virtual void Edit(BufferView *, int x, int y, unsigned int button);
155 virtual EDITABLE Editable() const;
156 /// This is called when the user clicks inside an inset
157 virtual void InsetButtonPress(BufferView *, int, int, int) {}
158 /// This is called when the user releases the button inside an inset
159 virtual void InsetButtonRelease(BufferView *, int, int, int) {}
160 /// This is caleld when the user moves the mouse inside an inset
161 virtual void InsetMotionNotify(BufferView *, int , int , int) {}
163 virtual bool IsTextInset() const { return false; }
165 virtual bool doClearArea() const { return true; }
167 virtual bool AutoDelete() const;
169 virtual void Write(Buffer const *, std::ostream &) const = 0;
171 virtual void Read(Buffer const *, LyXLex & lex) = 0;
172 /** returns the number of rows (\n's) of generated tex code.
173 fragile == true means, that the inset should take care about
174 fragile commands by adding a \protect before.
175 If the free_spc (freespacing) variable is set, then this inset
176 is in a free-spacing paragraph.
178 virtual int Latex(Buffer const *, std::ostream &, bool fragile,
179 bool free_spc) const = 0;
181 virtual int Ascii(Buffer const *,
182 std::ostream &, int linelen = 0) const = 0;
184 virtual int Linuxdoc(Buffer const *, std::ostream &) const = 0;
186 virtual int DocBook(Buffer const *, std::ostream &) const = 0;
187 /// Updates needed features for this inset.
188 virtual void Validate(LaTeXFeatures & features) const;
190 virtual bool Deletable() const;
192 /// returns LyX code associated with the inset. Used for TOC, ...)
193 virtual Inset::Code LyxCode() const { return NO_CODE; }
195 virtual std::vector<string> const getLabelList() const {
196 return std::vector<string>();
200 virtual Inset * Clone(Buffer const &) const = 0;
202 /// returns true to override begin and end inset in file
203 virtual bool DirectWrite() const;
205 /// Returns true if the inset should be centered alone
206 virtual bool display() const { return false; }
207 /// Changes the display state of the inset
208 virtual void display(bool) {}
210 /// returns true if this inset needs a row on it's own
212 virtual bool needFullRow() const { return false; }
214 virtual bool InsertInsetAllowed(Inset *) const { return false; }
216 void setInsetName(string const & s) { name = s; }
218 string const getInsetName() const { return name; }
220 void setOwner(Inset * inset) { owner_ = inset; }
222 Inset * owner() const { return owner_; }
224 int x() const { return top_x; }
226 int y() const { return top_baseline; }
228 // because we could have fake text insets and have to call this
229 // inside them without cast!!!
231 virtual LyXText * getLyXText(BufferView const *,
232 bool const recursive = false) const;
234 virtual void deleteLyXText(BufferView *, bool = true) const {}
236 virtual void resizeLyXText(BufferView *) const {}
237 /// returns the actuall scroll-value
238 int scroll() const { return scx; }
243 mutable int top_baseline;
254 // Updatable Insets. These insets can be locked and receive
255 // directly user interaction. Currently used only for mathed.
256 // Note that all pure methods from Inset class are pure here too.
257 // [Alejandro 080596]
259 /** Extracted from Matthias notes:
261 * An inset can simple call LockInset in it's edit call and *ONLY*
264 * Unlocking is either done by LyX or the inset itself with a
267 * During the lock, all button and keyboard events will be modified
268 * and send to the inset through the following inset-features. Note that
269 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
270 * to contain the code for restoring the menus and things like this.
272 * If a inset wishes any redraw and/or update it just has to call
275 * It's is completly irrelevant, where the inset is. UpdateInset will
276 * find it in any paragraph in any buffer.
277 * Of course the_locking_inset and the insets in the current paragraph/buffer
278 * are checked first, so no performance problem should occur.
280 class UpdatableInset : public Inset {
282 /** Dispatch result codes
283 Now that nested updatable insets are allowed, the local dispatch
284 becomes a bit complex, just two possible results (boolean)
287 DISPATCHED = the inset catched the action
288 DISPATCHED_NOUPDATE = the inset catched the action and no update
289 is needed here to redraw the inset
290 FINISHED = the inset must be unlocked as a result
292 UNDISPATCHED = the action was not catched, it should be
293 dispatched by lower level insets
302 /// To convert old binary dispatch results
303 RESULT DISPATCH_RESULT(bool b) {
304 return b ? DISPATCHED : FINISHED;
309 UpdatableInset() : cursor_visible_(false) {}
312 virtual EDITABLE Editable() const;
314 /// may call ToggleLockedInsetCursor
315 virtual void ToggleInsetCursor(BufferView *);
317 virtual void ShowInsetCursor(BufferView *, bool show = true);
319 virtual void HideInsetCursor(BufferView *);
321 virtual void GetCursorPos(BufferView *, int &, int &) const {}
323 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
325 virtual void InsetButtonRelease(BufferView *,
326 int x, int y, int button);
328 virtual void InsetKeyPress(XKeyEvent * ev);
330 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
332 virtual void InsetUnlock(BufferView *);
334 virtual void Edit(BufferView *, int x, int y, unsigned int button);
336 virtual void draw(BufferView *, LyXFont const &,
337 int baseline, float & x, bool cleared) const;
339 virtual void SetFont(BufferView *, LyXFont const &,
340 bool toggleall = false);
342 virtual bool InsertInset(BufferView *, Inset *) { return false; }
344 virtual bool InsertInsetAllowed(Inset *) const { return true; }
346 virtual UpdatableInset * GetLockingInset() { return this; }
348 virtual UpdatableInset * GetFirstLockingInsetOfType(Inset::Code c)
349 { return (c == LyxCode()) ? this : 0; }
351 virtual unsigned int InsetInInsetY() { return 0; }
353 virtual bool UpdateInsetInInset(BufferView *, Inset *)
356 virtual bool LockInsetInInset(BufferView *, UpdatableInset *)
359 virtual bool UnlockInsetInInset(BufferView *, UpdatableInset *,
362 /// An updatable inset could handle lyx editing commands
363 virtual RESULT LocalDispatch(BufferView *, kb_action, string const &);
365 bool isCursorVisible() const { return cursor_visible_; }
367 virtual int getMaxWidth(BufferView * bv, UpdatableInset const *) const;
370 // We need this method to not clobber the real method in Inset
371 return Inset::scroll();
374 virtual bool ShowInsetDialog(BufferView *) const { return false; }
377 void toggleCursorVisible() const {
378 cursor_visible_ = !cursor_visible_;
381 void setCursorVisible(bool b) const {
384 /// scrolls to absolute position in bufferview-workwidth * sx units
385 void scroll(BufferView *, float sx) const;
386 /// scrolls offset pixels
387 void scroll(BufferView *, int offset) const;
390 mutable bool cursor_visible_;