Page 3 of 3

Re: TreeItemValue bug

Posted: Fri Apr 28, 2017 8:03 pm
by Pablo César
Pablo César wrote:I am pretty sure what the user expect to be instead that
Congratulations. You have proved that You got the expected at expand/collapse event without any changing and I shame of me about persisting in something that you solved easily.

I was trying in this failed code:

Code: Select all

#include <hmg.ch>

FUNCTION Main()
PRIVATE aImageList := {}

DEFINE WINDOW Form_1 ;
	AT 0,0 ;
	WIDTH 286 ;
	HEIGHT 460 ;
	TITLE 'Tree Expand and Collapse Sample' ;
	MAIN
	
	DEFINE STATUSBAR FONT "Courier New" SIZE 10
        STATUSITEM ""
    END STATUSBAR

	DEFINE TREE Tree_1 AT 10,10 WIDTH 260 HEIGHT 400 VALUE 3 ;
	    ON CHANGE OnChangeTree(This.TreeItemValue) ;
		ON EXPAND OnExpandTree(This.TreeItemValue) ;
		ON COLLAPSE OnCollapseTree(This.TreeItemValue) ;
		NODEIMAGES { "NODE1_CL", "NODE1_OP" } ;
	    ITEMIMAGES { "PAGE_CL", "PAGE_OP" } ;
		NOROOTBUTTON 
		//ITEMIDS
		
	 	NODE 'Root' ; AADD(aImageList,0)
			TREEITEM 'Item 1.1' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,0)
			TREEITEM 'Item 1.2' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,0) 
			TREEITEM 'Item 1.3' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,0) 

			NODE 'Docs' IMAGES { "NODE1_CL", "NODE1_OP" } ; AADD(aImageList,2)
				TREEITEM 'Docs 1' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,4)
				TREEITEM 'Docs 2' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,4)
			END NODE
			
			NODE 'Folder' IMAGES { "NODE2_CL", "NODE2_OP" } ; AADD(aImageList,6)
				TREEITEM 'Folder 1' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,8)
				TREEITEM 'Folder 2' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,8)
			END NODE

			NODE 'Notes' IMAGES { "NODE3_CL", "NODE3_OP" } ; AADD(aImageList,10)
				TREEITEM 'Notes 1' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,12)
				TREEITEM 'Notes 2' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,12) 
				TREEITEM 'Notes 3' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,12) 
				TREEITEM 'Notes 4' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,12) 
				TREEITEM 'Notes 5' IMAGES { "PAGE_CL", "PAGE_OP" } ; AADD(aImageList,12) 
			END NODE

		END NODE
	END TREE

END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
RETURN Nil

FUNCTION OnChangeTree(nItem)
Form_1.StatusBar.Item(1) := AllTrim(Str(nItem))+" - On Change - "+hb_ValToExp(Form_1.Tree_1.ImageIndex(nItem))
RETURN Nil

FUNCTION OnExpandTree(nItem)
LOCAL aImageList := Form_1.Tree_1.ImageIndex(nItem)
LOCAL nPos, aNewVal := {0,1}, lIsPair := IsPair(nItem)

nPos := AScan(aImageList,nItem)
If nPos>0
   If lIsPair
      aNewVal := {nItem,nItem+1}
   Else
      aNewVal := {nItem-1,nItem}
   Endif
Endif
msgdebug(nPos,Form_1.Tree_1.ImageCount,aImageList,aImageList[nItem])

Form_1.StatusBar.Item(1) := AllTrim(Str(nItem))+" - On Expand - "+hb_ValToExp(Form_1.Tree_1.ImageIndex(nItem))
*Form_1.Tree_1.ImageIndex(nItem):={1,1}
Form_1.Tree_1.ImageIndex(nItem):=aNewVal
RETURN Nil

FUNCTION OnCollapseTree(nItem)
LOCAL aImageList := Form_1.Tree_1.ImageIndex(nItem)
LOCAL nPos, aNewVal := {0,1}, lIsPair := IsPair(nItem)

nPos := AScan(aImageList,nItem)
If nPos>0
   If lIsPair
      aNewVal := {nItem-1,nItem}
   Else
      aNewVal := {nItem,nItem-1}
   Endif
Endif
msgdebug(nPos,Form_1.Tree_1.ImageCount,aImageList,aImageList[nItem])

Form_1.StatusBar.Item(1) := AllTrim(Str(nItem))+" - On Collapse - "+hb_ValToExp(Form_1.Tree_1.ImageIndex(nItem))
*Form_1.Tree_1.ImageIndex(nItem):={0,1}
Form_1.Tree_1.ImageIndex(nItem):=aNewVal
RETURN Nil

FUNCTION IsPair(nVal)
LOCAL lRet := .F.

If (nVal-Int(nVal))=0
   lRet := .T.
Endif
RETURN lRet
But for me suprise, you got it. :shock: but I'm very happy :P too.
 
edk wrote:
Fri Apr 28, 2017 7:23 pm
Let me disagree with you.
Point me to where is the definition of tree object (+) / (-)? This is not a Node. Nodes are: 'Root', 'Docs', 'Folder', 'Notes'
(+) / (-) these are elements that have no definition, and as such values in Tree. So they are not part of a tree - in the sense that Expanded / Collapsed does not affect tree values.
They only serve to change the presentation of tree elements. And therefore they are handled separately from the rest of the tree.
It's your right to be in disagreed.

I was wrong. :oops:

I noted these _HMG_This_TreeItem_Value := NIL at h_windows.prg and I thought tremendaly wrong. But it seems not.

