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