]> git.lyx.org Git - lyx.git/blob - src/insets/inset.C
Make LFUN_QUOTE work for InsetText.
[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
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
63 LyXFont const Inset::ConvertFont(LyXFont const & font) const
64 {
65     return LyXFont(font);
66 }
67
68
69 string const Inset::EditMessage() const 
70 {
71     return _("Opened inset");
72 }
73
74
75 LyXText * Inset::getLyXText(BufferView const * bv) const
76 {
77     if (owner())
78             return owner()->getLyXText(bv);
79     else
80             return bv->text;
81 }
82
83
84  /* some stuff for inset locking */
85
86 void UpdatableInset::InsetButtonPress(BufferView *, int x, int y, int button)
87 {
88     lyxerr.debug() << "Inset Button Press x=" << x
89                    << ", y=" << y << ", button=" << button << endl;
90 }
91
92
93 void UpdatableInset::InsetButtonRelease(BufferView *, int x, int y, int button)
94 {
95     lyxerr.debug() << "Inset Button Release x=" << x
96                    << ", y=" << y << ", button=" << button << endl;
97 }
98
99
100 void UpdatableInset::InsetKeyPress(XKeyEvent *)
101 {
102     lyxerr.debug() << "Inset Keypress" << endl;
103 }
104
105
106 void UpdatableInset::InsetMotionNotify(BufferView *, int x, int y, int state)
107 {
108     lyxerr.debug() << "Inset Motion Notify x=" << x
109                    << ", y=" << y << ", state=" << state << endl;
110 }
111
112
113 void UpdatableInset::InsetUnlock(BufferView *)
114 {
115     lyxerr.debug() << "Inset Unlock" << endl;
116 }
117
118
119 // An updatable inset is highly editable by definition
120 Inset::EDITABLE UpdatableInset::Editable() const
121 {
122     return HIGHLY_EDITABLE;
123 }
124
125
126 void UpdatableInset::ToggleInsetCursor(BufferView *)
127 {
128 }
129
130
131 void UpdatableInset::ShowInsetCursor(BufferView *, bool)
132 {
133 }
134
135
136 void UpdatableInset::HideInsetCursor(BufferView *)
137 {
138 }
139
140
141 void UpdatableInset::Edit(BufferView *, int, int, unsigned int)
142 {
143 }
144
145
146 void UpdatableInset::draw(BufferView *, LyXFont const &,
147                           int /* baseline */, float & x, bool/*cleared*/) const
148 {
149     x += float(scx);
150 // ATTENTION: don't do the following here!!!
151 //    top_x = int(x);
152 //    top_baseline = baseline;
153 }
154
155
156 void UpdatableInset::SetFont(BufferView *, LyXFont const &, bool )
157 {
158 }
159
160
161 void UpdatableInset::scroll(BufferView * bv, float s) const
162 {
163     LyXFont font;
164
165     if (!s) {
166         scx = 0;
167         return;
168     }
169     if (((top_x - scx) > 0) && 
170         (top_x - scx + width(bv, font)) < bv->workWidth())
171         return;
172     if ((s > 0) && (top_x > 0))
173         return;
174
175 //    int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
176     int save_scx = scx;
177     
178     scx = int(s*bv->workWidth()/2);
179 //    if (!display())
180 //      scx += 20;
181
182     if ((top_x - save_scx + scx + width(bv, font)) < (bv->workWidth()/2)) {
183         scx += (bv->workWidth()/2) - (top_x - save_scx + scx + width(bv,font));
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 += offset - (top_x - scx + offset - 20);
195         else
196             scx += offset;
197     } else {
198         LyXFont font;
199         if (!scx && (top_x+width(bv, font)) < (bv->workWidth()-20))
200             return;
201         if ((top_x - scx + offset + width(bv,font)) < (bv->workWidth()-20)) {
202             scx = bv->workWidth() - width(bv,font) - top_x + scx - 20; 
203         } else {
204             scx += offset;
205         }
206     }
207 //    bv->updateInset(const_cast<UpdatableInset *>(this), false);
208 }
209
210 ///  An updatable inset could handle lyx editing commands
211 UpdatableInset::RESULT
212 UpdatableInset::LocalDispatch(BufferView * bv, 
213                               int action, string const & arg) 
214 {
215     if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
216         if (arg.find('.') != arg.npos) {
217             float xx = static_cast<float>(strToDbl(arg));
218             scroll(bv, xx);
219         } else {
220             int 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(Painter & pain, UpdatableInset const *) const
232 {
233     if (owner())
234         return static_cast<UpdatableInset*>(owner())->getMaxWidth(pain, this);
235     return pain.paperWidth();
236 }