Question about Drag and Drop Events

Just starting out? Need help? Post your questions and find answers here.
User avatar
susan
User
User
Posts: 27
Joined: Mon Aug 08, 2022 4:06 am

Question about Drag and Drop Events

Post by susan »

I am working on using drag and drop to move a bookmark into a different folder in My Bookmark Manager. I am making progress, but while examining the DragDrop.pb example, I wonder something.

Is there a specific reason (that I don't yet have understanding for) about how the #PB_Event_GadgetDrop event is not returned by EventType(), like #PB_EventType_DragStart is?

My initial expectation is that both would be part of the #PB_Event_Gadget grouping of events.
User avatar
idle
Always Here
Always Here
Posts: 6188
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Question about Drag and Drop Events

Post by idle »

I'm not sure if I understand the question but it's a window event to say that a gadget got a drop event. So you can use EventGadget() then EventDropType() if it's required before calling EventDropText() or EventDropfiles() or EventDropImage() to get the data

Code: Select all

 
 EnableGadgetDrop(#TargetText,     #PB_Drop_Text ,    #PB_Drag_Copy) ; <-- drop text
 EnableGadgetDrop(#TargetText,     #PB_Drop_Files,    #PB_Drag_Copy) ; <---drop files 
 ;....
 ElseIf Event = #PB_Event_GadgetDrop
                  
        Select EventGadget()
            
          Case #TargetText      
            
            Select EventDropType()  ;<----  See what the drop event type is 
              Case #PB_Drop_Text  
                AddGadgetItem(#TargetText, -1, EventDropText())
              Case #PB_Drop_Files
                Files$ = EventDropFiles()
                Count  = CountString(Files$, Chr(10)) + 1
                For i = 1 To Count
                  Debug StringField(Files$, i, Chr(10))
                Next i
             EndSelect    
     
you can also use EventDropType() on a #PB_Event_WindowDrop
User avatar
susan
User
User
Posts: 27
Joined: Mon Aug 08, 2022 4:06 am

Re: Question about Drag and Drop Events

Post by susan »

idle wrote: Sun Dec 07, 2025 4:41 am it's a window event to say that a gadget got a drop event.
That sort of clears it up. Using this terminology what I was wondering is why #PB_Event_GadgetDrop is a Windows event, and not a Gadget event?

I was expecting a sort of "symmetry" where all the drag and drop events would be at the same level in my event loop code. But since #PB_Event_GadgetDrop is a window event and #PB_EventType_DragStart is a gadget event, they aren't.

I am trying to see patterns in the way PureBasic works, and this difference in the event (one is for the window the other is for the gadgets) even though they are both related to drag and drop, stood out to me.

I hope that explains my (wrong) thinking better, and why I was wondering if there is a reason they aren't both Gadget events?
miso
Enthusiast
Enthusiast
Posts: 675
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Question about Drag and Drop Events

Post by miso »

I always got confused with these things. They might be straightforward, but I use them so rarely, that I forget all these behaviors.
User avatar
TI-994A
Addict
Addict
Posts: 2791
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Question about Drag and Drop Events

Post by TI-994A »

susan wrote: Sun Dec 07, 2025 5:41 amI was expecting a sort of "symmetry" where all the drag and drop events would be at the same level in my event loop code. But since #PB_Event_GadgetDrop is a window event and #PB_EventType_DragStart is a gadget event, they aren't.
So, your question is, why not just add a corresponding drop event-type to d&d-enabled gadgets, like #PB_EventType_Drop?

Firstly, the drag and drop functionality is meant to be system-wide, meaning that any d&d-enabled element should be able to have its content dragged from it, or allow external content to be dropped into it, even between separate and external applications. In such inter-application drops, no gadget events would be triggered.

Therefore, PureBasic coordinates these exchanges with its gadget drop library, which triggers the system-wide #PB_Event_GadgetDrop event.

Hope it clarifies. :D
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
mk-soft
Always Here
Always Here
Posts: 6539
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Question about Drag and Drop Events

Post by mk-soft »

In PureBasic, all events are passed to the user program via WaitWindowEvent.
This makes it very easy for us to process events (thanks, Fred). Especially with the different operating systems Windows, Linux, macOS.
Fred has thus pre-processed the window, the object (EventGadget, EventMenu, EventTimer) and the event type that is passed on to an event.
Otherwise, we would have to program each OS differently ourselves

- Window Messages
- Linux g_signal_connect
- macOS object delegate

You can see how the internal event system works in PureBasic by looking at the PB function PostEvent.
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
User avatar
susan
User
User
Posts: 27
Joined: Mon Aug 08, 2022 4:06 am

Re: Question about Drag and Drop Events

Post by susan »

TI-994A wrote: Sun Dec 07, 2025 11:02 am So, your question is, why not just add a corresponding drop event-type to d&d-enabled gadgets, like #PB_EventType_Drop?

Firstly, the drag and drop functionality is meant to be system-wide, meaning that any d&d-enabled element should be able to have its content dragged from it, or allow external content to be dropped into it, even between separate and external applications. In such inter-application drops, no gadget events would be triggered.
I understand now, thanks. I was too focussed on the gadgets and thinking only the gadgets were capable of drag and drop. But if the app (as a whole) needs to know about a drop action, that makes sense.

I knew there would be a good reason!
Post Reply