Sorry to cause confusion and I thank you very much your valious patient.

Re: TreeItemValue bug

Posted: Fri Apr 28, 2017 8:14 pm
by Pablo César
srvet_claudio wrote:
Thu Apr 27, 2017 11:08 pm
Is not a bug, This.TreeItemValue is only available inside some events, see the doc.
Sorry Claudio for my insistence. :oops:
You were right from the begining. It cost me a lot to understand that This.TreeItemValue is valid within events and not out.

My intention was to force this value to be seen at any moment.
But I am not understand why _HMG_This_TreeItem_Value := NIL is attribed at h_windows.prg as NIL value.

Regarding modifications at i_tree.ch in order to accept ITEMIDS clause in all 4 syntaxes as in the same way, am I correct ?

I humbly apologize for this.

Re: TreeItemValue bug

Posted: Fri Apr 28, 2017 8:24 pm
by edk
Cool that I could help.
It is important to note how Node and Item images are stored.
If they are in the definition of "main tree":
NODEIMAGES {"NODE1_CL", "NODE1_OP"};
ITEMIMAGES {"PAGE_CL", "PAGE_OP"};
Get indexes:
NODEIMAGES {0, 1};
ITEMIMAGES {2, 3};

Each next definition receives another pair of indexes:
TREEITEM 'Item 1.1' IMAGES {"PAGE_CL", "PAGE_OP"} => {4, 5}
NODE 'Folder' IMAGES {"NODE2_CL", "NODE2_OP"} => {nLastImageIndex + 1, nLastImageIndex + 2}
e.t.c.
Therefore, you should retrieve the current Node index, not just the definition of "main tree" Node ({0,1}).

I'm sorry, but English is not my native language, and sometimes it's hard for me to write correctly so that the reader understands exactly what I mean.

Edward.

Re: TreeItemValue bug

Posted: Fri Apr 28, 2017 8:49 pm
by Pablo César
Yes Edward you helped much meanly to understand more about this event and also I understood.

I will wait Dr. Claudio answer to my questions but I am still thinking that I was not so wrong.

What idea is this to change TreeItemValue value at EXPAND/COLLAPSE event ? And why attribing to NIL ?

WHY, WHY ?

Can you test my changing indications a creating another HMG version for testing proposes ?

You will see that's working in better way.

I am really suprised that TreeItemValue worked properly at EXPAND/COLLAPSE event trigging function. But I believe this happinig OK cause the attrib to NIL were not be actioned yet (in prior of running the UDF). Do you understand me ?

Re: TreeItemValue bug

Posted: Fri Apr 28, 2017 9:27 pm
by edk
Pablo César wrote:
Fri Apr 28, 2017 8:49 pm
Do you understand me ?
Yes, I understand you. But I'm always trying do not "ram through an open door".

Re: TreeItemValue bug

Posted: Fri Apr 28, 2017 11:05 pm
by srvet_claudio
Pablo César wrote:
Fri Apr 28, 2017 8:14 pm
srvet_claudio wrote:
Thu Apr 27, 2017 11:08 pm
Is not a bug, This.TreeItemValue is only available inside some events, see the doc.
Sorry Claudio for my insistence. :oops:
You were right from the begining. It cost me a lot to understand that This.TreeItemValue is valid within events and not out.

My intention was to force this value to be seen at any moment.
But I am not understand why _HMG_This_TreeItem_Value := NIL is attribed at h_windows.prg as NIL value.

Regarding modifications at i_tree.ch in order to accept ITEMIDS clause in all 4 syntaxes as in the same way, am I correct ?

I humbly apologize for this.
OK, no problem Pablo.

In regards to your question, I do not know, I would have to analyze the changes

Re: TreeItemValue bug

Posted: Fri Apr 28, 2017 11:53 pm
by Pablo César
edk wrote:
Fri Apr 28, 2017 9:27 pm
I'm always trying do not "ram through an open door"
:lol: I guess to understanding you... but not sure. Is it a idiomatic expression ?

I like to make things in right order. Sometimes I am perfectionist, sometimes I lose time in one point and never give up.

I always prefer the truth, no matter what it costs.

I am racional person and need to understand what it's wrong...

Otherwise you will see a Basque man in my DNA (hard head in my way). :D

Dr. Claudio wrote:In regards to your question, I do not know, I would have to analyze the changes
Thank you Claudio, I am feel better at knowing that you will consider my appointments.

Thanks a lot dear Claudio.

Re: TreeItemValue bug

Posted: Sat Apr 29, 2017 2:58 pm
by Pablo César
Hi all,

I am learning more about TREE, is very good control but not so easy to ride...

I am still having trouble to update node images at expand/collapse. :|

When user DoubleClick on the node invocates expand/collapse but images not changing.

I know there "another" event that it could control that: OnDblClick but I can not make working... :|
 
FYI (for your information),

The name of this (rounded in red):
Screen208.png
Screen208.png (8.79 KiB) Viewed 398 times
Is called HasButton.

And the name of this (squared in red):
Screen209.png
Screen209.png (4.09 KiB) Viewed 398 times
Is called HasLines.

I think one of the best way to understand more about TREEs is the ..\SAMPLES\Controls\Tree\TreeSortDir:
Screen210.png
Screen210.png (39.06 KiB) Viewed 398 times
Thanks to Dr. Claudio.

Re: TreeItemValue bug

Posted: Sat Apr 29, 2017 3:09 pm
by serge_girard
The best way to understand more about TREEs is the ..\SAMPLES\Controls\Tree\TreeSortDir:
That's where I got it from...

Complex material ..!

Serge