]> git.lyx.org Git - lyx.git/blob - src/insets/inset.C
reformatting and remove using delc
[lyx.git] / src / insets / inset.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation "lyxinset.h"
15 #endif
16
17 #include "lyxinset.h"
18 #include "debug.h"
19 #include "BufferView.h"
20 #include "support/lstrings.h"
21 #include "Painter.h"
22 #include "commandtags.h"
23 #include "support/lstrings.h"
24
25 using std::endl;
26
27 // Insets default methods
28
29 bool Inset::Deletable() const
30 {
31         return true;
32 }
33
34
35 bool Inset::DirectWrite() const
36 {
37         return false;
38 }
39
40
41 Inset::EDITABLE Inset::Editable() const
42 {
43         return NOT_EDITABLE;
44 }
45
46
47 void Inset::Validate(LaTeXFeatures &) const
48 {}
49
50
51 bool Inset::AutoDelete() const
52 {
53         return false;
54 }
55
56
57 void Inset::Edit(BufferView *, int, int, unsigned int)
58 {}
59
60
61 LyXFont const Inset::ConvertFont(LyXFont const & font) const
62 {
63         return LyXFont(font);
64 }
65
66
67 string const Inset::EditMessage() const 
68 {
69         return _("Opened inset");
70 }
71
72
73 LyXText * Inset::getLyXText(BufferView const * bv, bool const) const
74 {
75         if (owner())
76                 return owner()->getLyXText(bv, false);
77         else
78                 return bv->text;
79 }
80
81
82 // some stuff for inset locking
83
84 void UpdatableInset::InsetButtonPress(BufferView *, int x, int y, int button)
85 {
86         lyxerr.debug() << "Inset Button Press x=" << x
87                        << ", y=" << y << ", button=" << button << endl;
88 }
89
90
91 void UpdatableInset::InsetButtonRelease(BufferView *, int x, int y, int button)
92 {
93         lyxerr.debug() << "Inset Button Release x=" << x
94                        << ", y=" << y << ", button=" << button << endl;
95 }
96
97
98 void UpdatableInset::InsetKeyPress(XKeyEvent *)
99 {
100         lyxerr.debug() << "Inset Keypress" << endl;
101 }
102
103
104 void UpdatableInset::InsetMotionNotify(BufferView *, int x, int y, int state)
105 {
106         lyxerr.debug() << "Inset Motion Notify x=" << x
107                        << ", y=" << y << ", state=" << state << endl;
108 }
109
110
111 void UpdatableInset::InsetUnlock(BufferView *)
112 {
113         lyxerr.debug() << "Inset Unlock" << endl;
114 }
115
116
117 // An updatable inset is highly editable by definition
118 Inset::EDITABLE UpdatableInset::Editable() const
119 {
120         return HIGHLY_EDITABLE;
121 }
122
123
124 void UpdatableInset::ToggleInsetCursor(BufferView *)
125 {}
126
127
128 void UpdatableInset::ShowInsetCursor(BufferView *, bool)
129 {}
130
131
132 void UpdatableInset::HideInsetCursor(BufferView *)
133 {}
134
135
136 void UpdatableInset::Edit(BufferView *, int, int, unsigned int)
137 {}
138
139
140 void UpdatableInset::draw(BufferView *, LyXFont const &,
141                           int /* baseline */, float & x,
142                           bool/*cleared*/) const
143 {
144         x += float(scx);
145         // ATTENTION: don't do the following here!!!
146         //    top_x = int(x);
147         //    top_baseline = baseline;
148 }
149
150
151 void UpdatableInset::SetFont(BufferView *, LyXFont const &, bool )
152 {}
153
154
155 void UpdatableInset::scroll(BufferView * bv, float s) const
156 {
157         LyXFont font;
158         
159         if (!s) {
160                 scx = 0;
161                 return;
162         }
163
164         int const workW = bv->workWidth();
165         int const tmp_top_x = top_x - scx;
166         
167         if (tmp_top_x > 0 && 
168             (tmp_top_x + width(bv, font)) < workW)
169                 return;
170         if (s > 0 && top_x > 0)
171                 return;
172
173         // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
174         //int const save_scx = scx;
175     
176         scx = int(s * workW / 2);
177         // if (!display())
178         // scx += 20;
179
180         if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
181                 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
182         }
183         // bv->updateInset(const_cast<UpdatableInset *>(this), false);
184 }
185
186 void UpdatableInset::scroll(BufferView * bv, int offset) const
187 {
188         if (offset > 0) {
189                 if (!scx && top_x >= 20)
190                         return;
191                 if ((top_x + offset) > 20)
192                         scx = 0;
193                 // scx += offset - (top_x - scx + offset - 20);
194                 else
195                         scx += offset;
196         } else {
197                 LyXFont const font;
198                 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
199                         return;
200                 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
201                         scx = bv->workWidth() - width(bv, font) - top_x + scx - 20; 
202                 } else {
203                         scx += offset;
204                 }
205         }
206         // bv->updateInset(const_cast<UpdatableInset *>(this), false);
207 }
208
209
210 ///  An updatable inset could handle lyx editing commands
211 UpdatableInset::RESULT
212 UpdatableInset::LocalDispatch(BufferView * bv, 
213                               kb_action action, string const & arg) 
214 {
215         if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
216                 if (arg.find('.') != arg.npos) {
217                         float const xx = static_cast<float>(strToDbl(arg));
218                         scroll(bv, xx);
219                 } else {
220                         int const xx = strToInt(arg);
221                         scroll(bv, xx);
222                 }
223                 bv->updateInset(this, false);
224                 
225                 return DISPATCHED;
226         }
227         return UNDISPATCHED; 
228 }
229
230
231 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
232 {
233         if (owner())
234                 return static_cast<UpdatableInset*>
235                         (owner())->getMaxWidth(bv, this);
236         return bv->workWidth();
237 }