comparison os2/dw.c @ 1752:2d3cd1f616a9

Fixed some gcc compiler warnings on OS/2. Also added initial support for Unicode cut and paste on OS/2.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 15 Jun 2012 23:04:32 +0000
parents 96c6133ce3b2
children 9f7fc4fca5a6
comparison
equal deleted inserted replaced
1751:96c6133ce3b2 1752:2d3cd1f616a9
2961 } 2961 }
2962 } 2962 }
2963 break; 2963 break;
2964 case WM_CHAR: 2964 case WM_CHAR:
2965 { 2965 {
2966 int (API_FUNC keypressfunc)(HWND, char, int, int, void *, char *) = (int (API_FUNC)(HWND, char, int, int, void *, char *))tmp->signalfunction; 2966 int (API_FUNC keypressfunc)(HWND, char, int, int, void *, char *) = (int (API_FUNC)(HWND, char, int, int, void *, char *))tmp->signalfunction;
2967 2967
2968 if((hWnd == tmp->window || _toplevel_window(hWnd) == tmp->window) && !(SHORT1FROMMP(mp1) & KC_KEYUP)) 2968 if((hWnd == tmp->window || _toplevel_window(hWnd) == tmp->window) && !(SHORT1FROMMP(mp1) & KC_KEYUP))
2969 { 2969 {
2970 int vk; 2970 int vk;
2971 char ch[2] = {0}; 2971 char ch[2] = {0};
2972 char *utf8 = NULL; 2972 char *utf8 = NULL;
2973 #ifdef UNICODE 2973 #ifdef UNICODE
2974 UniChar uc[2] = {0}; 2974 UniChar uc[2] = {0};
2975 VDKEY vdk; 2975 VDKEY vdk;
2976 BYTE bscan; 2976 BYTE bscan;
2977 2977 UniTranslateKey(Keyboard, SHORT1FROMMP(mp1) & KC_SHIFT ? 1 : 0, CHAR4FROMMP(mp1), uc, &vdk, &bscan);
2978 UniTranslateKey(Keyboard, 0, CHAR4FROMMP(mp1), uc, &vdk, &bscan);
2979 utf8 = _WideToUTF8(uc); 2978 utf8 = _WideToUTF8(uc);
2980 #endif 2979 #endif
2981 2980
2982 if(SHORT1FROMMP(mp1) & KC_CHAR) 2981 if(SHORT1FROMMP(mp1) & KC_CHAR)
2983 ch[0] = (char)SHORT1FROMMP(mp2); 2982 ch[0] = (char)SHORT1FROMMP(mp2);
4211 HFILE handle; 4210 HFILE handle;
4212 struct 4211 struct
4213 { 4212 {
4214 USHORT length; 4213 USHORT length;
4215 USHORT codepage; 4214 USHORT codepage;
4216 UCHAR strings[8]; 4215 CHAR strings[8];
4217 } kd; 4216 } kd;
4218 ULONG action; 4217 ULONG action;
4219 UniChar *buf = NULL; 4218 UniChar *buf = NULL;
4220 4219
4221 if(DosOpen("KBD$", &handle, &action, 0, 0, 4220 if(DosOpen((PSZ)"KBD$", &handle, &action, 0, 0,
4222 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, 4221 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
4223 OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, 4222 OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE,
4224 NULL) == 0) 4223 NULL) == 0)
4225 { 4224 {
4226 ULONG plen = 0, dlen = sizeof(kd); 4225 ULONG plen = 0, dlen = sizeof(kd);
4227 4226
4228 kd.length = dlen; 4227 kd.length = dlen;
4229 4228
11689 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not 11688 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not
11690 * be converted to text. 11689 * be converted to text.
11691 */ 11690 */
11692 char * API dw_clipboard_get_text(void) 11691 char * API dw_clipboard_get_text(void)
11693 { 11692 {
11694 APIRET rc;
11695 char *retbuf = NULL; 11693 char *retbuf = NULL;
11696 ULONG fmtInfo; 11694 #ifdef UNICODE
11695 UniChar *unistr;
11696 #endif
11697 11697
11698 WinOpenClipbrd(dwhab); 11698 WinOpenClipbrd(dwhab);
11699 11699
11700 rc = WinQueryClipbrdFmtInfo(dwhab, CF_TEXT, &fmtInfo); 11700 #ifdef UNICODE
11701 if (rc) /* Text data in clipboard */ 11701 if(!Unicode || !(unistr = (UniChar *)WinQueryClipbrdData(dwhab, Unicode)) ||
11702 !(retbuf = _WideToUTF8(unistr)))
11703 #endif
11702 { 11704 {
11703 PSZ pszClipText = (PSZ)WinQueryClipbrdData(dwhab, CF_TEXT); /* Query data handle */ 11705 ULONG fmtInfo;
11704 retbuf = strdup((char *)pszClipText); 11706
11707 if (WinQueryClipbrdFmtInfo(dwhab, CF_TEXT, &fmtInfo)) /* Text data in clipboard */
11708 {
11709 PSZ pszClipText = (PSZ)WinQueryClipbrdData(dwhab, CF_TEXT); /* Query data handle */
11710 retbuf = strdup((char *)pszClipText);
11711 }
11705 } 11712 }
11706 WinCloseClipbrd(dwhab); 11713 WinCloseClipbrd(dwhab);
11707 return retbuf; 11714 return retbuf;
11708 } 11715 }
11709 11716
11712 * Parameters: 11719 * Parameters:
11713 * Text. 11720 * Text.
11714 */ 11721 */
11715 void API dw_clipboard_set_text( char *str, int len ) 11722 void API dw_clipboard_set_text( char *str, int len )
11716 { 11723 {
11717 APIRET rc;
11718 static PVOID shared; 11724 static PVOID shared;
11725 PVOID old = shared, src = str;
11726 int buflen = len + 1;
11719 11727
11720 WinOpenClipbrd(dwhab); /* Open clipboard */ 11728 WinOpenClipbrd(dwhab); /* Open clipboard */
11721 WinEmptyClipbrd(dwhab); /* Empty clipboard */ 11729 WinEmptyClipbrd(dwhab); /* Empty clipboard */
11722 11730
11723 /* Ok, clipboard wants giveable unnamed shared memory */ 11731 /* Ok, clipboard wants giveable unnamed shared memory */
11724
11725 shared = NULL; 11732 shared = NULL;
11726 rc = DosAllocSharedMem(&shared, NULL, len, OBJ_GIVEABLE | PAG_COMMIT | PAG_READ | PAG_WRITE); 11733 if(!DosAllocSharedMem(&shared, NULL, buflen, OBJ_GIVEABLE | PAG_COMMIT | PAG_READ | PAG_WRITE))
11727
11728 if (rc == 0)
11729 { 11734 {
11730 memcpy(shared, str, len); 11735 memcpy(shared, src, buflen);
11731 11736
11732 WinSetClipbrdData(dwhab, (ULONG)shared, CF_TEXT, CFI_POINTER); 11737 WinSetClipbrdData(dwhab, (ULONG)shared, CF_TEXT, CFI_POINTER);
11733 } 11738 }
11739 if(old)
11740 DosFreeMem(old);
11741
11742 #ifdef UNICODE
11743 if(Unicode)
11744 {
11745 UniChar *unistr = NULL;
11746 static PVOID ushared;
11747 PVOID uold = ushared;
11748
11749 src = calloc(len + 1, 1);
11750
11751 memcpy(src, str, len);
11752 unistr = _UTF8toWide((char *)src);
11753 free(src);
11754
11755 if(unistr)
11756 {
11757 buflen = (UniStrlen(unistr) + 1) * sizeof(UniChar);
11758 src = unistr;
11759 /* Ok, clipboard wants giveable unnamed shared memory */
11760 ushared = NULL;
11761 if(!DosAllocSharedMem(&ushared, NULL, buflen, OBJ_GIVEABLE | PAG_COMMIT | PAG_READ | PAG_WRITE))
11762 {
11763 memcpy(ushared, src, buflen);
11764
11765 WinSetClipbrdData(dwhab, (ULONG)ushared, Unicode, CFI_POINTER);
11766 }
11767 free(unistr);
11768 }
11769 if(uold)
11770 DosFreeMem(uold);
11771 }
11772 #endif
11734 11773
11735 WinCloseClipbrd(dwhab); /* Close clipboard */ 11774 WinCloseClipbrd(dwhab); /* Close clipboard */
11736 return; 11775 return;
11737 } 11776 }
11738 11777