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