namespace lyx {
InsetCollapsable::InsetCollapsable(Buffer * buf, InsetText::UsePlain ltype)
- : InsetText(buf, ltype), status_(Open), openinlined_(false)
+ : InsetText(buf, ltype), status_(Open)
{
setDrawFrame(true);
setFrameColor(Color_collapsableframe);
: InsetText(rhs),
status_(rhs.status_),
labelstring_(rhs.labelstring_),
- button_dim(rhs.button_dim),
+ button_dim_(rhs.button_dim_),
openinlined_(rhs.openinlined_)
{}
switch (decoration()) {
case InsetLayout::CLASSIC:
if (status(bv) == Open)
- return openinlined_ ? LeftButton : TopButton;
+ return openinlined_[&bv] ? LeftButton : TopButton;
return ButtonOnly;
case InsetLayout::MINIMALISTIC:
}
-InsetCollapsable::Geometry InsetCollapsable::geometry() const
-{
- switch (decoration()) {
- case InsetLayout::CLASSIC:
- if (status_ == Open)
- return openinlined_ ? LeftButton : TopButton;
- return ButtonOnly;
-
- case InsetLayout::MINIMALISTIC:
- return status_ == Open ? NoButton : ButtonOnly ;
-
- case InsetLayout::CONGLOMERATE:
- return status_ == Open ? SubLabel : Corners ;
-
- case InsetLayout::DEFAULT:
- break; // this shouldn't happen
- }
-
- // dummy return value to shut down a warning,
- // this is dead code.
- return NoButton;
-}
-
-
docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
{
Dimension const dim = dimensionCollapsed(bv);
case LeftButton:
case ButtonOnly:
if (hasFixedWidth()){
- int const mindim = button_dim.x2 - button_dim.x1;
+ int const mindim = button_dim_[&bv].x2 - button_dim_[&bv].x1;
if (mi.base.textwidth < mindim)
mi.base.textwidth = mindim;
}
dim = dimensionCollapsed(bv);
- if (geometry(bv) == TopButton
- || geometry(bv) == LeftButton) {
+ if (geometry(bv) == TopButton || geometry(bv) == LeftButton) {
Dimension textdim;
InsetText::metrics(mi, textdim);
- openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth;
- if (openinlined_) {
+ openinlined_[&bv] = (textdim.wid + dim.wid) < mi.base.textwidth;
+ if (openinlined_[&bv]) {
// Correct for button width.
dim.wid += textdim.wid;
dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des);
if (geometry(bv) == TopButton ||
geometry(bv) == LeftButton ||
geometry(bv) == ButtonOnly) {
- button_dim.x1 = x + 0;
- button_dim.x2 = x + dimc.width();
- button_dim.y1 = y - dimc.asc;
- button_dim.y2 = y + dimc.des;
+ button_dim_[&bv].x1 = x + 0;
+ button_dim_[&bv].x2 = x + dimc.width();
+ button_dim_[&bv].y1 = y - dimc.asc;
+ button_dim_[&bv].y2 = y + dimc.des;
FontInfo labelfont = getLabelfont();
labelfont.setColor(labelColor());
pi.pain.buttonText(x, y, buttonLabel(bv), labelfont,
mouse_hover_[&bv]);
} else {
- button_dim.x1 = 0;
- button_dim.y1 = 0;
- button_dim.x2 = 0;
- button_dim.y2 = 0;
+ button_dim_[&bv].x1 = 0;
+ button_dim_[&bv].y1 = 0;
+ button_dim_[&bv].x2 = 0;
+ button_dim_[&bv].y2 = 0;
}
Dimension const textdim = InsetText::dimension(bv);
bool InsetCollapsable::editable() const
{
- return geometry() != ButtonOnly;
+ switch (decoration()) {
+ case InsetLayout::CLASSIC:
+ case InsetLayout::MINIMALISTIC:
+ return status_ == Open;
+ default:
+ return true;
+ }
}
}
-bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
+bool InsetCollapsable::clickable(BufferView const & bv, int x, int y) const
{
- return button_dim.contains(cmd.x(), cmd.y());
-}
-
-
-bool InsetCollapsable::clickable(BufferView const &, int x, int y) const
-{
- FuncRequest cmd(LFUN_NOACTION, x, y, mouse_button::none);
- return hitButton(cmd);
+ return button_dim_[&bv].contains(x, y);
}
{
//lyxerr << "InsetCollapsable: edit xy" << endl;
if (geometry(cur.bv()) == ButtonOnly
- || (button_dim.contains(x, y)
- && geometry(cur.bv()) != NoButton))
+ || (button_dim_[&cur.bv()].contains(x, y)
+ && geometry(cur.bv()) != NoButton))
return this;
cur.push(*this);
return InsetText::editXY(cur, x, y);
//lyxerr << "InsetCollapsable::doDispatch (begin): cmd: " << cmd
// << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
+ bool const hitButton = clickable(cur.bv(), cmd.x(), cmd.y());
+
switch (cmd.action()) {
case LFUN_MOUSE_PRESS:
- if (hitButton(cmd)) {
+ if (hitButton) {
switch (cmd.button()) {
case mouse_button::button1:
case mouse_button::button3:
case LFUN_MOUSE_MOTION:
case LFUN_MOUSE_DOUBLE:
case LFUN_MOUSE_TRIPLE:
- if (hitButton(cmd))
+ if (hitButton)
cur.noScreenUpdate();
else if (geometry(cur.bv()) != ButtonOnly)
InsetText::doDispatch(cur, cmd);
break;
case LFUN_MOUSE_RELEASE:
- if (!hitButton(cmd)) {
+ if (!hitButton) {
// The mouse click has to be within the inset!
if (geometry(cur.bv()) != ButtonOnly)
InsetText::doDispatch(cur, cmd);
/// return x,y of given position relative to the inset's baseline
void cursorPos(BufferView const & bv, CursorSlice const & sl,
bool boundary, int & x, int & y) const;
- /// Returns true if (mouse) action is over the inset's button.
- /// Always returns false when the inset does not have a
- /// button.
- bool hitButton(FuncRequest const &) const;
///
docstring const getNewLabel(docstring const & l) const;
///
bool editable() const;
///
bool hasSettings() const { return true; }
- ///
- bool clickable(BufferView const &, int x, int y) const;
+ /// Returns true if coordinates are over the inset's button.
+ /// Always returns false when the inset does not have a
+ /// button.
+ bool clickable(BufferView const & bv, int x, int y) const;
/// can we go further down on mouse click?
bool descendable(BufferView const & bv) const;
///
/// (status_), auto_open_[BufferView] and openinlined_,
/// and of course decoration().
Geometry geometry(BufferView const & bv) const;
- /// Returns the geometry disregarding auto_open_
- Geometry geometry() const;
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
///
Dimension dimensionCollapsed(BufferView const & bv) const;
///
docstring labelstring_;
+
+ /// FIXME: the variables below should be grouped in a View subclass (as in MVC)
+
///
- mutable Box button_dim;
+ mutable std::map<BufferView const *, Box> button_dim_;
/// a substatus of the Open status, determined automatically in metrics
- mutable bool openinlined_;
+ mutable std::map<BufferView const *, bool> openinlined_;
/// the inset will automatically open when the cursor is inside. This is
/// dependent on the bufferview, compare with MathMacro::editing_.
mutable std::map<BufferView const *, bool> auto_open_;