TTreeNode displaying state image on left lazarus / 31-LCL ---------------------------------------------------------------------- BenLaz · 2014-06-30 15:25 Hello, I wonder if someone knows a fast way to draw the state image on the left of the normal image in a TTreeView (without drwing it by hand). Moreover, I think that TTreeNode constructor should be virtual because when we use "CreateNodeClass" event to override the TreeNode class, we loose the possibility to override the constructor. Best regards ---------------------------------------------------------------------- JuhaManninen · 2014-06-30 18:50 Quote from: BenLaz on June 30, 2014, 05:25:28 pmI wonder if someone knows a fast way to draw the state image on the left of the normal image in a TTreeView (without drwing it by hand). The best choice may be OnAdvancedCustomDrawItem event. QuoteMoreover, I think that TTreeNode constructor should be virtual because when we use "CreateNodeClass" event to override the TreeNode class, we loose the possibility to override the constructor. True. I made it virtual in r45740. There is a small performance penalty with a virtual constructor but I don't think it mattars. TTreeView is otherwise well optimized and can contain a huge amount of nodes. ---------------------------------------------------------------------- BenLaz · 2014-07-01 06:17 Thank you very much for your answers (and for the midification). I've found in an embarcedro's documentation ( http://docwiki.embarcade ro.com/Libraries/XE3/en/Vcl.ComCtrls.TCustomTreeView.StateImages ) that in delphi the state image do apears on the left of the item icon. I don't have a delphi here to check, but i will check it today. If it's the case, i think it would be a good idea to have the same comportement ? Best regards ---------------------------------------------------------------------- taazz · 2014-07-01 06:34 Oh you are looking something like the following? Code: [Select]procedure TSnippetsMainFrm.SetNodeIcons(const aNode : TTreeNode; Recursive:Boolean=False);   procedure DoRecursive;   var     vNode   : TTreeNode;   begin     if Recursive and aNode.HasChildren then begin       vNode:= aNode.GetFirstChild;       repeat         SetNodeIcons(vNode, Recursive);         vNode := vNode.GetNextSibling;       until vNode = Nil;     end;   end; var   vHL     : TSynCustomHighlighter;   vHLData : PHighlighterData; begin   vHL     := GetHighLighter(aNode);   vHLData := HighLighterData(vHL);   if IsFile(aNode) and Assigned(vHLData) then begin   // there is not way that the vHLData will not be assigned but just in case I fucked up somewhere     aNode.ImageIndex    := vHLData^.IconIndexNormal;     aNode.SelectedIndex := vHLData^.IconIndexSelected;   end else begin     if IsFolder(aNode) then begin       aNode.ImageIndex    := idxFolderNormal;       aNode.SelectedIndex := idxFolderSelected;       //DoRecursive;     end else begin      aNode.ImageIndex    := idxSnippetNormal;      aNode.SelectedIndex := idxSnippetSelected;     end;   end; end; method copied from my librarian http://sourceforge.net/projects/codelibrarian/ just make sure that property images of the ttreeview has a valid image list that has all the icons you need to show. ---------------------------------------------------------------------- BenLaz · 2014-07-01 07:20 Thank you for your answer, but it's not really what i wxant to do. I want to do a tree with images for nodes and checkbox or radio buttons on the left, that's why i want to use either images and stateimages. But the state image is displayed on the right of the node image, not on the left as it should be. Best regards ---------------------------------------------------------------------- BenLaz · 2014-07-01 09:42 hello, I checked, and in Delphi the state image appears on the left, so i think that's a bug in TTreeView Best regards ---------------------------------------------------------------------- JuhaManninen · 2014-07-01 11:44 Quote from: BenLaz on July 01, 2014, 11:42:20 amI checked, and in Delphi the state image appears on the left, so i think that's a bug in TTreeView A bug? It sounds like a missing feature to me. You can open a report about this feature if you like. Include code that _should_ work when the feature is implemented. Preferably also include a patch that implements it. ---------------------------------------------------------------------- BenLaz · 2014-07-01 12:27 Thank you for your answer. For me it's a kind of bug because, at least in windows, the stateimages are displayed on the left (it's the default comportement for Windows TTreeView Component). I'll make a fix to swap the order between image and stateimage and submit it to the bugtracker  . best regards ---------------------------------------------------------------------- taazz · 2014-07-01 12:33 Quote from: BenLaz on July 01, 2014, 02:27:40 pmI'll make a fix to swap the order between image and stateimage and submit it to the bugtracker  . 1) try to set the image list iconwidth to a double icon size ee 32 instead of 16, make sure that you have all possible Images and states combinations use the index that describes the correct combination of state and check for each node. See if that removes the need to use the state properties. 2) why swap? if you swap then the images are going to be painted on the right and the states on the left while you want everything on the left at least I would have problems with the images painted on the right. ---------------------------------------------------------------------- BenLaz · 2014-07-01 12:42 Thank you for your answer. I think I'm not really clear in my explanations : if you provide a stateIndex and an imageIndex to a TTreeNode it will be displayed like that : [Image][State]Caption The corret order is [State][Image]Caption Best regards ---------------------------------------------------------------------- taazz · 2014-07-01 12:52 that makes sense thank you. ---------------------------------------------------------------------- JuhaManninen · 2014-07-01 13:16 Quote from: BenLaz on July 01, 2014, 02:27:40 pmFor me it's a kind of bug because, at least in windows, the stateimages are displayed on the left (it's the default comportement for Windows TTreeView Component). Right. I did not realize there already is StateImages and StateIndex. Then it can be considered as a bug. QuoteI'll make a fix to swap the order between image and stateimage and submit it to the bugtracker  . Thanks.