Also, 'Label' or XML variant of text widget is not really documented. All of below code is based on hints elsewhere in the documentation - it took me hours to make it working. So ... sharing it to help someone save time.
Also, if you have some comments on how to make it working better (or more correct), I am always willing to learn.
Cheers
Code: Select all
; Based on:
; SpiderBasic - Simple dialog example file
; (c) Fantaisie Software
; simplified dialog fields, added example handlers and an example of text gadget
#Xml = 0
#Dialog = 0
Procedure EventProcHandler()
Debug "Event Triggered with event# " + EventGadget()
Select EventGadget()
Case 100003 ; ok
Debug "OK button clicked"
; get the text from the edit field
stringGadget = DialogGadget(#Dialog, "edit1")
Debug "Text in the string field: '" + GetGadgetText(stringGadget)+"'"
FreeDialog(#Dialog) ; close dialog as we do not need it
Case 100004 ; cancel
Debug "Cancel button clicked. Abort and Close."
FreeDialog(#Dialog) ; close dialog as we do not need it
EndSelect
EndProcedure
; Define our dialog window here, using regular XML
;
XML$ = "<window id='0' name='window0' text='Dialog Title' minwidth='300'" +
" minheight='auto' maxheight='auto'" +
" flags='#PB_Window_ScreenCentered | #PB_Window_BorderLess | #PB_Window_SizeGadget'>" +
" <vbox>" +
" <text name='label1' text='Enter String' />" +
" <string name='edit1' width='50' height='30' />" +
" <hbox>" +
" <button name='ok' text='Save/Close' height='30' />" +
" <button name='cancel' text='Cancel/Close' />" +
" </hbox>" +
" </vbox>" +
"</window>"
If ParseXML(#Xml, XML$) And XMLStatus(#Xml) = #PB_XML_Success
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "window0") ; window to open via ID
Debug "Dialog created"
; Example set values when dialog opens
edit1field = DialogGadget(#Dialog, "edit1")
SetGadgetText(edit1field, "Some predefined text") ; Set the text in the field
; Example bind buttons to execution
okbtn = DialogGadget(#Dialog, "ok")
cancelbtn = DialogGadget(#Dialog, "cancel")
BindGadgetEvent(okbtn, @EventProcHandler())
BindGadgetEvent(cancelbtn, @EventProcHandler())
; read of entered value in the gadget is done in handler
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
Else
Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
; line location not very helpful here all XML is one line string
EndIf