tree -is it possible to change image?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

tree -is it possible to change image?

Post by mol »

Hi!
I want to build a tree for selecting some options - like filtering in Excel 2007 - when you pressed once on item - picture changes to "selected" - second click on this item changes image to "non selected".

But - images are accessible only while definition time...
has sb. any idea to change image of item?
User avatar
giuper63
Posts: 11
Joined: Wed Oct 17, 2012 10:40 pm
DBs Used: DBF, mysql, sqlite, PostgresSQL
Location: Montecassiano
Contact:

Re: tree -is it possible to change image?

Post by giuper63 »

Hi to all,
same problem of mol!
Is there a way to change the images of a tree after it's definition?
I have found the instruction TreeItemSetImageIndex ("Tree_1", "Main", Main.Tree_1.value,{2,2} ) where I put the image of the item n. 2 to the actual item, but it not solve the problem.
I could use hidden items bat it's not the correct way.
Can someone help us?
Giuseppe
Italian developer
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: tree -is it possible to change image?

Post by edk »

Hi Giuseppe and Marek.
giuper63 wrote: Tue Apr 25, 2017 12:06 pm Is there a way to change the images of a tree after it's definition?
Here is an example:

Code: Select all


// by Andrés González López, September 2014

#include "hmg.ch"

FUNCTION Main()

   DEFINE WINDOW Form_1; 
      AT 0,0; 
      WIDTH 800; 
      HEIGHT 600; 
      NOSIZE; 
      NOMAXIMIZE;
      ON GOTFOCUS Form_1.Tree_1.SetFocus;
      MAIN
      
      ON KEY F1  OF Form_1 ACTION OnKeyFx (  2 )
      ON KEY F2  OF Form_1 ACTION OnKeyFx (  5 )
      ON KEY F3  OF Form_1 ACTION OnKeyFx (  8 )
      ON KEY F4  OF Form_1 ACTION OnKeyFx ( 12 )
      ON KEY F5  OF Form_1 ACTION OnKeyFx ( 22 )

      ON KEY F6  OF Form_1 ACTION Form_1.Tree_1.ImageIndex(Form_1.Tree_1.Value):={4 , 5}

      ON KEY F9  OF Form_1 ACTION ( Form_1.Tree_1.Value:= 1,;
                                    IF ( Form_1.Tree_1.IsExpand (Form_1.Tree_1.Value) == .T.,; 
                                         Form_1.Tree_1.Collapse (Form_1.Tree_1.Value, .T.),;   // Collapse All
                                         Form_1.Tree_1.Expand   (Form_1.Tree_1.Value, .T.)))   // Expand All

      DEFINE TREE Tree_1;
         AT 10,10; 
         WIDTH 250; 
         HEIGHT 550; 
         VALUE 1; 
         FONT "Calibri" SIZE 11; 
         ON CHANGE OnChangeTree (This.Value);
         NODEIMAGES { "folder.gif", "folder_page.gif" }; 
         ITEMIMAGES { "Page.gif",   "page_next.gif"   }; 
         NOROOTBUTTON 
         
         NODE 'MY APP '
            
            NODE 'BOOK      [F1]'
               TREEITEM 'Science'
               TREEITEM 'Literature' 
            END NODE
            
            NODE 'MUSIC     [F2]'
               TREEITEM 'Rock' 
               TREEITEM 'Classic'
            END NODE
            
            NODE 'VIDEOS    [F3]'
               TREEITEM 'Documentary' 
               TREEITEM 'Series'
               TREEITEM 'Sports'
            END NODE
            
            NODE 'EMAIL     [F4]'
               TREEITEM 'Send' 
               TREEITEM 'Inbox' 
               TREEITEM 'Outbox' 
               TREEITEM 'Drafts'
               TREEITEM 'Spam'
               TREEITEM 'Sent Items'
               NODE 'OTHER'
                  TREEITEM 'Backup'
                  TREEITEM 'Calendar'
               END NODE
            END NODE
            
            NODE 'ABOUT...  [F5]'
            END NODE
            
         END NODE
      END TREE

   Form_1.Tree_1.AddImage:="Page2.gif"
   Form_1.Tree_1.AddImage:="page_next2.gif"

   Form_1.Tree_1.Expand (1)
   Form_1.Tree_1.NodeFlag (22) := .T.
   Form_1.Tree_1.FontSize := 12 // The control must have a size greater than or equal to font size of DynamicFont so that the text does not appear cut
   Form_1.Tree_1.DynamicFont      := {|| TreeFont() }
   Form_1.Tree_1.DynamicBackColor := {|| IF (This.TreeItemValue == Form_1.Tree_1.Value, WHITE, NIL ) }
   Form_1.Tree_1.DynamicForeColor := {|| IF (This.TreeItemValue == Form_1.Tree_1.Value, BLUE,  NIL ) }

   END WINDOW

   CENTER WINDOW Form_1
   ACTIVATE WINDOW Form_1
   
