]> git.lyx.org Git - lyx.git/blob - src/insets/inset.C
Insetcite updates from Angus
[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 font)
62 {
63   return font;
64 }
65
66
67 char const * Inset::EditMessage() const 
68 {
69         return _("Opened inset");
70 }
71
72  /* some stuff for inset locking */
73
74 void UpdatableInset::InsetButtonPress(BufferView *, int x, int y, int button)
75 {
76         lyxerr.debug() << "Inset Button Press x=" << x
77                        << ", y=" << y << ", button=" << button << endl;
78 }
79
80
81 void UpdatableInset::InsetButtonRelease(BufferView *, int x, int y, int button)
82 {
83         lyxerr.debug() << "Inset Button Release x=" << x
84                        << ", y=" << y << ", button=" << button << endl;
85 }
86
87
88 void UpdatableInset::InsetKeyPress(XKeyEvent *)
89 {
90         lyxerr.debug() << "Inset Keypress" << endl;
91 }
92
93
94 void UpdatableInset::InsetMotionNotify(BufferView *, int x, int y, int state)
95 {
96         lyxerr.debug() << "Inset Motion Notify x=" << x
97                        << ", y=" << y << ", state=" << state << endl;
98 }
99
100
101 void UpdatableInset::InsetUnlock(BufferView *)
102 {
103         lyxerr.debug() << "Inset Unlock" << endl;
104 }
105
106
107 // An updatable inset is highly editable by definition
108 Inset::EDITABLE UpdatableInset::Editable() const
109 {
110         return HIGHLY_EDITABLE;
111 }
112
113
114 void UpdatableInset::ToggleInsetCursor(BufferView *)
115 {
116 }
117
118
119 void UpdatableInset::ShowInsetCursor(BufferView *)
120 {
121 }
122
123
124 void UpdatableInset::HideInsetCursor(BufferView *)
125 {
126 }
127
128
129 void UpdatableInset::Edit(BufferView * bv, int, int, unsigned int)
130 {
131     LyXFont font;
132
133     scx = 0;
134
135     mx_scx = abs((width(bv->painter(), font) - bv->workWidth()) / 2);
136 }
137
138
139 void UpdatableInset::draw(BufferView *, LyXFont const &,
140                           int /* baseline */, float & x) const
141 {
142     if (scx) x += float(scx);
143 // ATTENTION: don't do the following here!!!
144 //    top_x = int(x);
145 //    top_baseline = baseline;
146 }
147
148
149 void UpdatableInset::SetFont(BufferView *, LyXFont const &, bool )
150 {
151 }
152
153
154 ///  An updatable inset could handle lyx editing commands
155 #ifdef SCROLL_INSET
156 UpdatableInset::RESULT
157 UpdatableInset::LocalDispatch(BufferView *, 
158                               int action, string const & arg) 
159 #else
160 UpdatableInset::RESULT
161 UpdatableInset::LocalDispatch(BufferView *, int, string const &)
162 #endif
163 {
164 #ifdef SCROLL_INSET
165     if (action==LFUN_SCROLL_INSET)
166         {
167             float xx;
168             sscanf(arg.c_str(), "%f", &xx);     
169             scroll(xx);
170
171             return DISPATCHED;
172         }
173 #endif
174     return UNDISPATCHED; 
175 }
176
177
178 int UpdatableInset::getMaxWidth(Painter & pain, UpdatableInset const *) const
179 {
180     if (owner())
181         return static_cast<UpdatableInset*>(owner())->getMaxWidth(pain, this);
182     return pain.paperWidth();
183 }