Page 1 of 1
Question about Drag and Drop Events
Posted: Sun Dec 07, 2025 2:38 am
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.
Re: Question about Drag and Drop Events
Posted: Sun Dec 07, 2025 4:41 am
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
Re: Question about Drag and Drop Events
Posted: Sun Dec 07, 2025 5:41 am
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?
Re: Question about Drag and Drop Events
Posted: Sun Dec 07, 2025 5:54 am
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.
Re: Question about Drag and Drop Events
Posted: Sun Dec 07, 2025 11:02 am
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.

Re: Question about Drag and Drop Events
Posted: Sun Dec 07, 2025 11:09 am
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.
Re: Question about Drag and Drop Events
Posted: Sun Dec 07, 2025 9:47 pm
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!