Just starting out? Need help? Post your questions and find answers here.
davido
Addict
Posts: 1890 Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK
Post
by davido » Thu Jan 18, 2018 9:05 pm
I want to be able to drop text onto a CanvasGadget.
I can get it to work with the 'old fashioned' way.
Can someone show me how to do it with Bind Event?
Code: Select all
EnableExplicit
CompilerIf #PB_Compiler_Unicode
#XmlEncoding = #PB_UTF8
CompilerElse
#XmlEncoding = #PB_Ascii
CompilerEndIf
#Dialog = 0
#Xml = 0
Global XML$, Event.i
Runtime Enumeration Windows
#WinMain
EndEnumeration
Runtime Enumeration Gadgets
#CanvasCDrop
EndEnumeration
Runtime Procedure EventCavnas()
Select EventType()
Case #PB_EventType_LeftClick
EndSelect
EndProcedure
Runtime Procedure SetUP()
EnableGadgetDrop(#CanvasCDrop, #PB_Drop_Text, #PB_Drag_Copy)
EndProcedure
XML$ = "<dialogs>"+
" <window id='#WinMain' name='CTest' text='CTest Drop' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered |"+
" #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
" <canvas id='#CanvasCDrop' width='200' height='200' onevent='EventCavnas()'/>"+
" </window>"+
"</dialogs>"
If CatchXML(#Xml, @XML$, StringByteLength(XML$), 0, #XmlEncoding) And XMLStatus(#Xml) = #PB_XML_Success
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "CTest")
SetUp()
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventType() = #PB_EventType_DragStart
; Drop event on the target gadgets, receive the dropped data
;
ElseIf Event = #PB_Event_GadgetDrop
Select EventGadget()
Case #CanvasCDrop
Debug EventDropText()
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
Else
Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
DE AA EB
Zebuddi123
Enthusiast
Posts: 794 Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:
Post
by Zebuddi123 » Thu Jan 18, 2018 10:19 pm
Hi davido
Look to where I`ve Highlighted.....
Zebuddi.
Code: Select all
CompilerIf #PB_Compiler_Unicode
#XmlEncoding = #PB_UTF8
CompilerElse
#XmlEncoding = #PB_Ascii
CompilerEndIf
#Dialog = 0
#Xml = 0
Global XML$, Event.i
Runtime Enumeration Windows
#WinMain
EndEnumeration
Runtime Enumeration Gadgets
#CanvasCDrop
EndEnumeration
Runtime Procedure EventCavnas()
Select EventType()
Case #PB_EventType_LeftClick
EndSelect
EndProcedure
Runtime Procedure SetUP()
EnableGadgetDrop(#CanvasCDrop, #PB_Drop_Text, #PB_Drag_Copy)
EndProcedure
;------------------------------------------------------------------------------------------------------------------
;---- Zebuddi......
Procedure gettext()
Debug "dropped"
EndProcedure
;-----------------
;------------------------------------------------------------------------------------------------------------------
XML$ = "<dialogs>"+
" <window id='#WinMain' name='CTest' text='CTest Drop' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered |"+
" #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
" <canvas id='#CanvasCDrop' width='200' height='200' onevent='EventCavnas()'/>"+
" </window>"+
"</dialogs>"
If CatchXML(#Xml, @XML$, StringByteLength(XML$), 0, #XmlEncoding) And XMLStatus(#Xml) = #PB_XML_Success
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "CTest")
;--------------------------------------------------------------------------------------------------------------------------------------------------------
;---- Zebuddi......
BindEvent(#PB_Event_GadgetDrop, @gettext(), #CanvasCDrop)
;-----------------
;--------------------------------------------------------------------------------------------------------------------------------------------------------
SetUp()
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventType() = #PB_EventType_DragStart
; Drop event on the target gadgets, receive the dropped data
;
ElseIf Event = #PB_Event_GadgetDrop
Select EventGadget()
Case #CanvasCDrop
Debug EventDropText()
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
Else
Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
malleo, caput, bang. Ego, comprehendunt in tempore
davido
Addict
Posts: 1890 Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK
Post
by davido » Thu Jan 18, 2018 10:43 pm
Hi
Zebuddi123 ,
Thank you very much. It works perfectly.
I posted the code from my PC.
Without thinking I tested
your code on my MacBook, well, it worked! Odd because I thought that the Drag Drop library didn't work on OS X.
DE AA EB
mk-soft
Always Here
Posts: 5335 Joined: Fri May 12, 2006 6:51 pm
Location: Germany
Post
by mk-soft » Thu Jan 18, 2018 10:45 pm
That's right,
but how to bind event over xml? '... onevent='gettext()' ...
Zebuddi123
Enthusiast
Posts: 794 Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:
Post
by Zebuddi123 » Thu Jan 18, 2018 10:49 pm
Hi davido your welcome updated code. Have`nt looked into this much actually, but caught my eye and would be useful for something im` doing currently
Code: Select all
Runtime Procedure EventCavnas()
Select EventType()
Case #PB_EventType_LeftClick
EndSelect
EndProcedure
Runtime Procedure SetUP()
EnableGadgetDrop(#CanvasCDrop, #PB_Drop_Text, #PB_Drag_Copy)
EndProcedure
;---- Zebuddi......
Procedure gettext()
ClearDebugOutput()
Debug "dropped"
Debug EventDropText()
EndProcedure
;-----------------
XML$ = "<dialogs>"+
" <window id='#WinMain' name='CTest' text='CTest Drop' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered |"+
" #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
" <canvas id='#CanvasCDrop' width='200' height='200' onevent='EventCavnas()'/>"+
" </window>"+
"</dialogs>"
If CatchXML(#Xml, @XML$, StringByteLength(XML$), 0, #XmlEncoding) And XMLStatus(#Xml) = #PB_XML_Success
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "CTest")
;---- Zebuddi......
BindEvent(#PB_Event_GadgetDrop, @gettext(), #WinMain, #CanvasCDrop)
;-----------------
SetUp()
Repeat
Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
Else
Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
malleo, caput, bang. Ego, comprehendunt in tempore
davido
Addict
Posts: 1890 Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK
Post
by davido » Thu Jan 18, 2018 11:29 pm
HI
Zebuddi123 ,
Thank you for taking so much time on this one: it is appreciated.
DE AA EB