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.3.x-osx-clip.patch 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. diff -up fltk-1.3.3/src/Fl_cocoa.mm.clip fltk-1.3.3/src/Fl_cocoa.mm
  2. --- fltk-1.3.3/src/Fl_cocoa.mm.clip 2014-11-02 22:06:07.000000000 +0100
  3. +++ fltk-1.3.3/src/Fl_cocoa.mm 2015-04-20 13:45:03.526688921 +0200
  4. @@ -3061,6 +3061,14 @@ static void clipboard_check(void)
  5. fl_trigger_clipboard_notify(1);
  6. }
  7. +static void resize_selection_buffer(int len, int clipboard) {
  8. + if (len <= fl_selection_buffer_length[clipboard])
  9. + return;
  10. + delete[] fl_selection_buffer[clipboard];
  11. + fl_selection_buffer[clipboard] = new char[len+100];
  12. + fl_selection_buffer_length[clipboard] = len+100;
  13. +}
  14. +
  15. /*
  16. * create a selection
  17. * stuff: pointer to selected data
  18. @@ -3069,11 +3077,7 @@ static void clipboard_check(void)
  19. */
  20. void Fl::copy(const char *stuff, int len, int clipboard, const char *type) {
  21. if (!stuff || len<0) return;
  22. - if (len+1 > fl_selection_buffer_length[clipboard]) {
  23. - delete[] fl_selection_buffer[clipboard];
  24. - fl_selection_buffer[clipboard] = new char[len+100];
  25. - fl_selection_buffer_length[clipboard] = len+100;
  26. - }
  27. + resize_selection_buffer(len+1, clipboard);
  28. memcpy(fl_selection_buffer[clipboard], stuff, len);
  29. fl_selection_buffer[clipboard][len] = 0; // needed for direct paste
  30. fl_selection_length[clipboard] = len;
  31. @@ -3087,7 +3091,7 @@ void Fl::copy(const char *stuff, int len
  32. }
  33. }
  34. -static int get_plain_text_from_clipboard(char **buffer, int previous_length)
  35. +static int get_plain_text_from_clipboard(int clipboard)
  36. {
  37. NSInteger length = 0;
  38. NSPasteboard *clip = [NSPasteboard generalPasteboard];
  39. @@ -3109,21 +3113,17 @@ static int get_plain_text_from_clipboard
  40. len = strlen(aux_c) + 1;
  41. }
  42. else len = [data length] + 1;
  43. - if ( len >= previous_length ) {
  44. - length = len;
  45. - delete[] *buffer;
  46. - *buffer = new char[len];
  47. - }
  48. + resize_selection_buffer(len, clipboard);
  49. if (![found isEqualToString:utf8_format]) {
  50. - strcpy(*buffer, aux_c);
  51. - free(aux_c);
  52. + strcpy(fl_selection_buffer[clipboard], aux_c);
  53. + free(aux_c);
  54. }
  55. else {
  56. - [data getBytes:*buffer];
  57. + [data getBytes:fl_selection_buffer[clipboard]];
  58. }
  59. - (*buffer)[len - 1] = 0;
  60. + fl_selection_buffer[clipboard][len - 1] = 0;
  61. length = len - 1;
  62. - convert_crlf(*buffer, len - 1); // turn all \r characters into \n:
  63. + convert_crlf(fl_selection_buffer[clipboard], len - 1); // turn all \r characters into \n:
  64. Fl::e_clipboard_type = Fl::clipboard_plain_text;
  65. }
  66. }
  67. @@ -3218,7 +3218,7 @@ void Fl::paste(Fl_Widget &receiver, int
  68. if (clipboard) {
  69. Fl::e_clipboard_type = "";
  70. if (strcmp(type, Fl::clipboard_plain_text) == 0) {
  71. - fl_selection_length[1] = get_plain_text_from_clipboard( &fl_selection_buffer[1], fl_selection_length[1]);
  72. + fl_selection_length[1] = get_plain_text_from_clipboard(1);
  73. }
  74. else if (strcmp(type, Fl::clipboard_image) == 0) {
  75. Fl::e_clipboard_data = get_image_from_clipboard( );