summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2017-08-05 14:25:09 +0000
committerManolo Gouy <Manolo>2017-08-05 14:25:09 +0000
commit6126e8cb0ebcf5ce02603facf017c6c4d80d58ea (patch)
tree6d49a38118683f4729f5f5f8929a26b7a2fffe46 /src
parent090f3257805bfacece14db19863b6db98051aed2 (diff)
Strenghten Fl_WinAPI_System_Driver::paste(): the widget's handle method may change Fl::e_text.
The widget's handle method may change the value of Fl::e_text. This occurs for instance if this method calls fl_choice(). So, memorize the value of Fl::e_text before, to delete the correct array after the call to the handle method. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12371 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_win32.cxx22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx
index ebca3c57d..b8deb0e91 100644
--- a/src/Fl_win32.cxx
+++ b/src/Fl_win32.cxx
@@ -718,17 +718,18 @@ void Fl_WinAPI_System_Driver::paste(Fl_Widget &receiver, int clipboard, const ch
Fl::e_text = 0;
return;
}
- Fl::e_text = new char[fl_selection_length[clipboard]+1];
- char *o = Fl::e_text;
+ char *clip_text = new char[fl_selection_length[clipboard]+1];
+ char *o = clip_text;
while (*i) { // Convert \r\n -> \n
if ( *i == '\r' && *(i+1) == '\n') i++;
else *o++ = *i++;
}
*o = 0;
+ Fl::e_text = clip_text;
Fl::e_length = (int) (o - Fl::e_text);
Fl::e_clipboard_type = Fl::clipboard_plain_text;
- receiver.handle(FL_PASTE);
- delete [] Fl::e_text;
+ receiver.handle(FL_PASTE); // this may change Fl::e_text
+ delete [] clip_text;
Fl::e_text = 0;
} else if (clipboard) {
HANDLE h;
@@ -737,21 +738,22 @@ void Fl_WinAPI_System_Driver::paste(Fl_Widget &receiver, int clipboard, const ch
if ((h = GetClipboardData(CF_UNICODETEXT))) { // there's text in the clipboard
wchar_t *memLock = (wchar_t*) GlobalLock(h);
size_t utf16_len = wcslen(memLock);
- Fl::e_text = new char[utf16_len * 4 + 1];
- unsigned utf8_len = fl_utf8fromwc(Fl::e_text, (unsigned) (utf16_len * 4), memLock, (unsigned) utf16_len);
- *(Fl::e_text + utf8_len) = 0;
+ char *clip_text = new char[utf16_len * 4 + 1];
+ unsigned utf8_len = fl_utf8fromwc(clip_text, (unsigned) (utf16_len * 4), memLock, (unsigned) utf16_len);
+ *(clip_text + utf8_len) = 0;
GlobalUnlock(h);
LPSTR a,b;
- a = b = Fl::e_text;
+ a = b = clip_text;
while (*a) { // strip the CRLF pairs ($%$#@^)
if (*a == '\r' && a[1] == '\n') a++;
else *b++ = *a++;
}
*b = 0;
+ Fl::e_text = clip_text;
Fl::e_length = (int) (b - Fl::e_text);
Fl::e_clipboard_type = Fl::clipboard_plain_text; // indicates that the paste event is for plain UTF8 text
- receiver.handle(FL_PASTE); // send the FL_PASTE event to the widget
- delete[] Fl::e_text;
+ receiver.handle(FL_PASTE); // send the FL_PASTE event to the widget. May change Fl::e_text
+ delete[] clip_text;
Fl::e_text = 0;
}
}