]> git.lyx.org Git - lyx.git/blob - src/insets/updatableinset.C
Re-add the RasterImage template.
[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 using lyx::support::strToDbl;
27 using lyx::support::strToInt;
28
29
30 // some stuff for inset locking
31
32 UpdatableInset::UpdatableInset()
33         : InsetOld()
34 {}
35
36
37 UpdatableInset::UpdatableInset(UpdatableInset const & in)
38         : InsetOld(in)
39 {}
40
41
42 void UpdatableInset::insetUnlock(BufferView *)
43 {
44         lyxerr[Debug::INFO] << "Inset Unlock" << std::endl;
45 }
46
47
48 // An updatable inset is highly editable by definition
49 InsetOld::EDITABLE UpdatableInset::editable() const
50 {
51         return HIGHLY_EDITABLE;
52 }
53
54
55 void UpdatableInset::fitInsetCursor(BufferView *) const
56 {}
57
58
59 void UpdatableInset::draw(PainterInfo &, int, int) const
60 {
61         // ATTENTION: don't do the following here!!!
62         //    top_x = x;
63         //    top_baseline = y;
64 }
65
66
67 void UpdatableInset::scroll(BufferView * bv, float s) const
68 {
69         //LyXFont font;
70
71         if (!s) {
72                 scx = 0;
73                 return;
74         }
75
76         int const workW = bv->workWidth();
77         int const tmp_top_x = top_x - scx;
78
79         if (tmp_top_x > 0 && tmp_top_x + width() < workW)
80                 return;
81         if (s > 0 && top_x > 0)
82                 return;
83
84         scx = int(s * workW / 2);
85         // if (!display())
86         // scx += 20;
87
88 #warning metrics?
89         if (tmp_top_x + scx + width() < workW / 2) {
90                 scx += workW / 2 - (tmp_top_x + scx + width());
91         }
92 }
93
94 void UpdatableInset::scroll(BufferView * bv, int offset) const
95 {
96         if (offset > 0) {
97                 if (!scx && top_x >= 20)
98                         return;
99                 if ((top_x + offset) > 20)
100                         scx = 0;
101                 // scx += offset - (top_x - scx + offset - 20);
102                 else
103                         scx += offset;
104         } else {
105 #warning metrics?
106                 if (!scx && top_x + width() < bv->workWidth() - 20)
107                         return;
108                 if (top_x - scx + offset + width() < bv->workWidth() - 20) {
109                         scx += bv->workWidth() - width() - top_x - 20;
110                 } else {
111                         scx += offset;
112                 }
113         }
114 }
115
116
117 ///  An updatable inset could handle lyx editing commands
118 InsetOld::RESULT UpdatableInset::localDispatch(FuncRequest const & ev)
119 {
120         if (ev.action == LFUN_MOUSE_RELEASE)
121                 return (editable() == IS_EDITABLE) ? DISPATCHED : UNDISPATCHED;
122
123         if (!ev.argument.empty() && ev.action == LFUN_SCROLL_INSET) {
124                 if (ev.argument.find('.') != ev.argument.npos) {
125                         float const xx = static_cast<float>(strToDbl(ev.argument));
126                         scroll(ev.view(), xx);
127                 } else {
128                         int const xx = strToInt(ev.argument);
129                         scroll(ev.view(), xx);
130                 }
131                 ev.view()->updateInset(this);
132
133                 return DISPATCHED;
134         }
135         return UNDISPATCHED;
136 }
137
138
139 LyXCursor const & InsetOld::cursor(BufferView * bv) const
140 {
141         if (owner())
142                 return owner()->getLyXText(bv, false)->cursor;
143         return bv->text->cursor;
144 }
145
146
147 WordLangTuple const
148 UpdatableInset::selectNextWordToSpellcheck(BufferView *bv, float & value) const
149 {
150         // we have to unlock ourself in this function by default!
151         bv->unlockInset(const_cast<UpdatableInset *>(this));
152         value = 0;
153         return WordLangTuple();
154 }
155
156
157 bool UpdatableInset::nextChange(BufferView * bv, lyx::pos_type &)
158 {
159         // we have to unlock ourself in this function by default!
160         bv->unlockInset(const_cast<UpdatableInset *>(this));
161         return false;
162 }
163
164
165 bool UpdatableInset::searchForward(BufferView * bv, string const &,
166                                    bool, bool)
167 {
168         // we have to unlock ourself in this function by default!
169         bv->unlockInset(const_cast<UpdatableInset *>(this));
170         return false;
171 }
172
173
174 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
175                                     bool, bool)
176 {
177         // we have to unlock ourself in this function by default!
178         bv->unlockInset(const_cast<UpdatableInset *>(this));
179         return false;
180 }