2 // "$Id: howto-drag-and-drop.cxx 8221 2011-01-08 18:58:50Z greg.ercolano $"
4 // A simple demo of drag+drop with FLTK.
5 // Originally from erco's cheat sheet, permission by author.
6 // Inspired by Michael Sephton's original example posted on fltk.general.
8 // When you run the program, just drag the red square over
9 // to the green square to show a 'drag and drop' sequence.
11 // Copyright 1998-2010 by Bill Spitzak and others.
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Library General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Library General Public License for more details.
23 // You should have received a copy of the GNU Library General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 // Please report all bugs and problems on the following page:
30 // http://www.fltk.org/str.php
35 #include <FL/Fl_Window.H>
36 #include <FL/Fl_Box.H>
38 // SIMPLE SENDER CLASS
39 class Sender
: public Fl_Box
{
42 Sender(int x
,int y
,int w
,int h
) : Fl_Box(x
,y
,w
,h
) {
45 label("Drag\nfrom\nhere..");
47 // Sender event handler
48 int handle(int event
) {
49 int ret
= Fl_Box::handle(event
);
51 case FL_PUSH
: { // do 'copy/dnd' when someone clicks on box
52 const char *msg
= "It works!";
53 Fl::copy(msg
,strlen(msg
),0);
62 // SIMPLE RECEIVER CLASS
63 class Receiver
: public Fl_Box
{
66 Receiver(int x
,int y
,int w
,int h
) : Fl_Box(x
,y
,w
,h
) {
67 box(FL_FLAT_BOX
); color(10); label("..to\nhere");
69 // Receiver event handler
70 int handle(int event
) {
71 int ret
= Fl_Box::handle(event
);
73 case FL_DND_ENTER
: // return(1) for these events to 'accept' dnd
78 case FL_PASTE
: // handle actual drop (paste) operation
79 label(Fl::event_text());
80 fprintf(stderr
, "Pasted '%s'\n", Fl::event_text());
87 int main(int argc
, char **argv
) {
88 // Create sender window and widget
89 Fl_Window
win_a(0,0,200,100,"Sender");
90 Sender
a(0,0,100,100);
93 // Create receiver window and widget
94 Fl_Window
win_b(400,0,200,100,"Receiver");
95 Receiver
b(100,0,100,100);
102 // End of "$Id: howto-drag-and-drop.cxx 8221 2011-01-08 18:58:50Z greg.ercolano $".