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