#include "Lexer.h"
#include "MetricsInfo.h"
#include "OutputParams.h"
+#include "TextClass.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
InsetCollapsable::InsetCollapsable(Buffer * buf, InsetText::UsePlain ltype)
: InsetText(buf, ltype), status_(Open), openinlined_(false)
{
- setAutoBreakRows(true);
setDrawFrame(true);
setFrameColor(Color_collapsableframe);
}
docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
{
- Dimension dim = dimensionCollapsed(bv);
+ Dimension const dim = dimensionCollapsed(bv);
if (geometry(bv) == NoButton)
return translateIfPossible(getLayout().labelstring());
if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des || isOpen(bv))
Dimension InsetCollapsable::dimensionCollapsed(BufferView const & bv) const
{
Dimension dim;
- theFontMetrics(getLayout().labelfont()).buttonText(
+ FontInfo labelfont(getLabelfont());
+ labelfont.realize(sane_font);
+ theFontMetrics(labelfont).buttonText(
buttonLabel(bv), dim.wid, dim.asc, dim.des);
return dim;
}
auto_open_[mi.base.bv] = mi.base.bv->cursor().isInside(this);
FontInfo tmpfont = mi.base.font;
- mi.base.font = getLayout().font();
+ mi.base.font = getFont();
mi.base.font.realize(tmpfont);
BufferView const & bv = *mi.base.bv;
case SubLabel: {
InsetText::metrics(mi, dim);
// consider width of the inset label
- FontInfo font(getLayout().labelfont());
+ FontInfo font(getLabelfont());
font.realize(sane_font);
font.decSize();
font.decSize();
bool InsetCollapsable::setMouseHover(BufferView const * bv, bool mouse_hover)
+ const
{
mouse_hover_[bv] = mouse_hover;
return true;
auto_open_[&bv] = bv.cursor().isInside(this);
FontInfo tmpfont = pi.base.font;
- pi.base.font = getLayout().font();
+ pi.base.font = getFont();
pi.base.font.realize(tmpfont);
// Draw button first -- top, left or only
button_dim.y1 = y - dimc.asc;
button_dim.y2 = y + dimc.des;
- FontInfo labelfont = getLayout().labelfont();
+ FontInfo labelfont = getLabelfont();
labelfont.setColor(labelColor());
pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
mouse_hover_[&bv]);
// the label below the text. Can be toggled.
if (geometry(bv) == SubLabel) {
- FontInfo font(getLayout().labelfont());
+ FontInfo font(getLabelfont());
font.realize(sane_font);
font.decSize();
font.decSize();
}
+bool InsetCollapsable::clickable(int x, int y) const
+{
+ FuncRequest cmd(LFUN_NOACTION, x, y, mouse_button::none);
+ return hitButton(cmd);
+}
+
+
docstring const InsetCollapsable::getNewLabel(docstring const & l) const
{
docstring label;
else if (cmd.argument() == "close")
setStatus(cur, Collapsed);
else if (cmd.argument() == "toggle" || cmd.argument().empty())
- if (status_ == Open) {
+ if (status_ == Open)
setStatus(cur, Collapsed);
- if (geometry(cur.bv()) == ButtonOnly)
- cur.top().forwardPos();
- } else
+ else
setStatus(cur, Open);
else // if assign or anything else
cur.undispatched();
docstring const InsetCollapsable::buttonLabel(BufferView const & bv) const
{
- docstring const label = labelstring_.empty() ?
- translateIfPossible(getLayout().labelstring()) : labelstring_;
InsetLayout const & il = getLayout();
+ docstring const label = labelstring_.empty() ?
+ translateIfPossible(il.labelstring()) : labelstring_;
if (!il.contentaslabel() || geometry(bv) != ButtonOnly)
return label;
return getNewLabel(label);
}
-docstring InsetCollapsable::contextMenu(BufferView const & bv, int x,
+string InsetCollapsable::contextMenu(BufferView const & bv, int x,
int y) const
{
+ string context_menu = contextMenuName();
+ string const it_context_menu = InsetText::contextMenuName();
if (decoration() == InsetLayout::CONGLOMERATE)
- return from_ascii("context-conglomerate");
+ return context_menu + ";" + it_context_menu;
+
+ string const ic_context_menu = InsetCollapsable::contextMenuName();
+ if (ic_context_menu != context_menu)
+ context_menu += ";" + ic_context_menu;
if (geometry(bv) == NoButton)
- return from_ascii("context-collapsable");
+ return context_menu + ";" + it_context_menu;
Dimension dim = dimensionCollapsed(bv);
if (x < xo(bv) + dim.wid && y < yo(bv) + dim.des)
- return from_ascii("context-collapsable");
+ return context_menu;
+
+ return it_context_menu;
+}
- return InsetText::contextMenu(bv, x, y);
+
+string InsetCollapsable::contextMenuName() const
+{
+ if (decoration() == InsetLayout::CONGLOMERATE)
+ return "context-conglomerate";
+ else
+ return "context-collapsable";
}
} // namespace lyx