Return nil



Function TreeFont
LOCAL aFont
   IF Form_1.Tree_1.NodeFlag (This.TreeItemValue) == .T.   // for default: True Node always has the NodeFlag() == .T.
      aFont := ARRAY FONT "Calibri" SIZE 12 BOLD
   ELSE
      aFont := ARRAY FONT "Calibri" SIZE 11
   ENDIF
Return aFont



FUNCTION OnKeyFx ( nItem )
   OnChangeTree( nItem )
   Form_1.Tree_1.Value:= nItem
   IF Form_1.Tree_1.IsExpand( Form_1.Tree_1.Value )
      Form_1.Tree_1.Collapse( Form_1.Tree_1.Value )
   ELSE   
      Form_1.Tree_1.Expand( Form_1.Tree_1.Value )
   ENDIF
RETURN nil


FUNCTION OnChangeTree ( nItem )
   DO CASE
      CASE nItem = 1
      CASE nItem = 2
      CASE nItem = 3
      //  CASE nOption 4 to 22  ....
   ENDCASE
   Form_1.TITLE := "#"+HB_NTOS (nItem) + " --> " + HB_VALTOEXP ( Form_1.Tree_1.GetPathName (nItem) )
RETURN nil

Tree_NodeFlag.7z
(1.13 MiB) Downloaded 208 times
You need to add new image files:
Form_1.Tree_1.AddImage:="Page2.gif" //will be No. 4
Form_1.Tree_1.AddImage:="page_next2.gif" //will be No. 5

Then assign to the item:
Form_1.Tree_1.ImageIndex(Form_1.Tree_1.Value):={4 , 5}

In example above you can change images by F6 key.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: tree -is it possible to change image?

Post by Rathinagiri »

Thanks a lot!

I think we need a sample for implementation of hImageList also.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: tree -is it possible to change image?

Post by Pablo César »

Rathinagiri wrote: Tue Apr 25, 2017 1:52 pm I think we need a sample for implementation of hImageList also.
It would be great ! :D

But I think it would nothing happen if the TREE event is malfunctioning. :?

I do not know if it happens only with me or it's a bug to recognize the "Selected item ID" (Tree Value property) at Expand and Collapse event.

When I click to "+" it opens the subitems or clicking to "-" but I can not changes the image even if the images are predefined for the item.

@ Dr. Claudio Soto:
I saw the source code and I'm confused in this:
Screen198.png
Screen198.png (131 KiB) Viewed 6304 times
I'm confused because I believe that in TVE_EXPAND and TVE_COLLAPSE events, it should update the TreeItem Value.

Would you confirm if there is any reason for that or it's was just a mistake to change the value for Nil ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
giuper63
Posts: 11
Joined: Wed Oct 17, 2012 10:40 pm
DBs Used: DBF, mysql, sqlite, PostgresSQL
Location: Montecassiano
Contact:

Re: tree -is it possible to change image?

Post by giuper63 »

Solved!
For me the problem was to understand the image system of trees.
When you define a tree you MUST give 2 images to NODEIMAGES and 2 images to ITEMIMAGES.
Now you can add more images with AddImages.
In the example of edk there are 6 images: "folder.gif", "folder_page.gif", "Page.gif", "page_next.gif" , "Page2.gif" and "page_next2.gif" in this order.
Using "Form_1.Tree_1.ImageIndex(Form_1.Tree_1.Value):={5,5}" you give the image n. 5 (Page2.gif) to the item.
Thanks to all!
Giuseppe
Italian developer
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: tree -is it possible to change image?

Post by Pablo César »

I found a bug and fully reported at: viewtopic.php?p=51101#p51101
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Post Reply