]> git.lyx.org Git - lyx.git/blob - src/insets/insetbase.C
* dispatchresult.h: rename 'FINISHED' to 'FINISHED_LEFT'
[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 "BufferView.h"
17 #include "LColor.h"
18 #include "cursor.h"
19 #include "debug.h"
20 #include "dimension.h"
21 #include "dispatchresult.h"
22 #include "gettext.h"
23 #include "lyxtext.h"
24 #include "metricsinfo.h"
25
26 #include "frontends/Painter.h"
27
28
29
30 void InsetBase::dispatch(LCursor & cur, FuncRequest const & cmd)
31 {
32         priv_dispatch(cur, cmd);
33 }
34
35
36 void InsetBase::priv_dispatch(LCursor & cur, FuncRequest const &)
37 {
38         cur.noupdate();
39         cur.notdispatched();
40 }
41
42
43 bool InsetBase::getStatus(LCursor &, FuncRequest const &, FuncStatus &)
44 {
45         return false;
46 }
47
48
49 void InsetBase::edit(LCursor &, bool)
50 {
51         lyxerr << "InsetBase: edit left/right" << std::endl;
52 }
53
54
55 InsetBase * InsetBase::editXY(LCursor &, int x, int y)
56 {
57         lyxerr << "InsetBase: editXY x:" << x << " y: " << y << std::endl;
58         return this;
59 }
60
61
62 InsetBase::idx_type InsetBase::index(row_type row, col_type col) const
63 {
64         if (row != 0)
65                 lyxerr << "illegal row: " << row << std::endl;
66         if (col != 0)
67                 lyxerr << "illegal col: " << col << std::endl;
68         return 0;
69 }
70
71
72 bool InsetBase::idxBetween(idx_type idx, idx_type from, idx_type to) const
73 {
74         return from <= idx && idx <= to;
75 }
76
77
78 bool InsetBase::idxUpDown(LCursor &, bool) const
79 {
80         return false;
81 }
82
83
84 bool InsetBase::idxUpDown2(LCursor &, bool) const
85 {
86         return false;
87 }
88
89
90 int InsetBase::plaintext(Buffer const &,
91         std::ostream &, OutputParams const &) const
92 {
93         return 0;
94 }
95
96
97 int InsetBase::linuxdoc(Buffer const &,
98         std::ostream &, OutputParams const &) const
99 {
100         return 0;
101 }
102
103
104 int InsetBase::docbook(Buffer const &,
105         std::ostream &, OutputParams const &) const
106 {
107         return 0;
108 }
109
110
111 bool InsetBase::directWrite() const
112 {
113         return false;
114 }
115
116
117 InsetBase::EDITABLE InsetBase::editable() const
118 {
119         return NOT_EDITABLE;
120 }
121
122
123 bool InsetBase::autoDelete() const
124 {
125         return false;
126 }
127
128
129 std::string const InsetBase::editMessage() const
130 {
131         return _("Opened inset");
132 }
133
134
135 std::string const & InsetBase::getInsetName() const
136 {
137         static std::string const name = "unknown";
138         return name;
139 }
140
141
142 void InsetBase::markErased()
143 {}
144
145
146 void InsetBase::getCursorPos(CursorSlice const &, int & x, int & y) const
147 {
148         lyxerr << "InsetBase::getCursorPos called directly" << std::endl;
149         x = 100;
150         y = 100;
151 }
152
153
154 void InsetBase::metricsMarkers(Dimension & dim, int) const
155 {
156         dim.wid += 2;
157         dim.asc += 1;
158 }
159
160
161 void InsetBase::metricsMarkers2(Dimension & dim, int) const
162 {
163         dim.wid += 2;
164         dim.asc += 1;
165         dim.des += 1;
166 }
167
168
169 void InsetBase::drawMarkers(PainterInfo & pi, int x, int y) const
170 {
171         if (!editing(pi.base.bv))
172                 return;
173         int const t = x + width() - 1;
174         int const d = y + descent();
175         pi.pain.line(x, d - 3, x, d, LColor::mathframe);
176         pi.pain.line(t, d - 3, t, d, LColor::mathframe);
177         pi.pain.line(x, d, x + 3, d, LColor::mathframe);
178         pi.pain.line(t - 3, d, t, d, LColor::mathframe);
179         setPosCache(pi, x, y);
180 }
181
182
183 void InsetBase::drawMarkers2(PainterInfo & pi, int x, int y) const
184 {
185         if (!editing(pi.base.bv))
186                 return;
187         drawMarkers(pi, x, y);
188         int const t = x + width() - 1;
189         int const a = y - ascent();
190         pi.pain.line(x, a + 3, x, a, LColor::mathframe);
191         pi.pain.line(t, a + 3, t, a, LColor::mathframe);
192         pi.pain.line(x, a, x + 3, a, LColor::mathframe);
193         pi.pain.line(t - 3, a, t, a, LColor::mathframe);
194         setPosCache(pi, x, y);
195 }
196
197
198 bool InsetBase::editing(BufferView * bv) const
199 {
200         return bv->cursor().isInside(this);
201 }
202
203
204 bool InsetBase::covers(int x, int y) const
205 {
206         return x >= xo()
207                         && x <= xo() + width()
208                         && y >= yo() - ascent()
209                         && y <= yo() + descent();
210 }
211
212
213 void InsetBase::dump() const
214 {
215         Buffer buf("foo", 1);
216         write(buf, lyxerr);
217 }
218
219
220 /////////////////////////////////////////
221
222 bool isEditableInset(InsetBase const * inset)
223 {
224         return inset && inset->editable();
225 }
226
227
228 bool isHighlyEditableInset(InsetBase const * inset)
229 {
230         return inset && inset->editable() == InsetBase::HIGHLY_EDITABLE;
231 }
232
233