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