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.
25 #include "support/types.h"
28 /** Extracted from Matthias notes:
30 * An inset can simple call LockInset in it's edit call and *ONLY*
33 * Unlocking is either done by LyX or the inset itself with a
36 * During the lock, all button and keyboard events will be modified
37 * and send to the inset through the following inset-features. Note that
38 * InsetOld::insetUnlock will be called from inside UnlockInset. It is meant
39 * to contain the code for restoring the menus and things like this.
41 * If a inset wishes any redraw and/or update it just has to call
44 * It's is completly irrelevant, where the inset is. UpdateInset will
45 * find it in any paragraph in any buffer.
46 * Of course the_locking_inset and the insets in the current paragraph/buffer
47 * are checked first, so no performance problem should occur.
49 class UpdatableInset : public InsetOld {
51 /// check if the font of the char we want inserting is correct
52 /// and modify it if it is not.
53 virtual bool checkInsertChar(LyXFont &) { return true; }
55 virtual EDITABLE editable() const;
58 virtual void fitInsetCursor(BufferView *) const;
60 virtual void getCursorPos(BufferView *, int &, int &) const {}
61 /// Get the absolute document x,y of the cursor
62 virtual void getCursor(BufferView &, int &, int &) const = 0;
64 virtual void insetUnlock(BufferView *);
66 virtual void draw(PainterInfo & pi, int x, int y) const;
68 virtual bool insertInset(BufferView *, InsetOld *) { return false; }
70 virtual UpdatableInset * getLockingInset() const
71 { return const_cast<UpdatableInset *>(this); }
73 virtual UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code c)
74 { return (c == lyxCode()) ? this : 0; }
76 virtual int insetInInsetY() const { return 0; }
78 virtual bool lockInsetInInset(BufferView *, UpdatableInset *)
81 virtual bool unlockInsetInInset(BufferView *, UpdatableInset *,
84 /// An updatable inset could handle lyx editing commands
85 virtual dispatch_result localDispatch(FuncRequest const & cmd);
86 // We need this method to not clobber the real method in Inset
87 int scroll(bool recursive = true) const
88 { return InsetOld::scroll(recursive); }
90 virtual bool showInsetDialog(BufferView *) const { return false; }
92 // needed for spellchecking text
94 virtual bool allowSpellcheck() const { return false; }
96 virtual WordLangTuple const
97 selectNextWordToSpellcheck(BufferView *, float & value) const;
99 virtual void selectSelectedWord(BufferView *) {}
101 virtual void toggleSelection(BufferView *, bool /*kill_selection*/) {}
103 /// find the next change in the inset
104 virtual bool nextChange(BufferView * bv, lyx::pos_type & length);
107 // needed for search/replace functionality
109 virtual bool searchForward(BufferView *, std::string const &,
110 bool = true, bool = false);
112 virtual bool searchBackward(BufferView *, std::string const &,
113 bool = true, bool = false);
116 /// scrolls to absolute position in bufferview-workwidth * sx units
117 void scroll(BufferView *, float sx) const;
118 /// scrolls offset pixels
119 void scroll(BufferView *, int offset) const;