From aacb5277e7499ed087cff495169484f6f6274d3c Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Mon, 28 Mar 2016 17:36:07 +0000 Subject: [PATCH] Rewrite Fl_dnd.cxx under the driver model. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11455 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/Fl_System_Driver.H | 3 +++ FL/mac.H | 1 - src/CMakeLists.txt | 3 ++- src/Fl.cxx | 5 +++++ src/Fl_Input.cxx | 7 ++----- src/Fl_Text_Display.cxx | 7 ++----- src/Fl_cocoa.mm | 7 ++----- src/Makefile | 7 ++++--- src/drivers/Darwin/Fl_Darwin_System_Driver.H | 1 + src/drivers/Posix/Fl_Posix_System_Driver.H | 1 + src/drivers/WinAPI/Fl_WinAPI_System_Driver.H | 1 + src/fl_dnd_win32.cxx | 3 ++- src/fl_dnd_x.cxx | 9 +++++---- 13 files changed, 30 insertions(+), 25 deletions(-) diff --git a/FL/Fl_System_Driver.H b/FL/Fl_System_Driver.H index 21726b8a4..6e3a92aee 100644 --- a/FL/Fl_System_Driver.H +++ b/FL/Fl_System_Driver.H @@ -90,6 +90,9 @@ public: virtual int compose(int &del) {del = 0; return 0;} // default implementation may be enough virtual void compose_reset() { Fl::compose_state = 0; } + // implement to support drag-n-drop. use_selection = 1 means the GUI is welcome to display + // the selected text during the D&D operation + virtual int dnd(int use_selection) {return 0;} }; #endif // FL_SYSTEM_DRIVER_H diff --git a/FL/mac.H b/FL/mac.H index 0f4a6ae80..48fd2255d 100644 --- a/FL/mac.H +++ b/FL/mac.H @@ -191,7 +191,6 @@ public: static int insertion_point_location(int *px, int *py, int *pheight); // computes window coordinates & height of insertion point static const int CoreText_threshold; // Mac OS version from which the Core Text API is used to display text static Fl_Fontdesc* calc_fl_fonts(void); // computes the fl_fonts global variable - static int dnd(int use_selection); // call Fl_X::dnd(1) to support text dragging static int calc_mac_os_version(void); // computes the fl_mac_os_version global variable static void clip_to_rounded_corners(CGContextRef gc, int w, int h); static void complete_copy_pdf_and_tiff(CGContextRef gc, CFMutableDataRef pdfdata); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d572be517..96e0ea8a9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -113,7 +113,6 @@ set (CPPFILES fl_cursor.cxx fl_curve.cxx fl_diamond_box.cxx - fl_dnd.cxx fl_draw.cxx fl_draw_pixmap.cxx fl_engraved_label.cxx @@ -185,6 +184,7 @@ if (USE_X11) drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx Fl_x.cxx + fl_dnd_x.cxx ) if (USE_XFT) set (DRIVER_FILES ${DRIVER_FILES} @@ -278,6 +278,7 @@ else () drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx Fl_win32.cxx + fl_dnd_win32.cxx ) set (DRIVER_HEADER_FILES drivers/WinAPI/Fl_WinAPI_System_Driver.H diff --git a/src/Fl.cxx b/src/Fl.cxx index 742129fc4..e45119c9d 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -1876,6 +1877,10 @@ Fl_Widget_Tracker::~Fl_Widget_Tracker() int Fl::use_high_res_GL_ = 0; +int Fl::dnd() +{ + return Fl_System_Driver::driver()->dnd(0); +} // // End of "$Id$". diff --git a/src/Fl_Input.cxx b/src/Fl_Input.cxx index cf9bcb4a7..f752b2b68 100644 --- a/src/Fl_Input.cxx +++ b/src/Fl_Input.cxx @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -687,11 +688,7 @@ int Fl_Input::handle(int event) { dnd_save_focus = this; // drag the data: copy(0); -#ifdef __APPLE__ // PORTME: dnd - Fl_X::dnd(1); -#else - Fl::dnd(); -#endif + Fl_System_Driver::driver()->dnd(1); return 1; } } diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx index cae7aedfd..cf9e0c9e5 100644 --- a/src/Fl_Text_Display.cxx +++ b/src/Fl_Text_Display.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #if defined(WIN32) || defined(__APPLE__) // PORTME: Fl_Screen_Driver - platform editor feel #elif defined(FL_PORTING) @@ -3913,11 +3914,7 @@ int Fl_Text_Display::handle(int event) { if (dragType==DRAG_START_DND) { if (!Fl::event_is_click() && Fl::dnd_text_ops()) { const char* copy = buffer()->selection_text(); -#ifdef __APPLE__ // PORTME: Fl_Screen_Driver - platform behavior - Fl_X::dnd(1); -#else - Fl::dnd(); -#endif + Fl_System_Driver::driver()->dnd(1); free((void*)copy); } return 1; diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index ba61563c3..b6be6baba 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -45,6 +45,7 @@ extern "C" { #include "drivers/Quartz/Fl_Quartz_Graphics_Driver.H" #include "drivers/Cocoa/Fl_Cocoa_Screen_Driver.H" #include "drivers/Cocoa/Fl_Cocoa_Window_Driver.H" +#include "drivers/Darwin/Fl_Darwin_System_Driver.H" #include #include #include @@ -3945,12 +3946,8 @@ static NSImage *defaultDragImage(int *pwidth, int *pheight) return image; } -int Fl::dnd() -{ - return Fl_X::dnd(0); -} -int Fl_X::dnd(int use_selection) +int Fl_Darwin_System_Driver::dnd(int use_selection) { CFDataRef text = CFDataCreate(kCFAllocatorDefault, (UInt8*)fl_selection_buffer[0], fl_selection_length[0]); if (text==NULL) return false; diff --git a/src/Makefile b/src/Makefile index a8f6562db..bcd9f9faa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -132,7 +132,6 @@ CPPFILES = \ fl_cursor.cxx \ fl_curve.cxx \ fl_diamond_box.cxx \ - fl_dnd.cxx \ fl_draw.cxx \ fl_draw_pixmap.cxx \ fl_encoding_latin1.cxx \ @@ -253,7 +252,8 @@ XLIBCPPFILES = \ drivers/X11/Fl_X11_Screen_Driver.cxx \ drivers/Posix/Fl_Posix_System_Driver.cxx \ drivers/Posix/Fl_Posix_Printer_Driver.cxx \ - Fl_x.cxx + Fl_x.cxx \ + fl_dnd_x.cxx XLIBFONTFILES = \ drivers/Xlib/Fl_Xlib_Graphics_Driver_font_x.cxx @@ -276,7 +276,8 @@ GDICPPFILES = \ drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx \ drivers/WinAPI/Fl_WinAPI_System_Driver.cxx \ drivers/WinAPI/Fl_WinAPI_Printer_Driver.cxx \ - Fl_win32.cxx + Fl_win32.cxx \ + fl_dnd_win32.cxx PSCPPFILES = \ drivers/PostScript/Fl_PostScript.cxx \ diff --git a/src/drivers/Darwin/Fl_Darwin_System_Driver.H b/src/drivers/Darwin/Fl_Darwin_System_Driver.H index 61a7c961e..fdf34c5e0 100644 --- a/src/drivers/Darwin/Fl_Darwin_System_Driver.H +++ b/src/drivers/Darwin/Fl_Darwin_System_Driver.H @@ -44,6 +44,7 @@ public: virtual int single_arg(const char *arg); virtual int arg_and_value(const char *name, const char *value); virtual int compose(int &del); + virtual int dnd(int use_selection); }; #endif // FL_DARWIN_SYSTEM_DRIVER_H diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.H b/src/drivers/Posix/Fl_Posix_System_Driver.H index 56a6675d3..0000a0dc2 100644 --- a/src/drivers/Posix/Fl_Posix_System_Driver.H +++ b/src/drivers/Posix/Fl_Posix_System_Driver.H @@ -45,6 +45,7 @@ public: virtual int XParseGeometry(const char*, int*, int*, unsigned int*, unsigned int*); virtual int compose(int &del); virtual void compose_reset(); + virtual int dnd(int unused); }; #endif // FL_POSIX_SYSTEM_DRIVER_H diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H index 049c516d4..d0fb2d634 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H @@ -46,6 +46,7 @@ public: virtual void error(const char *format, va_list args); virtual void fatal(const char *format, va_list args); virtual int compose(int &del); + virtual int dnd(int unused); }; #endif // FL_WINAPI_SYSTEM_DRIVER_H diff --git a/src/fl_dnd_win32.cxx b/src/fl_dnd_win32.cxx index b56561f28..8e0b88f11 100644 --- a/src/fl_dnd_win32.cxx +++ b/src/fl_dnd_win32.cxx @@ -24,6 +24,7 @@ #include #include #include +#include "drivers/WinAPI/Fl_WinAPI_System_Driver.H" #include "flstring.h" #include #include @@ -520,7 +521,7 @@ public: }; -int Fl::dnd() +int Fl_WinAPI_System_Driver::dnd(int unused) { DWORD dropEffect; ReleaseCapture(); diff --git a/src/fl_dnd_x.cxx b/src/fl_dnd_x.cxx index ca449cfa5..da33e0ecc 100644 --- a/src/fl_dnd_x.cxx +++ b/src/fl_dnd_x.cxx @@ -20,6 +20,7 @@ #include #include #include "flstring.h" +#include "drivers/Posix/Fl_Posix_System_Driver.H" extern Atom fl_XdndAware; @@ -79,7 +80,7 @@ static int local_handle(int event, Fl_Window* window) { return ret; } -int Fl::dnd() { +int Fl_Posix_System_Driver::dnd(int unused) { Fl_Window *source_fl_win = Fl::first_window(); Fl::first_window()->cursor(FL_CURSOR_MOVE); Window source_window = fl_xid(Fl::first_window()); @@ -97,7 +98,7 @@ int Fl::dnd() { for (Window child = RootWindow(fl_display, fl_screen);;) { Window root; unsigned int junk3; XQueryPointer(fl_display, child, &root, &child, - &e_x_root, &e_y_root, &dest_x, &dest_y, &junk3); + &Fl::e_x_root, &Fl::e_y_root, &dest_x, &dest_y, &junk3); if (!child) { if (!new_window && (new_version = dnd_aware(root))) new_window = root; break; @@ -151,7 +152,7 @@ int Fl::dnd() { local_handle(FL_DND_DRAG, local_window); } else if (dndversion) { fl_sendClientMessage(target_window, fl_XdndPosition, source_window, - 0, (e_x_root<<16)|e_y_root, fl_event_time, + 0, (Fl::e_x_root<<16)|Fl::e_y_root, fl_event_time, fl_XdndActionCopy); } Fl::wait(); @@ -159,7 +160,7 @@ int Fl::dnd() { if (local_window) { fl_i_own_selection[0] = 1; - if (local_handle(FL_DND_RELEASE, local_window)) paste(*belowmouse(), 0); + if (local_handle(FL_DND_RELEASE, local_window)) Fl::paste(*Fl::belowmouse(), 0); } else if (dndversion) { fl_sendClientMessage(target_window, fl_XdndDrop, source_window, 0, fl_event_time);