2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995-2001 the LyX Team.
9 * ====================================================== */
21 #include "commandtags.h"
39 /** This is not quite the correct place for this enum. I think
40 the correct would be to let each subclass of Inset declare
41 its own enum code. Actually the notion of an Inset::Code
42 should be avoided, but I am not sure how this could be done
48 TOC_CODE, // do these insets really need a code? (ale)
94 SPECIALCHAR_CODE, // 25
106 MATHMACRO_CODE, // 30
120 TEXT_TO_INSET_OFFSET = 2
136 Inset(Inset const & in, bool same_id = false);
140 virtual int ascent(BufferView *, LyXFont const &) const = 0;
142 virtual int descent(BufferView *, LyXFont const &) const = 0;
144 virtual int width(BufferView *, LyXFont const &) const = 0;
146 virtual void draw(BufferView *, LyXFont const &,
147 int baseline, float & x, bool cleared) const = 0;
148 /// update the inset representation
149 virtual void update(BufferView *, LyXFont const &, bool = false)
153 virtual LyXFont const convertFont(LyXFont const & font) const;
155 /// what appears in the minibuffer when opening
156 virtual string const editMessage() const;
158 virtual void edit(BufferView *, int x, int y, unsigned int button);
160 virtual void edit(BufferView *, bool front = true);
162 virtual EDITABLE editable() const;
163 /// This is called when the user clicks inside an inset
164 virtual void insetButtonPress(BufferView *, int, int, int) {}
165 /// This is called when the user releases the button inside an inset
166 virtual void insetButtonRelease(BufferView *, int, int, int) {}
167 /// This is called when the user moves the mouse inside an inset
168 virtual void insetMotionNotify(BufferView *, int , int , int) {}
170 virtual bool isTextInset() const { return false; }
172 virtual bool doClearArea() const { return true; }
174 virtual bool autoDelete() const;
175 /// returns true the inset can hold an inset of given type
176 virtual bool insetAllowed(Inset::Code) const { return false; }
177 /// wrapper around the above
178 bool insetAllowed(Inset * in) const;
180 virtual void write(Buffer const *, std::ostream &) const = 0;
182 virtual void read(Buffer const *, LyXLex & lex) = 0;
183 /** returns the number of rows (\n's) of generated tex code.
184 fragile == true means, that the inset should take care about
185 fragile commands by adding a \protect before.
186 If the free_spc (freespacing) variable is set, then this inset
187 is in a free-spacing paragraph.
189 virtual int latex(Buffer const *, std::ostream &, bool fragile,
190 bool free_spc) const = 0;
192 virtual int ascii(Buffer const *,
193 std::ostream &, int linelen = 0) const = 0;
195 virtual int linuxdoc(Buffer const *, std::ostream &) const = 0;
197 virtual int docBook(Buffer const *, std::ostream &) const = 0;
198 /// Updates needed features for this inset.
199 virtual void validate(LaTeXFeatures & features) const;
201 virtual bool deletable() const;
203 /// returns LyX code associated with the inset. Used for TOC, ...)
204 virtual Inset::Code lyxCode() const { return NO_CODE; }
206 virtual std::vector<string> const getLabelList() const {
207 return std::vector<string>();
211 virtual Inset * clone(Buffer const &, bool same_ids = false) const = 0;
213 /// returns true to override begin and end inset in file
214 virtual bool directWrite() const;
216 /// Returns true if the inset should be centered alone
217 virtual bool display() const { return false; }
218 /// Changes the display state of the inset
219 virtual void display(bool) {}
221 /// returns true if this inset needs a row on it's own
223 virtual bool needFullRow() const { return false; }
225 void setInsetName(string const & s) { name_ = s; }
227 string const & getInsetName() const { return name_; }
229 void setOwner(Inset * inset) { owner_ = inset; }
231 Inset * owner() const { return owner_; }
233 void setBackgroundColor(LColor::color);
235 LColor::color backgroundColor() const;
237 int x() const { return top_x; }
239 int y() const { return top_baseline; }
241 // because we could have fake text insets and have to call this
242 // inside them without cast!!!
244 virtual LyXText * getLyXText(BufferView const *,
245 bool const recursive = false) const;
247 virtual void deleteLyXText(BufferView *, bool = true) const {}
249 virtual void resizeLyXText(BufferView *, bool /*force*/= false) const {}
250 /// returns the actuall scroll-value
251 virtual int scroll(bool recursive=true) const {
252 if (!recursive || !owner_)
256 /// try to get a paragraph pointer from it's id if we have a
257 /// paragraph to give back!
258 virtual Paragraph * getParFromID(int /* id */) const {
261 /// try to get a inset pointer from it's id if we have
262 /// an inset to give back!
263 virtual Inset * getInsetFromID(int /* id */) const {
266 /// if this insets owns paragraphs (f.ex. InsetText) then it
267 /// should return it's very first one!
268 virtual Paragraph * firstParagraph() const {
271 /// return the cursor if we own one otherwise giv'em just the
272 /// BufferView cursor to work with.
273 virtual LyXCursor const & cursor(BufferView * bview) const;
279 /// used to toggle insets
280 // is the inset open?
281 virtual bool isOpen() const { return false; }
283 virtual void open(BufferView *) {}
285 virtual void close(BufferView *) {}
286 /// check if the font of the char we want inserting is correct
287 /// and modify it if it is not.
288 virtual bool checkInsertChar(LyXFont &);
289 /// we need this here because collapsed insets are only EDITABLE
290 virtual void setFont(BufferView *, LyXFont const &,
291 bool toggleall = false, bool selectall = false);
296 mutable int top_baseline;
302 static unsigned int inset_id;
310 LColor::color background_color_;
315 bool Inset::insetAllowed(Inset * in) const
317 return insetAllowed(in->lyxCode());
322 bool Inset::checkInsertChar(LyXFont &)
327 // Updatable Insets. These insets can be locked and receive
328 // directly user interaction. Currently used only for mathed.
329 // Note that all pure methods from Inset class are pure here too.
330 // [Alejandro 080596]
332 /** Extracted from Matthias notes:
334 * An inset can simple call LockInset in it's edit call and *ONLY*
337 * Unlocking is either done by LyX or the inset itself with a
340 * During the lock, all button and keyboard events will be modified
341 * and send to the inset through the following inset-features. Note that
342 * Inset::insetUnlock will be called from inside UnlockInset. It is meant
343 * to contain the code for restoring the menus and things like this.
345 * If a inset wishes any redraw and/or update it just has to call
348 * It's is completly irrelevant, where the inset is. UpdateInset will
349 * find it in any paragraph in any buffer.
350 * Of course the_locking_inset and the insets in the current paragraph/buffer
351 * are checked first, so no performance problem should occur.
353 class UpdatableInset : public Inset {
355 /** Dispatch result codes
356 Now that nested updatable insets are allowed, the local dispatch
357 becomes a bit complex, just two possible results (boolean)
360 DISPATCHED = the inset catched the action
361 DISPATCHED_NOUPDATE = the inset catched the action and no update
362 is needed here to redraw the inset
363 FINISHED = the inset must be unlocked as a result
365 UNDISPATCHED = the action was not catched, it should be
366 dispatched by lower level insets
375 /// To convert old binary dispatch results
376 RESULT DISPATCH_RESULT(bool b) {
377 return b ? DISPATCHED : FINISHED;
383 UpdatableInset(UpdatableInset const & in, bool same_id = false);
386 virtual EDITABLE editable() const;
388 /// may call ToggleLockedInsetCursor
389 virtual void toggleInsetCursor(BufferView *);
391 virtual void showInsetCursor(BufferView *, bool show = true);
393 virtual void hideInsetCursor(BufferView *);
395 virtual void fitInsetCursor(BufferView *) const;
397 virtual void getCursorPos(BufferView *, int &, int &) const {}
399 virtual void insetButtonPress(BufferView *, int x, int y, int button);
401 virtual void insetButtonRelease(BufferView *,
402 int x, int y, int button);
404 virtual void insetKeyPress(XKeyEvent * ev);
406 virtual void insetMotionNotify(BufferView *, int x, int y, int state);
408 virtual void insetUnlock(BufferView *);
410 virtual void edit(BufferView *, int x, int y, unsigned int button);
412 virtual void edit(BufferView *, bool front = true);
414 virtual void draw(BufferView *, LyXFont const &,
415 int baseline, float & x, bool cleared) const;
417 virtual bool insertInset(BufferView *, Inset *) { return false; }
419 virtual UpdatableInset * getLockingInset() const {
420 return const_cast<UpdatableInset *>(this);
423 virtual UpdatableInset * getFirstLockingInsetOfType(Inset::Code c)
424 { return (c == lyxCode()) ? this : 0; }
426 virtual unsigned int insetInInsetY() { return 0; }
428 virtual bool updateInsetInInset(BufferView *, Inset *)
431 virtual bool lockInsetInInset(BufferView *, UpdatableInset *)
434 virtual bool unlockInsetInInset(BufferView *, UpdatableInset *,
437 /// An updatable inset could handle lyx editing commands
438 virtual RESULT localDispatch(BufferView *, kb_action, string const &);
440 bool isCursorVisible() const { return cursor_visible_; }
442 virtual int getMaxWidth(BufferView * bv, UpdatableInset const *) const;
444 int scroll(bool recursive = true) const {
445 // We need this method to not clobber the real method in Inset
446 return Inset::scroll(recursive);
449 virtual bool showInsetDialog(BufferView *) const { return false; }
451 virtual void nodraw(bool b) const {
455 virtual bool nodraw() const {
456 return block_drawing_;
459 // needed for spellchecking text
461 virtual string const selectNextWord(BufferView *, float & value) const;
463 virtual void selectSelectedWord(BufferView *) { return; }
465 virtual void toggleSelection(BufferView *, bool /*kill_selection*/) {
469 // needed for search/replace functionality
471 virtual bool searchForward(BufferView *, string const &,
472 bool const & = true, bool const & = false);
474 virtual bool searchBackward(BufferView *, string const &,
475 bool const & = true, bool const & = false);
479 void toggleCursorVisible() const {
480 cursor_visible_ = !cursor_visible_;
483 void setCursorVisible(bool b) const {
486 /// scrolls to absolute position in bufferview-workwidth * sx units
487 void scroll(BufferView *, float sx) const;
488 /// scrolls offset pixels
489 void scroll(BufferView *, int offset) const;
493 mutable bool cursor_visible_;
495 mutable bool block_drawing_;