+2003-12-12 Michael Schmitt <michael.schmitt@teststep.org>
+
+ * insetert.[Ch]:
+ * insetcollapsable.[Ch]: Move all CollapseStatus code from
+ insetert to insetcollapsable; introduce virtual function
+ setButtonLabel and invoke it from collapsable
+
2003-12-12 Angus Leeming <leeming@lyx.org>
* insetinclude.C (draw): cache x,y and so enable the
xo_ = x;
yo_ = y;
- status_ = Inlined;
+ // FIXME: setStatus(Inlined); this is not a const operation
inset.setDrawFrame(InsetText::NEVER);
inset.draw(pi, x, y);
using std::ostream;
-InsetCollapsable::InsetCollapsable(BufferParams const & bp, bool collapsed)
- : UpdatableInset(), inset(bp), status_(collapsed ? Collapsed : Open),
+InsetCollapsable::InsetCollapsable(BufferParams const & bp, CollapseStatus status)
+ : UpdatableInset(), inset(bp), status_(status),
label("Label")
-#if 0
- ,autocollapse(false)
-#endif
{
inset.setOwner(this);
inset.setAutoBreakRows(true);
inset.setDrawFrame(InsetText::ALWAYS);
inset.setFrameColor(LColor::collapsableframe);
setInsetName("Collapsable");
+
+ setButtonLabel();
}
InsetCollapsable::InsetCollapsable(InsetCollapsable const & in)
: UpdatableInset(in), inset(in.inset), status_(in.status_),
labelfont_(in.labelfont_), label(in.label)
-#if 0
- ,autocollapse(in.autocollapse)
-#endif
{
inset.setOwner(this);
+ setButtonLabel();
}
void InsetCollapsable::write(Buffer const & buf, ostream & os) const
{
- os << "collapsed " << (status_ == Collapsed ? "true" : "false") << "\n";
+ string st;
+
+ switch (status_) {
+ case Open:
+ st = "open";
+ break;
+ case Collapsed:
+ st = "collapsed";
+ break;
+ case Inlined:
+ st = "inlined";
+ break;
+ }
+ os << "status " << st << "\n";
inset.text_.write(buf, os);
}
void InsetCollapsable::read(Buffer const & buf, LyXLex & lex)
{
+ bool token_found = false;
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
- if (token == "collapsed") {
+ if (token == "status") {
lex.next();
- status_ = lex.getBool() ? Collapsed : Open;
+ string const tmp_token = lex.getString();
+
+ if (tmp_token == "inlined") {
+ status_ = Inlined;
+ token_found = true;
+ } else if (tmp_token == "collapsed") {
+ status_ = Collapsed;
+ token_found = true;
+ } else if (tmp_token == "open") {
+ status_ = Open;
+ token_found = true;
+ } else {
+ lyxerr << "InsetCollapsable::read: Missing status!"
+ << endl;
+ // Take countermeasures
+ lex.pushToken(token);
+ }
} else {
- lyxerr << "InsetCollapsable::Read: Missing collapsed!"
- << endl;
- // Take countermeasures
+ lyxerr << "InsetCollapsable::Read: Missing 'status'-tag!"
+ << endl;
+ // take countermeasures
lex.pushToken(token);
}
}
inset.read(buf, lex);
+
+ if (!token_found) {
+ if (isOpen())
+ status_ = Open;
+ else
+ status_ = Collapsed;
+ }
+
+ setButtonLabel();
}
if (cmd.button() == mouse_button::button3) {
lyxerr << "InsetCollapsable::lfunMouseRelease 0" << endl;
- if (hitButton(cmd))
- showInsetDialog(bv);
+ showInsetDialog(bv);
return DispatchResult(true, true);
}
- if (status_ == Collapsed) {
+ switch (status_) {
+ case Collapsed:
lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
setStatus(Open);
edit(bv, true);
return DispatchResult(true, true);
- }
- if (hitButton(cmd)) {
- if (status_ == Open) {
- setStatus(Collapsed);
+ case Open:
+ if (hitButton(cmd)) {
lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
+ setStatus(Collapsed);
return DispatchResult(false, FINISHED_RIGHT);
- }
- setStatus(Open);
- lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
- } else if (status_ == Open && cmd.y > button_dim.y2) {
- lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
- return inset.dispatch(adjustCommand(cmd));
+ } else {
+ lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
+ return inset.dispatch(adjustCommand(cmd));
+ }
+
+ case Inlined:
+ return inset.dispatch(cmd);
}
- lyxerr << "InsetCollapsable::lfunMouseRelease 5" << endl;
return DispatchResult(true, true);
}
if (inset.paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
la += "...";
}
- if (la.empty()) {
- la = l;
- }
- return la;
+ return la.empty() ? l : la;
}
{
lyxerr << "InsetCollapsable: edit left/right" << endl;
inset.edit(bv, left);
- setStatus(Open);
+ open();
bv->cursor().push(this);
}
// << " button y: " << button_dim.y2 << endl;
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
- if (!status_ && cmd.y > button_dim.y2)
+ if (status_ == Inlined)
+ inset.dispatch(cmd);
+ else if (status_ == Open && cmd.y > button_dim.y2)
inset.dispatch(adjustCommand(cmd));
return DispatchResult(true, true);
case LFUN_MOUSE_MOTION:
- if (!status_)
+ if (status_ == Inlined)
+ inset.dispatch(cmd);
+ else if (status_ == Open && cmd.y > button_dim.y2)
inset.dispatch(adjustCommand(cmd));
return DispatchResult(true, true);
case LFUN_MOUSE_RELEASE:
- if (!status_ && cmd.y > button_dim.y2)
- inset.dispatch(adjustCommand(cmd));
- else
- return lfunMouseRelease(cmd);
- return DispatchResult(true, true);
+ return lfunMouseRelease(cmd);
case LFUN_INSET_TOGGLE:
if (inset.text_.toggleInset())
return DispatchResult(true, true);
- close();
+ if (status_ == Open)
+ setStatus(Inlined);
+ return DispatchResult(true, true);
+ setStatus(Collapsed);
return DispatchResult(false, FINISHED_RIGHT);
default:
void InsetCollapsable::open()
{
- setStatus(Open);
+ if (status_ == Collapsed) // ...but not inlined
+ setStatus(Open);
}
}
-void InsetCollapsable::setLabel(string const & l) const
+void InsetCollapsable::setLabel(string const & l)
{
label = l;
}
-void InsetCollapsable::setStatus(CollapseStatus s)
+void InsetCollapsable::setStatus(CollapseStatus st)
{
- status_ = s;
+ status_ = st;
+ setButtonLabel();
}
}
-void InsetCollapsable::setLabelFont(LyXFont & f)
-{
- labelfont_ = f;
-}
-
-
-#if 0
-void InsetCollapsable::setAutoCollapse(bool f)
+void InsetCollapsable::setLabelFont(LyXFont & font)
{
- autocollapse = f;
+ labelfont_ = font;
}
-#endif
void InsetCollapsable::scroll(BufferView * bv, float sx) const
Collapsed,
Inlined
};
- /// inset is initially collapsed if bool = true
- InsetCollapsable(BufferParams const &, bool collapsed = false);
+ ///
+ InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
///
InsetCollapsable(InsetCollapsable const & in);
///
/// get the screen x,y of the cursor
void getCursorPos(int & x, int & y) const;
///
- void setLabel(std::string const & l) const;
+ void setLabel(std::string const & l);
///
+ virtual void setButtonLabel() {};
+ ///
void setLabelFont(LyXFont & f);
-#if 0
- ///
- void setAutoCollapse(bool f);
-#endif
/// Appends \c list with all labels found within this inset.
void getLabelList(Buffer const &, std::vector<std::string> & list) const;
///
///
void setBackgroundColor(LColor_color);
///
- virtual void setStatus(CollapseStatus st);
+ void setStatus(CollapseStatus st);
protected:
///
public:
///
mutable InsetText inset;
-protected:
+private:
///
mutable CollapseStatus status_;
+protected:
///
LyXFont labelfont_;
///
mutable int topbaseline;
///
mutable std::string label;
-#if 0
- ///
- bool autocollapse;
-#endif
};
#endif
}
-InsetERT::InsetERT(BufferParams const & bp, bool collapsed)
- : InsetCollapsable(bp, collapsed)
+InsetERT::InsetERT(BufferParams const & bp, CollapseStatus status)
+ : InsetCollapsable(bp, status)
{
- status_ = collapsed ? Collapsed : Open;
init();
}
InsetERT::InsetERT(BufferParams const & bp,
- Language const * l, string const & contents, bool collapsed)
- : InsetCollapsable(bp, collapsed)
+ Language const * l, string const & contents, CollapseStatus status)
+ : InsetCollapsable(bp, status)
{
- status_ = collapsed ? Collapsed : Open;
-
LyXFont font(LyXFont::ALL_INHERIT, l);
string::const_iterator cit = contents.begin();
string::const_iterator end = contents.end();
}
-void InsetERT::read(Buffer const & buf, LyXLex & lex)
-{
- bool token_found = false;
- if (lex.isOK()) {
- lex.next();
- string const token = lex.getString();
- if (token == "status") {
- lex.next();
- string const tmp_token = lex.getString();
-
- if (tmp_token == "Inlined") {
- status_ = Inlined;
- } else if (tmp_token == "Collapsed") {
- status_ = Collapsed;
- } else {
- // leave this as default!
- status_ = Open;
- }
-
- token_found = true;
- } else {
- lyxerr << "InsetERT::Read: Missing 'status'-tag!"
- << endl;
- // take countermeasures
- lex.pushToken(token);
- }
- }
- inset.read(buf, lex);
-
- if (!token_found) {
- if (isOpen())
- status_ = Open;
- else
- status_ = Collapsed;
- }
- setButtonLabel();
-}
-
-
void InsetERT::write(Buffer const & buf, ostream & os) const
{
- string st;
-
- switch (status_) {
- case Open:
- st = "Open";
- break;
- case Collapsed:
- st = "Collapsed";
- break;
- case Inlined:
- st = "Inlined";
- break;
- }
-
- os << getInsetName() << "\n" << "status "<< st << "\n";
-
- //inset.writeParagraphData(buf, os);
- string const layout(buf.params().getLyXTextClass().defaultLayoutName());
- ParagraphList::iterator par = inset.paragraphs().begin();
- ParagraphList::iterator end = inset.paragraphs().end();
- for (; par != end; ++par) {
- os << "\n\\begin_layout " << layout << "\n";
- pos_type siz = par->size();
- for (pos_type i = 0; i < siz; ++i) {
- Paragraph::value_type c = par->getChar(i);
- switch (c) {
- case Paragraph::META_INSET:
- if (par->getInset(i)->lyxCode() != InsetOld::NEWLINE_CODE) {
- lyxerr << "Element is not allowed in insertERT"
- << endl;
- } else {
- par->getInset(i)->write(buf, os);
- }
- break;
-
- case '\\':
- os << "\n\\backslash \n";
- break;
- default:
- os << c;
- break;
- }
- }
- os << "\n\\end_layout\n";
- }
+ os << "ERT" << "\n";
+ InsetCollapsable::write(buf, os);
}
}
-void InsetERT::updateStatus(bool swap) const
-{
- if (status_ != Inlined) {
- if (isOpen())
- status_ = swap ? Collapsed : Open;
- else
- status_ = swap ? Open : Collapsed;
- setButtonLabel();
- }
-}
-
-
-void InsetERT::lfunMousePress(FuncRequest const & cmd)
-{
- if (status_ == Inlined)
- inset.dispatch(cmd);
- else {
- idx_type idx = 0;
- pos_type pos = 0;
- InsetCollapsable::priv_dispatch(cmd, idx, pos);
- }
-}
-
-
-bool InsetERT::lfunMouseRelease(FuncRequest const & cmd)
-{
- BufferView * bv = cmd.view();
-
- if (cmd.button() == mouse_button::button3) {
- showInsetDialog(bv);
- return true;
- }
-
- if (status_ != Inlined && hitButton(cmd)) {
- updateStatus(true);
- } else {
- FuncRequest cmd1 = cmd;
-#warning metrics?
- cmd1.y = ascent() + cmd.y - inset.ascent();
-
- // inlined is special - the text appears above
- if (status_ == Inlined)
- inset.dispatch(cmd1);
- else if (isOpen() && cmd.y > buttonDim().y2) {
- cmd1.y -= height_collapsed();
- inset.dispatch(cmd1);
- }
- }
- return false;
-}
-
-
-void InsetERT::lfunMouseMotion(FuncRequest const & cmd)
-{
- if (status_ == Inlined)
- inset.dispatch(cmd);
- else {
- idx_type idx = 0;
- pos_type pos = 0;
- InsetCollapsable::priv_dispatch(cmd, idx, pos);
- }
-}
-
-
int InsetERT::latex(Buffer const &, ostream & os,
OutputParams const &) const
{
}
-void InsetERT::edit(BufferView * bv, bool left)
-{
- if (status_ == Inlined)
- inset.edit(bv, left);
- else
- InsetCollapsable::edit(bv, left);
- updateStatus();
-}
-
-
DispatchResult
InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
{
switch (cmd.action) {
- case LFUN_MOUSE_PRESS:
- lfunMousePress(cmd);
- return DispatchResult(true, true);
-
- case LFUN_MOUSE_MOTION:
- lfunMouseMotion(cmd);
- return DispatchResult(true, true);
-
- case LFUN_MOUSE_RELEASE:
- lfunMouseRelease(cmd);
- return DispatchResult(true, true);
-
case LFUN_INSET_MODIFY:
- InsetERTMailer::string2params(cmd.argument, status_);
- setButtonLabel();
- return DispatchResult(true, true);
+ {
+ InsetCollapsable::CollapseStatus st;
+
+ InsetERTMailer::string2params(cmd.argument, st);
+ setStatus(st);
+ return DispatchResult(true, true);
+ }
case LFUN_LAYOUT:
case LFUN_BOLD:
}
-void InsetERT::setButtonLabel() const
+void InsetERT::setButtonLabel()
{
- setLabel(status_ == Collapsed ? getNewLabel(_("ERT")) : _("ERT"));
+ setLabel(status() == Collapsed ? getNewLabel(_("ERT")) : _("ERT"));
}
}
-void InsetERT::setStatus(CollapseStatus st)
-{
- status_ = st;
- setButtonLabel();
-}
-
-
bool InsetERT::showInsetDialog(BufferView * bv) const
{
InsetERTMailer(const_cast<InsetERT &>(*this)).showDialog(bv);
class InsetERT : public InsetCollapsable {
public:
///
- InsetERT(BufferParams const &, bool collapsed = false);
+ InsetERT(BufferParams const &, CollapseStatus status = Open);
///
InsetERT(InsetERT const &);
///
virtual std::auto_ptr<InsetBase> clone() const;
///
InsetERT(BufferParams const &,
- Language const *, std::string const & contents, bool collapsed);
+ Language const *, std::string const & contents, CollapseStatus status);
///
~InsetERT();
///
InsetOld::Code lyxCode() const { return InsetOld::ERT_CODE; }
///
- void read(Buffer const & buf, LyXLex & lex);
- ///
void write(Buffer const & buf, std::ostream & os) const;
///
std::string const editMessage() const;
void getDrawFont(LyXFont &) const;
///
bool forceDefaultParagraphs(InsetOld const *) const { return true; }
- ///
- void setStatus(CollapseStatus st);
protected:
///
virtual
DispatchResult
priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
private:
- ///
- void lfunMousePress(FuncRequest const &);
- ///
- // the bool return is used to see if we opened a dialog so that we can
- // check this from an outer inset and open the dialog of the outer inset
- // if that one has one!
- ///
- bool lfunMouseRelease(FuncRequest const &);
- ///
- void lfunMouseMotion(FuncRequest const &);
///
void init();
///
- void setButtonLabel() const;
- /// update status on button
- void updateStatus(bool = false) const;
- ///
- void edit(BufferView * bv, bool left);
+ void setButtonLabel();
///
bool allowSpellCheck() const { return false; }
};
InsetOptArg::InsetOptArg(BufferParams const & ins)
- : InsetCollapsable(ins, true)
+ : InsetCollapsable(ins, Collapsed)
{
LyXFont font(LyXFont::ALL_SANE);
font.setColor(LColor::collapsable);