int handle(int event) { // handle paste operations if (event == FL_PASTE) { // ignore paste operations that weren't due to drag-and-drop // since they could be any arbitrary data/text, and not just filenames. if (dragpending) { int len = Fl::event_length(); // ignore zero-length paste events (why do these occur???) if (len > 0) { int numfiles, i; const char *lastc; int lasti; FileSpec spec; const char *ctext = Fl::event_text(); char *filename = (char *) malloc((1 + len) * sizeof(char)); for (lasti=0,lastc=ctext,numfiles=0,i=0; i<len; i++) { // parse out all but last filename, which doesn't have a CR if (ctext[i] == '\n') { memcpy(filename, lastc, (i-lasti)*sizeof(char)); filename[i-lasti] = '\0'; // attempt to load the file into a new molecule app->molecule_load(-1, filename, NULL, &spec); lasti=i+1; lastc=&ctext[lasti]; numfiles++; } // special-case last filename, since there's no CR if (i == (len-1)) { memcpy(filename, lastc, (1+i-lasti)*sizeof(char)); filename[1+i-lasti] = '\0'; // attempt to load the file into a new molecule app->molecule_load(-1, filename, NULL, &spec); numfiles++; } } free(filename); } dragpending = 0; // no longer waiting for drag-and-drop paste } return 1; // indicate that we handled the paste operation } // handle drag-and-drop operations if (event == FL_DND_ENTER || event == FL_DND_DRAG) { return 1; // indicate that we want the drag-and-drop operation } if (event == FL_DND_RELEASE) { Fl::paste(*this); dragpending = 1; // flag to expect incoming paste due to DND operation return 1; } // end of cut-paste and drag-and-drop handling switch (event) { case FL_MOUSEWHEEL: dispdev->lastevent = event; dispdev->lastzdelta = Fl::event_dy(); break; case FL_PUSH: dispdev->lastevent = event; dispdev->lastbtn = Fl::event_button(); if (dispdev->lastbtn == FL_LEFT_MOUSE && Fl::event_state(FL_META)) { dispdev->lastbtn = FL_MIDDLE_MOUSE; } break; case FL_DRAG: dispdev->lastevent = event; break; case FL_RELEASE: dispdev->lastevent = event; break; #if (FL_MAJOR_VERSION >= 1) && (FL_MINOR_VERSION >= 1) case FL_KEYDOWN: #else // This event code is superceded by FL_KEYDOWN in newer revs of FLTK case FL_KEYBOARD: #endif dispdev->lastevent = event; dispdev->lastkeycode = Fl::event_key(); dispdev->lastbtn = *Fl::event_text(); break; default: return Fl_Gl_Window::handle(event); } return 1; }