Code: Select all
;-TOP
;XIncludeFile "FixWayland.pb"
Structure udtChildren
Level.i
Widget.i
Name.s
EndStructure
Procedure FindChild(Widget, Name.s)
Protected *Name, *child, *list.glist, *children.GList, *widget
*Name = gtk_widget_get_name_(Widget)
If *Name
If LCase(Name) = LCase(PeekS(*Name, -1, #PB_UTF8))
ProcedureReturn Widget
EndIf
EndIf
*child = gtk_bin_get_child_(Widget)
If *child
ProcedureReturn FindChild(*child, name)
EndIf
*list = gtk_container_get_children_(Widget)
If *list
*children = *list
While *children
*widget = FindChild(*children\data, name);
If *widget <> #Null
ProcedureReturn *widget;
EndIf
*children = *children\next
Wend
g_list_free_(*list)
EndIf
ProcedureReturn #Null
EndProcedure
Procedure ListChildren(Widget, List Children.udtChildren(), Level = 0)
Protected *Name, *child, *list.glist, *children.glist
If Level = 0
ClearList(Children())
EndIf
*Name = gtk_widget_get_name_(Widget)
If *Name
AddElement(Children())
Children()\Level = Level
Children()\Widget = Widget
Children()\Name = PeekS(*Name, -1, #PB_UTF8)
EndIf
*list = gtk_container_get_children_(Widget)
If *list
*children = *list
While *children
ListChildren(*children\data, Children(), Level + 1);
*children = *children\next
Wend
g_list_free_(*list)
ProcedureReturn #Null
EndIf
*child = gtk_bin_get_child_(Widget);
If *child
*Name = gtk_widget_get_name_(Widget)
ProcedureReturn ListChildren(*child, Children(), Level + 1)
EndIf
ProcedureReturn #Null;
EndProcedure
;-Test
;-TOP
Enumeration Windows
#Main
EndEnumeration
Enumeration MenuBar
#MainMenu
EndEnumeration
Enumeration MenuItems
EndEnumeration
Enumeration Gadgets
#MainEdit
#MainButtonOk
#MainButtonCancel
EndEnumeration
Enumeration StatusBar
#MainStatusBar
EndEnumeration
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar)
; Resize gadgets
ResizeGadget(#MainEdit, 5, 5, dx -10, dy - 45)
ResizeGadget(#MainButtonok, 10, dy - 35, 120, 30)
ResizeGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30)
EndProcedure
Procedure Main()
Protected dx, dy
#MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
; Menu
CreateMenu(#MainMenu, WindowID(#Main))
; StatusBar
CreateStatusBar(#MainStatusBar, WindowID(#Main))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar)
EditorGadget(#MainEdit, 5, 5, dx -10, dy - 45)
ButtonGadget(#MainButtonok, 10, dy - 35, 120, 30, "Ok")
ButtonGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30, "Abbruch")
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
Debug "Find GtkTextView: " + FindChild(WindowID(#Main), "GtkTextView")
Define NewList Childs.udtChildren()
ListChildren(WindowID(#Main), Childs())
ForEach Childs()
Debug "Level " + Childs()\Level + ": " + Childs()\Name + " [" + Childs()\Widget + "]"
Next
If gtk_window_get_decorated_(WindowID(#Main))
Debug "Decorated"
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
Select EventMenu()
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Case #PB_Menu_About
Case #PB_Menu_Preferences
Case #PB_Menu_Quit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
CompilerEndIf
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #MainEdit
Select EventType()
Case #PB_EventType_Change
;
EndSelect
Case #MainButtonOk
Select EventType()
Case #PB_EventType_LeftClick
;
EndSelect
Case #MainButtonCancel
Select EventType()
Case #PB_EventType_LeftClick
;
EndSelect
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()