Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » TreeCtrl » FIX - Single Click does not open/close items
FIX - Single Click does not open/close items [message #13464] Wed, 09 January 2008 23:33 Go to next message
loki is currently offline  loki
Messages: 36
Registered: October 2007
Member
Hello,

if the TreeCtrl is scrolled to the left, the calculation for the one-click open/close goes wrong.

I think this fix it.
void TreeCtrl::DoClick(Point p, dword flags, bool down)
{
	Point org = sb;
	if(p.y + org.y > sb.GetTotal().cy)
		return;
	int i = FindLine(p.y + org.y);
	const Line& l = line[i];
	int x = levelcx + l.level * levelcx - org.x - (levelcx >> 1) /*- org.x*/;
	if(p.x > x - 6 && p.x < x + 6) {
		if(down)
			Open(l.itemi, !IsOpen(l.itemi));
	}
	else {
		if(down && IsSel(l.itemi)) {
			selclick = true;
			return;
		}
		SetFocus();
		int q = cursor;
		SetCursorLine(i, true, false, true);
		if(multiselect) {
			int id = GetCursor();
			if(flags & K_CTRL) {
				SelectOne(id, !IsSelected(id));
				anchor = cursor;
			}
			else
				if(flags & K_SHIFT)
					ShiftSelect(anchor < 0 ? cursor : anchor, cursor);
				else {
					if(selectcount) SelClear(0);
					SelectOne(id);
					anchor = cursor;
				}
		}
		if(cursor != q)
			WhenAction();
	}
}



Could it be, that withopen has no effect? In the testcase it does not work.
tree.Add(int parentid¸ const Image& img¸ Value v¸ bool withopen)


greetings
loki
Re: FIX - Single Click does not open/close items [message #13500 is a reply to message #13464] Fri, 11 January 2008 10:54 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
Nice one.

And you are correct, there was no check for withopen/canopen. I've attached a copy of TreeCtrl.cpp (modified from SVN revision 89) that includes both fixes.

My changes:
TreeCtrl::Clear() - Root node now has canopen = true by default.
TreeCtrl::Open() - Check for canopen added. Nodes can still be closed even with canopen = false.
  • Attachment: TreeCtrl.cpp
    (Size: 29.96KB, Downloaded 629 times)
Re: FIX - Single Click does not open/close items [message #13527 is a reply to message #13500] Sat, 12 January 2008 19:50 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mrjt wrote on Fri, 11 January 2008 04:54

Nice one.

And you are correct, there was no check for withopen/canopen. I've attached a copy of TreeCtrl.cpp (modified from SVN revision 89) that includes both fixes.

My changes:
TreeCtrl::Clear() - Root node now has canopen = true by default.
TreeCtrl::Open() - Check for canopen added. Nodes can still be closed even with canopen = false.


Thanks, patch applied.

Mirek
Re: FIX - Single Click does not open/close items [message #13561 is a reply to message #13527] Mon, 14 January 2008 22:51 Go to previous messageGo to next message
loki is currently offline  loki
Messages: 36
Registered: October 2007
Member
Thanks mrjt,

but in Open() we should also check for m.child.GetCount() to get it synchron with Paint()

Fix:
void TreeCtrl::Open(int id, bool open)
{
	Item& m = item[id];
	if(m.isopen != open && (m.canopen || m.child.GetCount() || !open)) {
		m.isopen = open;
		int q = GetCursor();
		while(q >= 0) {
			q = GetParent(q);
			if(q == id) {
				SetCursor(id, true, true, true);
				break;
			}
		}
		Dirty(id);
		if(open)
			WhenOpen(id);
		else
			WhenClose(id);
	}
}



In Paint:
if(m.canopen || m.child.GetCount()) {
	Image im = m.isopen ? CtrlImg::treeminus() : CtrlImg::treeplus();
	op -= im.GetSize() / 2;
	w.DrawImage(op.x, op.y, im);


greetings
loki
Re: FIX - Single Click does not open/close items [message #13564 is a reply to message #13561] Tue, 15 January 2008 00:01 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
ok.

Mirek
Re: FIX - Single Click does not open/close items [message #13583 is a reply to message #13564] Tue, 15 January 2008 15:48 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
I'm not sure about that.

The purpose of the check in Paint is to draw the +/- indicator, but adding the check to open means that the node can be opened when canopen == false if the node has children. This makes canopen redundant and seems like incorrect behaviour.

If you want consistency I would rather remove the check from Paint:
if(m.canopen) { // or possibly: && m.child.GetCount())
	Image im = m.isopen ? CtrlImg::treeminus() : CtrlImg::treeplus();
	op -= im.GetSize() / 2;
	w.DrawImage(op.x, op.y, im);

Why would you want to indicate to the user that the node can be opened when it can't actually be opened (canopen == false)?

[Updated on: Tue, 15 January 2008 15:53]

Report message to a moderator

Re: FIX - Single Click does not open/close items [message #13589 is a reply to message #13583] Tue, 15 January 2008 20:54 Go to previous messageGo to next message
loki is currently offline  loki
Messages: 36
Registered: October 2007
Member
Ok. I have corrected it to match the painting. But if the painting is wrong, my correction is also wrong... Rolling Eyes

In other words we should change the painting. I think you are right. (I had an other meaning about canopen).

1) (canopen && childcount > 0) ---> +/- is drawn.
2) (canopen && childcount <= 0) ---> +/- is not drawn.
3) (!canopen && childcount > 0) ---> +/- is drawn in disabled state (grey)
4) (!canopen && childcount <= 0) ---> +/- is not drawn.

if(m.child.GetCount()) {
	Image im;
	if(m.canopen)
		im = m.isopen ? CtrlImg::treeminus() : CtrlImg::treeplus();
	else
		im = m.isopen ? CtrlImg::treeminusgrey() : CtrlImg::treeplusgrey();
	op -= im.GetSize() / 2;
	w.DrawImage(op.x, op.y, im);
}

treeminusgrey and treeplusgrey are new. I don't know if there is a drawing function which could grey the normal ones.

Is this ok?

greetings
loki

[Updated on: Tue, 15 January 2008 21:40]

Report message to a moderator

Re: FIX - Single Click does not open/close items [message #13593 is a reply to message #13589] Wed, 16 January 2008 08:32 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, this not how it was meant Smile

"WithOpen" (and canopen) is "override" flag for nodes that have not children (yet), but are supposed to be opened anyway.

The point is that such nodes get content only after being opened (via WhenOpen Callback). See reference/TreeCtrl tree1.

Mirek
Re: FIX - Single Click does not open/close items [message #13603 is a reply to message #13464] Wed, 16 January 2008 16:27 Go to previous messageGo to next message
loki is currently offline  loki
Messages: 36
Registered: October 2007
Member
Ok. Than my first interpretation of canopen (because of withopen) was right.

But maybe we can add some new option like bool disable and bool showdisable?
This could be usefull.
Re: FIX - Single Click does not open/close items [message #13616 is a reply to message #13603] Thu, 17 January 2008 16:23 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
loki wrote on Wed, 16 January 2008 10:27

Ok. Than my first interpretation of canopen (because of withopen) was right.

But maybe we can add some new option like bool disable and bool showdisable?
This could be usefull.


Well, I usually add things when they are required by some usage scenario / application. Are you in need of them now? Wink

Mirek
Re: FIX - Single Click does not open/close items [message #13626 is a reply to message #13616] Thu, 17 January 2008 21:48 Go to previous message
loki is currently offline  loki
Messages: 36
Registered: October 2007
Member
No, I don't need it at the moment. But good to know that we can ask you if we need something.

And thanks for the tip "add things when they are required". I still have to learn lots of things.

greetings
loki
Previous Topic: How to turn of tool-tips please?
Next Topic: A [TreeCtrl] bug
Goto Forum:
  


Current Time: Thu Mar 28 14:58:43 CET 2024

Total time taken to generate the page: 0.00845 seconds