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
Bug changing text after node insertion [message #16834] Wed, 16 July 2008 10:33 Go to next message
cbpporter is currently offline  cbpporter
Messages: 1351
Registered: September 2007
Senior Contributor
I have an OptionTree which I need to populate with dummy nodes and then change their text at a later moment. Since I couldn't find a way to change the text directly, I used GetNode/SetNode combination. The strange part is that the OptionTree will now display both the old text and the new one. If the dummy nodes have no text, when selecting a node only the null text will be highlighted. Also, nodes select differently based on where you click: the old text or the new text.

Test case attached.

PS: Is it only me, or is gdb/gdb integration a lot stupider than with MinGW. The debugger is barely functional and very slow to start-up.
  • Attachment: Test.zip
    (Size: 1.20KB, Downloaded 227 times)
Re: Bug changing text after node insertion [message #16840 is a reply to message #16834] Wed, 16 July 2008 17:54 Go to previous messageGo to next message
masu is currently offline  masu
Messages: 378
Registered: February 2006
Senior Member
I found this solution:

#include "Test.h"

Test::Test()
{
	CtrlLayout(*this, "Window title");

	int n;
	
	n = t.Add(0, "DUMMY1");
	t.Remove(t.GetChildIndex(0, n)+1);
	t.Add(0, "real1");

	n = t.Add(0, "DUMMY2");
	t.Remove(t.GetChild(0, 1));
	t.Add(0, "real2");

	t.Open(0);
}

GUI_APP_MAIN
{
	Test().Run();
}

GetChildIndex somehow returns an id 1 less than the needed one that is why there is +1. I am not sure if this is the wanted behavior.

Matthias
Re: Bug changing text after node insertion [message #16859 is a reply to message #16840] Thu, 17 July 2008 16:43 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11822
Registered: November 2005
Ultimate Member
The problem here is that the text in Add (which is defined in OptionTree) actually sets the label of Ctrl. So in fact you should change the "ctrl" member of Node.

Anyway, to make this simpler, I have added this:

void OptionTree::SetLabel(int id, const char *text)
{
	Node n = GetNode(id);
	Option *o = dynamic_cast<Option *>(~n.ctrl);
	if(o)
		o->SetLabel(text);
	SetNode(id, n);
}


Mirek
Re: Bug changing text after node insertion [message #16860 is a reply to message #16859] Thu, 17 July 2008 17:57 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1351
Registered: September 2007
Senior Contributor
Thank you masu for investigating. Still, removing nodes and adding then is much more complicated that it should be and doesn't address the problem directly.

Mirek's function would solve the problem but from a purist point of view it doesn't make that much sense. Nodes do not logically have a label property. If we accept setting the label as a valid operation, than what is the difference between setting the label and setting the key. Are both operations defined? Can you mix them? If you mix them can you get a combination that results in two labels again? And why does adding a node behave differently than setting the node to a different value?

Shouldn't we rather add SetKey/SetValue functions, or just Set variant for both, as in Node and other cases? Anyway, which value is the key and which is the values and which is passed to Display/Converts is not too clear.

[Updated on: Thu, 17 July 2008 17:57]

Report message to a moderator

Re: Bug changing text after node insertion [message #16861 is a reply to message #16860] Thu, 17 July 2008 18:27 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11822
Registered: November 2005
Ultimate Member
cbpporter wrote on Thu, 17 July 2008 11:57

Thank you masu for investigating. Still, removing nodes and adding then is much more complicated that it should be and doesn't address the problem directly.

Mirek's function would solve the problem but from a purist point of view it doesn't make that much sense. Nodes do not logically have a label property. If we accept setting the label as a valid operation, than what is the difference between setting the label and setting the key. Are both operations defined? Can you mix them? If you mix them can you get a combination that results in two labels again? And why does adding a node behave differently than setting the node to a different value?

Shouldn't we rather add SetKey/SetValue functions, or just Set variant for both, as in Node and other cases? Anyway, which value is the key and which is the values and which is passed to Display/Converts is not too clear.


I believe "SetLabel" is perfectly logical. If you start putting widgets into tree (which is what you do when you are going to use OptionTree), you must accept the fact these widgets have some properties.

Note that OptionTree has already "Get" method to read the value of option...

Mirek
Re: Bug changing text after node insertion [message #16887 is a reply to message #16859] Sat, 19 July 2008 16:03 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1351
Registered: September 2007
Senior Contributor
Very well, I'll use something that works, rather than argue about semantics.

But SetLabel does not seem to work for me. I tried both before and after setting the key and value, and it does not set the text.

The reason is because it does not resize the child control whose label is set, so there is not enough space to display the text.

Also, setting canselect to false for a node does not allow you to select it, but it's check value can still be set.
Re: Bug changing text after node insertion [message #16888 is a reply to message #16887] Sat, 19 July 2008 19:37 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11822
Registered: November 2005
Ultimate Member
Well, I am afraid this will be more difficult to fix... Sad

Anyway, for now, what about leaving the "label" empty (in Add) and using Node to set the text?

Mirek
Re: Bug changing text after node insertion [message #16901 is a reply to message #16888] Sun, 20 July 2008 08:25 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1351
Registered: September 2007
Senior Contributor
That's exactly what I'm using right now, but it is only a temporary solution since it has some display bugs as it is.

Since the control reacts differently depending on which part you clicked (the option or outside of it), it will always highlight the empty text from the option and color the rest gray. This is not a high priority task for me to get it fixed, but it about a two weeks it would be great to have it working. I don't have time this week to look into OptionTree, but I'll try to fix it myself when I'll have time (or I really need it Smile).
Re: Bug changing text after node insertion [message #16921 is a reply to message #16901] Mon, 21 July 2008 09:12 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11822
Registered: November 2005
Ultimate Member
Well, I hope this fixes the fix:

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;
}


Mirek
Re: Bug changing text after node insertion [message #16923 is a reply to message #16921] Mon, 21 July 2008 10:23 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1351
Registered: September 2007
Senior Contributor
It is getting closer. There is still a problem as you can see in this screenshot I created. The text is diplayed once for the label and once for the key/value. It seems to display the value.

I'm using SetLabel, and also the normal Set to set key and value. I also use a modified version of Copy to repopulate another tree with the checked items of this tree.

int CopyIfSelected(TreeCtrl& dst, int did, const OptionTree& src, int id)
{
	TreeCtrl::Node x = src.GetNode(id);
	x.ctrl = NULL;
	int orig = did;
	if (src.Get(id))
		did = dst.Add(did, x);
	dst.Open(orig);
	for(int i = 0; i < src.GetChildCount(id); i++)
		CopyIfSelected(dst, did, src, src.GetChild(id, i));
	return did;
}


When I use Set, the first parameter is a struct and the second one is the string that I display. Swapping these around or leaving out the second string parameter will clear the extra text that appears in the right, but the are is still clickable, leaving a small little gray rect when clicked. I could live with that for now, but both swapping the parameters or leaving one out will render my CoyIfSelected function useless, because it will not set the text in the destination Tree.
  • Attachment: untitled5.PNG
    (Size: 11.78KB, Downloaded 225 times)
Re: Bug changing text after node insertion [message #16924 is a reply to message #16923] Mon, 21 July 2008 10:43 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11822
Registered: November 2005
Ultimate Member
cbpporter wrote on Mon, 21 July 2008 04:23

It is getting closer. There is still a problem as you can see in this screenshot I created. The text is diplayed once for the label and once for the key/value. It seems to display the value.

I'm using SetLabel, and also the normal Set to set key and value. I also use a modified version of Copy to repopulate another tree with the checked items of this tree.

int CopyIfSelected(TreeCtrl& dst, int did, const OptionTree& src, int id)
{
	TreeCtrl::Node x = src.GetNode(id);
	x.ctrl = NULL;
	int orig = did;
	if (src.Get(id))
		did = dst.Add(did, x);
	dst.Open(orig);
	for(int i = 0; i < src.GetChildCount(id); i++)
		CopyIfSelected(dst, did, src, src.GetChild(id, i));
	return did;
}


When I use Set, the first parameter is a struct and the second one is the string that I display. Swapping these around or leaving out the second string parameter will clear the extra text that appears in the right, but the are is still clickable, leaving a small little gray rect when clicked. I could live with that for now, but both swapping the parameters or leaving one out will render my CoyIfSelected function useless, because it will not set the text in the destination Tree.


I guess we will need GetLabel too....

Mirek
Re: Bug changing text after node insertion [message #16925 is a reply to message #16924] Mon, 21 July 2008 11:11 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1351
Registered: September 2007
Senior Contributor
If the double text is fixed, I think we can drop GetLabel (and maybe even SetLabel). If the value is set, TreeCtrl will still display the text.
Re: Bug changing text after node insertion [message #16926 is a reply to message #16925] Mon, 21 July 2008 11:52 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11822
Registered: November 2005
Ultimate Member
cbpporter wrote on Mon, 21 July 2008 05:11

If the double text is fixed, I think we can drop GetLabel (and maybe even SetLabel). If the value is set, TreeCtrl will still display the text.


Ehm, but it is not a double text... These are different things, the label is an attribute of widget... Widget can have more than one attributes.

OK, one possible solution would be to supress the "value" when ctrl is set for the node. OTOH I believe that current solution when both are used is in fact more general.

Mirek
Re: Bug changing text after node insertion [message #16927 is a reply to message #16926] Mon, 21 July 2008 12:36 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1351
Registered: September 2007
Senior Contributor
luzr wrote on Mon, 21 July 2008 12:52


Ehm, but it is not a double text... These are different things, the label is an attribute of widget... Widget can have more than one attributes.

OK, one possible solution would be to supress the "value" when ctrl is set for the node.
Mirek

I know that the two text are from different sources, one is the label of the Option and the other is the value painted on the control (with a huge space between then, probably because of the Width of the Option), but still by my definition if there are two text (doesn't matter why), that constitutes a double text Smile.

Yes, suppressing it and moving the region in which when you click an item it will be highlighted with a dotted rect so that it encapsulates the Option would probably work.

Quote:


OTOH I believe that current solution when both are used is in fact more general.


I'm not sure I understand. What is current solution? Or do you mean solution as in the way things work right now, not "solution to my problem".
Re: Bug changing text after node insertion [message #16928 is a reply to message #16927] Mon, 21 July 2008 12:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11822
Registered: November 2005
Ultimate Member
cbpporter wrote on Mon, 21 July 2008 06:36


I'm not sure I understand. What is current solution? Or do you mean solution as in the way things work right now, not "solution to my problem".



As things work right now.

I believe that there are many usage cases where you would like to see both the widget and the value.

Mirek
Re: Bug changing text after node insertion [message #16929 is a reply to message #16928] Mon, 21 July 2008 14:04 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1351
Registered: September 2007
Senior Contributor
So you mean that the way that screenshot looks is the intended behavior?
Re: Bug changing text after node insertion [message #16930 is a reply to message #16929] Mon, 21 July 2008 14:29 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11822
Registered: November 2005
Ultimate Member
cbpporter wrote on Mon, 21 July 2008 08:04

So you mean that the way that screenshot looks is the intended behavior?


I am not sure where that big whitespace gap came from.

But double texts are OK.

Mirek
Re: Bug changing text after node insertion [message #16932 is a reply to message #16930] Mon, 21 July 2008 14:56 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1351
Registered: September 2007
Senior Contributor
I guess we have different representations on what a tree control should do.

Maybe it would be better for me to find a different solution rather than tweak OptionTree to suit my needs, since it seems that it was built with other needs in mind.

Also, I think there is something broken with MINGW debugger. I download RC2 today and debugging doesn't work for me. It was always a little buggy under MINGW, but it was usable. But now, break points are sometimes ignored step in and over don't work at all.

[Updated on: Mon, 21 July 2008 14:56]

Report message to a moderator

Re: Bug changing text after node insertion [message #16933 is a reply to message #16932] Mon, 21 July 2008 15:47 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11822
Registered: November 2005
Ultimate Member
cbpporter wrote on Mon, 21 July 2008 08:56

I guess we have different representations on what a tree control should do.

Maybe it would be better for me to find a different solution rather than tweak OptionTree to suit my needs, since it seems that it was built with other needs in mind.



Actually, you might be right about this - since the first moment I wonder why do you need such complicated manipulation with the tree.

Usually, in cases like this, I tend to have separate data model and only dump it into the widget before user interaction is required.

Mirek
Re: Bug changing text after node insertion [message #16934 is a reply to message #16933] Mon, 21 July 2008 17:28 Go to previous messageGo to previous message
cbpporter is currently offline  cbpporter
Messages: 1351
Registered: September 2007
Senior Contributor
It's not that complicated. All I need is to populate a tree, replace the text of nodes (the text can only be determined after the structure, kind of stupid really but no easy way to change this now) and a tree with options which displays/has/can use exactly one value under these circumstances. I also need the nodes to be selectable, not just check/unchecked toggle.
Previous Topic: IsSelected(id)
Next Topic: Clear() and external controls as nodes
Goto Forum:
  


Current Time: Thu Apr 18 23:05:09 CEST 2019

Total time taken to generate the page: 0.00773 seconds