move 'Inline' state from InsetERT to InsetCollapsable

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8177 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-12-02 07:15:42 +00:00
parent 4e56732c89
commit 35f1ab544b
9 changed files with 127 additions and 183 deletions

View File

@ -231,9 +231,9 @@ InsetOld * createInset(FuncRequest const & cmd)
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();

View File

@ -23,9 +23,9 @@ public:
///
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.
@ -36,7 +36,7 @@ public:
virtual bool isBufferDependent() const { return true; }
private:
///
InsetERT::ERTStatus status_;
InsetCollapsable::CollapseStatus status_;
};
#endif

View File

@ -1,3 +1,8 @@
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.

View File

@ -237,7 +237,7 @@ public:
/// 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?

View File

@ -40,7 +40,8 @@ using std::ostream;
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
@ -54,7 +55,7 @@ InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed)
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)
@ -77,7 +78,7 @@ bool InsetCollapsable::insertInset(BufferView * bv, InsetOld * in)
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);
}
@ -89,7 +90,7 @@ void InsetCollapsable::read(Buffer const & buf, LyXLex & lex)
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;
@ -118,12 +119,16 @@ int InsetCollapsable::height_collapsed() const
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;
@ -136,50 +141,42 @@ void InsetCollapsable::draw_collapsed(PainterInfo & pi, int x, int y) const
}
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
{
// by default we don't draw inline
draw(pi, x, y, false);
}
InsetOld::EDITABLE InsetCollapsable::editable() const
{
return collapsed_ ? IS_EDITABLE : HIGHLY_EDITABLE;
return status_ != Collapsed ? HIGHLY_EDITABLE : IS_EDITABLE;
}
bool InsetCollapsable::descendable() const
{
return status_ != Collapsed;
}
@ -202,22 +199,22 @@ DispatchResult InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd)
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));
}
@ -289,7 +286,7 @@ void InsetCollapsable::edit(BufferView * bv, bool left)
{
lyxerr << "InsetCollapsable: edit left/right" << endl;
inset.edit(bv, left);
open();
setStatus(Open);
bv->cursor().push(this);
}
@ -297,8 +294,8 @@ void InsetCollapsable::edit(BufferView * bv, bool left)
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;
@ -313,35 +310,36 @@ void InsetCollapsable::edit(BufferView * bv, int x, int y)
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;
}
@ -354,7 +352,8 @@ void InsetCollapsable::validate(LaTeXFeatures & features) const
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();
}
@ -396,13 +395,13 @@ LyXText * InsetCollapsable::getText(int i) const
void InsetCollapsable::open()
{
collapsed_ = false;
setStatus(Open);
}
void InsetCollapsable::close() const
void InsetCollapsable::close()
{
collapsed_ = true;
setStatus(Collapsed);
}
@ -412,9 +411,9 @@ void InsetCollapsable::setLabel(string const & l) const
}
void InsetCollapsable::setCollapsed(bool c) const
void InsetCollapsable::setStatus(CollapseStatus s)
{
collapsed_ = c;
status_ = s;
}
@ -462,12 +461,6 @@ void InsetCollapsable::scroll(BufferView * bv, int offset) const
}
bool InsetCollapsable::isOpen() const
{
return !collapsed_;
}
Box const & InsetCollapsable::buttonDim() const
{
return button_dim;

View File

@ -34,6 +34,12 @@ public:
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);
///
@ -46,8 +52,6 @@ public:
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;
///
@ -55,7 +59,7 @@ public:
///
EDITABLE editable() const;
/// can we go further down on mouse click?
bool descendable() const { return isOpen(); }
bool descendable() const;
///
bool insertInset(BufferView *, InsetOld * inset);
///
@ -101,19 +105,23 @@ public:
///
LyXText * getText(int) const;
///
bool display() const { return isOpen(); }
bool isOpen() const { return status_ == Open || status_ == Inlined; }
///
bool isOpen() const;
bool inlined() const { return status_ == Inlined; }
///
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:
///
@ -128,8 +136,6 @@ 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;
///
@ -146,9 +152,9 @@ private:
public:
///
mutable InsetText inset;
private:
protected:
///
mutable bool collapsed_;
mutable CollapseStatus status_;
///
LyXFont labelfont_;
///

View File

@ -66,7 +66,7 @@ InsetERT::InsetERT(BufferParams const & bp, bool collapsed)
InsetERT::InsetERT(InsetERT const & in)
: InsetCollapsable(in), status_(in.status_)
: InsetCollapsable(in)
{
init();
}
@ -119,12 +119,12 @@ void InsetERT::read(Buffer const & buf, LyXLex & lex)
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;
@ -154,9 +154,9 @@ void InsetERT::read(Buffer const & buf, LyXLex & lex)
if (!token_found) {
if (isOpen())
status(Open);
status_ = Open;
else
status(Collapsed);
status_ = Collapsed;
}
setButtonLabel();
}
@ -228,19 +228,13 @@ void InsetERT::updateStatus(bool swap) const
{
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)
@ -411,9 +405,7 @@ InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetERT::ERTStatus status_;
InsetERTMailer::string2params(cmd.argument, status_);
status(status_);
bv->update();
return DispatchResult(true, true);
}
@ -457,24 +449,22 @@ void InsetERT::setButtonLabel() const
}
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);
}
@ -489,25 +479,10 @@ void InsetERT::setLatexFont(BufferView * /*bv*/)
}
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();
}
@ -518,22 +493,6 @@ bool InsetERT::showInsetDialog(BufferView * bv) const
}
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);
@ -556,9 +515,9 @@ string const InsetERTMailer::inset2string(Buffer const &) const
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, ' ');
@ -566,11 +525,12 @@ void InsetERTMailer::string2params(string const & in,
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);
}

View File

@ -29,12 +29,6 @@ class Language;
class InsetERT : public InsetCollapsable {
public:
///
enum ERTStatus {
Open,
Collapsed,
Inlined
};
///
InsetERT(BufferParams const &, bool collapsed = false);
///
@ -57,11 +51,7 @@ public:
///
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;
@ -77,29 +67,17 @@ public:
///
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
@ -128,9 +106,6 @@ private:
void edit(BufferView * bv, bool left);
///
bool allowSpellCheck() const { return false; }
///
mutable ERTStatus status_;
};
@ -147,9 +122,10 @@ public:
///
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_;

View File

@ -282,6 +282,7 @@ int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const
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();
@ -294,6 +295,9 @@ int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const
x += font_metrics::signedWidth(layout->leftmargin,
tclass.defaultfont());
x += minfill;
#endif
// also wrong, but much shorter.
x += textwidth_ / 2;
break;
}
}
@ -1620,7 +1624,7 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
// 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;
}