return TopButton;
} else
return ButtonOnly;
- break;
+
case Minimalistic:
return NoButton;
- break;
+
case Conglomerate:
- return ( status_ == Open ? SubLabel : Corners );
- break;
+ return status_ == Open ? SubLabel : Corners;
}
+
+ // dummy return value to shut down a warning,
+ // this is dead code.
+ return NoButton;
}
InsetCollapsable::InsetCollapsable
(BufferParams const & bp, CollapseStatus status)
- : InsetText(bp), label(from_ascii("Label")), status_(status),
+ : InsetText(bp), status_(status),
openinlined_(false), autoOpen_(false), mouse_hover_(false)
{
setAutoBreakRows(true);
button_dim(rhs.button_dim),
topx(rhs.topx),
topbaseline(rhs.topbaseline),
- label(rhs.label),
layout_(rhs.layout_),
status_(rhs.status_),
openinlined_(rhs.openinlined_),
void InsetCollapsable::setLayout(BufferParams const & bp)
{
- setLabelFont(getLayout(bp).labelfont);
- setLabel(getLayout(bp).labelstring);
+ layout_ = getLayout(bp);
}
{
Dimension dim;
theFontMetrics(layout_.labelfont).buttonText(
- label, dim.wid, dim.asc, dim.des);
+ layout_.labelstring, dim.wid, dim.asc, dim.des);
return dim;
}
switch (decoration()) {
case Minimalistic:
+ InsetText::metrics(mi, dim);
+ break;
case Conglomerate:
InsetText::metrics(mi, dim);
+ if (status() == Open) {
+ // consider width of the inset label
+ Font font(layout_.labelfont);
+ font.realize(Font(Font::ALL_SANE));
+ font.decSize();
+ font.decSize();
+ int w = 0;
+ int a = 0;
+ int d = 0;
+ docstring s = layout_.labelstring;
+ theFontMetrics(font).rectText(s, w, a, d);
+ dim.wid = max(dim.wid, w);
+ }
+ if (status() == Open)
+ dim.des += ascent();
+ else {
+ dim.des -= 3;
+ dim.asc -= 3;
+ }
break;
case Classic:
dim = dimensionCollapsed();
{
const int xx = x + TEXT_TO_INSET_OFFSET;
- if (decoration() == Minimalistic) {
- InsetText::draw(pi, xx, y);
- } else {
- Dimension dimc = dimensionCollapsed();
- int const top = y - ascent() + TEXT_TO_INSET_OFFSET;
+ // Draw button first -- top, left or only
+ Dimension dimc = dimensionCollapsed();
+ int const top = y - ascent() + TEXT_TO_INSET_OFFSET;
+ if (decoration() == Classic) {
button_dim.x1 = xx + 0;
button_dim.x2 = xx + dimc.width();
button_dim.y1 = top;
button_dim.y2 = top + dimc.height();
- pi.pain.buttonText(xx, top + dimc.asc, label, layout_.labelfont, mouse_hover_);
+ pi.pain.buttonText(xx, top + dimc.asc, layout_.labelstring, layout_.labelfont, mouse_hover_);
+ }
- int textx, texty;
- switch (geometry()) {
- case LeftButton:
- textx = xx + dimc.width();
- texty = top + textdim_.asc;
- InsetText::draw(pi, textx, texty);
- break;
- case TopButton:
- textx = xx;
- texty = top + dimc.height() + textdim_.asc;
- InsetText::draw(pi, textx, texty);
- break;
- case ButtonOnly:
- break;
- case NoButton:
- textx = xx;
- texty = top + textdim_.asc;
- InsetText::draw(pi, textx, texty);
- break;
- case SubLabel:
- case Corners:
- // FIXME add handling of SubLabel, Corners
- // still in CharStyle
- break;
+ int textx, texty;
+ switch (geometry()) {
+ case LeftButton:
+ textx = xx + dimc.width();
+ texty = top + textdim_.asc;
+ InsetText::draw(pi, textx, texty);
+ break;
+ case TopButton:
+ textx = xx;
+ texty = top + dimc.height() + textdim_.asc;
+ InsetText::draw(pi, textx, texty);
+ break;
+ case ButtonOnly:
+ break;
+ case NoButton:
+ textx = xx;
+ texty = y + textdim_.asc;
+ InsetText::draw(pi, textx, texty);
+ break;
+ case SubLabel:
+ case Corners:
+ textx = xx;
+ texty = y + textdim_.asc;
+ const_cast<InsetCollapsable *>(this)->setDrawFrame(false);
+ InsetText::draw(pi, textx, texty);
+ const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
+
+ int desc = InsetText::descent();
+ if (status() == Open)
+ desc -= ascent();
+ else
+ desc -= 3;
+
+ pi.pain.line(x, y + desc - 4, x, y + desc,
+ layout_.labelfont.color());
+ if (internalStatus() == Open)
+ pi.pain.line(x, y + desc,
+ x + dim_.wid - 3, y + desc,
+ layout_.labelfont.color());
+ else {
+ // Make status_ value visible:
+ pi.pain.line(x, y + desc,
+ x + 4, y + desc,
+ layout_.labelfont.color());
+ pi.pain.line(x + dim_.wid - 7, y + desc,
+ x + dim_.wid -3, y + desc,
+ layout_.labelfont.color());
+ }
+ pi.pain.line(x + dim_.wid - 3, y + desc, x + dim_.wid - 3, y + desc - 4,
+ layout_.labelfont.color());
+
+ // the label of the charstyle. Can be toggled.
+ if (status() == Open) {
+ Font font(layout_.labelfont);
+ font.realize(Font(Font::ALL_SANE));
+ font.decSize();
+ font.decSize();
+ int w = 0;
+ int a = 0;
+ int d = 0;
+ // FIXME UNICODE
+ docstring s = layout_.labelstring;
+ theFontMetrics(font).rectText(s, w, a, d);
+ pi.pain.rectText(x + (dim_.wid - w) / 2, y + desc + a,
+ s, font, Color::none, Color::none);
+ }
+
+ // a visual cue when the cursor is inside the inset
+ Cursor & cur = pi.base.bv->cursor();
+ if (cur.isInside(this)) {
+ y -= ascent();
+ y += 3;
+ pi.pain.line(x, y + 4, x, y, layout_.labelfont.color());
+ pi.pain.line(x + 4, y, x, y, layout_.labelfont.color());
+ pi.pain.line(x + dim_.wid - 3, y + 4, x + dim_.wid - 3, y,
+ layout_.labelfont.color());
+ pi.pain.line(x + dim_.wid - 7, y, x + dim_.wid - 3, y,
+ layout_.labelfont.color());
}
+ break;
}
setPosCache(pi, x, y);
}
case LFUN_MOUSE_RELEASE:
if (cmd.button() == mouse_button::button3) {
- // Open the Inset configuration dialog
- showInsetDialog(&cur.bv());
- break;
+ if (decoration() == Conglomerate) {
+
+ if (internalStatus() == Open)
+ setStatus(cur, Collapsed);
+ else
+ setStatus(cur, Open);
+ break;
+ } else {
+ // Open the Inset
+ // configuration dialog
+ showInsetDialog(&cur.bv());
+ break;
+ }
}
if (decoration() == Minimalistic) {
else if (cmd.argument() == "close")
setStatus(cur, Collapsed);
else if (cmd.argument() == "toggle" || cmd.argument().empty())
- if (isOpen()) {
+ if (internalStatus() == Open) {
setStatus(cur, Collapsed);
- cur.top().forwardPos();
- }
- else
+ if (geometry() == ButtonOnly)
+ cur.top().forwardPos();
+ } else
setStatus(cur, Open);
else // if assign or anything else
cur.undispatched();
void InsetCollapsable::setLabel(docstring const & l)
{
- label = l;
+ layout_.labelstring = l;
}
// Because the collapse status is part of the inset and thus an
// integral part of the Buffer contents a changed status must be
// signaled to all views of current buffer.
- cur.bv().buffer()->changed();
+ cur.bv().buffer().changed();
}
}
+
+int InsetCollapsable::latex(Buffer const & buf, odocstream & os,
+ OutputParams const & runparams) const
+{
+ // This implements the standard way of handling the LaTeX output of
+ // a collapsable inset, either a command or an environment. Standard
+ // collapsable insets should not redefine this, non-standard ones may
+ // call this.
+ if (!layout_.latexname.empty()) {
+ if (layout_.latextype == "command") {
+ // FIXME UNICODE
+ os << '\\' << from_utf8(layout_.latexname);
+ if (!layout_.latexparam.empty())
+ os << from_utf8(layout_.latexparam);
+ os << '{';
+ } else if (layout_.latextype == "environment") {
+ os << "%\n\\begin{" << from_utf8(layout_.latexname) << "}\n";
+ if (!layout_.latexparam.empty())
+ os << from_utf8(layout_.latexparam);
+ }
+ }
+ int i = InsetText::latex(buf, os, runparams);
+ if (!layout_.latexname.empty())
+ if (layout_.latextype == "command") {
+ os << "}";
+ } else if (layout_.latextype == "environment") {
+ os << "\n\\end{" << from_utf8(layout_.latexname) << "}\n";
+ i += 4;
+ }
+ return i;
+}
+
+
} // namespace lyx