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 » Bug changing text after node insertion
Re: Bug changing text after node insertion [message #16939 is a reply to message #16924] Tue, 22 July 2008 09:32 Go to previous messageGo to next message
masu is currently offline  masu
Messages: 378
Registered: February 2006
Senior Member
luzr wrote on Mon, 21 July 2008 10:43

I guess we will need GetLabel too....

I agree, I need it and it is more consistent to have Set and Get methods.

Matthias
Re: Bug changing text after node insertion [message #16942 is a reply to message #16939] Tue, 22 July 2008 12:10 Go to previous messageGo to next message
cbpporter is currently online  cbpporter
Messages: 1353
Registered: September 2007
Senior Contributor
Ok, so there are two solutions to my problem

Solution number 1: write a new TreeCtrl that behaves the way I consider it intuitive. This is the best solution, but developing and testing a powerful TreeCtrl would take a lot of time, time which I don't have right now. I'll put it on the list of "things to do in my holiday".

Solution number 2: try and use what there is.

I created a separate data model to hold the tree, and now I don't have to do all that manual node handling because I populate the tree with a four line recursive function.

I do need GetLabel and since Matthias also needs it, we should add something like this:
String OptionTree::GetLabel(int id) const
{
	Node n = GetNode(id);
	Option *o = dynamic_cast<Option *>(~n.ctrl);
	if(o)
		return o->GetLabel();
	
	return "";
}

For this to work, GetLabel must be added to Pusher also, class which strangely does not have this method.

Now all works pretty much as expected. All I need to do is make the control select the item that is clicked upon. Any suggestions how to do this with OptionTree?
Re: Bug changing text after node insertion [message #16947 is a reply to message #16942] Tue, 22 July 2008 15:56 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
cbpporter wrote on Tue, 22 July 2008 11:10

Now all works pretty much as expected. All I need to do is make the control select the item that is clicked upon. Any suggestions how to do this with OptionTree?

I must admit to not being able to follow this thread or work out exactly what it is you are trying to do Smile

However, I believe you can achieve the above like this (as long as you are using "" labels for the Options and setting the text with node values):
// Add a callback to the Option (must be added not to break SetOption)
tree.GetNode(nodeid).ctrl->WhenAction << THISBACK(OptionClick);

// Callback function
// Fake left click as if the option wasn't there
void OptionClick()
{
	dword flags = GetMouseFlags();
	Point p = tree.GetMouseViewPos();
	tree.LeftDown(p, flags);
	tree.LeftUp(p, flags);
}

The only other thing is that there seems to be a bug with MultSelect + Ctrls. To get selection working correctly with the Ctrl key I had to modify ChildGotFocus to stop it clearing the selection constantly.
void TreeCtrl::ChildGotFocus()
{
	if (multiselect) return; // Don't clear multi-selection!
	for(int i = 0; i < line.GetCount(); i++) {
		Item& m = item[line[i].itemi];
		if(m.ctrl && m.ctrl->HasFocusDeep()) {
			SetCursorLine(i);
			return;
		}
	}
}
but you could equally do this by using a sub-class of OptionTree with an empty ChildGotFocus function.
Re: Bug changing text after node insertion [message #16954 is a reply to message #16942] Wed, 23 July 2008 10:10 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11825
Registered: November 2005
Ultimate Member
cbpporter wrote on Tue, 22 July 2008 06:10


Now all works pretty much as expected. All I need to do is make the control select the item that is clicked upon. Any suggestions how to do this with OptionTree?


Well, this is deep trouble... Either you can have Option to respond to mouse or TreeCtrl to respond.

Partial solution is to not use Option's Label (leave it empty) and put its text to Node's Value (haha, back at it again Smile. Then clicking the option box will toggle the option, clicking the text will do selections.

Other possibility is to use create your own Option and somewhat connect clicks to Option's text to TreeCtrl selection. Then use plain TreeCtrl with this new creation.

Mirek

P.S.: Added GetLabel, in this simple form:
TreeCtrl::
	String GetLabel(int id) const                   { return option[id]->GetLabel(); }


and GetLabel to Pusher as well (being there, GetFont too...)

[Updated on: Wed, 23 July 2008 10:16]

Report message to a moderator

Re: Bug changing text after node insertion [message #16955 is a reply to message #16947] Wed, 23 July 2008 10:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11825
Registered: November 2005
Ultimate Member
mrjt wrote on Tue, 22 July 2008 09:56


void TreeCtrl::ChildGotFocus()
{
	if (multiselect) return; // Don't clear multi-selection!
	for(int i = 0; i < line.GetCount(); i++) {
		Item& m = item[line[i].itemi];
		if(m.ctrl && m.ctrl->HasFocusDeep()) {
			SetCursorLine(i);
			return;
		}
	}
}
but you could equally do this by using a sub-class of OptionTree with an empty ChildGotFocus function.


I am afraid this might not be consistent with interface behaviour e.g. in case there are EditFields in the TreeCtrl...

What makes me wonder, BTW, is how the Option gets the focus?!

Mirek
Re: Bug changing text after node insertion [message #16958 is a reply to message #16954] Wed, 23 July 2008 10:53 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
luzr wrote on Wed, 23 July 2008 09:10


Partial solution is to not use Option's Label (leave it empty) and put its text to Node's Value (haha, back at it again Smile. Then clicking the option box will toggle the option, clicking the text will do selections.

You have to do it like this anyway, otherwise the Option obscures the highlight rect.

Quote:

I am afraid this might not be consistent with interface behaviour e.g. in case there are EditFields in the TreeCtrl...

To be honest I think it makes as much sense as anything else in that situation, and it will only change behaviour when using multiselect and ctrls.

The existing way, where the current selection is cleared whenever a ctrl gets focus is broken. For instance, currently the selection is cleared if focus changes to another window then back again.
Quote:


What makes me wonder, BTW, is how the Option gets the focus?!

The sequence is:
LeftDown
DoClick
SetCursorLine
SetWantFocus on the ctrl
ChildGotFocus
SetCursorLine
SelectOne (obviously clears any other selected items)

Perhaps a better solution would be to stop the first CursorLine being called when using CTRL-key and multiselect, but the behaviour is definitely wrong.
Re: Bug changing text after node insertion [message #16963 is a reply to message #16958] Wed, 23 July 2008 13:45 Go to previous messageGo to next message
cbpporter is currently online  cbpporter
Messages: 1353
Registered: September 2007
Senior Contributor
Well mrjt solution works as he said it would. Thank you! I don't need multiselect, so I guess we can leave ChildGotFocus as is.

I actually need the option to change it's checked status only when I click the small rectangle to the left, not the entire region of the control.

Quote:

Partial solution is to not use Option's Label (leave it empty) and put its text to Node's Value (haha, back at it again . Then clicking the option box will toggle the option, clicking the text will do selections.

I'm not going back to that again Smile.

I'll leave it as it is for now, because there are other strange behaviors that I didn't find a reason for yet. Getting the changed checked status of a item in the OptionTree that is not checked doesn't seem to work only after it has been changed. I'll investigate these and if they'll look like a bug, I'll post about them. I hope they are just some mistake of mine.
Re: Bug changing text after node insertion [message #16969 is a reply to message #16958] Wed, 23 July 2008 22:03 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11825
Registered: November 2005
Ultimate Member
BTW, perhaps just another solution would be to have kind of Option that manages all selections itself...

However, I guess we need some refactoring in TreeCtrl to solve these issues...

Mirek
Re: Bug changing text after node insertion [message #17006 is a reply to message #16963] Thu, 24 July 2008 22:44 Go to previous messageGo to next message
cbpporter is currently online  cbpporter
Messages: 1353
Registered: September 2007
Senior Contributor
cbpporter wrote on Wed, 23 July 2008 14:45


I'll leave it as it is for now, because there are other strange behaviors that I didn't find a reason for yet. Getting the changed checked status of a item in the OptionTree that is not checked doesn't seem to work only after it has been changed. I'll investigate these and if they'll look like a bug, I'll post about them. I hope they are just some mistake of mine.

False alarm, it was my fault. My old friend: initialized class members... I wish C++ would warn me about this one. Or maybe we could add it later to the new C++ parser.

cbpporter wrote on Wed, 23 July 2008 14:45


I'm not going back to that again Smile.


Well I did and after a lot of work I pretty much got what I wanted. There are still some display issues, like strange background color and unaligned focus rect, but I can fix those. Still, this is almost the most (unnecessarily) complicated part of the whole program Sad.

But for it to work as expected, one of the previous fixes must be reverted:
TreeCtrl::Node::Node(const Image& img, Ctrl& ctrl, int cx, int cy)
{
	Init();
	SetCtrl(ctrl);
	image = img;
	size = Null;
	if(cx > 0)
		size.cx = cx;
	if(cy > 0)
		size.cy = cy;
}

With this fix, there is that huge cap between Option (which now has no text) and text displayed by tree. If we undo it, they will be side by side again.
Re: Bug changing text after node insertion [message #19010 is a reply to message #17006] Wed, 05 November 2008 10:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11825
Registered: November 2005
Ultimate Member
cbpporter wrote on Thu, 24 July 2008 16:44


False alarm, it was my fault. My old friend: initialized class members...



Hehe, I always do the same mistake too.

In fact, I really would not be sorry if C++ default initialized to 0...

Quote:


TreeCtrl::Node::Node(const Image& img, Ctrl& ctrl, int cx, int cy)
{
	Init();
	SetCtrl(ctrl);
	image = img;
	size = Null;
	if(cx > 0)
		size.cx = cx;
	if(cy > 0)
		size.cy = cy;
}


If we undo it, they will be side by side again.



Ehm, and what is the correct version then? Smile

Mirek
Re: Bug changing text after node insertion [message #19014 is a reply to message #19010] Wed, 05 November 2008 20:43 Go to previous messageGo to next message
cbpporter is currently online  cbpporter
Messages: 1353
Registered: September 2007
Senior Contributor
Quote:


Ehm, and what is the correct version then? Smile
Mirek


TreeCtrl::Node::Node(const Image& img, Ctrl& ctrl, int cx, int cy)
{
	Init();
	SetCtrl(ctrl);
	image = img;
	size = ctrl.GetMinSize();
	if(cx > 0)
		size.cx = cx;
	if(cy > 0)
		size.cy = cy;
}



I must say, I'm completelly confused. I've given up on this issue being fixed. Yet you brought it up after 3 months. Do you have some kind of special stack to handle issues or something?
Re: Bug changing text after node insertion [message #19159 is a reply to message #19014] Sat, 15 November 2008 20:42 Go to previous messageGo to next message
cbpporter is currently online  cbpporter
Messages: 1353
Registered: September 2007
Senior Contributor
Could you please confirm if it is OK to apply this patch? If not, I'll just modify it locally. It's not like I don't have about 20 minor modifications that I must apply to 2008.1 to get my apps to either compile or work correctly Smile. They don't compile under Linux Razz.
Re: Bug changing text after node insertion [message #19371 is a reply to message #19014] Sat, 29 November 2008 13:17 Go to previous message
mirek is currently offline  mirek
Messages: 11825
Registered: November 2005
Ultimate Member
cbpporter wrote on Wed, 05 November 2008 14:43

I must say, I'm completelly confused. I've given up on this issue being fixed. Yet you brought it up after 3 months. Do you have some kind of special stack to handle issues or something?


I am sorry, I guess I just clicked wrong topic, have not checked the date of post, then was confused with the patch...

Well, just to be sure: TreeCtrl in svn is OK now?

Mirek
Previous Topic: IsSelected(id)
Next Topic: Clear() and external controls as nodes
Goto Forum:
  


Current Time: Fri Apr 19 12:54:59 CEST 2019

Total time taken to generate the page: 0.00860 seconds