Tweak themes for more color consistency.
[ntk.git] / examples / howto-drag-and-drop.cxx
blobcb41a4803d27e7fada50a02a76448b497ce43d11
1 //
2 // "$Id: howto-drag-and-drop.cxx 8221 2011-01-08 18:58:50Z greg.ercolano $"
3 //
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.
7 //
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
26 // USA.
28 // Please report all bugs and problems on the following page:
30 // http://www.fltk.org/str.php
33 #include <stdio.h>
34 #include <FL/Fl.H>
35 #include <FL/Fl_Window.H>
36 #include <FL/Fl_Box.H>
38 // SIMPLE SENDER CLASS
39 class Sender : public Fl_Box {
40 public:
41 // Ctor
42 Sender(int x,int y,int w,int h) : Fl_Box(x,y,w,h) {
43 box(FL_FLAT_BOX);
44 color(9);
45 label("Drag\nfrom\nhere..");
47 // Sender event handler
48 int handle(int event) {
49 int ret = Fl_Box::handle(event);
50 switch ( 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);
54 Fl::dnd();
55 ret = 1;
56 break;
59 return(ret);
62 // SIMPLE RECEIVER CLASS
63 class Receiver : public Fl_Box {
64 public:
65 // Ctor
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);
72 switch ( event ) {
73 case FL_DND_ENTER: // return(1) for these events to 'accept' dnd
74 case FL_DND_DRAG:
75 case FL_DND_RELEASE:
76 ret = 1;
77 break;
78 case FL_PASTE: // handle actual drop (paste) operation
79 label(Fl::event_text());
80 fprintf(stderr, "Pasted '%s'\n", Fl::event_text());
81 ret = 1;
82 break;
84 return(ret);
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);
91 win_a.end();
92 win_a.show();
93 // Create receiver window and widget
94 Fl_Window win_b(400,0,200,100,"Receiver");
95 Receiver b(100,0,100,100);
96 win_b.end();
97 win_b.show();
98 return(Fl::run());
102 // End of "$Id: howto-drag-and-drop.cxx 8221 2011-01-08 18:58:50Z greg.ercolano $".