Code: Select all
Enumeration Gadgets
#GadgetInfo
#GadgetText
#GadgetOK
EndEnumeration
ForEach Gadgets
Debug "enumeration value: " + #PB_Compiler_EnumerationValue
Next
Code: Select all
Enumeration Gadgets
#GadgetInfo
#GadgetText
#GadgetOK
EndEnumeration
ForEach Gadgets
Debug "enumeration value: " + #PB_Compiler_EnumerationValue
Next
You can already do it:A.D. wrote:i wish we could iterate enumerations like this:
Code: Select all
Enumeration Gadgets #GadgetInfo #GadgetText #GadgetOK EndEnumeration ForEach Gadgets Debug "enumeration value: " + #PB_Compiler_EnumerationValue Next
Code: Select all
Enumeration
#GadgetInfo
#GadgetText
#GadgetOK
EndEnumeration
For v = #GadgetInfo To #GadgetOK
Debug "enumeration value: " + v
Next
Code: Select all
For v = #GadgetInfo To #GadgetOK
Debug "enumeration value: " + v
Next
Maybe I misunderstood. Didn't you want to show what the enumerated value of each constant was?A.D. wrote:I want to enumerate each Enumerationlist i want to with ForEach Enumerationlist!
Assuming that the named enumerations consist of valid PureBasic objects, this might do the trick:A.D. wrote:...i just wanted to iterate trough every gadget
Code: Select all
Enumeration Windows
#Window1
#Window2
EndEnumeration
Enumeration Gadgets
#Gadget1
#Gadget2
#Gadget3
EndEnumeration
Enumeration Fonts
#Font1
#Font2
#Font3
#Font4
EndEnumeration
Enumeration Images
#Image1
#Image2
#Image3
#Image4
#Image5
EndEnumeration
Macro NextEnumeration(e, name)
Enumeration name
EndEnumeration
e = #PB_Compiler_EnumerationValue
EndMacro
Procedure EnumerateGroup(objectType.s, lastEnumeration)
Debug objectType + ":"
For i = 0 To lastEnumeration
Select objectType
Case "windows":
If IsWindow(i)
Debug "#Window" + Str(i + 1) + " is in use."
EndIf
Case "gadgets":
If IsGadget(i)
Debug "#Gadget" + Str(i + 1) + " is in use."
EndIf
Case "fonts":
If IsFont(i)
Debug "#Font" + Str(i + 1) + " is in use."
EndIf
Case "images":
If IsImage(i)
Debug "#Image" + Str(i + 1) + " is in use."
EndIf
EndSelect
Next i
Debug "---"
EndProcedure
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#Window2, 0, 0, 300, 50, "Named Enumerations", wFlags)
ButtonGadget(#Gadget1, 10, 10, 135, 30, "Gadget 1")
ButtonGadget(#Gadget3, 155 , 10, 135, 30, "Gadget 3")
LoadFont(#Font2, "Arial", 10)
LoadFont(#Font4, "Arial", 10)
CreateImage(#Image2, 10, 10)
CreateImage(#Image5, 10, 10)
CreateImage(#Image1, 10, 10)
NextEnumeration(x, Windows)
EnumerateGroup("windows", x)
NextEnumeration(x, Fonts)
EnumerateGroup("fonts", x)
NextEnumeration(x, Images)
EnumerateGroup("images", x)
NextEnumeration(x, Gadgets)
EnumerateGroup("gadgets", x)
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
+1A.D. wrote:i wish we could iterate enumerations like this:
Code: Select all
Enumeration Gadgets #GadgetInfo #GadgetText #GadgetOK EndEnumeration ForEach Gadgets Debug "enumeration value: " + #PB_Compiler_EnumerationValue Next
The enumeration block no longer exists after compilation.A.D. wrote:i wish we could iterate enumerations like this:
Code: Select all
Enumeration Gadgets #GadgetInfo #GadgetText #GadgetOK EndEnumeration ForEach Gadgets Debug "enumeration value: " + #PB_Compiler_EnumerationValue Next
Code: Select all
ForEach Gadgets
Debug "enumeration value: " + #PB_Compiler_EnumerationValue
Next
Code: Select all
Debug "enumeration value: " + #GadgetInfo
Debug "enumeration value: " + #GadgetText
Debug "enumeration value: " + #GadgetOK
Code: Select all
For v = #GadgetInfo To #GadgetOK
Debug "enumeration value: " + v
Next
Code: Select all
Enumeration enum
#a ; 0
#b=10
#c=10
#d=5
#ee ; 6
EndEnumeration
Code: Select all
Macro IteraEnum(enum,const,val=)
Enumeration enum
const val
EndEnumeration
CompilerIf Not Defined(enum,#PB_List)
Global NewList enum()
CompilerEndIf
AddElement(enum())
enum()=#PB_Compiler_EnumerationValue - 1
EndMacro
IteraEnum(_t2,#bla1)
IteraEnum(_t2,#bla2,=2)
IteraEnum(_t2,#bla3)
ForEach _t2()
Debug _t2()
Next
Debug #bla2
Code: Select all
IteraEnum(_t2,#bla2,= 1 << 1 )
Code: Select all
;-TOP
DeclareModule System
Declare GetParentWindowID(Gadget)
Declare GetGadgetList(List Gadgets(), WindowID=0)
EndDeclareModule
; ---------------------------------------------------------------------------------------
Module System
EnableExplicit
;-- Import internal function
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Import ""
PB_Object_EnumerateStart( PB_Objects )
PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
PB_Object_EnumerateAbort( PB_Objects )
PB_Object_GetObject( PB_Object , DynamicOrArrayID)
PB_Window_Objects.i
PB_Gadget_Objects.i
PB_Image_Objects.i
;PB_Font_Objects.i
EndImport
CompilerElse
ImportC ""
PB_Object_EnumerateStart( PB_Objects )
PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
PB_Object_EnumerateAbort( PB_Objects )
PB_Object_GetObject( PB_Object , DynamicOrArrayID)
PB_Window_Objects.i
PB_Gadget_Objects.i
PB_Image_Objects.i
;PB_Font_Objects.i
EndImport
CompilerEndIf
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
; PB Interne Struktur Gadget MacOS
Structure sdkGadget
*gadget
*container
*vt
UserData.i
Window.i
Type.i
Flags.i
EndStructure
CompilerEndIf
; ---------------------------------------------------------------------------------------
Procedure GetParentWindowID(Gadget)
Protected GadgetID, GadgetWindowID
If IsGadget(Gadget)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_MacOS
Protected *Gadget.sdkGadget = IsGadget(Gadget)
GadgetWindowID = WindowID(*Gadget\Window)
CompilerCase #PB_OS_Linux
GadgetID = GadgetID(Gadget)
GadgetWindowID = gtk_widget_get_toplevel_ (GadgetID)
CompilerCase #PB_OS_Windows
GadgetID = GadgetID(Gadget)
GadgetWindowID = GetAncestor_(GadgetID, #GA_ROOT)
CompilerEndSelect
EndIf
ProcedureReturn GadgetWindowID
EndProcedure
; ---------------------------------------------------------------------------------------
Procedure GetGadgetList(List Gadgets(), WindowID=0)
Protected object
ClearList(Gadgets())
PB_Object_EnumerateStart(PB_Gadget_Objects)
While PB_Object_EnumerateNext(PB_Gadget_Objects, @object)
If WindowID = 0 Or GetParentWindowID(object) = WindowID
AddElement(Gadgets())
Gadgets() = object
EndIf
Wend
ProcedureReturn ListSize(Gadgets())
EndProcedure
; ---------------------------------------------------------------------------------------
EndModule
;-Test
UseModule System
Global NewList Gadgets()
; Zeigt mögliche Flags des ButtonGadget in Aktion...
If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 20, "Standard Button")
ButtonGadget(1, 10, 40, 200, 20, "Left Button", #PB_Button_Left)
ButtonGadget(2, 10, 70, 200, 20, "Right Button", #PB_Button_Right)
ButtonGadget(3, 10,100, 200, 60, "Multiline Button (längerer Text wird automatisch umgebrochen)", #PB_Button_MultiLine)
;ButtonGadget(4, 10,170, 200, 20, "Toggle Button", #PB_Button_Toggle)
ButtonGadget(#PB_Any, 10,170, 200, 20, "Toggle Button", #PB_Button_Toggle)
cnt = GetGadgetList(Gadgets());, WindowID(0))
Debug "Count of gadgets = " + cnt
ForEach Gadgets()
Debug "Gadget-Number = " + Gadgets() + " / Text = " + GetGadgetText(Gadgets())
Next
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Code: Select all
Macro DoubleQuote
"
EndMacro
Macro iEnum(EnumerationName, Constant, Value=)
Enumeration EnumerationName#Enum
Constant Value
EndEnumeration
CompilerIf Not Defined(LastEnum, #PB_Map)
Global NewMap LastEnum()
CompilerEndIf
LastEnum(Trim(DoubleQuote#EnumerationName#DoubleQuote)) = #PB_Compiler_EnumerationValue - 1
EndMacro
iEnum(Gadget, #a, = 1)
iEnum(Gadget, #b)
iEnum(Gadget, #c)
iEnum(Gadget, #d)
iEnum(Window, #wa)
iEnum(Window, #wb)
Debug LastEnum("Gadget")
Debug LastEnum("Window")
Code: Select all
Enumeration Gadgets
#BeginOfGadget
#Gadget1
#Gadget2
#Gadget3
#EndOfGadget
EndEnumeration
For i = #BeginOfGadget + 1 To #EndOfGadget - 1
Debug i
Next