Simple PropertyGrid

Share your advanced PureBasic knowledge/code with the community.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Simple PropertyGrid

Post by Andre »

@Guimauve: thanks a lot for your latest code! :D

I'm currently trying, if it makes sense to use it in my application. This way I came across a question: are the currently supported gadget types the only ones, which are usually included in the properties section?
Or would it be also (easily) possible to support further gadget types?

I have added a procedure for adding a listicon to a properties section. This is easy enough to do, but the problem is: it's also displayed only with "one line" (= the same gadget height than the other ones), but it should be displayed with an adjustable height (at least several the height of one current gadget).

Can this be done with the current code, or does it need a complete rework to support this?

This is what I've added at the moment:

1) Function for adding a listicon:

Code: Select all

Procedure AddPropertyGridListIconGadget(PropertyGridID, SectionNo, Description.s = "", Title.s = "", TitleWidth = 100, Flags = 0)
  
  *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
  
  If *PropertyGridDataA <> #Null
    
    If SectionNo >= 0 And SectionNo <= ListPropertyGridDataItemsSize(*PropertyGridDataA) - 1
      
      If SelectPropertyGridDataItemsElement(*PropertyGridDataA, SectionNo)
        AddPropertyGridItemSubItemsElement(GetPropertyGridDataItems(*PropertyGridDataA))
        OpenGadgetList(PropertyGridID)
        SetPropertyGridSubItemDescriptionGadget(GetPropertyGridItemSubItems(GetPropertyGridDataItems(*PropertyGridDataA)), StringGadget(#PB_Any, 0, 0, 0, 0, Description, #PB_String_ReadOnly))
        SetPropertyGridSubItemItemGadget(GetPropertyGridItemSubItems(GetPropertyGridDataItems(*PropertyGridDataA)), ListIconGadget(#PB_Any, 0, 0, 0, 100, Title, TitleWidth, Flags))   ; <= height of 100 is ignored by the properties section!
        CloseGadgetList()
      EndIf
      
    EndIf    
    
    Private_Update_PropertyGrid(PropertyGridID)
    
  EndIf
  
EndProcedure
2) Extension of the example code:

Code: Select all

 ....
      AddPropertyGridProgressBarGadget(#PropertyGrid, SectionID, "ProgressBar")
      AddPropertyGridListIconGadget(#PropertyGrid, SectionID, "ListIcon", "Column 1")
      
      SetPropertyGridSectionItemGadgetState(#PropertyGrid, SectionID, 0, 1)
      
      ; Add items to the combobox (GadgetID = 2):
      AddPropertyGridGadgetItems(#PropertyGrid, SectionID, 2, 0, "ComboBox Item 0")
      AddPropertyGridGadgetItems(#PropertyGrid, SectionID, 2, 1, "ComboBox Item 1")
      AddPropertyGridGadgetItems(#PropertyGrid, SectionID, 2, 2, "ComboBox Item 2")
      AddPropertyGridGadgetItems(#PropertyGrid, SectionID, 2, 3, "ComboBox Item 3")
      
      ; Add items to the listicon (GadgetID = 7):
      AddPropertyGridGadgetItems(#PropertyGrid, SectionID, 7, 0, "ListIcon Item 0")
      AddPropertyGridGadgetItems(#PropertyGrid, SectionID, 7, 1, "ListIcon Item 1")
      AddPropertyGridGadgetItems(#PropertyGrid, SectionID, 7, 2, "ListIcon Item 2")
  .....
Thanks a lot for your help!
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: Simple PropertyGrid

Post by Guimauve »

@Andre

First, sorry for the delay, I'm very busy right now. But about your question, for the moment it's impossible to add all possible gadget because they are more larger to be useful such as ListIconGadget(), ImageGadget(), PanelGadget() and so on.

Unfortunately, the original code to locate gadgets vertically are not very clear but the most important point it use a constant gadget height. It's possible to bypass this by setting the "Item" gadget height as parameter with default constant value then use GadgetHeight() + Gadget Gap constant (3 pixels or something) to calculate the vertical positions for all "Items". This way if some one want to override the default height, you just have to set the value you want.

I will try to implement this and maybe release a new version this week-end (probably Sunday November 25th).

Best regards
Guimauve
Dear Optimist, Pessimist,
and Realist,

While you guys were
busy arguing about the
glass of water, I DRANK IT !

Sincerely,
the Opportunist
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Simple PropertyGrid

Post by Andre »

Thanks, Guimauve, for your clarification! :-)

And even better, if you can provide a solution.

I was also interested in your opinion (yours, Guimauve, but also from other guys) about the use of the PropertyGrid. If you would say, it's thought only for preferences and similar stuff, it would be also ok for me.

Then I have to found an own solution for my GeoWorld project. But I just found the way a property grid work also very useful to present informations in a very good way: the user will get a overview (in my case informations about also administrative levels of a country), and when pressing the [+] sign, he will get further informations (in my case a listicon with all items of the choosen administrative level).
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: Simple PropertyGrid

Post by Guimauve »

Hello everyone,

OK it's done ! It's now possible to set the sub items gadget height. Unfortunately, the source code is to long to be posted on the forum (60 000 characters limits)
So it can be downloaded here : http://pages.videotron.com/gsaumure/fil ... Gadget.zip

As always, have fun !

Best regards
Guimauve
Dear Optimist, Pessimist,
and Realist,

While you guys were
busy arguing about the
glass of water, I DRANK IT !

Sincerely,
the Opportunist
nospam
Enthusiast
Enthusiast
Posts: 130
Joined: Mon Nov 12, 2012 9:15 am

Re: Simple PropertyGrid

Post by nospam »

Guimauve wrote:OK it's done !
Excellent work! Very nice, and thank you.

I have a question. Is there a way to label the TrackBar and ProgressBar so that their values are visible? Unlike with the SpinGadget, there seems to be no way to display their value within the PropertGrid, so I wonder about their usefulness.

Anyway, that aside, thanks again. It looks great.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Simple PropertyGrid

Post by Andre »

Thanks a lot, Guimauve, for this newest update! :D
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Simple PropertyGrid

Post by Andre »

While adapting the new PropertyGrid code by Guimauve to my needs I came to further "feature requests":

1) From the procedure declaration of AddPropertyGridListIconGadget():

Code: Select all

        SetPropertyGridSubItemDescriptionGadget(GetPropertyGridItemSubItems(GetPropertyGridDataItems(*PropertyGridDataA)), StringGadget(#PB_Any, 0, 0, 0, 0, Description, #PB_String_ReadOnly)) 
        SetPropertyGridSubItemItemGadget(GetPropertyGridItemSubItems(GetPropertyGridDataItems(*PropertyGridDataA)), ListIconGadget(#PB_Any, 0, 0, 0, 0, Title, TitleWidth, Flags))   ; <= height of 100 is ignored by the properties section! 
I would like to work with GadgetID's returned by the StringGadget and ListIconGadget definitions as well. Could you provide an example to do this / extend the code to return such values?
I need to check for events (mouse-click in the listicon...) later and need to store the GadgetID given by #PB_Any this way.

2) I would like to ask for another procedure giving the possibility to store further values with the ListIconGadget like I would normally do with the SetGadgetItemData(ListIcon, Position, Value) command. Of course it should be possible to do a GetGadgetItemData() too.

Sorry to ask for further assistance. Your code just look a bit too complicated for me, to simply extend it myself... :oops:
Thanks in advance! :)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: Simple PropertyGrid

Post by Guimauve »

Hello again,

@Andre

The following GetPropertyGridSectionDescriptionGadgetHandle() will always return the Description Gadget Handle then the GetPropertyGridSectionItemGadgetHandleEx() will always return Item Gadget Handle.

Code: Select all

Procedure GetPropertyGridSectionDescriptionGadgetHandle(PropertyGridID, SectionNo, ItemNo) 
  
  *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID) 
  
  If *PropertyGridDataA <> #Null 
    
    If SectionNo >= 0 And SectionNo <= ListPropertyGridDataItemsSize(*PropertyGridDataA) - 1 
      
      If SelectPropertyGridDataItemsElement(*PropertyGridDataA, SectionNo) 
        
        If ItemNo >= 0 And ItemNo <= ListPropertyGridItemSubItemsSize(GetPropertyGridDataItems(*PropertyGridDataA)) - 1 
          
          If SelectPropertyGridItemSubItemsElement(GetPropertyGridDataItems(*PropertyGridDataA), ItemNo) 
            
            If IsGadget(GetPropertyGridSubItemDescriptionGadget(GetPropertyGridItemSubItems(GetPropertyGridDataItems(*PropertyGridDataA)))) 
              ProcedureReturn GetPropertyGridSubItemDescriptionGadget(GetPropertyGridItemSubItems(GetPropertyGridDataItems(*PropertyGridDataA))) 
            Else 
              ProcedureReturn -1 
            EndIf 
            
          EndIf 
          
        EndIf 
        
      EndIf 
      
    EndIf 
    
  EndIf 
  
EndProcedure 

Procedure GetPropertyGridSectionItemGadgetHandleEx(PropertyGridID, SectionNo, ItemNo) 
  
  *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID) 
  
  If *PropertyGridDataA <> #Null 
    
    If SectionNo >= 0 And SectionNo <= ListPropertyGridDataItemsSize(*PropertyGridDataA) - 1 
      
      If SelectPropertyGridDataItemsElement(*PropertyGridDataA, SectionNo) 
        
        If ItemNo >= 0 And ItemNo <= ListPropertyGridItemSubItemsSize(GetPropertyGridDataItems(*PropertyGridDataA)) - 1 
          
          If SelectPropertyGridItemSubItemsElement(GetPropertyGridDataItems(*PropertyGridDataA), ItemNo) 
            
            If IsGadget(GetPropertyGridSubItemItemGadget(GetPropertyGridItemSubItems(GetPropertyGridDataItems(*PropertyGridDataA)))) 
              ProcedureReturn GetPropertyGridSubItemItemGadget(GetPropertyGridItemSubItems(GetPropertyGridDataItems(*PropertyGridDataA))) 
            Else 
              ProcedureReturn -1 
            EndIf 
            
          EndIf 
          
        EndIf 
        
      EndIf 
      
    EndIf 
    
  EndIf 
  
EndProcedure
Best regards
Guimauve
Dear Optimist, Pessimist,
and Realist,

While you guys were
busy arguing about the
glass of water, I DRANK IT !

Sincerely,
the Opportunist
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Simple PropertyGrid

Post by Andre »

Thanks again, Guimauve!

I'm currently trying to implement the PropertyGrid framework into my project, which has it's own event handling routine for all the #PB_Any created gadgets, for which the GadgetID's and further informations are stored in a linkedlist for later reference.

So it's a bit complicated to use the separate PropertyGrid functions, which are creating several further gadgets (the main ScrollArea, the [+] image button, etc....) using #PB_Any, but for which I don't know the GadgetID.
I would probably need more help with further Getxxx() function, e.g. to get the GadgetID for further gadgets like the ones mentioned above.

Or maybe it's a better idea - than many such Getxxx() functions - to change all the gadget creation routines in a way Danilo originally did it:

Code: Select all

Procedure AddHyperLinkGadget(PropertyGridGadget,section,Description.s,Text$,Color,flags=0)
    If __SetSection(PropertyGridGadget,section)
        gadget = HyperLinkGadget(#PB_Any,0,0,0,0,Text$,Color,flags)          ; <= gadget creation using #PB_Any and storing the return value
        If __AddSectionItem(PropertyGridGadget,section,Description,gadget)
            ProcedureReturn gadget    ; return the GadgetID of the sucessful created gadget
        EndIf
    EndIf
EndProcedure
Then (because of the known GadgetID) it's probably easier possible to "simply" use the standard PB functions...

Beside of that it would be even better, if we could have a code example showing the use of #PB_Any with PropertyGrid creation, as I can't use a fixed GadgetID number like the #PropertyGrid constant in the current example, because the user of my applications is able to open several windows each containing a PropertyGrid. That's why I need to do all stuff with #PB_Any, store the returned GadgetID's, etc....

That's why I'm also not able to simply use this 'Default' part of the event routine:

Code: Select all

            Default 
              CheckPropertyGridSectionClick(#PropertyGrid) 
Better would be, if I would know about the GadgetID's [+], which could be clicked by the user...

Beside that GadgetID stuff, I have another "feature request":

If I give Description = "" as parameter for gadget creation etc. in AddPropertyGridListIconGadget() function, than no StringGadget (for description) should be created, instead of that the requested gadget type (here the listicon) should use the full available width of the ScrollArea.
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: Simple PropertyGrid

Post by Guimauve »

Hello everyone,

1st : When I have re-created this lib I have remove the possibility to obtain the Gadget Handle on creation because in all of my programs I have 3 procedures like this :

Code: Select all

InitializeMyProgram(MyProgram.MyProgram)
OpenMyProgramWindow(MyProgram)
MyProgramEventManager(MyProgram)
But the only way to be able to use the GadgetHandle created by OpenMyProgramWindow() it's to use Global variables. Unfortunately, the use of Global variables are highly forbidden. But as I can see, it's not a good thing to do this for everyone. It's now 23h45 and I will go to the bed in few minutes. But tomorrow, I will add one of these code snippet to each Gadget creation commands :

Code: Select all

If IsGadget(GetPropertyGridSubItemDescriptionGadget(GetPropertyGridItemSubItems(GetPropertyGridDataItems(*PropertyGridDataA))))
  ProcedureReturn GetPropertyGridSubItemDescriptionGadget(GetPropertyGridItemSubItems(GetPropertyGridDataItems(*PropertyGridDataA)))
Else
  ProcedureReturn -1
EndIf

Code: Select all

If IsGadget(GetPropertyGridSubItemItemGadget(GetPropertyGridItemSubItems(GetPropertyGridDataItems(*PropertyGridDataA))))
  ProcedureReturn GetPropertyGridSubItemItemGadget(GetPropertyGridItemSubItems(GetPropertyGridDataItems(*PropertyGridDataA)))
Else
  ProcedureReturn -1
EndIf
This way you will be able to interact with all created gadget. But this will very different form what I have in mind about the PropertyGridGadget() should work. In my point of view the access of the PropertyGridGadget() items should work like the PanelGadget(). For example, when you use the PanelGadget() you can't get the "Panel Tab Handle" right. This why I have removed the ProcedureReturn with Gadget Handle to all Gadget creation command and I have created command to retrieve this handle using SectionID and SectionItemID.

2nd : About the ListIcon creation, I'm not sure about what you what ? If I'm understand correctly when you call :

Code: Select all

AddPropertyGridListIconGadget(PropertyGridID, 0, "", "My title") 
There is not "Description" Gadget then when you call it like :

Code: Select all

AddPropertyGridListIconGadget(PropertyGridID, 0, "Description", "My title") 
You want to have one ?

If so it will be a real nightmare to implement specially if someone use a remote procedure to set all text using a remote procedure to put GUI texts in one shot. In this case if he want to have a description gadget created, he will have to put a dummy text (aka : "DUMMY TEXT") for description on creation then set the correct text later. I have consider this during my re-design of the lib but I have throw away this idea because in my point of view it look like a real mess but it's possible to do it.

Best regards
Guimauve
Dear Optimist, Pessimist,
and Realist,

While you guys were
busy arguing about the
glass of water, I DRANK IT !

Sincerely,
the Opportunist
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Simple PropertyGrid

Post by Andre »

Hi Guimauve,

thanks again for your very fast and helpful answers!

About the 1st point:
I understand your point of view, why you have created it like it is. That's my problem of course - it's just because I try to implement the PropertyGridGadget into my existing project (>30,000 lines) with it's own gadget and event handling, all based of creating the gadgets with #PB_Any and storing the returned GadgetID's for all further functions.
Maybe this is also caused by the different type of projects you and I create... for you it's probably enough to work with fixed gadget numbers, while in my GeoWorld application it's possible to open the same window (with different informations, e.g. about different countries) several times. That's why I do all window and gadget creation with #PB_Any.

Any further addition, like your planned possibility to return the GadgetID for each created gadget, would help me a lot! :D


About the 2nd:
Yes, you're right with the suggestion. But I already used an empty string as 'description parameter' of AddPropertyGridListIconGadget(), but a description stringgadget is still created and displayed. See the following snippet from my code:

Code: Select all

           gad = PropertyGridGadget(#PB_Any, 10, y, containerwidth - 10, 400)
           Debug "GadgetID of the PropertyGadget (ScrollArea) = " + Str(gad)
           GadgetList_Add(gad, CountryInfoWin, #EvType_CountryInfoWin_AdminDivPropertyGrid)
           
           ; The returned 'gad' value identifies the created ScrollArea, and will be used as parameter for the further functions now:
           AddPropertyGridSection(gad, a$)
           AddPropertyGridListIconGadget(gad, 0, "", "Dummy", containerwidth-50, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
And now see the related screenshot, where the (empty) description field is left beside the listicon:
Image

That's why I made a "feature request" - but as it's already implemented, there seems to be a "bug". Or do I something wrong?


3rd point - a new question:
Just to be sure - does the FreePropertyGridGadget() procedure really free all gadgets in the PropertyGrid and release the reserved memory, even if #PB_Any is used for all gadget creations?
(I think so, as the used ScrollArea should like a Container, for which the manual states, that the gadget itself and it's gadgetlist will be freed.)

Thanks a lot for your effort!
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: Simple PropertyGrid

Post by Guimauve »

Hello everyone,

Sorry for the delay, but I have finally be able to update my code. Now all AddPropertyGrid_xxxxxx_Gadget() return the Item Gadget Handle or the Description Gadget Handle.

the now source code can be downloaded here : http://pages.videotron.com/gsaumure/fil ... Gadget.zip

Best regards
Guimauve
Dear Optimist, Pessimist,
and Realist,

While you guys were
busy arguing about the
glass of water, I DRANK IT !

Sincerely,
the Opportunist
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Simple PropertyGrid

Post by Andre »

Hi Guimauve,

thank you for your further additions, with which I can now easily have the GadgetID's of the created gadgets.

Would be nice if I would also be able to get the GadgetID of the ImageGadget with the [-/+] button, to explicitly react on this one, instead of having to use the 'Default' part in the Gadget event-handling routine.

Creating a listicon with AddPropertyGridListIconGadget() and an empty 'decription' parameter causes now, that only the listicon and no stringgadget will be created. But there still could be something improved/corrected, when giving "" as description parameter:
- given height of the listicon is now ignored -> only "1 line height" for the listicon, which is not usable...
- the listicon should now use the full width of the PropertyGridSection, if there is no description stringgadget

Beside that I suggest to support 'EnableExplicit' in your source (which I do use in my project, and others should do the same...).
To support this I've added

Code: Select all

;- EXAMPLE
  Define SectionID, EventID, ListIcon, EventGadget
before the example code starts, and I've added

Code: Select all

  Protected *PropertyGridDataA.PropertyGridData
in each procedure, where needed (plus some other gadgets, if needed too).

As I've read, that for speed issues the 'integer' variable type should be used, I've cutted each .b or .l used for some of the variables in the functions (which causes the compiler to use the standard variable type integer...). Maybe that's also a (minor) issue, which you can think about.

Btw. - did you see my question about the FreePropertyGridGadget() function in my last post?

Thanks again!
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: Simple PropertyGrid

Post by Guimauve »

Hello Andre,

I have many real life issue right now, I have updated my code to help to continue your project. So for the FreePropertyGridGadget() instruction

Code: Select all

Procedure FreePropertyGridGadget(PropertyGridID)
  
  *PropertyGridDataA.PropertyGridData = GetGadgetData(PropertyGridID)
  
  If *PropertyGridDataA <> #Null
    ResetPropertyGridData(*PropertyGridDataA)
    FreeMemory(*PropertyGridDataA)
    FreeGadget(PropertyGridID)
  EndIf
  
EndProcedure
The ResetPropertyGridData() macro is "called", so let's see the code inside of this "Instruction"

Code: Select all

Macro ResetPropertyGridData(PropertyGridDataA)
 
  SetPropertyGridDataItemHeight(PropertyGridDataA, 0)
  
  If IsFont(GetPropertyGridDataFont(PropertyGridDataA))
    FreeFont(GetPropertyGridDataFont(PropertyGridDataA))
    SetPropertyGridDataFont(PropertyGridDataA, 0)
  EndIf
    
  SetPropertyGridDataBackColor(PropertyGridDataA, 0)
  SetPropertyGridDataFrontColor(PropertyGridDataA, 0)
 
  ForEach GetPropertyGridDataItems(PropertyGridDataA)
    ResetPropertyGridItem(GetPropertyGridDataItems(PropertyGridDataA))
  Next
  
  ClearPropertyGridDataItemsList(PropertyGridDataA)
  
  ClearStructure(PropertyGridDataA, PropertyGridData)
  InitializeStructure(PropertyGridDataA, PropertyGridData)

EndMacro
As we can see all basic field are set to 0, we perform a FreeFont() then we call ResetPropertyGridItem() "Instruction" on each items. Again let's see the code inside of this "Instruction"

Code: Select all

Macro ResetPropertyGridItem(PropertyGridItemA)
  
  If IsGadget(GetPropertyGridItemSectionDescriptionGadget(PropertyGridItemA))
    FreeGadget(GetPropertyGridItemSectionDescriptionGadget(PropertyGridItemA))
    SetPropertyGridItemSectionDescriptionGadget(PropertyGridItemA, 0)
  EndIf
  
  If IsGadget(GetPropertyGridItemSectionButtonGadget(PropertyGridItemA))
    FreeGadget(GetPropertyGridItemSectionButtonGadget(PropertyGridItemA))
    SetPropertyGridItemSectionButtonGadget(PropertyGridItemA, 0)
  EndIf
  
  SetPropertyGridItemIsSection(PropertyGridItemA, 0)
  SetPropertyGridItemOpened(PropertyGridItemA, 0)
  
  ForEach GetPropertyGridItemSubItems(PropertyGridItemA)
    ResetPropertyGridSubItem(GetPropertyGridItemSubItems(PropertyGridItemA))
  Next
  
  ClearPropertyGridItemSubItemsList(PropertyGridItemA)
  
  ClearStructure(PropertyGridItemA, PropertyGridItem)
  InitializeStructure(PropertyGridItemA, PropertyGridItem)
  
EndMacro
As we can see, the [+/-] button and Section name gadgets are released and then the ResetPropertyGridSubItem() "instruction" is called for all SubItems. And finally

Code: Select all

Macro ResetPropertyGridSubItem(PropertyGridSubItemA)
  
  If IsGadget(GetPropertyGridSubItemDescriptionGadget(PropertyGridSubItemA))
    FreeGadget(GetPropertyGridSubItemDescriptionGadget(PropertyGridSubItemA))
    SetPropertyGridSubItemDescriptionGadget(PropertyGridSubItemA, 0)
  EndIf
  
  If IsGadget(GetPropertyGridSubItemItemGadget(PropertyGridSubItemA))
    FreeGadget(GetPropertyGridSubItemItemGadget(PropertyGridSubItemA))
    SetPropertyGridSubItemItemGadget(PropertyGridSubItemA, 0)
    SetPropertyGridSubItemItemGadgetHeight(PropertyGridSubItemA, 0)
  EndIf
  
EndMacro
So when FreePropertyGridGadget() is called all created gadget are Free from the parent window gadget list. All elements in interleaved Linked list inside the PropertyGridData structure field are carefully reset to 0, if a field is linked with something else (Font or Gadget) they are also released during the process. After the call of this instruction nothing is left behind. But of course if the Gadget User Data (Aka SetGadgetData()) are used to store a pointer to some allocated memory, this command can lead to memory leak problem. And I can't do anything about this because it's impossible to know the nature about what is stored in the gadget data.
I hope my explanation are clear about this aspect of my code.

About 'EnableExplicit' support, personally, I never use it so this is not an issue for me but since many other programmer use my code I will add this support too.

About the ImageGadget() support it should be created with a description string gadget or not ?

About the ListIcon without description, you are right, the current code consider Description gadget to have the default height, I will correct this, sorry it's my fault.

Edit :
The new source correcting the ListIcon problem is online and can be downloaded here : http://pages.videotron.com/gsaumure/fil ... Gadget.zip

Best regards
Guimauve
Dear Optimist, Pessimist,
and Realist,

While you guys were
busy arguing about the
glass of water, I DRANK IT !

Sincerely,
the Opportunist
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Simple PropertyGrid

Post by Andre »

Thanks again, Guimauve. :D

I have no time today to test/implement your latest update, sorry.

Thanks for your explanation about freeing all the gadget stuff.

With the ImageGadget() I don't mean to add an image inside the PropertyGridGadget, at least I don't need this for now.
What I really mean is the [+] or [-] sign in front of a PropertySection, from which one I would like to have the GadgetID.

Then I would be able to check for open/collapse the PropertySection within in my own event-handler, without need to use the extra

Code: Select all

          Default 
            CheckPropertyGridSectionClick(#PropertyGrid) 
code section (which is more complicate to do with hundreds of #PB_Any created gadget, including the #PropertyGrid).

Thanks again - credits to you in our project are already noted! :-)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Post Reply