#include "metricsinfo.h"
#include "paragraph.h"
-#include "frontends/Application.h"
-#include "frontends/FontLoader.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
-using lyx::docstring;
-using lyx::graphics::PreviewLoader;
+
+namespace lyx {
+
+using graphics::PreviewLoader;
using std::endl;
using std::string;
InsetCollapsable::InsetCollapsable
(BufferParams const & bp, CollapseStatus status)
- : InsetText(bp), label(lyx::from_ascii("Label")), status_(status),
+ : InsetText(bp), label(from_ascii("Label")), status_(status),
openinlined_(false), autoOpen_(false)
{
setAutoBreakRows(true);
setDrawFrame(true);
setFrameColor(LColor::collapsableframe);
- setInsetName("Collapsable");
+ setInsetName(from_ascii("Collapsable"));
setButtonLabel();
}
Dimension InsetCollapsable::dimensionCollapsed() const
{
Dimension dim;
- docstring dlab(label.begin(), label.end());
- theApp->fontLoader().metrics(labelfont_).buttonText(
- dlab, dim.wid, dim.asc, dim.des);
+ theFontMetrics(labelfont_).buttonText(
+ label, dim.wid, dim.asc, dim.des);
return dim;
}
button_dim.y1 = top;
button_dim.y2 = top + dimc.height();
- docstring dlab(label.begin(), label.end());
- pi.pain.buttonText(xx, top + dimc.asc, dlab, labelfont_);
+ pi.pain.buttonText(xx, top + dimc.asc, label, labelfont_);
if (status() == Open) {
int textx, texty;
}
-void InsetCollapsable::cursorPos
- (CursorSlice const & sl, bool boundary, int & x, int & y) const
+void InsetCollapsable::cursorPos(BufferView const & bv,
+ CursorSlice const & sl, bool boundary, int & x, int & y) const
{
BOOST_ASSERT(status() != Collapsed);
- InsetText::cursorPos(sl, boundary, x, y);
+ InsetText::cursorPos(bv, sl, boundary, x, y);
if (status() == Open) {
if (openinlined_)
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
+ if (cmd.button() == mouse_button::button1 && hitButton(cmd)) {
+ cur.dispatched();
+ cur.noUpdate();
+ break;
+ }
if (status() == Inlined)
InsetText::doDispatch(cur, cmd);
else if (status() == Open && !hitButton(cmd))
case LFUN_MOUSE_RELEASE:
if (cmd.button() == mouse_button::button3) {
+ // Open the Inset configuration dialog
showInsetDialog(&cur.bv());
break;
}
- switch (status()) {
-
- case Collapsed:
- //lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
- setStatus(cur, Open);
- edit(cur, true);
- cur.bv().cursor() = cur;
+ if (status() == Inlined) {
+ // The mouse click has to be within the inset!
+ InsetText::doDispatch(cur, cmd);
break;
+ }
- case Open: {
- if (hitButton(cmd)) {
- //lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
+ if (cmd.button() == mouse_button::button1 && hitButton(cmd)) {
+ // Left button is clicked, the user asks to toggle the inset
+ // visual state.
+ cur.dispatched();
+ cur.updateFlags(Update::Force | Update::FitCursor);
+ if (status() == Collapsed) {
+ setStatus(cur, Open);
+ edit(cur, true);
+ }
+ else {
setStatus(cur, Collapsed);
- cur.bv().cursor() = cur;
- } else {
- //lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
- InsetText::doDispatch(cur, cmd);
}
+ cur.bv().cursor() = cur;
break;
}
- case Inlined:
- //lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
- InsetText::doDispatch(cur, cmd);
- break;
- }
+ // The mouse click is within the opened inset.
+ InsetText::doDispatch(cur, cmd);
break;
case LFUN_INSET_TOGGLE:
FloatList const & floats = bp.getLyXTextClass().floats();
FloatList::const_iterator it = floats[type];
// FIXME UNICODE
- return (it == floats.end()) ? lyx::from_ascii(type) : _(it->second.name());
+ return (it == floats.end()) ? from_ascii(type) : _(it->second.name());
}
+
+
+} // namespace lyx