]> git.lyx.org Git - lyx.git/blob - src/insets/updatableinset.C
Final touch 'inset display()'; fix 'is a bit silly' bug
[lyx.git] / src / insets / updatableinset.C
1 /**
2  * \file updatableinset.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author Jürgen Vigna
8  * \author Lars Gullik Bjønnes
9  * \author Matthias Ettrich
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "updatableinset.h"
17
18 #include "BufferView.h"
19 #include "debug.h"
20 #include "funcrequest.h"
21 #include "lyxtext.h"
22 #include "WordLangTuple.h"
23
24 #include "support/lstrings.h"
25
26
27 using lyx::support::strToDbl;
28 using lyx::support::strToInt;
29
30 using std::string;
31
32
33 // some stuff for inset locking
34
35 void UpdatableInset::insetUnlock(BufferView *)
36 {
37         lyxerr[Debug::INFO] << "Inset Unlock" << std::endl;
38 }
39
40
41 // An updatable inset is highly editable by definition
42 InsetOld::EDITABLE UpdatableInset::editable() const
43 {
44         return HIGHLY_EDITABLE;
45 }
46
47
48 void UpdatableInset::fitInsetCursor(BufferView *) const
49 {}
50
51
52 void UpdatableInset::draw(PainterInfo &, int, int) const
53 {
54         // ATTENTION: don't do the following here!!!
55         //    top_x = x;
56         //    top_baseline = y;
57 }
58
59
60 void UpdatableInset::scroll(BufferView * bv, float s) const
61 {
62         //LyXFont font;
63
64         if (!s) {
65                 scx = 0;
66                 return;
67         }
68
69         int const workW = bv->workWidth();
70         int const tmp_top_x = top_x - scx;
71
72         if (tmp_top_x > 0 && tmp_top_x + width() < workW)
73                 return;
74         if (s > 0 && top_x > 0)
75                 return;
76
77         scx = int(s * workW / 2);
78         // if (!display())
79         // scx += 20;
80
81 #warning metrics?
82         if (tmp_top_x + scx + width() < workW / 2) {
83                 scx += workW / 2 - (tmp_top_x + scx + width());
84         }
85 }
86
87 void UpdatableInset::scroll(BufferView * bv, int offset) const
88 {
89         if (offset > 0) {
90                 if (!scx && top_x >= 20)
91                         return;
92                 if ((top_x + offset) > 20)
93                         scx = 0;
94                 // scx += offset - (top_x - scx + offset - 20);
95                 else
96                         scx += offset;
97         } else {
98 #warning metrics?
99                 if (!scx && top_x + width() < bv->workWidth() - 20)
100                         return;
101                 if (top_x - scx + offset + width() < bv->workWidth() - 20) {
102                         scx += bv->workWidth() - width() - top_x - 20;
103                 } else {
104                         scx += offset;
105                 }
106         }
107 }
108
109
110 ///  An updatable inset could handle lyx editing commands
111 dispatch_result
112 UpdatableInset::priv_dispatch(FuncRequest const & ev, idx_type &, pos_type &)
113 {
114         if (ev.action == LFUN_MOUSE_RELEASE)
115                 return (editable() == IS_EDITABLE) ? DISPATCHED : UNDISPATCHED;
116
117         if (!ev.argument.empty() && ev.action == LFUN_SCROLL_INSET) {
118                 if (ev.argument.find('.') != ev.argument.npos) {
119                         float const xx = static_cast<float>(strToDbl(ev.argument));
120                         scroll(ev.view(), xx);
121                 } else {
122                         int const xx = strToInt(ev.argument);
123                         scroll(ev.view(), xx);
124                 }
125                 ev.view()->updateInset(this);
126
127                 return DISPATCHED;
128         }
129         return UNDISPATCHED;
130 }
131
132
133 LyXCursor const & InsetOld::cursor(BufferView * bv) const
134 {
135         if (owner())
136                 return owner()->getLyXText(bv, false)->cursor;
137         return bv->text->cursor;
138 }
139
140
141 WordLangTuple const
142 UpdatableInset::selectNextWordToSpellcheck(BufferView *bv, float & value) const
143 {
144         // we have to unlock ourself in this function by default!
145         bv->unlockInset(const_cast<UpdatableInset *>(this));
146         value = 0;
147         return WordLangTuple();
148 }
149
150
151 bool UpdatableInset::nextChange(BufferView * bv, lyx::pos_type &)
152 {
153         // we have to unlock ourself in this function by default!
154         bv->unlockInset(const_cast<UpdatableInset *>(this));
155         return false;
156 }
157
158
159 bool UpdatableInset::searchForward(BufferView * bv, string const &,
160                                    bool, bool)
161 {
162         // we have to unlock ourself in this function by default!
163         bv->unlockInset(const_cast<UpdatableInset *>(this));
164         return false;
165 }
166
167
168 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
169                                     bool, bool)
170 {
171         // we have to unlock ourself in this function by default!
172         bv->unlockInset(const_cast<UpdatableInset *>(this));
173         return false;
174 }