diff -up ./Fl.cxx.b5111 ./Fl.cxx diff -up ./Fl_win32.cxx.b5111 ./Fl_win32.cxx --- ./Fl_win32.cxx.b5111 2014-05-23 13:11:10.341222221 +0200 +++ ./Fl_win32.cxx 2014-05-28 11:28:36.791545786 +0200 @@ -652,9 +652,20 @@ static HWND clipboard_wnd = 0; static HWND next_clipboard_wnd = 0; static bool initial_clipboard = true; +void fl_clipboard_notify_target(HWND wnd); void fl_clipboard_notify_change() { - // No need to do anything here... + // untarget clipboard monitor if no handlers are registered + if (clipboard_wnd != NULL && fl_clipboard_notify_empty()) + { + fl_clipboard_notify_untarget(clipboard_wnd); + return; + } + + // if there are clipboard notify handlers but no window targeted + // target first window if available + if (clipboard_wnd == NULL && Fl::first_window()) + fl_clipboard_notify_target(fl_xid(Fl::first_window())); } void fl_clipboard_notify_target(HWND wnd) { @@ -983,8 +994,7 @@ static LRESULT CALLBACK WndProc(HWND hWn case WM_CLOSE: // user clicked close box Fl::handle(FL_CLOSE, window); - PostQuitMessage(0); - return 0; + break; case WM_SYNCPAINT : case WM_NCPAINT : @@ -1367,12 +1377,11 @@ static LRESULT CALLBACK WndProc(HWND hWn return 0; case WM_CHANGECBCHAIN: - if ((hWnd == clipboard_wnd) && - (next_clipboard_wnd == (HWND)wParam)) { + if ((hWnd == clipboard_wnd) && (next_clipboard_wnd == (HWND)wParam)) next_clipboard_wnd = (HWND)lParam; - return 0; - } - break; + else + SendMessage(next_clipboard_wnd, WM_CHANGECBCHAIN, wParam, lParam); + return 0; case WM_DRAWCLIPBOARD: // When the clipboard moves between two FLTK windows, @@ -1847,7 +1856,10 @@ Fl_X* Fl_X::make(Fl_Window* w) { x->next = Fl_X::first; Fl_X::first = x; - fl_clipboard_notify_target(x->xid); + // Setup clipboard monitor target if there are registered handlers and + // no window is targeted. + if (!fl_clipboard_notify_empty() && clipboard_wnd == NULL) + fl_clipboard_notify_target(x->xid); x->wait_for_expose = 1; if (fl_show_iconic) {showit = 0; fl_show_iconic = 0;}