Murga-Projects Forums

Full Version: drag 'n drop from external applications?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I'm currently evaluating the suitability of murgaLua for my needs and tried to build a basic application that receives drag and drop events from other applications (e.g., dragging file names from an explorer window on the murgaLua FLTK window).
In normal FLTK I'd to derive my own window class from Fl_Window and overwrite the handle() method in order to be able to reiceive and respond correctly to DND events, however, I'm not sure how to translate this to murgaLua. I've found the demo event_detection.lua, but this does not tell me how to correctly respond to such events.
Is there a way to implement a custom handle() method/callback, or is the handling of arbitrary events currently beyond murgaLua's scope?

Thanks for any reply, this is a great project!

znarf Wrote:
Hi,
I'm currently evaluating the suitability of murgaLua for my needs and tried to build a basic application that receives drag and drop events from other applications (e.g., dragging file names from an explorer window on the murgaLua FLTK window).
In normal FLTK I'd to derive my own window class from Fl_Window and overwrite the handle() method in order to be able to reiceive and respond correctly to DND events, however, I'm not sure how to translate this to murgaLua. I've found the demo event_detection.lua, but this does not tell me how to correctly respond to such events.
Is there a way to implement a custom handle() method/callback, or is the handling of arbitrary events currently beyond murgaLua's scope?

Thanks for any reply, this is a great project!

I've been playing with this as well and have not figured out how to drop something on a FLTK widow or widget.

I had once had a very inconsistent drag-and-drop working after several hours of hair pulling, but it seemed to work only if you dragged and dropped very deliberately, and only in certain desktop environments (definitely not portable). At the time I thought it was too flakey to bother with any further, so haven't touched it since, but you might be able to make something of it.

Code:
function dnd_check()
  if Fl:event() == fltk.FL_DND_RELEASE then
    Fl:paste(window)
    Fl:wait()
    local dropped_file=Fl:event_text()
    if dropped_file then
      print(dropped_file)
    end
  end
Fl:wait()
  timer:doWait(0.05)
end

timer=murgaLua.createFltkTimer()
timer:callback(dnd_check)
timer:do_callback()

Hey thanks! I'll give it a shot.
Dan
Keep in mind that I haven't looked at the result of this code in many months, so I can't remember if I might have done something to break it since.
Also "window" would be a pointer to the window that you want to receive the drop....I guess this could probably be made to be a parameter of the dnd_check function: function dnd_check(window)
Well the docs say that...

"FL_DND_* events cannot be used in widgets derived from Fl_Group or Fl_Window."

They should work with Fl_Box though. However I still can't get the box to want to accept the dnd event.
Weird ... I thought I had replied to this ...

I am pretty sure I know why it is not working, the DND events are probably being discarded (although they are definitely fired). If you create a window with a entry field you will see that you can drag anything to it, and then you could have a timer that checks if it's value has changed (I'll post an example in a second).

As far as trapping the DND_* (and other system events), I have implemented the event handler callback, which allows you to create a callback that responds to all events not being trapped elsewhere (including system/X events). I haven't had a chance to test this with DND events yet, but it'll should allow you to write more sensible code for these cases.

I'll push it out with the next build (hopefully this weekend).

Cheers
JohnM

JohnMurga Wrote:
If you create a window with a entry field you will see that you can drag anything to it, and then you could have a timer that checks if it's value has changed (I'll post an example in a second).


Do you still have that example handy? Also I can't seem to find the event_detection.lua demo in the examples directory.

dvw86 Wrote:
Also I can't seem to find the event_detection.lua demo in the examples directory.


Hmm I thought I replied to this thread last night.
I think you mean this event_detection available at the murgalua gallery

Thanks!
Pages: 1 2
Reference URL's