| 1 | /* $Id: clipboard.cpp,v 1.16 2002-11-25 09:48:13 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * Win32 Clipboard API functions for OS/2 | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1998 Sander van Leeuwen | 
|---|
| 7 | * Copyright 1998 Patrick Haller | 
|---|
| 8 | * Copyright 1998 Peter Fitzsimmons | 
|---|
| 9 | * | 
|---|
| 10 | * | 
|---|
| 11 | * NOTE: Use OS/2 frame handles for Open32 functions | 
|---|
| 12 | * | 
|---|
| 13 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 14 | * | 
|---|
| 15 | */ | 
|---|
| 16 |  | 
|---|
| 17 | #include <os2win.h> | 
|---|
| 18 | #include <string.h> | 
|---|
| 19 | #include "win32wbase.h" | 
|---|
| 20 | #include <unicode.h> | 
|---|
| 21 |  | 
|---|
| 22 | #define DBG_LOCALLOG    DBG_clipboard | 
|---|
| 23 | #include "dbglocal.h" | 
|---|
| 24 |  | 
|---|
| 25 | //****************************************************************************** | 
|---|
| 26 | //****************************************************************************** | 
|---|
| 27 | BOOL WIN32API ChangeClipboardChain( HWND hwndRemove, HWND hwndNext) | 
|---|
| 28 | { | 
|---|
| 29 | Win32BaseWindow *wndRemove, *wndNext; | 
|---|
| 30 | HWND hwndOS2Remove, hwndOS2Next = 0; | 
|---|
| 31 |  | 
|---|
| 32 | wndRemove = Win32BaseWindow::GetWindowFromHandle(hwndRemove); | 
|---|
| 33 | if(!wndRemove) { | 
|---|
| 34 | dprintf(("ChangeClipboardChain, window %x not found", hwndRemove)); | 
|---|
| 35 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 36 | return 0; | 
|---|
| 37 | } | 
|---|
| 38 | hwndOS2Remove = wndRemove->getOS2WindowHandle(); | 
|---|
| 39 | RELEASE_WNDOBJ(wndRemove); | 
|---|
| 40 |  | 
|---|
| 41 | if(hwndNext) { | 
|---|
| 42 | wndNext = Win32BaseWindow::GetWindowFromHandle(hwndNext); | 
|---|
| 43 | if(!wndNext) { | 
|---|
| 44 | dprintf(("ChangeClipboardChain, window %x not found", hwndNext)); | 
|---|
| 45 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 46 | return 0; | 
|---|
| 47 | } | 
|---|
| 48 | hwndOS2Next = wndNext->getOS2WindowHandle(); | 
|---|
| 49 | RELEASE_WNDOBJ(wndNext); | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | dprintf(("USER32:  ChangeClipboardChain\n")); | 
|---|
| 53 | return O32_ChangeClipboardChain(hwndOS2Remove, hwndOS2Next); | 
|---|
| 54 | } | 
|---|
| 55 | //****************************************************************************** | 
|---|
| 56 | //****************************************************************************** | 
|---|
| 57 | int WIN32API CountClipboardFormats(void) | 
|---|
| 58 | { | 
|---|
| 59 | dprintf(("USER32: CountClipboardFormats")); | 
|---|
| 60 | return O32_CountClipboardFormats(); | 
|---|
| 61 | } | 
|---|
| 62 | //****************************************************************************** | 
|---|
| 63 | //****************************************************************************** | 
|---|
| 64 | BOOL WIN32API EmptyClipboard(void) | 
|---|
| 65 | { | 
|---|
| 66 | dprintf(("USER32: EmptyClipboard")); | 
|---|
| 67 | return O32_EmptyClipboard(); | 
|---|
| 68 | } | 
|---|
| 69 | //****************************************************************************** | 
|---|
| 70 | //****************************************************************************** | 
|---|
| 71 | UINT WIN32API EnumClipboardFormats(UINT arg1) | 
|---|
| 72 | { | 
|---|
| 73 | dprintf(("USER32: EnumClipboardFormats %d", arg1)); | 
|---|
| 74 | return O32_EnumClipboardFormats(arg1); | 
|---|
| 75 | } | 
|---|
| 76 | //****************************************************************************** | 
|---|
| 77 | //****************************************************************************** | 
|---|
| 78 | int WIN32API GetClipboardFormatNameA(UINT format,LPSTR lpszFormatName,int cchMaxCount) | 
|---|
| 79 | { | 
|---|
| 80 | dprintf(("USER32: GetClipboardFormatNameA %d\n",format)); | 
|---|
| 81 | return O32_GetClipboardFormatName(format,lpszFormatName,cchMaxCount); | 
|---|
| 82 | } | 
|---|
| 83 | //****************************************************************************** | 
|---|
| 84 | //****************************************************************************** | 
|---|
| 85 | int WIN32API GetClipboardFormatNameW(UINT format,LPWSTR lpszFormatName,int cchMaxCount) | 
|---|
| 86 | { | 
|---|
| 87 | int   rc; | 
|---|
| 88 | char *astring = (CHAR*)malloc(cchMaxCount); | 
|---|
| 89 |  | 
|---|
| 90 | rc = GetClipboardFormatNameA(format,astring,cchMaxCount); | 
|---|
| 91 | if (rc) AsciiToUnicode(astring,lpszFormatName); | 
|---|
| 92 | free(astring); | 
|---|
| 93 | return(rc); | 
|---|
| 94 | } | 
|---|
| 95 | //****************************************************************************** | 
|---|
| 96 | //****************************************************************************** | 
|---|
| 97 | HWND WIN32API GetClipboardOwner(void) | 
|---|
| 98 | { | 
|---|
| 99 | HWND hwndOwner; | 
|---|
| 100 | Win32BaseWindow *window; | 
|---|
| 101 |  | 
|---|
| 102 | dprintf(("USER32: GetClipboardOwner\n")); | 
|---|
| 103 | hwndOwner = O32_GetClipboardOwner(); | 
|---|
| 104 |  | 
|---|
| 105 | window = Win32BaseWindow::GetWindowFromOS2Handle(hwndOwner); | 
|---|
| 106 | if(!window) { | 
|---|
| 107 | //an OS/2 window probably owns the clipboard, we pretend nobody owns it | 
|---|
| 108 | return NULL; | 
|---|
| 109 | } | 
|---|
| 110 | hwndOwner = window->getWindowHandle(); | 
|---|
| 111 | RELEASE_WNDOBJ(window); | 
|---|
| 112 | return hwndOwner; | 
|---|
| 113 | } | 
|---|
| 114 | //****************************************************************************** | 
|---|
| 115 | //****************************************************************************** | 
|---|
| 116 | HWND WIN32API GetClipboardViewer(void) | 
|---|
| 117 | { | 
|---|
| 118 | Win32BaseWindow *window; | 
|---|
| 119 | HWND hwndViewer; | 
|---|
| 120 |  | 
|---|
| 121 | dprintf(("USER32: GetClipboardViewer")); | 
|---|
| 122 | hwndViewer = O32_GetClipboardViewer(); | 
|---|
| 123 |  | 
|---|
| 124 | window = Win32BaseWindow::GetWindowFromOS2Handle(hwndViewer); | 
|---|
| 125 | if(!window) { | 
|---|
| 126 | //probably an OS/2 window, we pretend it's nobody | 
|---|
| 127 | return NULL; | 
|---|
| 128 | } | 
|---|
| 129 | hwndViewer = window->getWindowHandle(); | 
|---|
| 130 | RELEASE_WNDOBJ(window); | 
|---|
| 131 | return hwndViewer; | 
|---|
| 132 | } | 
|---|
| 133 | //****************************************************************************** | 
|---|
| 134 | //****************************************************************************** | 
|---|
| 135 | HWND WIN32API SetClipboardViewer( HWND hwndNew) | 
|---|
| 136 | { | 
|---|
| 137 | Win32BaseWindow *wndnew, *wndold; | 
|---|
| 138 | HWND hwndOld; | 
|---|
| 139 | HWND hwndOS2New; | 
|---|
| 140 |  | 
|---|
| 141 | wndnew = Win32BaseWindow::GetWindowFromHandle(hwndNew); | 
|---|
| 142 | if(!wndnew) { | 
|---|
| 143 | dprintf(("SetClipboardViewer, window %x not found", hwndNew)); | 
|---|
| 144 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 145 | return 0; | 
|---|
| 146 | } | 
|---|
| 147 | dprintf(("USER32: SetClipboardViewer %x", hwndNew)); | 
|---|
| 148 | hwndOS2New = wndnew->getOS2WindowHandle(); | 
|---|
| 149 | RELEASE_WNDOBJ(wndnew); | 
|---|
| 150 |  | 
|---|
| 151 | hwndOld = O32_SetClipboardViewer(hwndOS2New); | 
|---|
| 152 |  | 
|---|
| 153 | wndold = Win32BaseWindow::GetWindowFromOS2Handle(hwndOld); | 
|---|
| 154 | if(!wndold) { | 
|---|
| 155 | //probably an OS/2 window, so pretend it's nobody | 
|---|
| 156 | return 0; | 
|---|
| 157 | } | 
|---|
| 158 | hwndOld = wndold->getWindowHandle(); | 
|---|
| 159 | RELEASE_WNDOBJ(wndold); | 
|---|
| 160 | return hwndOld; | 
|---|
| 161 | } | 
|---|
| 162 | //****************************************************************************** | 
|---|
| 163 | //****************************************************************************** | 
|---|
| 164 | HWND WIN32API GetOpenClipboardWindow(void) | 
|---|
| 165 | { | 
|---|
| 166 | Win32BaseWindow *window; | 
|---|
| 167 | HWND hwnd; | 
|---|
| 168 |  | 
|---|
| 169 | dprintf(("USER32: GetOpenClipboardWindow")); | 
|---|
| 170 | hwnd = O32_GetOpenClipboardWindow(); | 
|---|
| 171 |  | 
|---|
| 172 | window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd); | 
|---|
| 173 | if(!window) { | 
|---|
| 174 | //probably an OS/2 window, we pretend it's nobody | 
|---|
| 175 | return NULL; | 
|---|
| 176 | } | 
|---|
| 177 | hwnd = window->getWindowHandle(); | 
|---|
| 178 | RELEASE_WNDOBJ(window); | 
|---|
| 179 | return hwnd; | 
|---|
| 180 | } | 
|---|
| 181 | //****************************************************************************** | 
|---|
| 182 | //****************************************************************************** | 
|---|
| 183 | int WIN32API GetPriorityClipboardFormat( PUINT arg1, int arg2) | 
|---|
| 184 | { | 
|---|
| 185 | dprintf(("USER32: GetPriorityClipboardFormat")); | 
|---|
| 186 | return O32_GetPriorityClipboardFormat(arg1, arg2); | 
|---|
| 187 | } | 
|---|
| 188 | //****************************************************************************** | 
|---|
| 189 | //****************************************************************************** | 
|---|
| 190 | BOOL WIN32API IsClipboardFormatAvailable( UINT arg1) | 
|---|
| 191 | { | 
|---|
| 192 | dprintf(("USER32: IsClipboardFormatAvailable %x", arg1)); | 
|---|
| 193 | return O32_IsClipboardFormatAvailable(arg1); | 
|---|
| 194 | } | 
|---|
| 195 | //****************************************************************************** | 
|---|
| 196 | //****************************************************************************** | 
|---|
| 197 | BOOL WIN32API OpenClipboard( HWND hwnd) | 
|---|
| 198 | { | 
|---|
| 199 | Win32BaseWindow *window; | 
|---|
| 200 |  | 
|---|
| 201 | if (hwnd) { | 
|---|
| 202 | window = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 203 | if(!window) { | 
|---|
| 204 | dprintf(("OpenClipboard, window %x not found", hwnd)); | 
|---|
| 205 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 206 | return 0; | 
|---|
| 207 | } | 
|---|
| 208 | hwnd = window->getOS2WindowHandle(); | 
|---|
| 209 | RELEASE_WNDOBJ(window); | 
|---|
| 210 | } | 
|---|
| 211 | dprintf(("USER32: OpenClipboard %x", hwnd)); | 
|---|
| 212 | return O32_OpenClipboard(hwnd); | 
|---|
| 213 | } | 
|---|
| 214 | //****************************************************************************** | 
|---|
| 215 | //****************************************************************************** | 
|---|
| 216 | BOOL WIN32API CloseClipboard(void) | 
|---|
| 217 | { | 
|---|
| 218 | dprintf(("USER32: CloseClipboard")); | 
|---|
| 219 | return O32_CloseClipboard(); | 
|---|
| 220 | } | 
|---|
| 221 | //****************************************************************************** | 
|---|
| 222 | //****************************************************************************** | 
|---|
| 223 | UINT WIN32API RegisterClipboardFormatA( LPCSTR arg1) | 
|---|
| 224 | { | 
|---|
| 225 | dprintf(("USER32:  RegisterClipboardFormatA %s", arg1)); | 
|---|
| 226 | return O32_RegisterClipboardFormat(arg1); | 
|---|
| 227 | } | 
|---|
| 228 | //****************************************************************************** | 
|---|
| 229 | //****************************************************************************** | 
|---|
| 230 | UINT WIN32API RegisterClipboardFormatW(LPCWSTR arg1) | 
|---|
| 231 | { | 
|---|
| 232 | UINT  rc; | 
|---|
| 233 | char *astring = UnicodeToAsciiString((LPWSTR)arg1); | 
|---|
| 234 |  | 
|---|
| 235 | dprintf(("USER32:  RegisterClipboardFormatW %s\n", astring)); | 
|---|
| 236 | rc = O32_RegisterClipboardFormat(astring); | 
|---|
| 237 | FreeAsciiString(astring); | 
|---|
| 238 | dprintf(("USER32:  RegisterClipboardFormatW returned %d\n", rc)); | 
|---|
| 239 | return(rc); | 
|---|
| 240 | } | 
|---|
| 241 | //****************************************************************************** | 
|---|
| 242 | //****************************************************************************** | 
|---|
| 243 | HANDLE WIN32API GetClipboardData(UINT uFormat) | 
|---|
| 244 | { | 
|---|
| 245 | HANDLE hRet = O32_GetClipboardData(uFormat); | 
|---|
| 246 | dprintf(("GetClipboardData %x returned %x", uFormat, hRet)); | 
|---|
| 247 | #ifdef DEBUG | 
|---|
| 248 | if(hRet) { | 
|---|
| 249 | if(uFormat == CF_TEXT || uFormat == CF_DSPTEXT) { | 
|---|
| 250 | char *lpszText = (char *)GlobalLock(hRet); | 
|---|
| 251 | if(lpszText) dprintf(("GetClipboardData %s", lpszText)); | 
|---|
| 252 | GlobalUnlock(hRet); | 
|---|
| 253 | } | 
|---|
| 254 | if(uFormat == CF_UNICODETEXT) { | 
|---|
| 255 | LPWSTR lpszText = (LPWSTR)GlobalLock(hRet); | 
|---|
| 256 | if(lpszText) dprintf(("GetClipboardData %ls", lpszText)); | 
|---|
| 257 | GlobalUnlock(hRet); | 
|---|
| 258 | } | 
|---|
| 259 | } | 
|---|
| 260 | #endif | 
|---|
| 261 | return hRet; | 
|---|
| 262 | } | 
|---|
| 263 | //****************************************************************************** | 
|---|
| 264 | //****************************************************************************** | 
|---|
| 265 | HANDLE WIN32API SetClipboardData( UINT uFormat, HANDLE hClipObj) | 
|---|
| 266 | { | 
|---|
| 267 | dprintf(("SetClipboardData %x %x", uFormat, hClipObj)); | 
|---|
| 268 | #ifdef DEBUG | 
|---|
| 269 | if(hClipObj) { | 
|---|
| 270 | if(uFormat == CF_TEXT || uFormat == CF_DSPTEXT) { | 
|---|
| 271 | char *lpszText = (char *)GlobalLock(hClipObj); | 
|---|
| 272 | if(lpszText) dprintf(("SetClipboardData %s", lpszText)); | 
|---|
| 273 | GlobalUnlock(hClipObj); | 
|---|
| 274 | } | 
|---|
| 275 | if(uFormat == CF_UNICODETEXT) { | 
|---|
| 276 | LPWSTR lpszText = (LPWSTR)GlobalLock(hClipObj); | 
|---|
| 277 | if(lpszText) dprintf(("SetClipboardData %ls", lpszText)); | 
|---|
| 278 | GlobalUnlock(hClipObj); | 
|---|
| 279 | } | 
|---|
| 280 | } | 
|---|
| 281 | #endif | 
|---|
| 282 | return O32_SetClipboardData(uFormat, hClipObj); | 
|---|
| 283 | } | 
|---|
| 284 | //****************************************************************************** | 
|---|
| 285 | //****************************************************************************** | 
|---|