this is my first attempt for a XmlGadget Module. XmlGadget allows to render DialogLibrary functionality into a ContainerGadget.
Example:
Code: Select all
OpenWindow(#MainWindow, 0, 0, 200, 200, "XmlGadget", #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
Xml = "<vbox>" +
" <button name='myButton1' text='Button1' onevent='ButtonEvent1()' />" +
" <button name='myButton2' text='Button2' onevent='ButtonEvent2()' />" +
"</vbox>"
XmlGadget(#ContainerGadget, 10, 10, WindowWidth(#MainWindow) - 20, WindowHeight(#MainWindow) - 20, Xml, #PB_Container_Flat)
Feel free to ask, if you have any questions.
Greetings ... Peter
P.S.: I am not entirely happy with the naming of this module. If you have a better name, feel free to suggest it.
Module:
Code: Select all
DeclareModule XmlGadget
EnableExplicit
Declare XmlGadget(Gadget, x, y, Width, Height, Xml.s, Flags = 0)
Declare ResizeXmlGadget(Gadget, x, y, Width, Height)
Declare XmlDialogGadget(Gadget, Name.s)
EndDeclareModule
Module XmlGadget
EnableExplicit
Procedure ResizeXmlGadget(Gadget, x, y, Width, Height)
If IsGadget(Gadget)
ResizeGadget(Gadget, x, y, Width, Height)
Protected oDLG
Protected GID = GadgetID(Gadget)
! v_odlg = $(v_gid).data("oDLG");
ResizeWindow(DialogWindow(oDLG), 0, 0, Width, Height)
RefreshDialog(oDLG)
EndIf
EndProcedure
Procedure XmlGadget(Gadget, x, y, Width, Height, Xml.s, Flags = 0)
If Gadget = #PB_Any
Gadget = ContainerGadget(Gadget, x, y, Width, Height, Flags)
Else
ContainerGadget(Gadget, x, y, Width, Height, Flags)
EndIf
CloseGadgetList()
Protected WindowName.s = "window_" + Str(ElapsedMilliseconds())
Xml = "<window name='" + WindowName + "' flags='#PB_Window_BorderLess'>" + Xml + "</window>"
Protected oXML, oDLG
oXML = ParseXML(#PB_Any, Xml)
If oXML And XMLStatus(oXML) = #PB_XML_Success
oDLG = CreateDialog(#PB_Any)
If OpenXMLDialog(oDLG, oXML, WindowName)
Protected WID = WindowID(DialogWindow(oDLG))
Protected GID = GadgetID(Gadget)
! var e = $(v_wid.window).detach()
! $(v_gid.div.children[0]).append(e);
! $(v_gid).data("oXML", v_oxml);
! $(v_gid).data("oDLG", v_odlg);
ResizeWindow(DialogWindow(oDLG), 0, 0, Width, Height)
RefreshDialog(oDLG)
ProcedureReturn Gadget
Else
Debug "Dialog error: " + DialogError(oDLG)
EndIf
Else
Debug "XML error: " + XMLError(oXML)
EndIf
ProcedureReturn -1
EndProcedure
Procedure XmlDialogGadget(Gadget, Name.s)
If IsGadget(Gadget)
Protected oDLG
Protected GID = GadgetID(Gadget)
! v_odlg = $(v_gid).data("oDLG");
ProcedureReturn DialogGadget(oDLG, Name)
EndIf
EndProcedure
EndModule
CompilerIf #PB_Compiler_IsMainFile
EnableExplicit
; Example:
Enumeration
#MainWindow
#ContainerGadget
EndEnumeration
Runtime Procedure ButtonEvent1()
Debug "ButtonEvent1()"
EndProcedure
Runtime Procedure ButtonEvent2()
Debug "ButtonEvent2()"
EndProcedure
Procedure SizeWindowEvent()
XmlGadget::ResizeXmlGadget(#ContainerGadget, #PB_Ignore, #PB_Ignore, WindowWidth(#MainWindow) - 20, WindowHeight(#MainWindow) - 20)
EndProcedure
Define Xml.s
UseModule XmlGadget
OpenWindow(#MainWindow, 0, 0, 200, 200, "XmlGadget", #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
Xml = "<vbox>" +
" <button name='myButton1' text='Button1' onevent='ButtonEvent1()' />" +
" <button name='myButton2' text='Button2' onevent='ButtonEvent2()' />" +
"</vbox>"
XmlGadget(#ContainerGadget, 10, 10, WindowWidth(#MainWindow) - 20, WindowHeight(#MainWindow) - 20, Xml, #PB_Container_Flat)
SetGadgetText(XmlDialogGadget(#ContainerGadget, "myButton1"), "myNewButtonText")
BindEvent(#PB_Event_SizeWindow, @SizeWindowEvent(), #MainWindow)
UnuseModule XmlGadget
CompilerEndIf