using std::ostream;
-InsetCollapsable::InsetCollapsable(BufferParams const & bp, CollapseStatus status)
- : UpdatableInset(), inset(bp), status_(status),
- label("Label")
+void leaveInset(LCursor & cur, InsetBase const & in)
{
- inset.setOwner(this);
- inset.setAutoBreakRows(true);
- inset.setDrawFrame(InsetText::ALWAYS);
- inset.setFrameColor(LColor::collapsableframe);
- setInsetName("Collapsable");
-
- setButtonLabel();
+ for (unsigned int i = 0; i != cur.size(); ++i) {
+ if (&cur[i].inset() == &in) {
+ cur.resize(i);
+ return;
+ }
+ }
}
-InsetCollapsable::InsetCollapsable(InsetCollapsable const & in)
- : UpdatableInset(in), inset(in.inset), status_(in.status_),
- labelfont_(in.labelfont_), label(in.label)
+InsetCollapsable::InsetCollapsable(BufferParams const & bp,
+ CollapseStatus status)
+ : InsetText(bp), label("Label"), status_(status), openinlined_(false)
{
- inset.setOwner(this);
+ setAutoBreakRows(true);
+ setDrawFrame(true);
+ setFrameColor(LColor::collapsableframe);
+ setInsetName("Collapsable");
setButtonLabel();
}
void InsetCollapsable::write(Buffer const & buf, ostream & os) const
{
- string st;
-
+ os << "status ";
switch (status_) {
case Open:
- st = "open";
+ os << "open";
break;
case Collapsed:
- st = "collapsed";
+ os << "collapsed";
break;
case Inlined:
- st = "inlined";
+ os << "inlined";
break;
}
- os << "status " << st << "\n";
- inset.text_.write(buf, os);
+ os << "\n";
+ text_.write(buf, os);
}
lex.pushToken(token);
}
} else {
- lyxerr << "InsetCollapsable::Read: Missing 'status'-tag!"
+ lyxerr << "InsetCollapsable::read: Missing 'status'-tag!"
<< endl;
// take countermeasures
lex.pushToken(token);
}
}
- inset.read(buf, lex);
+ InsetText::read(buf, lex);
- if (!token_found) {
- if (isOpen())
- status_ = Open;
- else
- status_ = Collapsed;
- }
+ if (!token_found)
+ status_ = isOpen() ? Open : Collapsed;
setButtonLabel();
}
}
-int InsetCollapsable::height_collapsed() const
-{
- Dimension dim;
- font_metrics::buttonText(label, labelfont_, dim.wid, dim.asc, dim.des);
- return dim.asc + dim.des;
-}
-
-
void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
{
- //lyxerr << "InsetCollapsable::metrics: width: " << mi.base.textwidth << endl;
+ mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
if (status_ == Inlined) {
- inset.metrics(mi, dim);
+ InsetText::metrics(mi, dim);
} else {
dimension_collapsed(dim);
if (status_ == Open) {
- Dimension insetdim;
- inset.metrics(mi, insetdim);
- dim.des += insetdim.height() + TEXT_TO_BOTTOM_OFFSET;
- dim.wid = max(dim.wid, insetdim.wid);
+ InsetText::metrics(mi, textdim_);
+ openinlined_ = (textdim_.wid + dim.wid <= mi.base.textwidth);
+ if (openinlined_) {
+ dim.wid += textdim_.wid;
+ dim.des = max(dim.des, textdim_.des);
+ dim.asc = max(dim.asc, textdim_.asc);
+ } else {
+ dim.des += textdim_.height() + TEXT_TO_BOTTOM_OFFSET;
+ dim.wid = max(dim.wid, textdim_.wid);
+ }
}
}
+ dim.asc += TEXT_TO_INSET_OFFSET;
+ dim.des += TEXT_TO_INSET_OFFSET;
+ dim.wid += 2 * TEXT_TO_INSET_OFFSET;
+ mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
dim_ = dim;
- //lyxerr << "InsetCollapsable::metrics: dim.wid: " << dim.wid << endl;
}
void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
{
- xo_ = x;
- yo_ = y;
+ x += TEXT_TO_INSET_OFFSET;
+ y += TEXT_TO_INSET_OFFSET;
if (status_ == Inlined) {
- inset.draw(pi, x, y);
+ InsetText::draw(pi, x, y);
} else {
Dimension dimc;
dimension_collapsed(dimc);
-
int const aa = ascent();
- button_dim.x1 = 0;
- button_dim.x2 = dimc.width();
- button_dim.y1 = -aa;
- button_dim.y2 = -aa + dimc.height();
+ button_dim.x1 = x + 0;
+ button_dim.x2 = x + dimc.width();
+ button_dim.y1 = y - aa + pi.base.bv->top_y();
+ button_dim.y2 = y - aa + pi.base.bv->top_y() + dimc.height();
- draw_collapsed(pi, x, y);
+ draw_collapsed(pi, x, y - aa + dimc.asc);
if (status_ == Open) {
- if (!owner())
- x += scroll();
- inset.draw(pi, x, y - aa + dimc.height() + inset.ascent());
+ if (openinlined_)
+ InsetText::draw(pi, x + dimc.width(),
+ y - aa + textdim_.asc);
+ else
+ InsetText::draw(pi, x, dimc.height()
+ + y - aa + textdim_.asc);
}
}
+ setPosCache(pi, x, y);
}
}
-FuncRequest InsetCollapsable::adjustCommand(FuncRequest const & cmd)
-{
- FuncRequest cmd1 = cmd;
- cmd1.y += ascent() - height_collapsed();
- return cmd1;
-}
-
-
-DispatchResult
-InsetCollapsable::lfunMouseRelease(BufferView & bv, FuncRequest const & cmd)
-{
- if (cmd.button() == mouse_button::button3) {
- lyxerr << "InsetCollapsable::lfunMouseRelease 0" << endl;
- showInsetDialog(&bv);
- return DispatchResult(true, true);
- }
-
- switch (status_) {
- case Collapsed:
- lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
- setStatus(Open);
- edit(&bv, true);
- return DispatchResult(true, true);
-
- case Open:
- if (hitButton(cmd)) {
- lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
- setStatus(Collapsed);
- return DispatchResult(false, FINISHED_RIGHT);
- }
- lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
- return inset.dispatch(bv, adjustCommand(cmd));
-
- case Inlined:
- return inset.dispatch(bv, cmd);
- }
-
- return DispatchResult(true, true);
-}
-
-
-int InsetCollapsable::latex(Buffer const & buf, ostream & os,
- OutputParams const & runparams) const
-{
- return inset.latex(buf, os, runparams);
-}
-
-
-int InsetCollapsable::plaintext(Buffer const & buf, ostream & os,
- OutputParams const & runparams) const
-{
- return inset.plaintext(buf, os, runparams);
-}
-
-
-int InsetCollapsable::linuxdoc(Buffer const & buf, ostream & os,
- OutputParams const & runparams) const
-{
- return inset.linuxdoc(buf, os, runparams);
-}
-
-
-int InsetCollapsable::docbook(Buffer const & buf, ostream & os,
- OutputParams const & runparams) const
-{
- return inset.docbook(buf, os, runparams);
-}
-
-
-bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
+bool InsetCollapsable::hitButton(FuncRequest & cmd) const
{
return button_dim.contains(cmd.x, cmd.y);
}
string const InsetCollapsable::getNewLabel(string const & l) const
{
- string la;
+ string label;
pos_type const max_length = 15;
- pos_type const p_siz = inset.paragraphs().begin()->size();
+ pos_type const p_siz = paragraphs().begin()->size();
pos_type const n = min(max_length, p_siz);
pos_type i = 0;
pos_type j = 0;
for( ; i < n && j < p_siz; ++j) {
- if (inset.paragraphs().begin()->isInset(j))
+ if (paragraphs().begin()->isInset(j))
continue;
- la += inset.paragraphs().begin()->getChar(j);
+ label += paragraphs().begin()->getChar(j);
++i;
}
- if (inset.paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
- la += "...";
+ if (paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
+ label += "...";
}
- return la.empty() ? l : la;
+ return label.empty() ? l : label;
}
-void InsetCollapsable::edit(BufferView * bv, bool left)
+void InsetCollapsable::edit(LCursor & cur, bool left)
{
- lyxerr << "InsetCollapsable: edit left/right" << endl;
- inset.edit(bv, left);
+ //lyxerr << "InsetCollapsable: edit left/right" << endl;
+ cur.push(*this);
+ InsetText::edit(cur, left);
open();
- bv->fullCursor().push(this);
}
-void InsetCollapsable::edit(BufferView * bv, int x, int y)
+InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y) const
{
- lyxerr << "InsetCollapsable: edit xy" << endl;
+ cur.push(const_cast<InsetCollapsable&>(*this));
+ //lyxerr << "InsetCollapsable: edit xy" << endl;
if (status_ == Collapsed) {
- setStatus(Open);
- } else {
- if (y <= button_dim.y2)
- y = 0;
- else
- y += inset.ascent() - height_collapsed();
+ return const_cast<InsetCollapsable*>(this);
}
- inset.edit(bv, x, y);
- bv->fullCursor().push(this);
+ return InsetText::editXY(cur, x, y);
}
-DispatchResult
-InsetCollapsable::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd)
{
- //lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd
- // << " button y: " << button_dim.y2 << endl;
+// lyxerr << "InsetCollapsable::priv_dispatch (begin): cmd: " << cmd
+// << " button y: " << button_dim.y2
+// << " coll/inline/open: " << status_ << endl;
+
+ lyxerr << "InsetCollapsable::priv_dispatch (begin): cmd: " << cmd
+ << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
+
switch (cmd.action) {
- case LFUN_MOUSE_PRESS:
- if (status_ == Inlined)
- inset.dispatch(bv, cmd);
- else if (status_ == Open && cmd.y > button_dim.y2)
- inset.dispatch(bv, adjustCommand(cmd));
- return DispatchResult(true, true);
-
- case LFUN_MOUSE_MOTION:
- if (status_ == Inlined)
- inset.dispatch(bv, cmd);
- else if (status_ == Open && cmd.y > button_dim.y2)
- inset.dispatch(bv, adjustCommand(cmd));
- return DispatchResult(true, true);
-
- case LFUN_MOUSE_RELEASE:
- return lfunMouseRelease(bv, cmd);
-
- case LFUN_INSET_TOGGLE:
- if (inset.text_.toggleInset())
- return DispatchResult(true, true);
- if (status_ == Open) {
- setStatus(Inlined);
- return DispatchResult(true, true);
- } else {
- setStatus(Collapsed);
- return DispatchResult(false, FINISHED_RIGHT);
- }
+ case LFUN_MOUSE_PRESS:
+ if (status_ == Inlined)
+ InsetText::priv_dispatch(cur, cmd);
+ else if (status_ == Open && !hitButton(cmd))
+ InsetText::priv_dispatch(cur, cmd);
+ else
+ cur.noUpdate();
+ break;
- default:
- return inset.dispatch(bv, adjustCommand(cmd));
- }
- //lyxerr << "InsetCollapsable::priv_dispatch (end)" << endl;
-}
+ case LFUN_MOUSE_MOTION:
+ if (status_ == Inlined)
+ InsetText::priv_dispatch(cur, cmd);
+ else if (status_ == Open && !hitButton(cmd))
+ InsetText::priv_dispatch(cur, cmd);
+ break;
+ case LFUN_MOUSE_RELEASE:
+ if (cmd.button() == mouse_button::button3) {
+ showInsetDialog(&cur.bv());
+ break;
+ }
-void InsetCollapsable::validate(LaTeXFeatures & features) const
-{
- inset.validate(features);
-}
+ switch (status_) {
+ case Collapsed:
+ lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
+ setStatus(Open);
+ edit(cur, true);
+ cur.bv().cursor() = cur;
+ break;
-void InsetCollapsable::getCursorPos(int cell, int & x, int & y) const
-{
- inset.getCursorPos(cell, x, y);
- if (status_ != Inlined)
- y += - ascent() + height_collapsed() + inset.ascent();
-}
+ case Open: {
+ if (hitButton(cmd)) {
+ lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
+ setStatus(Collapsed);
+ leaveInset(cur, *this);
+ cur.bv().cursor() = cur;
+ } else {
+ lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
+ InsetText::priv_dispatch(cur, cmd);
+ }
+ break;
+ }
+ case Inlined:
+ lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
+ InsetText::priv_dispatch(cur, cmd);
+ break;
+ }
+ break;
-void InsetCollapsable::getLabelList(Buffer const & buffer,
- std::vector<string> & list) const
-{
- inset.getLabelList(buffer, list);
+ case LFUN_INSET_TOGGLE:
+ if (cmd.argument == "open")
+ setStatus(Open);
+ else if (cmd.argument == "close") {
+ setStatus(Collapsed);
+ leaveInset(cur, *this);
+ } else if (cmd.argument == "toggle"
+ || cmd.argument.empty()) {
+ if (isOpen()) {
+ setStatus(Collapsed);
+ leaveInset(cur, *this);
+ } else
+ setStatus(Open);
+ } else // if assign or anything else
+ cur.undispatched();
+ cur.dispatched();
+ break;
+
+ default:
+ InsetText::priv_dispatch(cur, cmd);
+ break;
+ }
}
int sx = UpdatableInset::scroll(false);
if (recursive)
- sx += inset.scroll(false);
+ sx += InsetText::scroll(false);
return sx;
}
-int InsetCollapsable::numParagraphs() const
-{
- return inset.numParagraphs();
-}
-
-
-LyXText * InsetCollapsable::getText(int i) const
-{
- return inset.getText(i);
-}
-
-
void InsetCollapsable::open()
{
if (status_ == Collapsed) // ...but not inlined
}
-void InsetCollapsable::markErased()
-{
- inset.markErased();
-}
-
-
-void InsetCollapsable::addPreview(PreviewLoader & loader) const
-{
- inset.addPreview(loader);
-}
-
-
-bool InsetCollapsable::insetAllowed(InsetOld::Code code) const
-{
- return inset.insetAllowed(code);
-}
-
-
void InsetCollapsable::setLabelFont(LyXFont & font)
{
labelfont_ = font;
{
return button_dim;
}
-
-
-void InsetCollapsable::setBackgroundColor(LColor_color color)
-{
- InsetOld::setBackgroundColor(color);
- inset.setBackgroundColor(color);
-}