]> git.lyx.org Git - lyx.git/blob - src/insets/updatableinset.h
The markDirty() and fitCursor() changes
[lyx.git] / src / insets / updatableinset.h
1 // -*- C++ -*-
2 /**
3  * \file updatableinset.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alejandro Aguilar Sierra
8  * \author Jürgen Vigna
9  * \author Lars Gullik Bjønnes
10  * \author Matthias Ettrich
11  *
12  * Full author contact details are available in file CREDITS
13  */
14
15 #ifndef UPDATABLEINSET_H
16 #define UPDATABLEINSET_H
17
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.
21 //  [Alejandro 080596]
22
23 #include "inset.h"
24
25
26 /** Extracted from Matthias notes:
27  *
28  * An inset can simple call LockInset in it's edit call and *ONLY*
29  * in it's edit call.
30  *
31  * Unlocking is either done by LyX or the inset itself with a
32  * UnlockInset-call
33  *
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.
38  *
39  * If a inset wishes any redraw and/or update it just has to call
40  * updateInset(this).
41  *
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.
46  */
47 class UpdatableInset : public Inset {
48 public:
49         ///
50         UpdatableInset();
51         ///
52         UpdatableInset(UpdatableInset const & in, bool same_id = false);
53
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 &);
57         ///
58         virtual EDITABLE editable() const;
59
60         ///
61         virtual void toggleInsetCursor(BufferView *);
62         ///
63         virtual void showInsetCursor(BufferView *, bool show = true);
64         ///
65         virtual void hideInsetCursor(BufferView *);
66         ///
67         virtual void fitInsetCursor(BufferView *) const;
68         ///
69         virtual void getCursorPos(BufferView *, int &, int &) const {}
70         ///
71         virtual void insetUnlock(BufferView *);
72         ///
73         virtual void edit(BufferView *, int x, int y, mouse_button::state button);
74         ///
75         virtual void edit(BufferView *, bool front = true);
76         ///
77         virtual void draw(BufferView *, LyXFont const &,
78                           int baseline, float & x) const;
79         ///
80         virtual bool insertInset(BufferView *, Inset *) { return false; }
81         ///
82         virtual UpdatableInset * getLockingInset() const {
83                 return const_cast<UpdatableInset *>(this);
84         }
85         ///
86         virtual UpdatableInset * getFirstLockingInsetOfType(Inset::Code c)
87                 { return (c == lyxCode()) ? this : 0; }
88         ///
89         virtual int insetInInsetY() const { return 0; }
90         ///
91         virtual bool updateInsetInInset(BufferView *, Inset *)
92                 { return false; }
93         ///
94         virtual bool lockInsetInInset(BufferView *, UpdatableInset *)
95                 { return false; }
96         ///
97         virtual bool unlockInsetInInset(BufferView *, UpdatableInset *,
98                                         bool /*lr*/ = false)
99                 { return false; }
100         ///  An updatable inset could handle lyx editing commands
101         virtual RESULT localDispatch(FuncRequest const & cmd);
102         ///
103         bool isCursorVisible() const { return cursor_visible_; }
104         ///
105         virtual int getMaxWidth(BufferView * bv, UpdatableInset const *) const;
106         ///
107         int scroll(bool recursive = true) const {
108                 // We need this method to not clobber the real method in Inset
109                 return Inset::scroll(recursive);
110         }
111         ///
112         virtual bool showInsetDialog(BufferView *) const { return false; }
113         ///
114         virtual void nodraw(bool b) const {
115                 block_drawing_ = b;
116         }
117         ///
118         virtual bool nodraw() const {
119                 return block_drawing_;
120         }
121         ///
122         // needed for spellchecking text
123         ///
124         virtual bool allowSpellcheck() const { return false; }
125         ///
126         virtual WordLangTuple const
127         selectNextWordToSpellcheck(BufferView *, float & value) const;
128         ///
129         virtual void selectSelectedWord(BufferView *) {}
130         ///
131         virtual void toggleSelection(BufferView *, bool /*kill_selection*/) {}
132
133         /// find the next change in the inset
134         virtual bool nextChange(BufferView * bv, lyx::pos_type & length);
135  
136         ///
137         // needed for search/replace functionality
138         ///
139         virtual bool searchForward(BufferView *, string const &,
140                                    bool = true, bool = false);
141         ///
142         virtual bool searchBackward(BufferView *, string const &,
143                                     bool = true, bool = false);
144
145 protected:
146         ///
147         void toggleCursorVisible() const {
148                 cursor_visible_ = !cursor_visible_;
149         }
150         ///
151         void setCursorVisible(bool b) const {
152                 cursor_visible_ = b;
153         }
154         /// scrolls to absolute position in bufferview-workwidth * sx units
155         void scroll(BufferView *, float sx) const;
156         /// scrolls offset pixels
157         void scroll(BufferView *, int offset) const;
158
159 private:
160         ///
161         mutable bool cursor_visible_;
162         ///
163         mutable bool block_drawing_;
164 };
165
166 inline
167 bool UpdatableInset::checkInsertChar(LyXFont &)
168 {
169         return true;
170 }
171
172 #endif