#include "InsetCollapsable.h"
#include "Buffer.h"
-#include "BufferParams.h"
#include "BufferView.h"
#include "Cursor.h"
#include "Dimension.h"
-#include "FloatList.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "InsetLayout.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();
case TopButton:
case LeftButton:
case ButtonOnly:
+ if (hasFixedWidth()){
+ int const mindim = button_dim.x2 - button_dim.x1;
+ if (mi.base.textwidth < mindim)
+ mi.base.textwidth = mindim;
+ }
dim = dimensionCollapsed(bv);
if (geometry(bv) == TopButton
|| geometry(bv) == LeftButton) {
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]);
const int xx2 = x + textdim.wid - TEXT_TO_INSET_OFFSET + 1;
pi.pain.line(xx1, y + desc - 4,
xx1, y + desc,
- labelColor());
+ Color_foreground);
if (status_ == Open)
pi.pain.line(xx1, y + desc,
xx2, y + desc,
- labelColor());
+ Color_foreground);
else {
// Make status_ value visible:
pi.pain.line(xx1, y + desc,
xx1 + 4, y + desc,
- labelColor());
+ Color_foreground);
pi.pain.line(xx2 - 4, y + desc,
xx2, y + desc,
- labelColor());
+ Color_foreground);
}
pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3,
- y + desc - 4, labelColor());
+ y + desc - 4, Color_foreground);
// 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();
int const ww = max(textdim.wid, w);
pi.pain.rectText(x + (ww - w) / 2, y + desc + a,
buttonLabel(bv), font, Color_none, Color_none);
- desc += d;
}
// a visual cue when the cursor is inside the inset
if (cur.isInside(this)) {
y -= textdim.asc;
y += 3;
- pi.pain.line(xx1, y + 4, xx1, y, labelColor());
- pi.pain.line(xx1 + 4, y, xx1, y, labelColor());
- pi.pain.line(xx2, y + 4, xx2, y,
- labelColor());
- pi.pain.line(xx2 - 4, y, xx2, y,
- labelColor());
+ pi.pain.line(xx1, y + 4, xx1, y, Color_foreground);
+ pi.pain.line(xx1 + 4, y, xx1, y, Color_foreground);
+ pi.pain.line(xx2, y + 4, xx2, y, Color_foreground);
+ pi.pain.line(xx2 - 4, y, xx2, y, Color_foreground);
}
break;
}
}
+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::floatName(string const & type) const
-{
- BufferParams const & bp = buffer().params();
- FloatList const & floats = bp.documentClass().floats();
- FloatList::const_iterator it = floats[type];
- // FIXME UNICODE
- return (it == floats.end()) ? from_ascii(type) : bp.B_(it->second.name());
-}
-
-
InsetLayout::InsetDecoration InsetCollapsable::decoration() const
{
InsetLayout::InsetDecoration const dec = getLayout().decoration();
}
-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 InsetText::contextMenu(bv, x, y);
+ return it_context_menu;
+}
+
+
+string InsetCollapsable::contextMenuName() const
+{
+ if (decoration() == InsetLayout::CONGLOMERATE)
+ return "context-conglomerate";
+ else
+ return "context-collapsable";
}
} // namespace lyx