2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995-2000 the LyX Team.
9 * ====================================================== */
24 #include "commandtags.h"
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)
118 TEXT_TO_INSET_OFFSET = 2
132 Inset() : top_x(0), top_baseline(0), scx(0), owner_(0) {}
136 virtual int ascent(BufferView *, LyXFont const &) const = 0;
138 virtual int descent(BufferView *, LyXFont const &) const = 0;
140 virtual int width(BufferView *, LyXFont const &) const = 0;
142 virtual void draw(BufferView *, LyXFont const &,
143 int baseline, float & x, bool cleared) const = 0;
144 /// update the inset representation
145 virtual void update(BufferView *, LyXFont const &, bool = false)
148 virtual LyXFont const ConvertFont(LyXFont const & font) const;
149 /// what appears in the minibuffer when opening
150 virtual string const EditMessage() const;
152 virtual void Edit(BufferView *, int x, int y, unsigned int button);
154 virtual EDITABLE Editable() const;
155 /// This is called when the user clicks inside an inset
156 virtual void InsetButtonPress(BufferView *, int, int, int) {}
157 /// This is called when the user releases the button inside an inset
158 virtual void InsetButtonRelease(BufferView *, int, int, int) {}
159 /// This is caleld when the user moves the mouse inside an inset
160 virtual void InsetMotionNotify(BufferView *, int , int , int) {}
162 virtual bool IsTextInset() const { return false; }
164 virtual bool doClearArea() const { return true; }
166 virtual bool AutoDelete() const;
168 virtual void Write(Buffer const *, std::ostream &) const = 0;
170 virtual void Read(Buffer const *, LyXLex & lex) = 0;
171 /** returns the number of rows (\n's) of generated tex code.
172 fragile == true means, that the inset should take care about
173 fragile commands by adding a \protect before.
174 If the free_spc (freespacing) variable is set, then this inset
175 is in a free-spacing paragraph.
177 virtual int Latex(Buffer const *, std::ostream &, bool fragile,
178 bool free_spc) const = 0;
180 virtual int Ascii(Buffer const *,
181 std::ostream &, int linelen = 0) const = 0;
183 virtual int Linuxdoc(Buffer const *, std::ostream &) const = 0;
185 virtual int DocBook(Buffer const *, std::ostream &) const = 0;
186 /// Updates needed features for this inset.
187 virtual void Validate(LaTeXFeatures & features) const;
189 virtual bool Deletable() const;
191 /// returns LyX code associated with the inset. Used for TOC, ...)
192 virtual Inset::Code LyxCode() const { return NO_CODE; }
194 virtual std::vector<string> const getLabelList() const {
195 return std::vector<string>();
199 virtual Inset * Clone(Buffer const &) const = 0;
201 /// returns true to override begin and end inset in file
202 virtual bool DirectWrite() const;
204 /// Returns true if the inset should be centered alone
205 virtual bool display() const { return false; }
206 /// Changes the display state of the inset
207 virtual void display(bool) {}
209 /// returns true if this inset needs a row on it's own
211 virtual bool needFullRow() const { return false; }
213 virtual bool InsertInsetAllowed(Inset *) const { return false; }
215 void setInsetName(string const & s) { name = s; }
217 string const getInsetName() const { return name; }
219 void setOwner(Inset * inset) { owner_ = inset; }
221 Inset * owner() const { return owner_; }
223 int x() const { return top_x; }
225 int y() const { return top_baseline; }
227 // because we could have fake text insets and have to call this
228 // inside them without cast!!!
230 virtual LyXText * getLyXText(BufferView const *,
231 bool const recursive = false) const;
233 virtual void deleteLyXText(BufferView *, bool = true) const {}
235 virtual void resizeLyXText(BufferView *) const {}
236 /// returns the actuall scroll-value
237 virtual int scroll(bool recursive=true) const {
238 if (!recursive || !owner_)
246 mutable int top_baseline;
257 // Updatable Insets. These insets can be locked and receive
258 // directly user interaction. Currently used only for mathed.
259 // Note that all pure methods from Inset class are pure here too.
260 // [Alejandro 080596]
262 /** Extracted from Matthias notes:
264 * An inset can simple call LockInset in it's edit call and *ONLY*
267 * Unlocking is either done by LyX or the inset itself with a
270 * During the lock, all button and keyboard events will be modified
271 * and send to the inset through the following inset-features. Note that
272 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
273 * to contain the code for restoring the menus and things like this.
275 * If a inset wishes any redraw and/or update it just has to call
278 * It's is completly irrelevant, where the inset is. UpdateInset will
279 * find it in any paragraph in any buffer.
280 * Of course the_locking_inset and the insets in the current paragraph/buffer
281 * are checked first, so no performance problem should occur.
283 class UpdatableInset : public Inset {
285 /** Dispatch result codes
286 Now that nested updatable insets are allowed, the local dispatch
287 becomes a bit complex, just two possible results (boolean)
290 DISPATCHED = the inset catched the action
291 DISPATCHED_NOUPDATE = the inset catched the action and no update
292 is needed here to redraw the inset
293 FINISHED = the inset must be unlocked as a result
295 UNDISPATCHED = the action was not catched, it should be
296 dispatched by lower level insets
305 /// To convert old binary dispatch results
306 RESULT DISPATCH_RESULT(bool b) {
307 return b ? DISPATCHED : FINISHED;
311 UpdatableInset() : cursor_visible_(false), block_drawing_(false) {}
313 virtual EDITABLE Editable() const;
315 /// may call ToggleLockedInsetCursor
316 virtual void ToggleInsetCursor(BufferView *);
318 virtual void ShowInsetCursor(BufferView *, bool show = true);
320 virtual void HideInsetCursor(BufferView *);
322 virtual void GetCursorPos(BufferView *, int &, int &) const {}
324 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
326 virtual void InsetButtonRelease(BufferView *,
327 int x, int y, int button);
329 virtual void InsetKeyPress(XKeyEvent * ev);
331 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
333 virtual void InsetUnlock(BufferView *);
335 virtual void Edit(BufferView *, int x, int y, unsigned int button);
337 virtual void draw(BufferView *, LyXFont const &,
338 int baseline, float & x, bool cleared) const;
340 virtual void SetFont(BufferView *, LyXFont const &,
341 bool toggleall = false);
343 virtual bool InsertInset(BufferView *, Inset *) { return false; }
345 virtual bool InsertInsetAllowed(Inset *) const { return true; }
347 virtual UpdatableInset * GetLockingInset() { return this; }
349 virtual UpdatableInset * GetFirstLockingInsetOfType(Inset::Code c)
350 { return (c == LyxCode()) ? this : 0; }
352 virtual unsigned int InsetInInsetY() { return 0; }
354 virtual bool UpdateInsetInInset(BufferView *, Inset *)
357 virtual bool LockInsetInInset(BufferView *, UpdatableInset *)
360 virtual bool UnlockInsetInInset(BufferView *, UpdatableInset *,
363 /// An updatable inset could handle lyx editing commands
364 virtual RESULT LocalDispatch(BufferView *, kb_action, string const &);
366 bool isCursorVisible() const { return cursor_visible_; }
368 virtual int getMaxWidth(BufferView * bv, UpdatableInset const *) const;
370 int scroll(bool recursive=true) const {
371 // We need this method to not clobber the real method in Inset
372 return Inset::scroll(recursive);
375 virtual bool ShowInsetDialog(BufferView *) const { return false; }
377 virtual void nodraw(bool b) {
381 virtual bool nodraw() const {
382 return block_drawing_;
386 void toggleCursorVisible() const {
387 cursor_visible_ = !cursor_visible_;
390 void setCursorVisible(bool b) const {
393 /// scrolls to absolute position in bufferview-workwidth * sx units
394 void scroll(BufferView *, float sx) const;
395 /// scrolls offset pixels
396 void scroll(BufferView *, int offset) const;
400 mutable bool cursor_visible_;