How to use BindEvent with GadgetDrop?

Just starting out? Need help? Post your questions and find answers here.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

How to use BindEvent with GadgetDrop?

Post by davido »

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
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 794
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Re: How to use BindEvent with GadgetDrop?

Post by Zebuddi123 »

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
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: How to use BindEvent with GadgetDrop?

Post by davido »

Hi Zebuddi123,
Thank you very much. It works perfectly. :D
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. :o
DE AA EB
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How to use BindEvent with GadgetDrop?

Post by mk-soft »

That's right,

but how to bind event over xml? '... onevent='gettext()' ...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 794
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Re: How to use BindEvent with GadgetDrop?

Post by Zebuddi123 »

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
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: How to use BindEvent with GadgetDrop?

Post by davido »

HI Zebuddi123,
Thank you for taking so much time on this one: it is appreciated. :D
DE AA EB
Post Reply