using std::ostream;
-InsetCollapsable::InsetCollapsable(BufferParams const & bp,
- CollapseStatus status)
- : inset(bp), label("Label"), status_(status)
+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),
- labelfont_(in.labelfont_), label(in.label), status_(in.status_)
+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();
}
break;
}
os << "\n";
- inset.text_.write(buf, os);
+ 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)
status_ = isOpen() ? Open : Collapsed;
}
-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
{
+ 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;
}
void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
{
- setPosCache(pi, x, 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);
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);
}
}
-}
-
-
-void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const
-{
- inset.drawSelection(pi, x, y);
+ setPosCache(pi, x, y);
}
}
-void InsetCollapsable::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
-{
- if (cmd.button() == mouse_button::button3) {
- showInsetDialog(&cur.bv());
- return;
- }
-
- switch (status_) {
-
- case Collapsed:
- lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
- setStatus(Open);
- edit(cur, true);
- break;
-
- case Open: {
- FuncRequest cmd1 = cmd;
- if (hitButton(cmd1)) {
- lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
- setStatus(Collapsed);
- cur.dispatched(FINISHED_RIGHT);
- break;
- }
- lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
- inset.dispatch(cur, cmd);
- break;
- }
-
- case Inlined:
- inset.dispatch(cur, cmd);
- break;
- }
-}
-
-
-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 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;
- label += inset.paragraphs().begin()->getChar(j);
+ label += paragraphs().begin()->getChar(j);
++i;
}
- if (inset.paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
+ if (paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
label += "...";
}
return label.empty() ? l : label;
void InsetCollapsable::edit(LCursor & cur, bool left)
{
//lyxerr << "InsetCollapsable: edit left/right" << endl;
- cur.push(this);
- inset.edit(cur, left);
+ cur.push(*this);
+ InsetText::edit(cur, left);
open();
}
-InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y)
+InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y) const
{
- cur.push(this);
+ cur.push(const_cast<InsetCollapsable&>(*this));
//lyxerr << "InsetCollapsable: edit xy" << endl;
if (status_ == Collapsed) {
- setStatus(Open);
- inset.edit(cur, true);
-#warning look here
-//we are not calling edit(x,y) because there are no coordinates in the
-//inset yet. I personally think it's ok. (ab)
- return this;
+ return const_cast<InsetCollapsable*>(this);
}
- return inset.editXY(cur, x, y);
+ return InsetText::editXY(cur, x, y);
}
-void InsetCollapsable::priv_dispatch(LCursor & cur, 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(cur, cmd);
- else if (status_ == Open && cmd.y > button_dim.y2)
- inset.dispatch(cur, cmd);
- break;
+ 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;
+
+ 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_MOTION:
- if (status_ == Inlined)
- inset.dispatch(cur, cmd);
- else if (status_ == Open && cmd.y > button_dim.y2)
- inset.dispatch(cur, cmd);
+ case LFUN_MOUSE_RELEASE:
+ if (cmd.button() == mouse_button::button3) {
+ showInsetDialog(&cur.bv());
break;
+ }
- case LFUN_MOUSE_RELEASE:
- lfunMouseRelease(cur, cmd);
+ switch (status_) {
+
+ case Collapsed:
+ lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
+ setStatus(Open);
+ edit(cur, true);
+ cur.bv().cursor() = cur;
break;
- case LFUN_INSET_TOGGLE:
- if (inset.text_.toggleInset(cur))
- break;
- if (status_ == Open) {
- setStatus(Inlined);
- break;
+ 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);
}
- setStatus(Collapsed);
- cur.dispatched(FINISHED_RIGHT);
break;
+ }
- default:
- inset.dispatch(cur, cmd);
+ case Inlined:
+ lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
+ InsetText::priv_dispatch(cur, cmd);
break;
- }
-}
-
-
-void InsetCollapsable::validate(LaTeXFeatures & features) const
-{
- inset.validate(features);
-}
-
-
-void InsetCollapsable::getCursorPos(CursorSlice const & cur,
- int & x, int & y) const
-{
- inset.getCursorPos(cur, x, y);
-}
+ }
+ break;
+ 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;
-void InsetCollapsable::getLabelList(Buffer const & buffer,
- std::vector<string> & list) const
-{
- inset.getLabelList(buffer, list);
+ default:
+ InsetText::priv_dispatch(cur, cmd);
+ break;
+ }
}
int sx = UpdatableInset::scroll(false);
if (recursive)
- sx += inset.scroll(false);
+ sx += InsetText::scroll(false);
return sx;
}
-size_t InsetCollapsable::nargs() const
-{
- return inset.nargs();
-}
-
-
-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);
-}