Good point. This would save the user having to manually keep track until needed (they can just parse when needed instead).netmaestro wrote:reading and listing them by type comes in very handy when you're doing say, a visual designer.
count number of gadgets in a container/gadget list
Re: count number of gadgets in a container/gadget list
Re: count number of gadgets in a container/gadget list
Why remove the Protected and make the variable Global?VB6_to_PBx wrote:thank you RASHAD , for your Code
i modified your Code a little :
Global.i containerID
- VB6_to_PBx
- Enthusiast
- Posts: 625
- Joined: Mon May 09, 2011 9:36 am
Re: count number of gadgets in a container/gadget list
with EnableExplicitDanilo wrote:Why remove the Protected and make the variable Global?VB6_to_PBx wrote:thank you RASHAD , for your Code
i modified your Code a little :
Global.i containerID
that's the only way i could think of to get the containerID
Code: Select all
If GetGadgetChilds(0, childGadgets())
ForEach childGadgets()
Debug "Found child gadget: " + childGadgets() + Space(3) + "in containerID = " + containerID ; found gadgets 3, 5, 9
Next
Debug "No. of found child gadgets = " + ListSize(childGadgets.i())
EndIf
maybe a way using GadgetID() instead of using containerID
i couldn't make GadgetID() work
in
Debug "Found child gadget: " + childGadgets() + Space(3) + "in containerID = " + containerID ; found gadgets 3, 5, 9
PureBasic .... making tiny electrons do what you want !
"With every mistake we must surely be learning" - George Harrison
Re: count number of gadgets in a container/gadget list
The container is created as gadget 0, so GadgetID(0) is fine.VB6_to_PBx wrote:Danilo , do you know of another way ?
maybe a way using GadgetID() instead of using containerID
i couldn't make GadgetID() work
Code: Select all
If GetGadgetChilds(0, childGadgets())
ForEach childGadgets()
Debug "Found child gadget: " + childGadgets() + Space(3) + "in containerID = " + GadgetID(0) ; found gadgets 3, 5, 9
Next
Debug "No. of found child gadgets = " + ListSize(childGadgets.i())
EndIf
- VB6_to_PBx
- Enthusiast
- Posts: 625
- Joined: Mon May 09, 2011 9:36 am
Re: count number of gadgets in a container/gadget list
Danilo , thanks for Code correction : GadgetID(0)
seeing 'containerID' has the same Gadget's # as GadgetID(0)
containerID = GadgetID(gadget) : Debug "containerID = " + containerID
i previously tried GadgetID(containerID) ... thinking containerID should hold the Gadget ID #
but that didn't work .
seeing 'containerID' has the same Gadget's # as GadgetID(0)
containerID = GadgetID(gadget) : Debug "containerID = " + containerID
i previously tried GadgetID(containerID) ... thinking containerID should hold the Gadget ID #
but that didn't work .
PureBasic .... making tiny electrons do what you want !
"With every mistake we must surely be learning" - George Harrison
Re: count number of gadgets in a container/gadget list
Thanks everyone. This seems a lot more complicated than I would've hoped for, but good to know there is a solution.
Re: count number of gadgets in a container/gadget list
Code Danilo -> Rashad -> mk-soft
Added Linux Version and correct internal gadget structure ...
Added Linux Version and correct internal gadget structure ...
Code: Select all
;-TOP
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Import ""
PB_Object_EnumerateStart(Object)
PB_Object_EnumerateNext(Object,*ID.Integer)
PB_Object_EnumerateAbort(Object)
PB_Object_Count( Objects )
PB_Object_FreeID (*Object, DynamicOrArrayID)
PB_Object_GetObject.i (*Object, DynamicOrArrayID)
PB_Object_GetObjectDirect (*Object, DynamicOrArrayID)
PB_Object_IsObject.i (*Object, DynamicOrArrayID)
PB_Object_GetOrAllocateID.i(*Object, ID)
PB_Gadget_Objects.i
EndImport
CompilerElse
ImportC ""
PB_Object_EnumerateStart(Object)
PB_Object_EnumerateNext(Object,*ID.Integer)
PB_Object_EnumerateAbort(Object)
PB_Object_Count( Objects )
PB_Object_FreeID (*Object, DynamicOrArrayID)
PB_Object_GetObject.i (*Object, DynamicOrArrayID)
PB_Object_GetObjectDirect (*Object, DynamicOrArrayID)
PB_Object_IsObject.i (*Object, DynamicOrArrayID)
PB_Object_GetOrAllocateID.i(*Object, ID)
PB_Gadget_Objects.i
EndImport
CompilerEndIf
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
;- PB Interne Struktur Gadget Windows
Structure PB_Gadget
*Gadget
*vt.GadgetVT
UserData.i
OldCallback.i
Daten.i[4]
EndStructure
CompilerCase #PB_OS_Linux
;- PB Interne Struktur Gadget Linux
Structure PB_Gadget
*Gadget
*GadgetContainer
*vt.GadgetVT
UserData.i
Daten.i[4]
EndStructure
CompilerCase #PB_OS_MacOS
; PB Interne Struktur Gadget MacOS
Structure PB_Gadget
*Gadget
*Container
*Functions
UserData.i
WindowID.i
Type.l
Flags.l
EndStructure
CompilerEndSelect
EnableExplicit
Procedure.i GetGadgetChilds(gadget, List childs.i())
Protected r1, gadgetID = -1, *theGadget.PB_Gadget
Protected count, containerID = GadgetID(gadget)
ClearList( childs() )
If PB_Gadget_Objects And containerID
PB_Object_EnumerateStart(PB_Gadget_Objects)
While PB_Object_EnumerateNext(PB_Gadget_Objects, @gadgetID)
If gadgetID <> -1 And IsGadget(gadgetID)
*theGadget = PB_Object_GetObject(PB_Gadget_Objects,gadgetID)
If *theGadget And *theGadget\Gadget <> containerID
r1 = 0
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
r1 = Bool(GetAncestor_(*theGadget\Gadget, #GA_PARENT) = containerID)
CompilerCase #PB_OS_MacOS
r1 = CocoaMessage(0, *theGadget\Gadget, "isDescendantOf:", containerID)
CompilerCase #PB_OS_Linux
Protected widget = gtk_widget_get_parent_(*theGadget\Gadget)
r1 = Bool(widget = containerID)
If Not r1
widget = gtk_widget_get_parent_(widget)
EndIf
r1 = Bool(widget = containerID)
CompilerEndSelect
If r1
count + 1
If AddElement( childs() )
childs() = gadgetID
EndIf
EndIf
EndIf
EndIf
gadgetID = -1
Wend
PB_Object_EnumerateAbort(PB_Gadget_Objects)
EndIf
ProcedureReturn count
EndProcedure
; ****
NewList childGadgets.i()
If OpenWindow(0, 0, 0, 322, 250, "ContainerGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ContainerGadget(0, 8, 8, 306, 133, #PB_Container_Raised)
ButtonGadget(3, 10, 15, 80, 24, "Button 1")
ButtonGadget(5, 95, 15, 80, 24, "Button 2")
ListViewGadget(9, 10,50,286,70)
CloseGadgetList()
ListViewGadget(11, 10, 150,302,70)
If GetGadgetChilds(0, childGadgets())
ForEach childGadgets()
Debug "Found child gadget: " + childGadgets() ; found gadgets 3, 5, 9
Next
Debug "No. of founded child gadget: " + ListSize(childGadgets.i())
EndIf
ClearList(childGadgets())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: count number of gadgets in a container/gadget list
Thanks to: Danilo -> Rashad -> mk-soft
I'm going to use this code for an app.
I'm going to use this code for an app.
A+
Denis
Denis
Re: count number of gadgets in a container/gadget list
Thanks a bunch, everyone.