Mercurial > dwindows
comparison win/dw.c @ 1754:eeec5ceec7a5
Enable unicode cut and paste on Windows.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 16 Jun 2012 08:49:10 +0000 |
parents | 1de7daad85a3 |
children | 3bbbb5a55cf8 |
comparison
equal
deleted
inserted
replaced
1753:87c215963fdc | 1754:eeec5ceec7a5 |
---|---|
11554 * be converted to text. | 11554 * be converted to text. |
11555 */ | 11555 */ |
11556 char * API dw_clipboard_get_text(void) | 11556 char * API dw_clipboard_get_text(void) |
11557 { | 11557 { |
11558 HANDLE handle; | 11558 HANDLE handle; |
11559 char *tmp, *ret = NULL; | 11559 char *ret = NULL; |
11560 TCHAR *tmp; | |
11561 #ifdef UNICODE | |
11562 int type = CF_UNICODETEXT; | |
11563 #else | |
11564 int type = CF_TEXT; | |
11565 #endif | |
11560 | 11566 |
11561 if ( !OpenClipboard( NULL ) ) | 11567 if ( !OpenClipboard( NULL ) ) |
11562 return ret; | 11568 return ret; |
11563 | 11569 |
11564 if ( ( handle = GetClipboardData( CF_TEXT) ) == NULL ) | 11570 if ( ( handle = GetClipboardData(type) ) == NULL ) |
11565 { | 11571 { |
11566 CloseClipboard(); | 11572 CloseClipboard(); |
11567 return ret; | 11573 return ret; |
11568 } | 11574 } |
11569 | 11575 |
11570 if ( (tmp = GlobalLock(handle)) && strlen(tmp) ) | 11576 if ( (tmp = GlobalLock(handle)) && _tcslen(tmp) ) |
11571 { | 11577 { |
11572 ret = _strdup(tmp); | 11578 ret = _strdup(WideToUTF8(tmp)); |
11573 GlobalUnlock(handle); | 11579 GlobalUnlock(handle); |
11574 } | 11580 } |
11575 CloseClipboard(); | 11581 CloseClipboard(); |
11576 return ret; | 11582 return ret; |
11577 } | 11583 } |
11583 */ | 11589 */ |
11584 void API dw_clipboard_set_text( char *str, int len ) | 11590 void API dw_clipboard_set_text( char *str, int len ) |
11585 { | 11591 { |
11586 HGLOBAL ptr1; | 11592 HGLOBAL ptr1; |
11587 LPTSTR ptr2; | 11593 LPTSTR ptr2; |
11594 TCHAR *buf; | |
11595 #ifdef UNICODE | |
11596 int type = CF_UNICODETEXT; | |
11597 char *src = calloc(len + 1, 1); | |
11598 | |
11599 memcpy(src, str, len); | |
11600 buf = UTF8toWide(src); | |
11601 free(src); | |
11602 len = _tcslen(buf); | |
11603 #else | |
11604 int type = CF_TEXT; | |
11605 | |
11606 buf = str; | |
11607 #endif | |
11588 | 11608 |
11589 if ( !OpenClipboard( NULL ) ) | 11609 if ( !OpenClipboard( NULL ) ) |
11590 return; | 11610 return; |
11591 | 11611 |
11592 ptr1 = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (len + 1) * sizeof(TCHAR) ); | 11612 ptr1 = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (len + 1) * sizeof(TCHAR) ); |
11594 if ( !ptr1 ) | 11614 if ( !ptr1 ) |
11595 return; | 11615 return; |
11596 | 11616 |
11597 ptr2 = GlobalLock( ptr1 ); | 11617 ptr2 = GlobalLock( ptr1 ); |
11598 | 11618 |
11599 memcpy( (char *)ptr2, str, len + 1); | 11619 memcpy(ptr2, buf, (len + 1) * sizeof(TCHAR)); |
11600 GlobalUnlock( ptr1 ); | 11620 GlobalUnlock( ptr1 ); |
11601 EmptyClipboard(); | 11621 EmptyClipboard(); |
11602 | 11622 |
11603 SetClipboardData( CF_TEXT, ptr1 ); | 11623 SetClipboardData( type, ptr1 ); |
11604 | 11624 |
11605 CloseClipboard(); | 11625 CloseClipboard(); |
11606 GlobalFree( ptr1 ); | 11626 GlobalFree( ptr1 ); |
11607 | |
11608 return; | |
11609 } | 11627 } |
11610 | 11628 |
11611 /* | 11629 /* |
11612 * Returns some information about the current operating environment. | 11630 * Returns some information about the current operating environment. |
11613 * Parameters: | 11631 * Parameters: |