Jean-Marc Lasgouttes wrote:
> Juergen> That does not particularly disqualify my approach, no?
>
> Did I write that? 

I just wanted to make clear that I got you right. Seems that misunderstandings 
scale very well ;-)

> I meant to say that your patch is OK with me, except 
> that I would like this particular bit of code (which is not yours)
> fixed.

I tried to move the setCursor call in front of the loop, but that leads to 
cursor misdrawings in the insets, so setCursor _has_ to be called afterwards. 

Now I have put a call before the loop and left the one behind (see attached 
patch). Does that make sense to you?

Jürgen
Index: BufferView.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v
retrieving revision 1.263
diff -u -r1.263 BufferView.C
--- BufferView.C	15 Jul 2005 22:10:15 -0000	1.263
+++ BufferView.C	27 Sep 2005 15:57:55 -0000
@@ -323,6 +323,7 @@
 
 void BufferView::setCursor(DocIterator const & dit)
 {
+	cursor().setCursor(dit);
 	size_t const n = dit.depth();
 	for (size_t i = 0; i < n; ++i)
 		dit[i].inset().edit(cursor(), true);
Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.135
diff -u -r1.135 cursor.C
--- cursor.C	21 Sep 2005 09:56:54 -0000	1.135
+++ cursor.C	27 Sep 2005 15:58:00 -0000
@@ -468,9 +468,6 @@
 	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);
 }
 
 
Index: insets/insetcollapsable.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v
retrieving revision 1.278
diff -u -r1.278 insetcollapsable.C
--- insets/insetcollapsable.C	15 Jul 2005 22:10:21 -0000	1.278
+++ insets/insetcollapsable.C	27 Sep 2005 15:58:05 -0000
@@ -40,9 +40,16 @@
 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 @@
 
 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::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 @@
 		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::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::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 @@
 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 @@
 
 	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 @@
 	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 @@
 			break;
 		}
 
-		switch (status_) {
+		switch (status()) {
 
 		case Collapsed:
 			//lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
Index: insets/insetcollapsable.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.h,v
retrieving revision 1.187
diff -u -r1.187 insetcollapsable.h
--- insets/insetcollapsable.h	15 Jul 2005 22:10:22 -0000	1.187
+++ insets/insetcollapsable.h	27 Sep 2005 15:58:05 -0000
@@ -69,7 +69,7 @@
 	///
 	bool inlined() const { return status_ == Inlined; }
 	///
-	CollapseStatus status() const { return status_; }
+	CollapseStatus status() const;
 	///
 	bool allowSpellCheck() const { return true; }
 	///
@@ -107,6 +107,8 @@
 	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_;
 };

Reply via email to