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