Andreas schrieb:
> Hi everyone!
> 
> I've been trying to get drag and drop to work in my application, but without 
> success.

gregs example works also with fltk2:

/*
fltk2-config --compile dnd.cxx && ./dnd
*/
#include "fltk/Box.h"
#include "fltk/events.h"
#include "fltk/Window.h"
#include "fltk/run.h"
#include <string.h>
#include <stdio.h>

using namespace fltk;

class Sender : public Widget
        {
        int no;
        int handle(int event)
                {
                switch (event)
                        {
                case PUSH:
                        char buf[16];
                        sprintf(buf,"message %d",no++);
                        copy(buf,strlen(buf),0);
                        dnd();
                        return 0;
                        }
                return Widget::handle(event);
                }
public:
        Sender(int x, int y, int w, int h)
                : Widget(x, y, w, h, "drag source")
                ,no(0)
                {
                box(UP_BOX);
                }
        };

class Receiver : public Widget
        {
        int handle(int event)
                {
                switch (event)
                        {
                case DND_ENTER:
                case DND_RELEASE:
                case DND_DRAG:
                        return 1;
                case PASTE:
                        //fprintf(stderr,"PASTE %s",event_text());
                        label(event_text());
                        redraw();
                        return 1;
                        }
                return Widget::handle(event);
                }
public:
        Receiver(int x, int y, int w, int h)
                : Widget(x, y, w, h, "drag target")
                {
                box(DOWN_BOX);
                }
        };

int main(int argc, char **argv) {
        // Create sender window and widget
        Window win_a(33,33,166,166,"Sender");
        win_a.begin();
        Sender a(33,33,100,100);
        win_a.end();
        win_a.show();
        // Create receiver window and widget
        Window win_b(433,33,166,166,"Receiver");
        win_b.begin();
        Receiver b(33,33,100,100);
        win_b.end();
        win_b.show();
        return run();
        }
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to