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