From 487f6eb3b43746460d090f643cd1e39f2d93a74b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Thu, 12 Jul 2001 14:35:38 +0000 Subject: [PATCH] Added various inset functions for Jean-Marc (see Changelog). Small fix in cua bind-file. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2228 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ChangeLog | 4 ++++ lib/bind/cua.bind | 2 +- src/insets/ChangeLog | 9 +++++++++ src/insets/inset.h | 6 ++++++ src/insets/insetcollapsable.C | 38 +++++++++++++++++++++-------------- src/insets/insetcollapsable.h | 11 ++++++++-- src/insets/insetert.C | 2 +- src/insets/insetfloat.C | 17 +++++++++------- src/insets/insetfloat.h | 1 + src/insets/insetfoot.C | 12 +---------- src/insets/insetfoot.h | 2 -- src/insets/insetfootlike.C | 13 ++++++++++++ src/insets/insetfootlike.h | 3 +++ src/insets/insetlist.C | 12 +---------- src/insets/insetlist.h | 2 -- src/insets/insetmarginal.C | 12 +---------- src/insets/insetmarginal.h | 2 -- src/insets/insetminipage.C | 18 ++++++++++------- src/insets/insetminipage.h | 1 + src/insets/insettext.C | 7 +++++++ src/insets/insettext.h | 1 + src/insets/insettheorem.C | 14 +------------ src/insets/insettheorem.h | 2 -- 23 files changed, 104 insertions(+), 87 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index e400493f91..6d6ec200f3 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2001-07-12 Juergen Vigna + + * bind/cua.bind: moved C-l from mode-tex to ert-insert + 2001-07-12 Jean-Marc Lasgouttes * images/ert-insert.xpm: renamed from tex-mode.xpm diff --git a/lib/bind/cua.bind b/lib/bind/cua.bind index 39ee9a5bc7..42be18c81f 100644 --- a/lib/bind/cua.bind +++ b/lib/bind/cua.bind @@ -47,7 +47,6 @@ \bind "C-e" "font-emph" # used below for line-delete-forward #\bind "C-k" "font-noun" # 'k' for capitals -\bind "C-l" "tex-mode" # 'l' for LaTeX \bind "C-u" "font-underline" \bind "C-S-P" "font-code" # 'P' for program @@ -73,6 +72,7 @@ \bind "M-S-Right" "depth-increment" \bind "M-S-Left" "depth-decrement" \bind "C-S-space" "protected-space-insert" +\bind "C-l" "ert-insert" # 'l' for LaTeX #bind "F1" "help" # Not yet implemented! #bind "C-F1" "help-context" # Not yet implemented! diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index d4809a166a..4efb88f929 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,5 +1,14 @@ 2001-07-12 Juergen Vigna + * insetcollapsable.h: added implementation of new function for + collapsable status. + + * various files: added implementation of new insertInsetAllowed-func + and redone the function a bit more. + + * inset.h: added isCollapsable(), bool collapsed(), + collapsed(BufferView *, bool) and insertInsetAllowed(Inset::Code). + * insetfloat.C (insertInsetAllowed): make a bit more checks. * insettext.C (getLyXText): use 'lt' to assure we're not erasing the diff --git a/src/insets/inset.h b/src/insets/inset.h index 264ab4b260..54ffa4720f 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -368,6 +368,7 @@ public: virtual bool insertInset(BufferView *, Inset *) { return false; } /// virtual bool insertInsetAllowed(Inset *) const { return false; } + virtual bool insertInsetAllowed(Inset::Code) const { return false; } /// virtual UpdatableInset * getLockingInset() const { return const_cast(this); @@ -408,6 +409,11 @@ public: virtual bool nodraw() const { return block_drawing_; } + /// + virtual bool isCollapsable() const { return false; } + /// + virtual bool collapsed() const { return false; } + virtual void collapsed(BufferView *, bool) {} protected: /// diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 278af604c8..8658cfe5de 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -36,7 +36,7 @@ InsetCollapsable::InsetCollapsable() : UpdatableInset() { inset.setOwner(this); - collapsed = false; + collapsed_ = false; label = "Label"; autocollapse = true; inset.setAutoBreakRows(true); @@ -62,7 +62,7 @@ bool InsetCollapsable::insertInset(BufferView * bv, Inset * in) void InsetCollapsable::write(Buffer const * buf, ostream & os) const { - os << "collapsed " << tostr(collapsed) << "\n"; + os << "collapsed " << tostr(collapsed_) << "\n"; inset.writeParagraphData(buf, os); } @@ -75,7 +75,7 @@ void InsetCollapsable::read(Buffer const * buf, LyXLex & lex) string const token = lex.GetString(); if (token == "collapsed") { lex.next(); - collapsed = lex.GetBool(); + collapsed_ = lex.GetBool(); } else { lyxerr << "InsetCollapsable::Read: Missing collapsed!" << endl; @@ -126,7 +126,7 @@ int InsetCollapsable::ascent(BufferView * bv, LyXFont const & font) const int InsetCollapsable::descent(BufferView * bv, LyXFont const & font) const { - if (collapsed) + if (collapsed_) return descent_collapsed(bv->painter(), font); return descent_collapsed(bv->painter(), font) @@ -138,7 +138,7 @@ int InsetCollapsable::descent(BufferView * bv, LyXFont const & font) const int InsetCollapsable::width(BufferView * bv, LyXFont const & font) const { - if (collapsed) + if (collapsed_) return widthCollapsed; return (inset.width(bv, font) > widthCollapsed) ? @@ -169,7 +169,7 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, button_bottom_y = -ascent(bv, f) + ascent_collapsed(pain,f) + descent_collapsed(pain, f); - if (collapsed) { + if (collapsed_) { draw_collapsed(pain, f, baseline, x); x += TEXT_TO_INSET_OFFSET; return; @@ -229,8 +229,8 @@ void InsetCollapsable::edit(BufferView * bv, int xp, int yp, { UpdatableInset::edit(bv, xp, yp, button); - if (collapsed) { - collapsed = false; + if (collapsed_) { + collapsed_ = false; if (!bv->lockInset(this)) return; bv->updateInset(this, false); @@ -245,7 +245,7 @@ void InsetCollapsable::edit(BufferView * bv, int xp, int yp, Inset::EDITABLE InsetCollapsable::editable() const { - if (collapsed) + if (collapsed_) return IS_EDITABLE; return HIGHLY_EDITABLE; } @@ -254,7 +254,7 @@ Inset::EDITABLE InsetCollapsable::editable() const void InsetCollapsable::insetUnlock(BufferView * bv) { if (autocollapse) { - collapsed = true; + collapsed_ = true; } inset.insetUnlock(bv); if (scroll()) @@ -266,7 +266,7 @@ void InsetCollapsable::insetUnlock(BufferView * bv) void InsetCollapsable::insetButtonPress(BufferView * bv, int x, int y, int button) { - if (!collapsed && (y > button_bottom_y)) { + if (!collapsed_ && (y > button_bottom_y)) { inset.insetButtonPress(bv, x, y + (top_baseline - inset.y()), button); } @@ -278,16 +278,16 @@ void InsetCollapsable::insetButtonRelease(BufferView * bv, { if ((x >= 0) && (x < button_length) && (y >= button_top_y) && (y <= button_bottom_y)) { - if (collapsed) { - collapsed = false; + if (collapsed_) { + collapsed_ = false; inset.insetButtonRelease(bv, 0, 0, button); bv->updateInset(this, false); } else { - collapsed = true; + collapsed_ = true; bv->unlockInset(this); bv->updateInset(this, false); } - } else if (!collapsed && (y > button_top_y)) { + } else if (!collapsed_ && (y > button_top_y)) { inset.insetButtonRelease(bv, x, y + (top_baseline-inset.y()), button); } @@ -523,3 +523,11 @@ Inset * InsetCollapsable::getInsetFromID(int id_arg) const return const_cast(this); return inset.getInsetFromID(id_arg); } + +void InsetCollapsable::collapsed(BufferView * bv, bool flag) +{ + if (flag == collapsed_) + return; + collapsed_ = flag; + bv->updateInset(this, false); +} diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index c58e20dd04..2bcc18955c 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -67,6 +67,9 @@ public: bool insertInsetAllowed(Inset * in) const { return inset.insertInsetAllowed(in); } + bool insertInsetAllowed(Inset::Code code) const { + return inset.insertInsetAllowed(code); + } /// bool isTextInset() const { return true; } /// @@ -74,7 +77,7 @@ public: /// void insetUnlock(BufferView *); /// - bool needFullRow() const { return !collapsed; } + bool needFullRow() const { return !collapsed_; } /// bool lockInsetInInset(BufferView *, UpdatableInset *); /// @@ -153,6 +156,10 @@ public: Paragraph * firstParagraph() const; /// LyXCursor const & cursor(BufferView *) const; + /// + bool isCollapsable() const { return true; } + bool collapsed() const { return collapsed_; } + void collapsed(BufferView *, bool); protected: /// @@ -167,7 +174,7 @@ protected: int getMaxTextWidth(Painter & pain, UpdatableInset const *) const; /// - bool collapsed; + bool collapsed_; /// LColor::color framecolor; /// diff --git a/src/insets/insetert.C b/src/insets/insetert.C index acdb6eb5d3..2528a5a50d 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -74,7 +74,7 @@ Inset * InsetERT::clone(Buffer const &, bool same_id) const InsetERT * result = new InsetERT; result->inset.init(&inset, same_id); - result->collapsed = collapsed; + result->collapsed_ = collapsed_; if (same_id) result->id_ = id_; return result; diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index a45e63a882..237c47dfc8 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -176,7 +176,7 @@ Inset * InsetFloat::clone(Buffer const &, bool same_id) const InsetFloat * result = new InsetFloat(floatType_); result->inset.init(&inset, same_id); - result->collapsed = collapsed; + result->collapsed_ = collapsed_; if (same_id) result->id_ = id_; return result; @@ -236,15 +236,18 @@ int InsetFloat::docBook(Buffer const * buf, ostream & os) const bool InsetFloat::insertInsetAllowed(Inset * in) const { - if (in->lyxCode() == Inset::FLOAT_CODE) + return insertInsetAllowed(in->lyxCode()); +} + + +bool InsetFloat::insertInsetAllowed(Inset::Code code) const +{ + if (code == Inset::FLOAT_CODE) return false; if (inset.getLockingInset() != this) - return inset.insertInsetAllowed(in); - if ((in->lyxCode() == Inset::FOOT_CODE) || - (in->lyxCode() == Inset::MARGIN_CODE)) - { + return inset.insertInsetAllowed(code); + if ((code == Inset::FOOT_CODE) || (code == Inset::MARGIN_CODE)) return false; - } return true; } diff --git a/src/insets/insetfloat.h b/src/insets/insetfloat.h index 4668c68f14..d7ec169fbc 100644 --- a/src/insets/insetfloat.h +++ b/src/insets/insetfloat.h @@ -45,6 +45,7 @@ public: string const editMessage() const; /// bool insertInsetAllowed(Inset * inset) const; + bool insertInsetAllowed(Inset::Code) const; /// void insetButtonRelease(BufferView * bv, int x, int y, int button); /// diff --git a/src/insets/insetfoot.C b/src/insets/insetfoot.C index 926176e66b..c188496afe 100644 --- a/src/insets/insetfoot.C +++ b/src/insets/insetfoot.C @@ -37,7 +37,7 @@ Inset * InsetFoot::clone(Buffer const &, bool same_id) const InsetFoot * result = new InsetFoot; result->inset.init(&inset, same_id); - result->collapsed = collapsed; + result->collapsed_ = collapsed_; if (same_id) result->id_ = id_; return result; @@ -60,13 +60,3 @@ int InsetFoot::latex(Buffer const * buf, return i + 2; } - - -bool InsetFoot::insertInsetAllowed(Inset * in) const -{ - if ((in->lyxCode() == Inset::FOOT_CODE) || - (in->lyxCode() == Inset::MARGIN_CODE)) { - return false; - } - return true; -} diff --git a/src/insets/insetfoot.h b/src/insets/insetfoot.h index 2495ebb67f..c3689c2ac1 100644 --- a/src/insets/insetfoot.h +++ b/src/insets/insetfoot.h @@ -35,8 +35,6 @@ public: int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// string const editMessage() const; - /// - bool insertInsetAllowed(Inset * inset) const; }; #endif diff --git a/src/insets/insetfootlike.C b/src/insets/insetfootlike.C index 09639ba8ee..141cde152d 100644 --- a/src/insets/insetfootlike.C +++ b/src/insets/insetfootlike.C @@ -38,3 +38,16 @@ void InsetFootlike::write(Buffer const * buf, std::ostream & os) const os << getInsetName() << "\n"; InsetCollapsable::write(buf, os); } + + +bool InsetFootlike::insertInsetAllowed(Inset * in) const +{ + return insertInsetAllowed(in->lyxCode()); +} + +bool InsetFootlike::insertInsetAllowed(Inset::Code code) const +{ + if ((code == Inset::FOOT_CODE) || (code == Inset::MARGIN_CODE)) + return false; + return InsetCollapsable::insertInsetAllowed(code); +} diff --git a/src/insets/insetfootlike.h b/src/insets/insetfootlike.h index b028d8062c..b6b2b54a71 100644 --- a/src/insets/insetfootlike.h +++ b/src/insets/insetfootlike.h @@ -31,6 +31,9 @@ public: InsetFootlike(); /// void write(Buffer const * buf, std::ostream & os) const; + /// + bool insertInsetAllowed(Inset * inset) const; + bool insertInsetAllowed(Inset::Code) const; }; #endif diff --git a/src/insets/insetlist.C b/src/insets/insetlist.C index d577c185ed..27ad75489c 100644 --- a/src/insets/insetlist.C +++ b/src/insets/insetlist.C @@ -62,7 +62,7 @@ Inset * InsetList::clone(Buffer const &, bool same_id) const InsetList * result = new InsetList; result->inset.init(&inset, same_id); - result->collapsed = collapsed; + result->collapsed_ = collapsed_; if (same_id) result->id_ = id_; return result; @@ -85,13 +85,3 @@ int InsetList::latex(Buffer const * buf, return i + 2; } - - -bool InsetList::insertInsetAllowed(Inset * in) const -{ - if ((in->lyxCode() == Inset::FOOT_CODE) || - (in->lyxCode() == Inset::MARGIN_CODE)) { - return false; - } - return true; -} diff --git a/src/insets/insetlist.h b/src/insets/insetlist.h index a5ea1f727d..d077849b3c 100644 --- a/src/insets/insetlist.h +++ b/src/insets/insetlist.h @@ -35,8 +35,6 @@ public: int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// string const editMessage() const; - /// - bool insertInsetAllowed(Inset * inset) const; }; #endif diff --git a/src/insets/insetmarginal.C b/src/insets/insetmarginal.C index b4aa735602..e61f47bb71 100644 --- a/src/insets/insetmarginal.C +++ b/src/insets/insetmarginal.C @@ -37,7 +37,7 @@ Inset * InsetMarginal::clone(Buffer const &, bool same_id) const InsetMarginal * result = new InsetMarginal; result->inset.init(&inset, same_id); - result->collapsed = collapsed; + result->collapsed_ = collapsed_; if (same_id) result->id_ = id_; return result; @@ -60,13 +60,3 @@ int InsetMarginal::latex(Buffer const * buf, return i + 2; } - - -bool InsetMarginal::insertInsetAllowed(Inset * in) const -{ - if ((in->lyxCode() == Inset::FOOT_CODE) || - (in->lyxCode() == Inset::MARGIN_CODE)) { - return false; - } - return true; -} diff --git a/src/insets/insetmarginal.h b/src/insets/insetmarginal.h index 26654106a6..741e992a32 100644 --- a/src/insets/insetmarginal.h +++ b/src/insets/insetmarginal.h @@ -33,8 +33,6 @@ public: int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// string const editMessage() const; - /// - bool insertInsetAllowed(Inset * inset) const; }; #endif diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 372c7bcef3..f425b2be1d 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -179,7 +179,7 @@ Inset * InsetMinipage::clone(Buffer const &, bool same_id) const InsetMinipage * result = new InsetMinipage; result->inset.init(&inset, same_id); - result->collapsed = collapsed; + result->collapsed_ = collapsed_; result->pos_ = pos_; result->inner_pos_ = inner_pos_; result->height_ = height_; @@ -192,7 +192,7 @@ Inset * InsetMinipage::clone(Buffer const &, bool same_id) const int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const { - if (collapsed) + if (collapsed_) return ascent_collapsed(bv->painter(), font); else { // Take placement into account. @@ -216,7 +216,7 @@ int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const { - if (collapsed) + if (collapsed_) return descent_collapsed(bv->painter(), font); else { // Take placement into account. @@ -271,11 +271,15 @@ int InsetMinipage::latex(Buffer const * buf, bool InsetMinipage::insertInsetAllowed(Inset * in) const { - if ((in->lyxCode() == Inset::FLOAT_CODE) || - (in->lyxCode() == Inset::MARGIN_CODE)) { + return insertInsetAllowed(in->lyxCode()); +} + +bool InsetMinipage::insertInsetAllowed(Inset::Code code) const +{ + if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE)) return false; - } - return true; + + return InsetCollapsable::insertInsetAllowed(code); } diff --git a/src/insets/insetminipage.h b/src/insets/insetminipage.h index fb6a72220d..246696d838 100644 --- a/src/insets/insetminipage.h +++ b/src/insets/insetminipage.h @@ -60,6 +60,7 @@ public: string const editMessage() const; /// bool insertInsetAllowed(Inset * inset) const; + bool insertInsetAllowed(Inset::Code) const; /// Position pos() const; /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index d4057cec57..d4142702a9 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -1436,6 +1436,13 @@ bool InsetText::insertInsetAllowed(Inset * in) const return true; } +bool InsetText::insertInsetAllowed(Inset::Code code) const +{ + if (the_locking_inset) + return the_locking_inset->insertInsetAllowed(code); + return true; +} + UpdatableInset * InsetText::getLockingInset() const { diff --git a/src/insets/insettext.h b/src/insets/insettext.h index fb20a03a88..682ff48d1e 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -153,6 +153,7 @@ public: bool insertInset(BufferView *, Inset *); /// bool insertInsetAllowed(Inset *) const; + bool insertInsetAllowed(Inset::Code) const; /// UpdatableInset * getLockingInset() const; /// diff --git a/src/insets/insettheorem.C b/src/insets/insettheorem.C index fa46fcb392..f5bddf4c32 100644 --- a/src/insets/insettheorem.C +++ b/src/insets/insettheorem.C @@ -59,7 +59,7 @@ Inset * InsetTheorem::clone(Buffer const &, bool) const #warning Is this inset used? If YES this is WRONG!!! (Jug) InsetTheorem * result = new InsetTheorem; - result->collapsed = collapsed; + result->collapsed_ = collapsed_; return result; } @@ -80,15 +80,3 @@ int InsetTheorem::latex(Buffer const * buf, return i + 2; } - - -bool InsetTheorem::insertInsetAllowed(Inset * inset) const -{ - lyxerr << "InsetTheorem::InsertInsetAllowed" << endl; - - if ((inset->lyxCode() == Inset::FOOT_CODE) || - (inset->lyxCode() == Inset::MARGIN_CODE)) { - return false; - } - return true; -} diff --git a/src/insets/insettheorem.h b/src/insets/insettheorem.h index 22e2edfe0a..24e9b8a215 100644 --- a/src/insets/insettheorem.h +++ b/src/insets/insettheorem.h @@ -37,8 +37,6 @@ public: int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// string const editMessage() const; - /// - bool insertInsetAllowed(Inset * inset) const; }; #endif -- 2.39.2