summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2018-08-10 15:44:39 +0000
committerManolo Gouy <Manolo>2018-08-10 15:44:39 +0000
commit1b25d1d3a054d187c3ab45d34c2a6f0671d0bde7 (patch)
tree77e32289f5b0d63ca975d6555f4710c68c779a93
parenta9e2a78bb0d6e243d904f1b0923559284cbe9e79 (diff)
Support recent MS Office apps that use \r\n as end of line in pasteboard.
FLTK now transforms that into \n as is expected under MacOS. Older MS Office apps used \r as old MacOS software. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@13014 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--src/Fl_cocoa.mm21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 1371d7a67..f20fb227f 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -80,7 +80,7 @@ extern int fl_send_system_handlers(void *e);
// forward definition of functions in this file
// converting cr lf converter function
-static void convert_crlf(char * string, size_t len);
+static size_t convert_crlf(char * string, size_t len);
static void createAppleMenu(void);
static void cocoaMouseHandler(NSEvent *theEvent);
static void clipboard_check(void);
@@ -3253,10 +3253,20 @@ Fl_Quartz_Copy_Surface_Driver::~Fl_Quartz_Copy_Surface_Driver()
// Copy & Paste fltk implementation.
////////////////////////////////////////////////////////////////
-static void convert_crlf(char * s, size_t len)
+static size_t convert_crlf(char * s, size_t len)
{
- // turn all \r characters into \n:
- for (size_t x = 0; x < len; x++) if (s[x] == '\r') s[x] = '\n';
+ // turn \r characters into \n and "\r\n" sequences into \n:
+ char *p;
+ size_t l = len;
+ while ((p = strchr(s, '\r'))) {
+ if (*(p+1) == '\n') {
+ memmove(p, p+1, l-(p-s));
+ len--; l--;
+ } else *p = '\n';
+ l -= p-s;
+ s = p + 1;
+ }
+ return len;
}
// clipboard variables definitions :
@@ -3339,8 +3349,7 @@ static int get_plain_text_from_clipboard(int clipboard)
[data getBytes:fl_selection_buffer[clipboard]];
}
fl_selection_buffer[clipboard][len - 1] = 0;
- length = len - 1;
- convert_crlf(fl_selection_buffer[clipboard], len - 1); // turn all \r characters into \n:
+ length = convert_crlf(fl_selection_buffer[clipboard], len - 1); // turn all \r characters into \n:
Fl::e_clipboard_type = Fl::clipboard_plain_text;
}
}