You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fltk-1_v3.3.x-clipboard-win32-fix.patch 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. diff -ur fltk-1.3.0r9110.org/src/Fl_win32.cxx fltk-1.3.0r9110/src/Fl_win32.cxx
  2. --- fltk-1.3.0r9110.org/src/Fl_win32.cxx 2012-06-17 19:42:02.169422400 +0200
  3. +++ fltk-1.3.0r9110/src/Fl_win32.cxx 2012-06-17 19:43:38.286031455 +0200
  4. @@ -543,6 +543,37 @@
  5. const char* GetValue() const { return(out); }
  6. };
  7. +void fl_update_clipboard(void) {
  8. + Fl_Window *w1 = Fl::first_window();
  9. + if (!w1)
  10. + return;
  11. +
  12. + HWND hwnd = fl_xid(w1);
  13. +
  14. + if (!OpenClipboard(hwnd))
  15. + return;
  16. +
  17. + EmptyClipboard();
  18. +
  19. + int utf16_len = fl_utf8toUtf16(fl_selection_buffer[1],
  20. + fl_selection_length[1], 0, 0);
  21. +
  22. + HGLOBAL hMem = GlobalAlloc(GHND, utf16_len * 2 + 2); // moveable and zero'ed mem alloc.
  23. + LPVOID memLock = GlobalLock(hMem);
  24. +
  25. + fl_utf8toUtf16(fl_selection_buffer[1], fl_selection_length[1],
  26. + (unsigned short*) memLock, utf16_len + 1);
  27. +
  28. + GlobalUnlock(hMem);
  29. + SetClipboardData(CF_UNICODETEXT, hMem);
  30. +
  31. + CloseClipboard();
  32. +
  33. + // In case Windows managed to lob of a WM_DESTROYCLIPBOARD during
  34. + // the above.
  35. + fl_i_own_selection[1] = 1;
  36. +}
  37. +
  38. // call this when you create a selection:
  39. void Fl::copy(const char *stuff, int len, int clipboard) {
  40. if (!stuff || len<0) return;
  41. @@ -560,25 +591,9 @@
  42. memcpy(fl_selection_buffer[clipboard], stuff, len);
  43. fl_selection_buffer[clipboard][len] = 0; // needed for direct paste
  44. fl_selection_length[clipboard] = len;
  45. - if (clipboard) {
  46. - // set up for "delayed rendering":
  47. - if (OpenClipboard(NULL)) {
  48. - // if the system clipboard works, use it
  49. - int utf16_len = fl_utf8toUtf16(fl_selection_buffer[clipboard], fl_selection_length[clipboard], 0, 0);
  50. - EmptyClipboard();
  51. - HGLOBAL hMem = GlobalAlloc(GHND, utf16_len * 2 + 2); // moveable and zero'ed mem alloc.
  52. - LPVOID memLock = GlobalLock(hMem);
  53. - fl_utf8toUtf16(fl_selection_buffer[clipboard], fl_selection_length[clipboard], (unsigned short*) memLock, utf16_len + 1);
  54. - GlobalUnlock(hMem);
  55. - SetClipboardData(CF_UNICODETEXT, hMem);
  56. - CloseClipboard();
  57. - GlobalFree(hMem);
  58. - fl_i_own_selection[clipboard] = 0;
  59. - } else {
  60. - // only if it fails, instruct paste() to use the internal buffers
  61. - fl_i_own_selection[clipboard] = 1;
  62. - }
  63. - }
  64. + fl_i_own_selection[clipboard] = 1;
  65. + if (clipboard)
  66. + fl_update_clipboard();
  67. }
  68. // Call this when a "paste" operation happens:
  69. @@ -1307,33 +1322,6 @@
  70. fl_i_own_selection[1] = 0;
  71. return 1;
  72. - case WM_RENDERALLFORMATS:
  73. - fl_i_own_selection[1] = 0;
  74. - // Windoze seems unhappy unless I do these two steps. Documentation
  75. - // seems to vary on whether opening the clipboard is necessary or
  76. - // is in fact wrong:
  77. - CloseClipboard();
  78. - OpenClipboard(NULL);
  79. - // fall through...
  80. - case WM_RENDERFORMAT: {
  81. - HANDLE h;
  82. -
  83. -// int l = fl_utf_nb_char((unsigned char*)fl_selection_buffer[1], fl_selection_length[1]);
  84. - int l = fl_utf8toUtf16(fl_selection_buffer[1], fl_selection_length[1], NULL, 0); // Pass NULL buffer to query length required
  85. - h = GlobalAlloc(GHND, (l+1) * sizeof(unsigned short));
  86. - if (h) {
  87. - unsigned short *g = (unsigned short*) GlobalLock(h);
  88. -// fl_utf2unicode((unsigned char *)fl_selection_buffer[1], fl_selection_length[1], (xchar*)g);
  89. - l = fl_utf8toUtf16(fl_selection_buffer[1], fl_selection_length[1], g, (l+1));
  90. - g[l] = 0;
  91. - GlobalUnlock(h);
  92. - SetClipboardData(CF_UNICODETEXT, h);
  93. - }
  94. -
  95. - // Windoze also seems unhappy if I don't do this. Documentation very
  96. - // unclear on what is correct:
  97. - if (fl_msg.message == WM_RENDERALLFORMATS) CloseClipboard();
  98. - return 1;}
  99. case WM_DISPLAYCHANGE: // occurs when screen configuration (number, position) changes
  100. Fl::call_screen_init();
  101. Fl::handle(FL_SCREEN_CONFIGURATION_CHANGED, NULL);
  102. diff -ur fltk-1.3.0r9110.org/src/Fl.cxx fltk-1.3.0r9110/src/Fl.cxx
  103. --- fltk-1.3.0r9110.org/src/Fl.cxx 2012-06-17 19:42:02.173422595 +0200
  104. +++ fltk-1.3.0r9110/src/Fl.cxx 2012-06-17 19:42:02.317429497 +0200
  105. @@ -1420,7 +1420,9 @@
  106. ////////////////////////////////////////////////////////////////
  107. // hide() destroys the X window, it does not do unmap!
  108. -#if !defined(WIN32) && USE_XFT
  109. +#if defined(WIN32)
  110. +extern void fl_update_clipboard(void);
  111. +#elif USE_XFT
  112. extern void fl_destroy_xft_draw(Window);
  113. #endif
  114. @@ -1467,14 +1469,8 @@
  115. #if defined(WIN32)
  116. // this little trick keeps the current clipboard alive, even if we are about
  117. // to destroy the window that owns the selection.
  118. - if (GetClipboardOwner()==ip->xid) {
  119. - Fl_Window *w1 = Fl::first_window();
  120. - if (w1 && OpenClipboard(fl_xid(w1))) {
  121. - EmptyClipboard();
  122. - SetClipboardData(CF_TEXT, NULL);
  123. - CloseClipboard();
  124. - }
  125. - }
  126. + if (GetClipboardOwner()==ip->xid)
  127. + fl_update_clipboard();
  128. // Send a message to myself so that I'll get out of the event loop...
  129. PostMessage(ip->xid, WM_APP, 0, 0);
  130. if (ip->private_dc) fl_release_dc(ip->xid, ip->private_dc);