From: André Pönitz Date: Fri, 12 Dec 2003 14:02:14 +0000 (+0000) Subject: Michael Schmitt's collapse status patch X-Git-Tag: 1.6.10~15654 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f4c49493be9b2fc38f631ff7ea4d401f0893c845;p=features.git Michael Schmitt's collapse status patch git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8241 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 925466afc8..b74da17061 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,10 @@ +2003-12-12 Michael Schmitt + + * 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 * insetinclude.C (draw): cache x,y and so enable the diff --git a/src/insets/insetcharstyle.C b/src/insets/insetcharstyle.C index afea571324..8de473e8e5 100644 --- a/src/insets/insetcharstyle.C +++ b/src/insets/insetcharstyle.C @@ -105,7 +105,7 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const xo_ = x; yo_ = y; - status_ = Inlined; + // FIXME: setStatus(Inlined); this is not a const operation inset.setDrawFrame(InsetText::NEVER); inset.draw(pi, x, y); diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 49d4ff4052..702c0e7651 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -39,55 +39,91 @@ using std::min; 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(); } @@ -183,32 +219,31 @@ DispatchResult InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd) 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); } @@ -264,10 +299,7 @@ string const InsetCollapsable::getNewLabel(string const & l) const if (inset.paragraphs().size() > 1 || (i > 0 && j < p_siz)) { la += "..."; } - if (la.empty()) { - la = l; - } - return la; + return la.empty() ? l : la; } @@ -275,7 +307,7 @@ void InsetCollapsable::edit(BufferView * bv, bool left) { lyxerr << "InsetCollapsable: edit left/right" << endl; inset.edit(bv, left); - setStatus(Open); + open(); bv->cursor().push(this); } @@ -303,26 +335,29 @@ InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) // << " 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: @@ -378,7 +413,8 @@ LyXText * InsetCollapsable::getText(int i) const void InsetCollapsable::open() { - setStatus(Open); + if (status_ == Collapsed) // ...but not inlined + setStatus(Open); } @@ -388,15 +424,16 @@ void InsetCollapsable::close() } -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(); } @@ -418,18 +455,10 @@ bool InsetCollapsable::insetAllowed(InsetOld::Code code) const } -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 diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 9d4ebbc1d0..4cbecbed74 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -40,8 +40,8 @@ public: 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); /// @@ -81,13 +81,11 @@ public: /// 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 & list) const; /// @@ -117,7 +115,7 @@ public: /// void setBackgroundColor(LColor_color); /// - virtual void setStatus(CollapseStatus st); + void setStatus(CollapseStatus st); protected: /// @@ -148,9 +146,10 @@ private: public: /// mutable InsetText inset; -protected: +private: /// mutable CollapseStatus status_; +protected: /// LyXFont labelfont_; /// @@ -161,10 +160,6 @@ protected: mutable int topbaseline; /// mutable std::string label; -#if 0 - /// - bool autocollapse; -#endif }; #endif diff --git a/src/insets/insetert.C b/src/insets/insetert.C index fbf577bbac..e81ec4795f 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -57,10 +57,9 @@ void InsetERT::init() } -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(); } @@ -79,11 +78,9 @@ auto_ptr InsetERT::clone() const 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(); @@ -103,92 +100,10 @@ InsetERT::~InsetERT() } -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); } @@ -198,70 +113,6 @@ string const InsetERT::editMessage() const } -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 { @@ -357,37 +208,19 @@ int InsetERT::docbook(Buffer const &, ostream & os, } -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: @@ -412,9 +245,9 @@ InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) } -void InsetERT::setButtonLabel() const +void InsetERT::setButtonLabel() { - setLabel(status_ == Collapsed ? getNewLabel(_("ERT")) : _("ERT")); + setLabel(status() == Collapsed ? getNewLabel(_("ERT")) : _("ERT")); } @@ -443,13 +276,6 @@ void InsetERT::draw(PainterInfo & pi, int x, int y) const } -void InsetERT::setStatus(CollapseStatus st) -{ - status_ = st; - setButtonLabel(); -} - - bool InsetERT::showInsetDialog(BufferView * bv) const { InsetERTMailer(const_cast(*this)).showDialog(bv); diff --git a/src/insets/insetert.h b/src/insets/insetert.h index 3fb04dd44f..ef23eb1f6c 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -30,21 +30,19 @@ class Language; class InsetERT : public InsetCollapsable { public: /// - InsetERT(BufferParams const &, bool collapsed = false); + InsetERT(BufferParams const &, CollapseStatus status = Open); /// InsetERT(InsetERT const &); /// virtual std::auto_ptr 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; @@ -74,32 +72,16 @@ public: 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; } }; diff --git a/src/insets/insetoptarg.C b/src/insets/insetoptarg.C index 55a8f2b380..9b5e42b441 100644 --- a/src/insets/insetoptarg.C +++ b/src/insets/insetoptarg.C @@ -24,7 +24,7 @@ using std::ostream; InsetOptArg::InsetOptArg(BufferParams const & ins) - : InsetCollapsable(ins, true) + : InsetCollapsable(ins, Collapsed) { LyXFont font(LyXFont::ALL_SANE); font.setColor(LColor::collapsable);