3 * \file updatableinset.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Alejandro Aguilar Sierra
9 * \author Lars Gullik Bjønnes
10 * \author Matthias Ettrich
12 * Full author contact details are available in file CREDITS
15 #ifndef UPDATABLEINSET_H
16 #define UPDATABLEINSET_H
18 // Updatable Insets. These insets can be locked and receive
19 // directly user interaction. Currently used only for mathed.
20 // Note that all pure methods from Inset class are pure here too.
26 /** Extracted from Matthias notes:
28 * An inset can simple call LockInset in it's edit call and *ONLY*
31 * Unlocking is either done by LyX or the inset itself with a
34 * During the lock, all button and keyboard events will be modified
35 * and send to the inset through the following inset-features. Note that
36 * Inset::insetUnlock will be called from inside UnlockInset. It is meant
37 * to contain the code for restoring the menus and things like this.
39 * If a inset wishes any redraw and/or update it just has to call
42 * It's is completly irrelevant, where the inset is. UpdateInset will
43 * find it in any paragraph in any buffer.
44 * Of course the_locking_inset and the insets in the current paragraph/buffer
45 * are checked first, so no performance problem should occur.
47 class UpdatableInset : public Inset {
52 UpdatableInset(UpdatableInset const & in, bool same_id = false);
54 /// check if the font of the char we want inserting is correct
55 /// and modify it if it is not.
56 virtual bool checkInsertChar(LyXFont &);
58 virtual EDITABLE editable() const;
61 virtual void fitInsetCursor(BufferView *) const;
63 virtual void getCursorPos(BufferView *, int &, int &) const {}
64 /// Get the absolute document x,y of the cursor
65 virtual void getCursor(BufferView &, int &, int &) const = 0;
67 virtual void insetUnlock(BufferView *);
69 virtual void draw(BufferView *, LyXFont const &,
70 int baseline, float & x) const;
72 virtual bool insertInset(BufferView *, Inset *) { return false; }
74 virtual UpdatableInset * getLockingInset() const {
75 return const_cast<UpdatableInset *>(this);
78 virtual UpdatableInset * getFirstLockingInsetOfType(Inset::Code c)
79 { return (c == lyxCode()) ? this : 0; }
81 virtual int insetInInsetY() const { return 0; }
83 virtual bool updateInsetInInset(BufferView *, Inset *)
86 virtual bool lockInsetInInset(BufferView *, UpdatableInset *)
89 virtual bool unlockInsetInInset(BufferView *, UpdatableInset *,
92 /// An updatable inset could handle lyx editing commands
93 virtual RESULT localDispatch(FuncRequest const & cmd);
95 virtual int getMaxWidth(BufferView * bv, UpdatableInset const *) const;
97 int scroll(bool recursive = true) const {
98 // We need this method to not clobber the real method in Inset
99 return Inset::scroll(recursive);
102 virtual bool showInsetDialog(BufferView *) const { return false; }
104 virtual void nodraw(bool b) const {
108 virtual bool nodraw() const {
109 return block_drawing_;
112 // needed for spellchecking text
114 virtual bool allowSpellcheck() const { return false; }
116 virtual WordLangTuple const
117 selectNextWordToSpellcheck(BufferView *, float & value) const;
119 virtual void selectSelectedWord(BufferView *) {}
121 virtual void toggleSelection(BufferView *, bool /*kill_selection*/) {}
123 /// find the next change in the inset
124 virtual bool nextChange(BufferView * bv, lyx::pos_type & length);
127 // needed for search/replace functionality
129 virtual bool searchForward(BufferView *, string const &,
130 bool = true, bool = false);
132 virtual bool searchBackward(BufferView *, string const &,
133 bool = true, bool = false);
136 /// scrolls to absolute position in bufferview-workwidth * sx units
137 void scroll(BufferView *, float sx) const;
138 /// scrolls offset pixels
139 void scroll(BufferView *, int offset) const;
143 mutable bool block_drawing_;
147 bool UpdatableInset::checkInsertChar(LyXFont &)