#include "Lexer.h"
#include "MetricsInfo.h"
#include "OutputParams.h"
+#include "TextClass.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
namespace lyx {
InsetCollapsable::InsetCollapsable(Buffer * buf, InsetText::UsePlain ltype)
- : InsetText(buf, ltype), status_(Open),
- openinlined_(false), mouse_hover_(false)
+ : InsetText(buf, ltype), status_(Open), openinlined_(false)
{
setAutoBreakRows(true);
setDrawFrame(true);
}
+// The sole purpose of this copy constructor is to make sure
+// that the mouse_hover_ map is not copied and remains empty.
InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
: InsetText(rhs),
status_(rhs.status_),
labelstring_(rhs.labelstring_),
button_dim(rhs.button_dim),
- openinlined_(rhs.openinlined_),
- auto_open_(rhs.auto_open_),
- // the sole purpose of this copy constructor
- mouse_hover_(false)
+ openinlined_(rhs.openinlined_)
+{}
+
+
+InsetCollapsable::~InsetCollapsable()
{
+ map<BufferView const *, bool>::iterator it = mouse_hover_.begin();
+ map<BufferView const *, bool>::iterator end = mouse_hover_.end();
+ for (; it != end; ++it)
+ if (it->second)
+ it->first->clearLastInset(this);
}
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))
return docstring();
- OutputParams rp(&buffer().params().encoding());
- odocstringstream ods;
- InsetText::plaintext(ods, rp);
- docstring const content_tip = ods.str();
- return support::wrapParas(content_tip, 4);
+ return toolTipText();
}
void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
{
- auto_open_[mi.base.bv] = mi.base.bv->cursor().isInside(this);
+ auto_open_[mi.base.bv] = mi.base.bv->cursor().isInside(this);
FontInfo tmpfont = mi.base.font;
mi.base.font = getLayout().font();
}
-bool InsetCollapsable::setMouseHover(bool mouse_hover)
+bool InsetCollapsable::setMouseHover(BufferView const * bv, bool mouse_hover)
+ const
{
- mouse_hover_ = mouse_hover;
+ mouse_hover_[bv] = mouse_hover;
return true;
}
{
BufferView const & bv = *pi.base.bv;
- auto_open_[&bv] = bv.cursor().isInside(this);
+ auto_open_[&bv] = bv.cursor().isInside(this);
FontInfo tmpfont = pi.base.font;
pi.base.font = getLayout().font();
FontInfo labelfont = getLayout().labelfont();
labelfont.setColor(labelColor());
pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
- mouse_hover_);
+ mouse_hover_[&bv]);
} else {
button_dim.x1 = 0;
button_dim.y1 = 0;
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) {
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::hitButton(FuncRequest const & cmd) const
{
- return button_dim.contains(cmd.x_, cmd.y_);
+ return button_dim.contains(cmd.x(), cmd.y());
+}
+
+
+bool InsetCollapsable::clickable(int x, int y) const
+{
+ FuncRequest cmd(LFUN_NOACTION, x, y, mouse_button::none);
+ return hitButton(cmd);
}
//lyxerr << "InsetCollapsable::doDispatch (begin): cmd: " << cmd
// << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
- switch (cmd.action_) {
+ switch (cmd.action()) {
case LFUN_MOUSE_PRESS:
if (hitButton(cmd)) {
switch (cmd.button()) {
case mouse_button::button4:
case mouse_button::button5:
// Nothing to do.
- cur.noUpdate();
+ cur.noScreenUpdate();
break;
}
} else if (geometry(cur.bv()) != ButtonOnly)
case LFUN_MOUSE_DOUBLE:
case LFUN_MOUSE_TRIPLE:
if (hitButton(cmd))
- cur.noUpdate();
+ cur.noScreenUpdate();
else if (geometry(cur.bv()) != ButtonOnly)
InsetText::doDispatch(cur, cmd);
else
}
if (cmd.button() != mouse_button::button1) {
// Nothing to do.
- cur.noUpdate();
+ cur.noScreenUpdate();
break;
}
// if we are selecting, we do not want to
// Left button is clicked, the user asks to
// toggle the inset visual state.
cur.dispatched();
- cur.updateFlags(Update::Force | Update::FitCursor);
+ cur.screenUpdateFlags(Update::Force | Update::FitCursor);
if (geometry(cur.bv()) == ButtonOnly) {
setStatus(cur, Open);
edit(cur, true);
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();
bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const
{
- switch (cmd.action_) {
+ switch (cmd.action()) {
case LFUN_INSET_TOGGLE:
if (cmd.argument() == "open")
flag.setEnabled(status_ != Open);
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);
{
status_ = status;
setButtonLabel();
- if (status_ == Collapsed) {
+ if (status_ == Collapsed)
cur.leaveInset(*this);
- mouse_hover_ = false;
- }
}
docstring InsetCollapsable::contextMenu(BufferView const & bv, int x,
int y) const
{
+ docstring context_menu = contextMenuName();
+ docstring const it_context_menu = InsetText::contextMenuName();
if (decoration() == InsetLayout::CONGLOMERATE)
- return from_ascii("context-conglomerate");
+ return context_menu + ";" + it_context_menu;
+
+ docstring 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);
+
+docstring InsetCollapsable::contextMenuName() const
+{
+ if (decoration() == InsetLayout::CONGLOMERATE)
+ return from_ascii("context-conglomerate");
+ else
+ return from_ascii("context-collapsable");
}
} // namespace lyx