Starting a new thread about my drag and drop problem since I have managed to 
extend Erco's drag and drop example to demonstrate the problem I'm seeing.  The 
problem happens when I have a window where I have overridden resize.  In this 
case I'm not doing any special processing in resize, but in my own app I am 
using it.  I have taken
control of it because I want my dividers to stay the same height while
letting the other widgets proportionally shrink/expand.  So in this example I 
leave it pretty much blank.  I am wondering if there is some code I should be 
doing to keep things right.

What you'll see when building is that the receiver's window will accept drag 
and drop operations right up at the top of the window; the box will turn blue 
there instead of when moving the dnd cursor over the box itself.  Eliminate 
resize() and you get expected behavior.

I am trying to comb the FLTK source code to see what the default code is for 
handling resize events in case there is some important housekeeping I am 
missing in my real code.


#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <iostream>

using namespace std;

//
// Demo of Drag+Drop (DND) from red sender to green receiver
// Most of this taken from Erco's FLTK Cheat Sheet page, particularly the
// drag and drop demonstration.  The receiver has been modified to expose the
// dilemma I have about how to update the receiver while the drag operation is
// in flight.
// Modifed by Adam Preble
//

// SENDER CLASS
class Sender : public Fl_Box {
public:
  // Sender Ctor
  Sender(int x,int y,int w,int h) : Fl_Box(x,y,w,h) {
    box(FL_FLAT_BOX); color(9); label("Drag from here");
  }
  // Sender event handler
  int handle(int event) {
    int ret = Fl_Box::handle(event);
    switch ( event ) {
    case FL_PUSH:               // do 'copy/dnd' when someone clicks on box
      Fl::copy("message",7,0);
      Fl::dnd();
      ret = 1;
      break;
    }
    return(ret);
  }
};

// RECEIVER CLASS
class Receiver : public Fl_Box {
public:
  // Receiver Ctor
  Receiver(int x,int y,int w,int h) : Fl_Box(x,y,w,h) {
    box(FL_FLAT_BOX); color(10); label("to here");
  }
  // Receiver event handler
  int handle(int event) {
    int ret = Fl_Box::handle(event);
    switch ( event ) {
    case FL_DND_ENTER:          // return(1) for these events to 'accept' dnd
      cout << "FL_DND_ENTER (" << Fl::event_x() << ", "
           << Fl::event_y() << ")" << endl;
      color(FL_BLUE);
      redraw();
      ret = 1;
      break;

    case FL_DND_LEAVE:
      cout << "FL_DND_LEAVE (" << Fl::event_x() << ", "
           << Fl::event_y() << ")" << endl;
      color(10);
      redraw();
      ret = 1;
      break;

    case FL_DND_DRAG:
      cout << "FL_DND_DRAG (" << Fl::event_x() << ", "
           << Fl::event_y() << ")" << endl;
      ret = 1;
      break;

    case FL_DND_RELEASE:
      cout << "FL_DND_RELEASE (" << Fl::event_x() << ", "
           << Fl::event_y() << ")" << endl;
      ret = 1;
      break;

    case FL_PASTE:
      cout << "FL_PASTE (" << Fl::event_x() << ", "
           << Fl::event_y() << ")" << endl;
      label(Fl::event_text());
      fprintf(stderr, "PASTE: %s\n", Fl::event_text());
      ret = 1;
      break;

    case FL_ENTER:
      cout << "FL_ENTER (" << Fl::event_x() << ", "
           << Fl::event_y() << ")" << endl;
      color(FL_YELLOW);
      redraw();
      break;
    case FL_LEAVE:
      cout << "FL_LEAVE (" << Fl::event_x() << ", "
           << Fl::event_y() << ")" << endl;
      color(10);
      redraw();
      break;
    }
    return(ret);
  }
};

class ReceiverWindow : public Fl_Window {
public:
  Receiver b;

  ReceiverWindow(int X, int Y) :
    Fl_Window(X, Y, 200, 100, "Receiver"), b(5, 40, 190, 20) {

  }

  int handle(int event) {
    return Fl_Window::handle(event);
  }

  // ********* Manual control of resize causes the problem ***************
  void resize(int X, int Y, int W, int H) {
    cout << "Receiver resize" << endl;
  }

};

int main(int argc, char **argv) {
  // Create sender window and widget
  Fl_Window win_a(0,0,200,100,"Sender");
  Sender a(0,0,100,100);
  win_a.end();
  win_a.show();
  ReceiverWindow win_b(400, 0);
  win_b.show();
  return(Fl::run());
}

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to