]> git.lyx.org Git - lyx.git/blob - src/insets/inset.C
Add code to check shortcuts in menu files
[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 (((top_x - scx) > 0) && 
171         (top_x - scx + width(bv, font)) < bv->workWidth())
172         return;
173     if ((s > 0) && (top_x > 0))
174         return;
175
176 //    int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
177     int save_scx = scx;
178     
179     scx = int(s*bv->workWidth()/2);
180 //    if (!display())
181 //      scx += 20;
182
183     if ((top_x - save_scx + scx + width(bv, font)) < (bv->workWidth()/2)) {
184         scx += (bv->workWidth()/2) - (top_x - save_scx + scx + width(bv,font));
185     }
186 //    bv->updateInset(const_cast<UpdatableInset *>(this), false);
187 }
188
189 void UpdatableInset::scroll(BufferView * bv, int offset) const
190 {
191     if (offset > 0) {
192         if (!scx && top_x > 0)
193             return;
194         if ((top_x + offset) > 20)
195             scx += offset - (top_x - scx + offset - 20);
196         else
197             scx += offset;
198     } else {
199         LyXFont 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 #endif
213
214 ///  An updatable inset could handle lyx editing commands
215 #ifdef SCROLL_INSET
216 UpdatableInset::RESULT
217 UpdatableInset::LocalDispatch(BufferView * bv, 
218                               int action, string const & arg) 
219 #else
220 UpdatableInset::RESULT
221 UpdatableInset::LocalDispatch(BufferView *, int, string const &)
222 #endif
223 {
224 #ifdef SCROLL_INSET
225
226     if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
227         if (arg.find('.') != arg.npos) {
228             float xx = static_cast<float>(strToDbl(arg));
229             scroll(bv, xx);
230         } else {
231             int xx = strToInt(arg);
232             scroll(bv, xx);
233         }
234         bv->updateInset(this, false);
235         
236         return DISPATCHED;
237     }
238 #endif
239     return UNDISPATCHED; 
240 }
241
242
243 int UpdatableInset::getMaxWidth(Painter & pain, UpdatableInset const *) const
244 {
245     if (owner())
246         return static_cast<UpdatableInset*>(owner())->getMaxWidth(pain, this);
247     return pain.paperWidth();
248 }