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