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