]> git.lyx.org Git - lyx.git/blob - src/insets/inset.C
more changes...read the Changelog
[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
23 using std::endl;
24
25 /* Insets default methods */
26
27 bool Inset::Deletable() const
28 {
29   return true;
30 }
31
32
33 bool Inset::DirectWrite() const
34 {
35   return false;
36 }
37
38
39 Inset::EDITABLE Inset::Editable() const
40 {
41   return NOT_EDITABLE;
42 }
43
44
45 void Inset::Validate(LaTeXFeatures &) const
46 {
47 }
48
49
50 bool Inset::AutoDelete() const
51 {
52   return false;
53 }
54
55
56 void Inset::Edit(BufferView *, int, int, unsigned int)
57 {
58 }
59
60
61 LyXFont Inset::ConvertFont(LyXFont const & font) const
62 {
63         return LyXFont(font);
64 }
65
66
67 char const * Inset::EditMessage() const 
68 {
69         return _("Opened inset");
70 }
71
72
73 LyXText * Inset::getLyXText(BufferView * bv) const
74 {
75     if (owner())
76             return owner()->getLyXText(bv);
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
129 void UpdatableInset::ShowInsetCursor(BufferView *)
130 {
131 }
132
133
134 void UpdatableInset::HideInsetCursor(BufferView *)
135 {
136 }
137
138
139 void UpdatableInset::Edit(BufferView * bv, int, int, unsigned int)
140 {
141     LyXFont font;
142
143     scx = 0;
144
145     mx_scx = abs((width(bv, font) - bv->workWidth()) / 2);
146 }
147
148
149 void UpdatableInset::draw(BufferView *, LyXFont const &,
150                           int /* baseline */, float & x, bool/*cleared*/) const
151 {
152     if (scx) x += float(scx);
153 // ATTENTION: don't do the following here!!!
154 //    top_x = int(x);
155 //    top_baseline = baseline;
156 }
157
158
159 void UpdatableInset::SetFont(BufferView *, LyXFont const &, bool )
160 {
161 }
162
163
164 ///  An updatable inset could handle lyx editing commands
165 #ifdef SCROLL_INSET
166 UpdatableInset::RESULT
167 UpdatableInset::LocalDispatch(BufferView *, 
168                               int action, string const & arg) 
169 #else
170 UpdatableInset::RESULT
171 UpdatableInset::LocalDispatch(BufferView *, int, string const &)
172 #endif
173 {
174 #ifdef SCROLL_INSET
175     if (action==LFUN_SCROLL_INSET)
176         {
177             float xx;
178             sscanf(arg.c_str(), "%f", &xx);     
179             scroll(xx);
180
181             return DISPATCHED;
182         }
183 #endif
184     return UNDISPATCHED; 
185 }
186
187
188 int UpdatableInset::getMaxWidth(Painter & pain, UpdatableInset const *) const
189 {
190     if (owner())
191         return static_cast<UpdatableInset*>(owner())->getMaxWidth(pain, this);
192     return pain.paperWidth();
193 }