On 19.12.2007, at 19:48, Alvin wrote: > I have created a little application that uses libmtp to communicate > with my > Samsung T10 mp3 player. The app supports dropping files onto in > order to > upload audio and video files to the device.
Um, the Subject of your mail seems to ask a different question than the text of your mail?! Anyway, this is how you do either: if you want your app to be a dnd source (dragging items from your app to somewhere else), you can use Fl::dnd(). You can use any reason to initiate a dnd operation, but normally it would be an FL_DRAG with Fl::event_is_click() returning 0. So here we go: - write a new handle() function for some widget. - on FL_PUSH, return 1, so you will receive subsequend FL_DRAG events - on FL_DRAG, test Fl::event_is_click() - as soon as the user draggs the mouse more than a few pixels, is_click() will return 0. This should initiate your dnd event - fill the clipboard with the text you want to send <http://www.fltk.org/documentation.php/doc-1.1/Fl.html#Fl.copy> + FLTK has a limitation here. Whatever is in the clipboard is always sent as text. So sending the path to a file might not actually send the file, but just the path and filename. Some apps interprete that correctly, some don't. On Unix, you may have better luck prepending the word "file:" to the pathname. - call Fl::dnd() and let the OS do the rest <http://www.fltk.org/documentation.php/doc-1.1/Fl.html#Fl.dnd> if a widget in your app is supposed to receive dnd data, you again override the handle() methood and implement a few handlers for the DND events. Again, step by step: These are the events: <http://www.fltk.org/documentation.php/doc-1.1/events.html#dnd> - FL_DND_ENTER is called when the mouse pointer enters your widget while carrying DND data. The copy-paste buffer may already contain whatever the user is about to drop, so you can peek and then decide if you want to accept the data. Accept by returning 1, decline by returning 0 - FL_DND_DRAG is sent whenever the mouse moves. Use this event to decide if you are going to accept the data (return 0 or 1) and also indicate to the user what the efect of a drop would be (for example, in a list, you would indicate where the data would be dropped and if it would replacea field or insert between two fields) - FL_DND_LEAVE should remove the previously explained preview. - FL_DND_RELEASE is sent if the user releases the mouse button on top of this widget. You can still accept or decline by returning 1 or 0 respectively - If you accepted, you will now get an FL_PASTE event with the data set in the copy-paste buffer. If a file was dropped, this will be the full file- and pathname, sometimes prepended with the letters "file:". If multiple files were dropped, you will receive a "\n" seperated list of file/pathnames. Matthias ---- http://robowerk.com/ _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

