3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "insetbase.h"
16 #include "coordcache.h"
17 #include "BufferView.h"
21 #include "dimension.h"
22 #include "dispatchresult.h"
25 #include "metricsinfo.h"
27 #include "frontends/Painter.h"
35 InsetName(std::string const & n, InsetBase::Code c)
42 typedef std::map<std::string, InsetBase::Code> TranslatorMap;
45 TranslatorMap const build_translator()
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),
91 std::size_t const insetnames_size =
92 sizeof(insetnames) / sizeof(insetnames[0]);
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;
106 InsetBase::Code InsetBase::translate(std::string const & name)
108 static TranslatorMap const translator = build_translator();
110 TranslatorMap::const_iterator it = translator.find(name);
111 return it == translator.end() ? NO_CODE : it->second;
115 void InsetBase::dispatch(LCursor & cur, FuncRequest & cmd)
119 priv_dispatch(cur, cmd);
123 void InsetBase::priv_dispatch(LCursor & cur, FuncRequest &)
130 bool InsetBase::getStatus(LCursor &, FuncRequest const &, FuncStatus &) const
136 void InsetBase::edit(LCursor &, bool)
138 lyxerr << "InsetBase: edit left/right" << std::endl;
142 InsetBase * InsetBase::editXY(LCursor &, int x, int y) const
144 lyxerr << "InsetBase: editXY x:" << x << " y: " << y << std::endl;
145 return const_cast<InsetBase*>(this);
149 InsetBase::idx_type InsetBase::index(row_type row, col_type col) const
152 lyxerr << "illegal row: " << row << std::endl;
154 lyxerr << "illegal col: " << col << std::endl;
159 bool InsetBase::idxBetween(idx_type idx, idx_type from, idx_type to) const
161 return from <= idx && idx <= to;
165 bool InsetBase::idxUpDown(LCursor &, bool) const
171 bool InsetBase::idxUpDown2(LCursor &, bool) const
177 int InsetBase::plaintext(Buffer const &,
178 std::ostream &, OutputParams const &) const
184 int InsetBase::linuxdoc(Buffer const &,
185 std::ostream &, OutputParams const &) const
191 int InsetBase::docbook(Buffer const &,
192 std::ostream &, OutputParams const &) const
198 bool InsetBase::directWrite() const
204 InsetBase::EDITABLE InsetBase::editable() const
210 bool InsetBase::autoDelete() const
216 std::string const InsetBase::editMessage() const
218 return _("Opened inset");
222 std::string const & InsetBase::getInsetName() const
224 static std::string const name = "unknown";
229 void InsetBase::markErased()
233 void InsetBase::getCursorPos(LCursor const &, int & x, int & y) const
235 lyxerr << "InsetBase::getCursorPos called directly" << std::endl;
241 void InsetBase::metricsMarkers(Dimension & dim, int framesize) const
243 dim.wid += 2 * framesize;
244 dim.asc += framesize;
248 void InsetBase::metricsMarkers2(Dimension & dim, int framesize) const
250 dim.wid += 2 * framesize;
251 dim.asc += framesize;
252 dim.des += framesize;
256 void InsetBase::drawMarkers(PainterInfo & pi, int x, int y) const
258 if (!editing(pi.base.bv))
260 int const t = x + width() - 1;
261 int const d = y + descent();
262 pi.pain.line(x, d - 3, x, d, LColor::mathframe);
263 pi.pain.line(t, d - 3, t, d, LColor::mathframe);
264 pi.pain.line(x, d, x + 3, d, LColor::mathframe);
265 pi.pain.line(t - 3, d, t, d, LColor::mathframe);
266 setPosCache(pi, x, y);
270 void InsetBase::drawMarkers2(PainterInfo & pi, int x, int y) const
272 if (!editing(pi.base.bv))
274 drawMarkers(pi, x, y);
275 int const t = x + width() - 1;
276 int const a = y - ascent();
277 pi.pain.line(x, a + 3, x, a, LColor::mathframe);
278 pi.pain.line(t, a + 3, t, a, LColor::mathframe);
279 pi.pain.line(x, a, x + 3, a, LColor::mathframe);
280 pi.pain.line(t - 3, a, t, a, LColor::mathframe);
281 setPosCache(pi, x, y);
285 bool InsetBase::editing(BufferView * bv) const
287 return bv->cursor().isInside(this);
291 int InsetBase::xo() const
293 return theCoords.insets_.x(this);
297 int InsetBase::yo() const
299 return theCoords.insets_.y(this);
303 bool InsetBase::covers(int x, int y) const
305 //lyxerr << "InsetBase::covers, x: " << x << " y: " << y
306 // << " xo: " << xo() << " yo: " << yo()
307 // << " x1: " << xo() << " x2: " << xo() + width()
308 // << " y1: " << yo() - ascent() << " y2: " << yo() + descent()
310 return theCoords.insets_.has(this)
312 && x <= xo() + width()
313 && y >= yo() - ascent()
314 && y <= yo() + descent();
318 void InsetBase::dump() const
320 Buffer buf("foo", 1);
325 /////////////////////////////////////////
327 bool isEditableInset(InsetBase const * inset)
329 return inset && inset->editable();
333 bool isHighlyEditableInset(InsetBase const * inset)
335 return inset && inset->editable() == InsetBase::HIGHLY_EDITABLE;