I know it can be done using the api but a native solution is needed.
Code: Select all
PostEvent(#CustEvent, GetGadgetWindow(gadget), gadget, #CustEventType, data)
Code: Select all
PostEvent(#CustEvent, GetGadgetWindow(gadget), gadget, #CustEventType, data)
Code: Select all
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Import ""
PB_Object_EnumerateStart (PB_Object)
PB_Object_EnumerateNext (PB_Object, ID)
PB_Object_EnumerateAbort (PB_Object)
PB_Gadget_GetRootWindow (GadgetID)
PB_Window_Objects
EndImport
CompilerElse
ImportC ""
PB_Object_EnumerateStart (PB_Object)
PB_Object_EnumerateNext (PB_Object, ID)
PB_Object_EnumerateAbort (PB_Object)
PB_Gadget_GetRootWindow(GadgetID)
PB_Window_Objects
EndImport
CompilerEndIf
Procedure.i GetWindowObject(WindowID)
Protected Result = -1
PB_Object_EnumerateStart(PB_Window_Objects)
While PB_Object_EnumerateNext(PB_Window_Objects, @Result)
If WindowID = WindowID(Result)
PB_Object_EnumerateAbort(PB_Window_Objects)
Break
EndIf
Wend
ProcedureReturn Result
EndProcedure
Procedure.i GetGadgetWindow(Gadget)
Protected hWnd, Window = -1
If IsGadget(Gadget)
hWnd = PB_Gadget_GetRootWindow(GadgetID(Gadget))
If hWnd
Window = GetWindowObject(hWnd)
EndIf
EndIf
ProcedureReturn Window
EndProcedure
+ 1Justin wrote: Thu Oct 17, 2024 8:26 am Hi, thanks for the suggestions. Like i said i already know about them, the point is to have a native solution that will always work regardless of some pb internal change.
And if the functionality is already implemented it should be very easy to do.
Code: Select all
GetParentGadget(#Gadget[, Flags]) ; #PB_ParentGadget (default), #PB_RootWindow
Code: Select all
PostEvent(#CustEvent, #PB_Any, Gadget, #CustEventType, Data)
Code: Select all
PostEvent(#PB_Event_CloseWindow, 0)
Code: Select all
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
; PB Internal Structure Gadget MacOS
Structure sdkGadget
*gadget
*container
*vt
UserData.i
Window.i
Type.i
Flags.i
EndStructure
Import ""
PB_Window_GetID(Object)
EndImport
CompilerEndIf
; ---------------------------------------------------------------------------------------
Procedure GetGadgetWindow(Gadget)
Protected ID, r1
If IsGadget(Gadget)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_MacOS
Protected *Gadget.sdkGadget = IsGadget(Gadget)
If *Gadget
ID = WindowID(*Gadget\Window)
r1 = PB_Window_GetID(ID)
Else
r1 = -1
EndIf
CompilerCase #PB_OS_Linux
ID = gtk_widget_get_toplevel_(GadgetID(Gadget))
If ID
r1 = g_object_get_data_(ID, "pb_id" )
Else
r1 = -1
EndIf
CompilerCase #PB_OS_Windows
ID = GetAncestor_(GadgetID(Gadget), #GA_ROOT)
r1 = GetProp_(ID, "PB_WINDOWID")
If r1 > 0
r1 - 1
Else
r1 = -1
EndIf
CompilerEndSelect
Else
r1 = -1
EndIf
ProcedureReturn r1
EndProcedure
; ---------------------------------------------------------------------------------------
;-Test
#ProgramTitle = "Main Window"
#ProgramVersion = "v1.01.2"
Enumeration Windows 5 ; Test set to 5
#Main
EndEnumeration
Enumeration MenuBar
#MainMenu
EndEnumeration
Enumeration MenuItems
#MainMenuAbout
#MainMenuExit
EndEnumeration
Enumeration Gadgets
#MainEdit
#MainButtonOk
#MainButtonCancel
EndEnumeration
Enumeration StatusBar
#MainStatusBar
EndEnumeration
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
; 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, #ProgramTitle , #MainStyle)
; Menu
CreateMenu(#MainMenu, WindowID(#Main))
MenuTitle("&File")
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
MenuItem(#PB_Menu_About, "")
CompilerElse
MenuItem(#MainMenuAbout, "About")
CompilerEndIf
; Menu File Items
CompilerIf Not #PB_Compiler_OS = #PB_OS_MacOS
MenuBar()
MenuItem(#MainMenuExit, "E&xit")
CompilerEndIf
; StatusBar
CreateStatusBar(#MainStatusBar, WindowID(#Main))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
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 GetGadgetWindow(#MainEdit)
Debug GetGadgetWindow(#MainButtonOk)
Debug GetGadgetWindow(#MainButtonCancel)
; Event Loop
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Main
Break
EndSelect
Case #PB_Event_Menu
Select EventMenu()
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Case #PB_Menu_About
PostEvent(#PB_Event_Menu, #Main, #MainMenuAbout)
Case #PB_Menu_Preferences
Case #PB_Menu_Quit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
CompilerEndIf
Case #MainMenuAbout
MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
Case #MainMenuExit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #MainEdit
Select EventType()
Case #PB_EventType_Change
;
EndSelect
Case #MainButtonOk
;
Case #MainButtonCancel
;
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()