return new InsetCitation(icp);
} else if (name == "ert") {
- InsetERT::ERTStatus s;
- InsetERTMailer::string2params(cmd.argument, s);
- return new InsetERT(params, s);
+ InsetCollapsable::CollapseStatus st;
+ InsetERTMailer::string2params(cmd.argument, st);
+ return new InsetERT(params, st);
} else if (name == "external") {
Buffer const & buffer = *cmd.view()->buffer();
///
ControlERT(Dialog &);
///
- InsetERT::ERTStatus status() const { return status_; }
+ InsetCollapsable::CollapseStatus status() const { return status_; }
///
- void setStatus(InsetERT::ERTStatus status) { status_ = status; }
+ void setStatus(InsetCollapsable::CollapseStatus status) { status_ = status; }
///
virtual bool initialiseParams(std::string const & data);
/// clean-up on hide.
virtual bool isBufferDependent() const { return true; }
private:
///
- InsetERT::ERTStatus status_;
+ InsetCollapsable::CollapseStatus status_;
};
#endif
+2003-12-01 André Pönitz <poenitz@gmx.net>
+
+ * insetcollapsable.[Ch]:
+ * insetert.[Ch]: move 'inline' state to InsetCollapsable
+
2003-12-01 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* insetvspace.C (read): handle 'end_inset' token.
/// open the inset
virtual void open() {}
/// close the inset
- virtual void close() const {}
+ virtual void close() {}
// should this inset be handled like a normal charater
virtual bool isChar() const { return false; }
// is this equivalent to a letter?
InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed)
- : UpdatableInset(), inset(bp), collapsed_(collapsed), label("Label")
+ : UpdatableInset(), inset(bp), status_(collapsed ? Collapsed : Open),
+ label("Label")
#if 0
,autocollapse(false)
#endif
InsetCollapsable::InsetCollapsable(InsetCollapsable const & in)
- : UpdatableInset(in), inset(in.inset), collapsed_(in.collapsed_),
+ : UpdatableInset(in), inset(in.inset), status_(in.status_),
labelfont_(in.labelfont_), label(in.label)
#if 0
,autocollapse(in.autocollapse)
void InsetCollapsable::write(Buffer const & buf, ostream & os) const
{
- os << "collapsed " << (collapsed_ ? "true" : "false") << "\n";
+ os << "collapsed " << (status_ == Collapsed ? "true" : "false") << "\n";
inset.writeParagraphData(buf, os);
}
string const token = lex.getString();
if (token == "collapsed") {
lex.next();
- collapsed_ = lex.getBool();
+ status_ = lex.getBool() ? Collapsed : Open;
} else {
lyxerr << "InsetCollapsable::Read: Missing collapsed!"
<< endl;
void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
{
//lyxerr << "InsetCollapsable::metrics: width: " << mi.base.textwidth << endl;
- dimension_collapsed(dim);
- if (!collapsed_) {
- Dimension insetdim;
- inset.metrics(mi, insetdim);
- dim.des += insetdim.height() + TEXT_TO_BOTTOM_OFFSET;
- dim.wid = max(dim.wid, insetdim.wid);
+ if (status_ == Inlined) {
+ inset.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);
+ }
}
dim_ = dim;
//lyxerr << "InsetCollapsable::metrics: dim.wid: " << dim.wid << endl;
}
-void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const
+void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
{
- Dimension dim_collapsed;
- dimension_collapsed(dim_collapsed);
-
- int const aa = ascent();
- button_dim.x1 = 0;
- button_dim.x2 = dim_collapsed.width();
- button_dim.y1 = -aa;
- button_dim.y2 = -aa + dim_collapsed.height();
-
xo_ = x;
yo_ = y;
- if (collapsed_) {
- draw_collapsed(pi, x, y);
- return;
- }
-
- int old_x = x;
-
- if (!owner())
- x += scroll();
-
- if (inlined) {
+ if (status_ == Inlined) {
inset.draw(pi, x, y);
} else {
- int const bl = y - aa + dim_collapsed.ascent();
- draw_collapsed(pi, old_x, bl);
- inset.draw(pi, x, bl + dim_collapsed.descent() + inset.ascent());
+ 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();
+
+ draw_collapsed(pi, x, y);
+ if (status_ == Open) {
+ if (!owner())
+ x += scroll();
+ inset.draw(pi, x, y - aa + dimc.height() + inset.ascent());
+ }
}
}
-void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
+InsetOld::EDITABLE InsetCollapsable::editable() const
{
- // by default we don't draw inline
- draw(pi, x, y, false);
+ return status_ != Collapsed ? HIGHLY_EDITABLE : IS_EDITABLE;
}
-InsetOld::EDITABLE InsetCollapsable::editable() const
+bool InsetCollapsable::descendable() const
{
- return collapsed_ ? IS_EDITABLE : HIGHLY_EDITABLE;
+ return status_ != Collapsed;
}
return DispatchResult(true, true);
}
- if (collapsed_) {
+ if (status_ == Collapsed) {
lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
- collapsed_ = false;
+ setStatus(Open);
edit(bv, true);
return DispatchResult(true, true);
}
if (hitButton(cmd)) {
- if (!collapsed_) {
- collapsed_ = true;
+ if (status_ == Open) {
+ setStatus(Collapsed);
lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
return DispatchResult(false, FINISHED_RIGHT);
}
- collapsed_ = false;
+ setStatus(Open);
lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
- } else if (!collapsed_ && cmd.y > button_dim.y2) {
+ } else if (status_ == Open && cmd.y > button_dim.y2) {
lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
return inset.dispatch(adjustCommand(cmd));
}
{
lyxerr << "InsetCollapsable: edit left/right" << endl;
inset.edit(bv, left);
- open();
+ setStatus(Open);
bv->cursor().push(this);
}
void InsetCollapsable::edit(BufferView * bv, int x, int y)
{
lyxerr << "InsetCollapsable: edit xy" << endl;
- if (collapsed_) {
- collapsed_ = false;
+ if (status_ == Collapsed) {
+ setStatus(Open);
} else {
if (y <= button_dim.y2)
y = 0;
DispatchResult
InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
{
- lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd
- << " button y: " << button_dim.y2 << endl;
+ //lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd
+ // << " button y: " << button_dim.y2 << endl;
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
- if (!collapsed_ && cmd.y > button_dim.y2)
+ if (!status_ && cmd.y > button_dim.y2)
inset.dispatch(adjustCommand(cmd));
return DispatchResult(true, true);
case LFUN_MOUSE_MOTION:
- if (!collapsed_)
+ if (!status_)
inset.dispatch(adjustCommand(cmd));
return DispatchResult(true, true);
case LFUN_MOUSE_RELEASE:
- if (!collapsed_ && cmd.y > button_dim.y2)
+ if (!status_ && cmd.y > button_dim.y2)
inset.dispatch(adjustCommand(cmd));
else
return lfunMouseRelease(cmd);
return DispatchResult(true, true);
case LFUN_INSET_TOGGLE:
- if (!inset.text_.toggleInset())
- close();
- return DispatchResult(true, true);
+ if (inset.text_.toggleInset())
+ return DispatchResult(true, true);
+ close();
+ return DispatchResult(false, FINISHED_RIGHT);
default:
return inset.dispatch(adjustCommand(cmd));
}
- lyxerr << "InsetCollapsable::priv_dispatch (end)" << endl;
+ //lyxerr << "InsetCollapsable::priv_dispatch (end)" << endl;
}
void InsetCollapsable::getCursorPos(int & x, int & y) const
{
inset.getCursorPos(x, y);
- y += - ascent() + height_collapsed() + inset.ascent();
+ if (status_ != Inlined)
+ y += - ascent() + height_collapsed() + inset.ascent();
}
void InsetCollapsable::open()
{
- collapsed_ = false;
+ setStatus(Open);
}
-void InsetCollapsable::close() const
+void InsetCollapsable::close()
{
- collapsed_ = true;
+ setStatus(Collapsed);
}
}
-void InsetCollapsable::setCollapsed(bool c) const
+void InsetCollapsable::setStatus(CollapseStatus s)
{
- collapsed_ = c;
+ status_ = s;
}
}
-bool InsetCollapsable::isOpen() const
-{
- return !collapsed_;
-}
-
-
Box const & InsetCollapsable::buttonDim() const
{
return button_dim;
static int const TEXT_TO_TOP_OFFSET = 2;
///
static int const TEXT_TO_BOTTOM_OFFSET = 2;
+ ///
+ enum CollapseStatus {
+ Open,
+ Collapsed,
+ Inlined
+ };
/// inset is initially collapsed if bool = true
InsetCollapsable(BufferParams const &, bool collapsed = false);
///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
- /// draw, either inlined (no button) or collapsed/open
- void draw(PainterInfo & pi, int x, int y, bool inlined) const;
///
bool hitButton(FuncRequest const &) const;
///
///
EDITABLE editable() const;
/// can we go further down on mouse click?
- bool descendable() const { return isOpen(); }
+ bool descendable() const;
///
bool insertInset(BufferView *, InsetOld * inset);
///
///
LyXText * getText(int) const;
///
- bool display() const { return isOpen(); }
+ bool isOpen() const { return status_ == Open || status_ == Inlined; }
+ ///
+ bool inlined() const { return status_ == Inlined; }
///
- bool isOpen() const;
+ CollapseStatus status() const { return status_; }
///
void open();
///
- void close() const;
+ void close();
///
void markErased();
///
void addPreview(lyx::graphics::PreviewLoader &) const;
///
void setBackgroundColor(LColor_color);
+ ///
+ virtual void setStatus(CollapseStatus st);
protected:
///
void draw_collapsed(PainterInfo & pi, int x, int y) const;
///
int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
- /// Should be non-const...
- void setCollapsed(bool) const;
///
Box const & buttonDim() const;
///
public:
///
mutable InsetText inset;
-private:
+protected:
///
- mutable bool collapsed_;
+ mutable CollapseStatus status_;
///
LyXFont labelfont_;
///
InsetERT::InsetERT(InsetERT const & in)
- : InsetCollapsable(in), status_(in.status_)
+ : InsetCollapsable(in)
{
init();
}
string const tmp_token = lex.getString();
if (tmp_token == "Inlined") {
- status(Inlined);
+ status_ = Inlined;
} else if (tmp_token == "Collapsed") {
- status(Collapsed);
+ status_ = Collapsed;
} else {
// leave this as default!
- status(Open);
+ status_ = Open;
}
token_found = true;
if (!token_found) {
if (isOpen())
- status(Open);
+ status_ = Open;
else
- status(Collapsed);
+ status_ = Collapsed;
}
setButtonLabel();
}
{
if (status_ != Inlined) {
if (isOpen())
- status(swap ? Collapsed : Open);
+ status_ = swap ? Collapsed : Open;
else
- status(swap ? Open : Collapsed);
+ status_ = swap ? Open : Collapsed;
}
}
-InsetOld::EDITABLE InsetERT::editable() const
-{
- return (status_ == Collapsed) ? IS_EDITABLE : HIGHLY_EDITABLE;
-}
-
-
void InsetERT::lfunMousePress(FuncRequest const & cmd)
{
if (status_ == Inlined)
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
- InsetERT::ERTStatus status_;
InsetERTMailer::string2params(cmd.argument, status_);
- status(status_);
bv->update();
return DispatchResult(true, true);
}
}
+bool InsetERT::insetAllowed(InsetOld::Code code) const
+{
+ return code == InsetOld::NEWLINE_CODE;
+}
+
+
void InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const
{
- setButtonLabel();
- if (inlined())
- inset.metrics(mi, dim);
- else
- InsetCollapsable::metrics(mi, dim);
- // Make it stand out on its own as it is code, not part of running
- // text:
- if (isOpen() && !inlined())
- dim.wid = mi.base.textwidth;
+ InsetCollapsable::metrics(mi, dim);
dim_ = dim;
}
void InsetERT::draw(PainterInfo & pi, int x, int y) const
{
- InsetCollapsable::draw(pi, x, y, inlined());
+ InsetCollapsable::draw(pi, x, y);
}
}
-void InsetERT::status(ERTStatus const st) const
+void InsetERT::setStatus(CollapseStatus st)
{
- if (st == status_)
- return;
-
status_ = st;
-
- switch (st) {
- case Inlined:
- break;
- case Open:
- setCollapsed(false);
- setButtonLabel();
- break;
- case Collapsed:
- setCollapsed(true);
- setButtonLabel();
- break;
- }
+ setButtonLabel();
}
}
-void InsetERT::open()
-{
- if (!isOpen())
- status(Open);
-}
-
-
-void InsetERT::close() const
-{
- if (status_ == Collapsed || status_ == Inlined)
- return;
-
- status(Collapsed);
-}
-
-
void InsetERT::getDrawFont(LyXFont & font) const
{
font = LyXFont(LyXFont::ALL_INHERIT, latex_language);
void InsetERTMailer::string2params(string const & in,
- InsetERT::ERTStatus & status)
+ InsetCollapsable::InsetCollapsable::CollapseStatus & status)
{
- status = InsetERT::Collapsed;
+ status = InsetCollapsable::Collapsed;
string name;
string body = split(in, name, ' ');
if (body.empty())
return;
- status = static_cast<InsetERT::ERTStatus>(strToInt(body));
+ status = static_cast<InsetCollapsable::CollapseStatus>(strToInt(body));
}
-string const InsetERTMailer::params2string(InsetERT::ERTStatus status)
+string const
+InsetERTMailer::params2string(InsetCollapsable::CollapseStatus status)
{
return name_ + ' ' + tostr(status);
}
class InsetERT : public InsetCollapsable {
public:
- ///
- enum ERTStatus {
- Open,
- Collapsed,
- Inlined
- };
///
InsetERT(BufferParams const &, bool collapsed = false);
///
///
bool insertInset(BufferView *, InsetOld *);
///
- bool insetAllowed(InsetOld::Code code) const {
- return code == InsetOld::NEWLINE_CODE;
- }
- ///
- EDITABLE editable() const;
+ bool insetAllowed(InsetOld::Code code) const;
///
int latex(Buffer const &, std::ostream &,
OutputParams const &) const;
///
void validate(LaTeXFeatures &) const {}
///
- // these are needed here because of the label/inlined functionallity
- ///
- bool isOpen() const { return status_ == Open || status_ == Inlined; }
- ///
- bool inlined() const { return status_ == Inlined; }
- ///
- ERTStatus status() const { return status_; }
- ///
- void open();
- ///
- void close() const;
- ///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
- /// set the status of the inset
- void status(ERTStatus const st) const;
///
bool showInsetDialog(BufferView *) const;
///
void getDrawFont(LyXFont &) const;
///
bool forceDefaultParagraphs(InsetOld const *) const { return true; }
+ ///
+ void setStatus(CollapseStatus st);
protected:
///
virtual
void edit(BufferView * bv, bool left);
///
bool allowSpellCheck() const { return false; }
-
- ///
- mutable ERTStatus status_;
};
///
virtual std::string const inset2string(Buffer const &) const;
///
- static void string2params(std::string const &, InsetERT::ERTStatus &);
+ static void string2params(std::string const &,
+ InsetCollapsable::CollapseStatus &);
///
- static std::string const params2string(InsetERT::ERTStatus);
+ static std::string const params2string(InsetCollapsable::CollapseStatus);
private:
///
static std::string const name_;
break;
case MARGIN_RIGHT_ADDRESS_BOX: {
+#if 0
// ok, a terrible hack. The left margin depends on the widest
// row in this paragraph.
RowList::iterator rit = pit->rows.begin();
x += font_metrics::signedWidth(layout->leftmargin,
tclass.defaultfont());
x += minfill;
+#endif
+ // also wrong, but much shorter.
+ x += textwidth_ / 2;
break;
}
}
// final dimension
dim.asc = firstRow()->ascent_of_text();
dim.des = height - dim.asc;
- dim.wid = std::max(mi.base.textwidth, int(width));
+ dim.wid = width;
}