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