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 "BufferView.h"
20 #include "dimension.h"
21 #include "dispatchresult.h"
24 #include "metricsinfo.h"
26 #include "frontends/Painter.h"
34 InsetName(std::string const & n, InsetBase::Code c)
41 typedef std::map<std::string, InsetBase::Code> TranslatorMap;
44 TranslatorMap const build_translator()
46 InsetName const insetnames[] = {
47 InsetName("toc", InsetBase::TOC_CODE),
48 InsetName("quote", InsetBase::QUOTE_CODE),
49 InsetName("ref", InsetBase::REF_CODE),
50 InsetName("url", InsetBase::URL_CODE),
51 InsetName("htmlurl", InsetBase::HTMLURL_CODE),
52 InsetName("separator", InsetBase::SEPARATOR_CODE),
53 InsetName("ending", InsetBase::ENDING_CODE),
54 InsetName("label", InsetBase::LABEL_CODE),
55 InsetName("note", InsetBase::NOTE_CODE),
56 InsetName("accent", InsetBase::ACCENT_CODE),
57 InsetName("math", InsetBase::MATH_CODE),
58 InsetName("index", InsetBase::INDEX_CODE),
59 InsetName("include", InsetBase::INCLUDE_CODE),
60 InsetName("graphics", InsetBase::GRAPHICS_CODE),
61 InsetName("bibitem", InsetBase::BIBITEM_CODE),
62 InsetName("bibtex", InsetBase::BIBTEX_CODE),
63 InsetName("text", InsetBase::TEXT_CODE),
64 InsetName("ert", InsetBase::ERT_CODE),
65 InsetName("foot", InsetBase::FOOT_CODE),
66 InsetName("margin", InsetBase::MARGIN_CODE),
67 InsetName("float", InsetBase::FLOAT_CODE),
68 InsetName("wrap", InsetBase::WRAP_CODE),
69 InsetName("specialchar", InsetBase::SPECIALCHAR_CODE),
70 InsetName("tabular", InsetBase::TABULAR_CODE),
71 InsetName("external", InsetBase::EXTERNAL_CODE),
72 InsetName("caption", InsetBase::CAPTION_CODE),
73 InsetName("mathmacro", InsetBase::MATHMACRO_CODE),
74 InsetName("error", InsetBase::ERROR_CODE),
75 InsetName("cite", InsetBase::CITE_CODE),
76 InsetName("float_list", InsetBase::FLOAT_LIST_CODE),
77 InsetName("index_print", InsetBase::INDEX_PRINT_CODE),
78 InsetName("optarg", InsetBase::OPTARG_CODE),
79 InsetName("environment", InsetBase::ENVIRONMENT_CODE),
80 InsetName("hfill", InsetBase::HFILL_CODE),
81 InsetName("newline", InsetBase::NEWLINE_CODE),
82 InsetName("line", InsetBase::LINE_CODE),
83 InsetName("branch", InsetBase::BRANCH_CODE),
84 InsetName("box", InsetBase::BOX_CODE),
85 InsetName("charstyle", InsetBase::CHARSTYLE_CODE),
86 InsetName("vspace", InsetBase::VSPACE_CODE),
87 InsetName("mathmacroarg", InsetBase::MATHMACROARG_CODE),
90 std::size_t const insetnames_size =
91 sizeof(insetnames) / sizeof(insetnames[0]);
93 std::map<std::string, InsetBase::Code> data;
94 for (std::size_t i = 0; i != insetnames_size; ++i) {
95 InsetName const & var = insetnames[i];
96 data[var.name] = var.code;
105 InsetBase::Code InsetBase::translate(std::string const & name)
107 static TranslatorMap const translator = build_translator();
109 TranslatorMap::const_iterator it = translator.find(name);
110 return it == translator.end() ? NO_CODE : it->second;
114 void InsetBase::dispatch(LCursor & cur, FuncRequest & cmd)
118 priv_dispatch(cur, cmd);
122 void InsetBase::priv_dispatch(LCursor & cur, FuncRequest &)
129 bool InsetBase::getStatus(LCursor &, FuncRequest const &, FuncStatus &) const
135 void InsetBase::edit(LCursor &, bool)
137 lyxerr << "InsetBase: edit left/right" << std::endl;
141 InsetBase * InsetBase::editXY(LCursor &, int x, int y)
143 lyxerr << "InsetBase: editXY x:" << x << " y: " << y << std::endl;
148 InsetBase::idx_type InsetBase::index(row_type row, col_type col) const
151 lyxerr << "illegal row: " << row << std::endl;
153 lyxerr << "illegal col: " << col << std::endl;
158 bool InsetBase::idxBetween(idx_type idx, idx_type from, idx_type to) const
160 return from <= idx && idx <= to;
164 bool InsetBase::idxUpDown(LCursor &, bool) const
170 bool InsetBase::idxUpDown2(LCursor &, bool) const
176 int InsetBase::plaintext(Buffer const &,
177 std::ostream &, OutputParams const &) const
183 int InsetBase::linuxdoc(Buffer const &,
184 std::ostream &, OutputParams const &) const
190 int InsetBase::docbook(Buffer const &,
191 std::ostream &, OutputParams const &) const
197 bool InsetBase::directWrite() const
203 InsetBase::EDITABLE InsetBase::editable() const
209 bool InsetBase::autoDelete() const
215 std::string const InsetBase::editMessage() const
217 return _("Opened inset");
221 std::string const & InsetBase::getInsetName() const
223 static std::string const name = "unknown";
228 void InsetBase::markErased()
232 void InsetBase::getCursorPos(LCursor const &, int & x, int & y) const
234 lyxerr << "InsetBase::getCursorPos called directly" << std::endl;
240 void InsetBase::metricsMarkers(Dimension & dim, int framesize) const
242 dim.wid += 2 * framesize;
243 dim.asc += framesize;
247 void InsetBase::metricsMarkers2(Dimension & dim, int framesize) const
249 dim.wid += 2 * framesize;
250 dim.asc += framesize;
251 dim.des += framesize;
255 void InsetBase::drawMarkers(PainterInfo & pi, int x, int y) const
257 if (!editing(pi.base.bv))
259 int const t = x + width() - 1;
260 int const d = y + descent();
261 pi.pain.line(x, d - 3, x, d, LColor::mathframe);
262 pi.pain.line(t, d - 3, t, d, LColor::mathframe);
263 pi.pain.line(x, d, x + 3, d, LColor::mathframe);
264 pi.pain.line(t - 3, d, t, d, LColor::mathframe);
265 setPosCache(pi, x, y);
269 void InsetBase::drawMarkers2(PainterInfo & pi, int x, int y) const
271 if (!editing(pi.base.bv))
273 drawMarkers(pi, x, y);
274 int const t = x + width() - 1;
275 int const a = y - ascent();
276 pi.pain.line(x, a + 3, x, a, LColor::mathframe);
277 pi.pain.line(t, a + 3, t, a, LColor::mathframe);
278 pi.pain.line(x, a, x + 3, a, LColor::mathframe);
279 pi.pain.line(t - 3, a, t, a, LColor::mathframe);
280 setPosCache(pi, x, y);
284 bool InsetBase::editing(BufferView * bv) const
286 return bv->cursor().isInside(this);
290 bool InsetBase::covers(int x, int y) const
292 //lyxerr << "InsetBase::covers, x: " << x << " y: " << y
293 // << " xo: " << xo() << " yo: " << yo()
294 // << " x1: " << xo() << " x2: " << xo() + width()
295 // << " y1: " << yo() - ascent() << " y2: " << yo() + descent()
298 && x <= xo() + width()
299 && y >= yo() - ascent()
300 && y <= yo() + descent();
304 void InsetBase::dump() const
306 Buffer buf("foo", 1);
311 /////////////////////////////////////////
313 bool isEditableInset(InsetBase const * inset)
315 return inset && inset->editable();
319 bool isHighlyEditableInset(InsetBase const * inset)
321 return inset && inset->editable() == InsetBase::HIGHLY_EDITABLE;