From 5a704fe310287427c21905ff774fd3317bfa61e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Wed, 28 Sep 2005 15:02:47 +0000 Subject: [PATCH] the autoopen patch (fixes bug 1921) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10495 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 5 +++ src/cursor.C | 3 -- src/insets/ChangeLog | 6 ++++ src/insets/insetcollapsable.C | 61 +++++++++++++++++++---------------- src/insets/insetcollapsable.h | 4 ++- 5 files changed, 48 insertions(+), 31 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 32655b8321..68bc45e164 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2005-09-28 Jürgen Spitzmüller + + * cursor.C (setSelection): do not open collapsable insets; + the insets do by themselves now (autoopen). + 2005-09-28 Jürgen Spitzmüller * buffer.C: format is up to 244. diff --git a/src/cursor.C b/src/cursor.C index 2ed2722129..816981e2a3 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -468,9 +468,6 @@ void LCursor::setSelection(DocIterator const & where, size_t n) selection() = true; anchor_ = where; pos() += n; - // Open all collapsed insets - for (int i = depth() - 1; i >= 0; --i) - operator[](i).inset().setStatus(*this, InsetBase::Open); } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 9b79976ce3..4396aa9259 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,9 @@ +2005-09-28 Jürgen Spitzmüller + + * insetcollapsable.[Ch]: implement Alfredo Braunstein's approach + of autoopen, which means that collapsables automatically open + whenever the cursor enters (and close again on leave) (fixes bug 1921). + 2005-09-28 Jürgen Spitzmüller * insetspace.C: rename '\,' to '\thinspace{}' (avoid parsing error) diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index d688cf3301..6bcb0ff6e8 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -40,9 +40,16 @@ using std::min; using std::ostream; +InsetCollapsable::CollapseStatus InsetCollapsable::status() const +{ + return (autoOpen_ && status_ != Inlined) ? Open : status_; +} + + InsetCollapsable::InsetCollapsable (BufferParams const & bp, CollapseStatus status) - : InsetText(bp), label("Label"), status_(status), openinlined_(false) + : InsetText(bp), label("Label"), status_(status), + openinlined_(false), autoOpen_(false) { setAutoBreakRows(true); setDrawFrame(true); @@ -122,12 +129,14 @@ Dimension InsetCollapsable::dimensionCollapsed() const void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const { + autoOpen_ = mi.base.bv->cursor().isInside(this); mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET; - if (status_ == Inlined) { + + if (status() == Inlined) { InsetText::metrics(mi, dim); } else { dim = dimensionCollapsed(); - if (status_ == Open) { + if (status() == Open) { InsetText::metrics(mi, textdim_); openinlined_ = (textdim_.wid + dim.wid <= mi.base.textwidth); if (openinlined_) { @@ -151,7 +160,7 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const { const int xx = x + TEXT_TO_INSET_OFFSET; - if (status_ == Inlined) { + if (status() == Inlined) { InsetText::draw(pi, xx, y); } else { Dimension dimc = dimensionCollapsed(); @@ -162,7 +171,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const button_dim.y2 = top + dimc.height(); pi.pain.buttonText(xx, top + dimc.asc, label, labelfont_); - if (status_ == Open) { + if (status() == Open) { int textx, texty; if (openinlined_) { textx = xx + dimc.width(); @@ -181,13 +190,13 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const { x += TEXT_TO_INSET_OFFSET; - if (status_ == Open) { + if (status() == Open) { if (openinlined_) x += dimensionCollapsed().wid; else y += dimensionCollapsed().des + textdim_.asc; } - if (status_ != Collapsed) + if (status() != Collapsed) InsetText::drawSelection(pi, x, y); } @@ -195,32 +204,30 @@ void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const void InsetCollapsable::cursorPos (CursorSlice const & sl, bool boundary, int & x, int & y) const { - if (status_ == Collapsed) { - x = xo(); - y = yo(); - } else { - InsetText::cursorPos(sl, boundary, x, y); - if (status_ == Open) { - if (openinlined_) - x += dimensionCollapsed().wid; - else - y += dimensionCollapsed().height() - ascent() - + TEXT_TO_INSET_OFFSET + textdim_.asc; - } - x += TEXT_TO_INSET_OFFSET; + BOOST_ASSERT(status() != Collapsed); + + InsetText::cursorPos(sl, boundary, x, y); + + if (status() == Open) { + if (openinlined_) + x += dimensionCollapsed().wid; + else + y += dimensionCollapsed().height() - ascent() + + TEXT_TO_INSET_OFFSET + textdim_.asc; } + x += TEXT_TO_INSET_OFFSET; } InsetBase::EDITABLE InsetCollapsable::editable() const { - return status_ != Collapsed ? HIGHLY_EDITABLE : IS_EDITABLE; + return status() != Collapsed ? HIGHLY_EDITABLE : IS_EDITABLE; } bool InsetCollapsable::descendable() const { - return status_ != Collapsed; + return status() != Collapsed; } @@ -262,7 +269,7 @@ void InsetCollapsable::edit(LCursor & cur, bool left) InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y) { //lyxerr << "InsetCollapsable: edit xy" << endl; - if (status_ == Collapsed) + if (status() == Collapsed) return this; cur.push(*this); return InsetText::editXY(cur, x, y); @@ -276,9 +283,9 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd) switch (cmd.action) { case LFUN_MOUSE_PRESS: - if (status_ == Inlined) + if (status() == Inlined) InsetText::doDispatch(cur, cmd); - else if (status_ == Open && !hitButton(cmd)) + else if (status() == Open && !hitButton(cmd)) InsetText::doDispatch(cur, cmd); else cur.noUpdate(); @@ -289,7 +296,7 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd) case LFUN_MOUSE_TRIPLE: if (status_ == Inlined) InsetText::doDispatch(cur, cmd); - else if (status_ == Open && !hitButton(cmd)) + else if (status() && !hitButton(cmd)) InsetText::doDispatch(cur, cmd); else cur.undispatched(); @@ -301,7 +308,7 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd) break; } - switch (status_) { + switch (status()) { case Collapsed: //lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl; diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 6b351bf9d1..22697c4828 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -69,7 +69,7 @@ public: /// bool inlined() const { return status_ == Inlined; } /// - CollapseStatus status() const { return status_; } + CollapseStatus status() const; /// bool allowSpellCheck() const { return true; } /// @@ -107,6 +107,8 @@ private: mutable CollapseStatus status_; /// a substatus of the Open status, determined automatically in metrics mutable bool openinlined_; + /// the inset will automatically open when the cursor is inside + mutable bool autoOpen_; /// mutable Dimension textdim_; }; -- 2.39.2