]> git.lyx.org Git - lyx.git/blob - src/insets/insetbase.C
remove all trace if idxUpDown2
[lyx.git] / src / insets / insetbase.C
1 /**
2  * \file insetbase.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "insetbase.h"
14
15 #include "buffer.h"
16 #include "coordcache.h"
17 #include "BufferView.h"
18 #include "LColor.h"
19 #include "cursor.h"
20 #include "debug.h"
21 #include "dimension.h"
22 #include "dispatchresult.h"
23 #include "gettext.h"
24 #include "lyxtext.h"
25 #include "metricsinfo.h"
26
27 #include "frontends/Painter.h"
28
29 #include <map>
30
31
32 namespace {
33
34 struct InsetName {
35         InsetName(std::string const & n, InsetBase::Code c)
36                 : name(n), code(c) {}
37         std::string name;
38         InsetBase::Code code;
39 };
40
41
42 typedef std::map<std::string, InsetBase::Code> TranslatorMap;
43
44
45 TranslatorMap const build_translator()
46 {
47         InsetName const insetnames[] = {
48                 InsetName("toc", InsetBase::TOC_CODE),
49                 InsetName("quote", InsetBase::QUOTE_CODE),
50                 InsetName("ref", InsetBase::REF_CODE),
51                 InsetName("url", InsetBase::URL_CODE),
52                 InsetName("htmlurl", InsetBase::HTMLURL_CODE),
53                 InsetName("separator", InsetBase::SEPARATOR_CODE),
54                 InsetName("ending", InsetBase::ENDING_CODE),
55                 InsetName("label", InsetBase::LABEL_CODE),
56                 InsetName("note", InsetBase::NOTE_CODE),
57                 InsetName("accent", InsetBase::ACCENT_CODE),
58                 InsetName("math", InsetBase::MATH_CODE),
59                 InsetName("index", InsetBase::INDEX_CODE),
60                 InsetName("include", InsetBase::INCLUDE_CODE),
61                 InsetName("graphics", InsetBase::GRAPHICS_CODE),
62                 InsetName("bibitem", InsetBase::BIBITEM_CODE),
63                 InsetName("bibtex", InsetBase::BIBTEX_CODE),
64                 InsetName("text", InsetBase::TEXT_CODE),
65                 InsetName("ert", InsetBase::ERT_CODE),
66                 InsetName("foot", InsetBase::FOOT_CODE),
67                 InsetName("margin", InsetBase::MARGIN_CODE),
68                 InsetName("float", InsetBase::FLOAT_CODE),
69                 InsetName("wrap", InsetBase::WRAP_CODE),
70                 InsetName("specialchar", InsetBase::SPECIALCHAR_CODE),
71                 InsetName("tabular", InsetBase::TABULAR_CODE),
72                 InsetName("external", InsetBase::EXTERNAL_CODE),
73                 InsetName("caption", InsetBase::CAPTION_CODE),
74                 InsetName("mathmacro", InsetBase::MATHMACRO_CODE),
75                 InsetName("error", InsetBase::ERROR_CODE),
76                 InsetName("cite", InsetBase::CITE_CODE),
77                 InsetName("float_list", InsetBase::FLOAT_LIST_CODE),
78                 InsetName("index_print", InsetBase::INDEX_PRINT_CODE),
79                 InsetName("optarg", InsetBase::OPTARG_CODE),
80                 InsetName("environment", InsetBase::ENVIRONMENT_CODE),
81                 InsetName("hfill", InsetBase::HFILL_CODE),
82                 InsetName("newline", InsetBase::NEWLINE_CODE),
83                 InsetName("line", InsetBase::LINE_CODE),
84                 InsetName("branch", InsetBase::BRANCH_CODE),
85                 InsetName("box", InsetBase::BOX_CODE),
86                 InsetName("charstyle", InsetBase::CHARSTYLE_CODE),
87                 InsetName("vspace", InsetBase::VSPACE_CODE),
88                 InsetName("mathmacroarg", InsetBase::MATHMACROARG_CODE),
89         };
90
91         std::size_t const insetnames_size =
92                 sizeof(insetnames) / sizeof(insetnames[0]);
93
94         std::map<std::string, InsetBase::Code> data;
95         for (std::size_t i = 0; i != insetnames_size; ++i) {
96                 InsetName const & var = insetnames[i];
97                 data[var.name] = var.code;
98         }
99
100         return data;
101 }
102
103 } // namespace anon
104
105
106 InsetBase::InsetBase()
107 {}
108
109
110 InsetBase::InsetBase(InsetBase const &)
111 {}
112
113
114 InsetBase::Code InsetBase::translate(std::string const & name)
115 {
116         static TranslatorMap const translator = build_translator();
117
118         TranslatorMap::const_iterator it = translator.find(name);
119         return it == translator.end() ? NO_CODE : it->second;
120 }
121
122
123 void InsetBase::dispatch(LCursor & cur, FuncRequest & cmd)
124 {
125         cur.needsUpdate();
126         cur.dispatched();
127         doDispatch(cur, cmd);
128 }
129
130
131 void InsetBase::doDispatch(LCursor & cur, FuncRequest &)
132 {
133         cur.noUpdate();
134         cur.undispatched();
135 }
136
137
138 bool InsetBase::getStatus(LCursor &, FuncRequest const &, FuncStatus &) const
139 {
140         return false;
141 }
142
143
144 void InsetBase::edit(LCursor &, bool)
145 {
146         lyxerr << "InsetBase: edit left/right" << std::endl;
147 }
148
149
150 InsetBase * InsetBase::editXY(LCursor &, int x, int y) const
151 {
152         lyxerr << "InsetBase: editXY x:" << x << " y: " << y << std::endl;
153         return const_cast<InsetBase*>(this);
154 }
155
156
157 InsetBase::idx_type InsetBase::index(row_type row, col_type col) const
158 {
159         if (row != 0)
160                 lyxerr << "illegal row: " << row << std::endl;
161         if (col != 0)
162                 lyxerr << "illegal col: " << col << std::endl;
163         return 0;
164 }
165
166
167 bool InsetBase::idxBetween(idx_type idx, idx_type from, idx_type to) const
168 {
169         return from <= idx && idx <= to;
170 }
171
172
173 bool InsetBase::idxUpDown(LCursor &, bool) const
174 {
175         return false;
176 }
177
178
179 int InsetBase::plaintext(Buffer const &,
180         std::ostream &, OutputParams const &) const
181 {
182         return 0;
183 }
184
185
186 int InsetBase::linuxdoc(Buffer const &,
187         std::ostream &, OutputParams const &) const
188 {
189         return 0;
190 }
191
192
193 int InsetBase::docbook(Buffer const &,
194         std::ostream &, OutputParams const &) const
195 {
196         return 0;
197 }
198
199
200 bool InsetBase::directWrite() const
201 {
202         return false;
203 }
204
205
206 InsetBase::EDITABLE InsetBase::editable() const
207 {
208         return NOT_EDITABLE;
209 }
210
211
212 bool InsetBase::autoDelete() const
213 {
214         return false;
215 }
216
217
218 std::string const InsetBase::editMessage() const
219 {
220         return _("Opened inset");
221 }
222
223
224 std::string const & InsetBase::getInsetName() const
225 {
226         static std::string const name = "unknown";
227         return name;
228 }
229
230
231 void InsetBase::markErased()
232 {}
233
234
235 void InsetBase::getCursorPos(CursorSlice const &, int & x, int & y) const
236 {
237         lyxerr << "InsetBase::getCursorPos called directly" << std::endl;
238         x = 100;
239         y = 100;
240 }
241
242
243 void InsetBase::metricsMarkers(Dimension & dim, int framesize) const
244 {
245         dim.wid += 2 * framesize;
246         dim.asc += framesize;
247 }
248
249
250 void InsetBase::metricsMarkers2(Dimension & dim, int framesize) const
251 {
252         dim.wid += 2 * framesize;
253         dim.asc += framesize;
254         dim.des += framesize;
255 }
256
257
258 void InsetBase::drawMarkers(PainterInfo & pi, int x, int y) const
259 {
260         if (!editing(pi.base.bv))
261                 return;
262         int const t = x + width() - 1;
263         int const d = y + descent();
264         pi.pain.line(x, d - 3, x, d, LColor::mathframe);
265         pi.pain.line(t, d - 3, t, d, LColor::mathframe);
266         pi.pain.line(x, d, x + 3, d, LColor::mathframe);
267         pi.pain.line(t - 3, d, t, d, LColor::mathframe);
268         setPosCache(pi, x, y);
269 }
270
271
272 void InsetBase::drawMarkers2(PainterInfo & pi, int x, int y) const
273 {
274         if (!editing(pi.base.bv))
275                 return;
276         drawMarkers(pi, x, y);
277         int const t = x + width() - 1;
278         int const a = y - ascent();
279         pi.pain.line(x, a + 3, x, a, LColor::mathframe);
280         pi.pain.line(t, a + 3, t, a, LColor::mathframe);
281         pi.pain.line(x, a, x + 3, a, LColor::mathframe);
282         pi.pain.line(t - 3, a, t, a, LColor::mathframe);
283         setPosCache(pi, x, y);
284 }
285
286
287 bool InsetBase::editing(BufferView * bv) const
288 {
289         return bv->cursor().isInside(this);
290 }
291
292
293 int InsetBase::xo() const
294 {
295         return theCoords.insets_.x(this);
296 }
297
298
299 int InsetBase::yo() const
300 {
301         return theCoords.insets_.y(this);
302 }
303
304
305 bool InsetBase::covers(int x, int y) const
306 {
307         //lyxerr << "InsetBase::covers, x: " << x << " y: " << y
308         //      << " xo: " << xo() << " yo: " << yo()
309         //      << " x1: " << xo() << " x2: " << xo() + width()
310         //      << " y1: " << yo() - ascent() << " y2: " << yo() + descent()
311         //      << std::endl;
312         return theCoords.insets_.has(this)
313                         && x >= xo()
314                         && x <= xo() + width()
315                         && y >= yo() - ascent()
316                         && y <= yo() + descent();
317 }
318
319
320 void InsetBase::dump() const
321 {
322         Buffer buf("foo", 1);
323         write(buf, lyxerr);
324 }
325
326
327 /////////////////////////////////////////
328
329 bool isEditableInset(InsetBase const * inset)
330 {
331         return inset && inset->editable();
332 }
333
334
335 bool isHighlyEditableInset(InsetBase const * inset)
336 {
337         return inset && inset->editable() == InsetBase::HIGHLY_EDITABLE;
338 }