| 1 | /* $Id: clipboard.cpp,v 1.13 2001-07-08 15:51:41 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 | #ifdef USING_OPEN32CLIPBOARD | 
|---|
| 26 |  | 
|---|
| 27 | #define FLAG_TO_OPEN32       0 | 
|---|
| 28 | #define FLAG_FROM_OPEN32     1 | 
|---|
| 29 |  | 
|---|
| 30 | //****************************************************************************** | 
|---|
| 31 | //****************************************************************************** | 
|---|
| 32 | HGLOBAL GlobalCopy(HGLOBAL hDest, HGLOBAL hSource, BOOL fToOpen32) | 
|---|
| 33 | { | 
|---|
| 34 | LPVOID src; | 
|---|
| 35 | LPVOID dest; | 
|---|
| 36 | ULONG  size; | 
|---|
| 37 |  | 
|---|
| 38 | if(fToOpen32 == FLAG_TO_OPEN32) { | 
|---|
| 39 | src = GlobalLock(hSource); | 
|---|
| 40 | if(src) { | 
|---|
| 41 | size = GlobalSize(hSource); | 
|---|
| 42 | if(hDest == NULL) { | 
|---|
| 43 | hDest = O32_GlobalAlloc(GHND, size); | 
|---|
| 44 | } | 
|---|
| 45 | dest  = O32_GlobalLock(hDest); | 
|---|
| 46 | memcpy(dest, src, size); | 
|---|
| 47 | O32_GlobalUnlock(hDest); | 
|---|
| 48 | } | 
|---|
| 49 | GlobalUnlock(hSource); | 
|---|
| 50 | } | 
|---|
| 51 | else { | 
|---|
| 52 | src = O32_GlobalLock(hSource); | 
|---|
| 53 | if(src) { | 
|---|
| 54 | size = O32_GlobalSize(hSource); | 
|---|
| 55 | if(hDest == NULL) { | 
|---|
| 56 | hDest = GlobalAlloc(GHND, size); | 
|---|
| 57 | } | 
|---|
| 58 | dest  = GlobalLock(hDest); | 
|---|
| 59 | memcpy(dest, src, size); | 
|---|
| 60 | GlobalUnlock(hDest); | 
|---|
| 61 | } | 
|---|
| 62 | O32_GlobalUnlock(hSource); | 
|---|
| 63 | } | 
|---|
| 64 | return hDest; | 
|---|
| 65 | } | 
|---|
| 66 | #endif | 
|---|
| 67 |  | 
|---|
| 68 | //****************************************************************************** | 
|---|
| 69 | //****************************************************************************** | 
|---|
| 70 | BOOL WIN32API ChangeClipboardChain( HWND hwndRemove, HWND hwndNext) | 
|---|
| 71 | { | 
|---|
| 72 | Win32BaseWindow *wndRemove, *wndNext; | 
|---|
| 73 | HWND hwndOS2Remove, hwndOS2Next; | 
|---|
| 74 |  | 
|---|
| 75 | wndRemove = Win32BaseWindow::GetWindowFromHandle(hwndRemove); | 
|---|
| 76 | if(!wndRemove) { | 
|---|
| 77 | dprintf(("ChangeClipboardChain, window %x not found", hwndRemove)); | 
|---|
| 78 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 79 | return 0; | 
|---|
| 80 | } | 
|---|
| 81 | hwndOS2Remove = wndRemove->getOS2WindowHandle(); | 
|---|
| 82 | RELEASE_WNDOBJ(wndRemove); | 
|---|
| 83 |  | 
|---|
| 84 | wndNext = Win32BaseWindow::GetWindowFromHandle(hwndNext); | 
|---|
| 85 | if(!wndNext) { | 
|---|
| 86 | dprintf(("ChangeClipboardChain, window %x not found", hwndNext)); | 
|---|
| 87 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 88 | return 0; | 
|---|
| 89 | } | 
|---|
| 90 | hwndOS2Next = wndNext->getOS2WindowHandle(); | 
|---|
| 91 | RELEASE_WNDOBJ(wndNext); | 
|---|
| 92 |  | 
|---|
| 93 | dprintf(("USER32:  ChangeClipboardChain\n")); | 
|---|
| 94 | return O32_ChangeClipboardChain(hwndOS2Remove, hwndOS2Next); | 
|---|
| 95 | } | 
|---|
| 96 | //****************************************************************************** | 
|---|
| 97 | //****************************************************************************** | 
|---|
| 98 | BOOL WIN32API CloseClipboard(void) | 
|---|
| 99 | { | 
|---|
| 100 | dprintf(("USER32:  CloseClipboard\n")); | 
|---|
| 101 | return O32_CloseClipboard(); | 
|---|
| 102 | } | 
|---|
| 103 | //****************************************************************************** | 
|---|
| 104 | //****************************************************************************** | 
|---|
| 105 | int WIN32API CountClipboardFormats(void) | 
|---|
| 106 | { | 
|---|
| 107 | dprintf(("USER32:  CountClipboardFormats\n")); | 
|---|
| 108 | return O32_CountClipboardFormats(); | 
|---|
| 109 | } | 
|---|
| 110 | //****************************************************************************** | 
|---|
| 111 | //****************************************************************************** | 
|---|
| 112 | BOOL WIN32API EmptyClipboard(void) | 
|---|
| 113 | { | 
|---|
| 114 | dprintf(("USER32:  EmptyClipboard\n")); | 
|---|
| 115 | return O32_EmptyClipboard(); | 
|---|
| 116 | } | 
|---|
| 117 | //****************************************************************************** | 
|---|
| 118 | //****************************************************************************** | 
|---|
| 119 | UINT WIN32API EnumClipboardFormats(UINT arg1) | 
|---|
| 120 | { | 
|---|
| 121 | dprintf(("USER32:  EnumClipboardFormats\n")); | 
|---|
| 122 | return O32_EnumClipboardFormats(arg1); | 
|---|
| 123 | } | 
|---|
| 124 | //****************************************************************************** | 
|---|
| 125 | //****************************************************************************** | 
|---|
| 126 | HANDLE WIN32API GetClipboardData( UINT uFormat) | 
|---|
| 127 | { | 
|---|
| 128 | #ifdef USING_OPEN32CLIPBOARD | 
|---|
| 129 | HANDLE hClipObj = 0, hClipObjOpen32 = 0; | 
|---|
| 130 |  | 
|---|
| 131 | dprintf(("USER32: GetClipboardData %x", uFormat)); | 
|---|
| 132 | hClipObjOpen32 = O32_GetClipboardData(uFormat); | 
|---|
| 133 | //memory leak | 
|---|
| 134 | if(hClipObjOpen32) { | 
|---|
| 135 | hClipObj = GlobalCopy(NULL, hClipObjOpen32, FLAG_FROM_OPEN32); | 
|---|
| 136 | } | 
|---|
| 137 | return hClipObj; | 
|---|
| 138 | #else | 
|---|
| 139 | dprintf(("USER32: GetClipboardData %x", uFormat)); | 
|---|
| 140 | return O32_GetClipboardData(uFormat); | 
|---|
| 141 | #endif | 
|---|
| 142 | } | 
|---|
| 143 | //****************************************************************************** | 
|---|
| 144 | //****************************************************************************** | 
|---|
| 145 | int WIN32API GetClipboardFormatNameA(UINT format,LPSTR lpszFormatName,int cchMaxCount) | 
|---|
| 146 | { | 
|---|
| 147 | dprintf(("USER32:  GetClipboardFormatNameA %d\n",format)); | 
|---|
| 148 | return O32_GetClipboardFormatName(format,lpszFormatName,cchMaxCount); | 
|---|
| 149 | } | 
|---|
| 150 | //****************************************************************************** | 
|---|
| 151 | //****************************************************************************** | 
|---|
| 152 | int WIN32API GetClipboardFormatNameW(UINT format,LPWSTR lpszFormatName,int cchMaxCount) | 
|---|
| 153 | { | 
|---|
| 154 | int   rc; | 
|---|
| 155 | char *astring = (CHAR*)malloc(cchMaxCount); | 
|---|
| 156 |  | 
|---|
| 157 | dprintf(("USER32:  GetClipboardFormatNameW %d\n",format)); | 
|---|
| 158 | rc = O32_GetClipboardFormatName(format,astring,cchMaxCount); | 
|---|
| 159 | if (rc) AsciiToUnicode(astring,lpszFormatName); | 
|---|
| 160 | free(astring); | 
|---|
| 161 | return(rc); | 
|---|
| 162 | } | 
|---|
| 163 | //****************************************************************************** | 
|---|
| 164 | //****************************************************************************** | 
|---|
| 165 | HWND WIN32API GetClipboardOwner(void) | 
|---|
| 166 | { | 
|---|
| 167 | HWND hwndOwner; | 
|---|
| 168 | Win32BaseWindow *window; | 
|---|
| 169 |  | 
|---|
| 170 | dprintf(("USER32:  GetClipboardOwner\n")); | 
|---|
| 171 | hwndOwner = O32_GetClipboardOwner(); | 
|---|
| 172 |  | 
|---|
| 173 | window = Win32BaseWindow::GetWindowFromOS2Handle(hwndOwner); | 
|---|
| 174 | if(!window) { | 
|---|
| 175 | //an OS/2 window probably owns the clipboard, we pretend nobody owns it | 
|---|
| 176 | return NULL; | 
|---|
| 177 | } | 
|---|
| 178 | hwndOwner = window->getWindowHandle(); | 
|---|
| 179 | RELEASE_WNDOBJ(window); | 
|---|
| 180 | return hwndOwner; | 
|---|
| 181 | } | 
|---|
| 182 | //****************************************************************************** | 
|---|
| 183 | //****************************************************************************** | 
|---|
| 184 | HWND WIN32API GetClipboardViewer(void) | 
|---|
| 185 | { | 
|---|
| 186 | Win32BaseWindow *window; | 
|---|
| 187 | HWND hwndViewer; | 
|---|
| 188 |  | 
|---|
| 189 | dprintf(("USER32:  GetClipboardViewer\n")); | 
|---|
| 190 | hwndViewer = O32_GetClipboardViewer(); | 
|---|
| 191 |  | 
|---|
| 192 | window = Win32BaseWindow::GetWindowFromOS2Handle(hwndViewer); | 
|---|
| 193 | if(!window) { | 
|---|
| 194 | //probably an OS/2 window, we pretend it's nobody | 
|---|
| 195 | return NULL; | 
|---|
| 196 | } | 
|---|
| 197 | hwndViewer = window->getWindowHandle(); | 
|---|
| 198 | RELEASE_WNDOBJ(window); | 
|---|
| 199 | return hwndViewer; | 
|---|
| 200 | } | 
|---|
| 201 | //****************************************************************************** | 
|---|
| 202 | //****************************************************************************** | 
|---|
| 203 | HWND WIN32API GetOpenClipboardWindow(void) | 
|---|
| 204 | { | 
|---|
| 205 | Win32BaseWindow *window; | 
|---|
| 206 | HWND hwnd; | 
|---|
| 207 |  | 
|---|
| 208 | dprintf(("USER32:  GetOpenClipboardWindow\n")); | 
|---|
| 209 | hwnd = O32_GetOpenClipboardWindow(); | 
|---|
| 210 |  | 
|---|
| 211 | window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd); | 
|---|
| 212 | if(!window) { | 
|---|
| 213 | //probably an OS/2 window, we pretend it's nobody | 
|---|
| 214 | return NULL; | 
|---|
| 215 | } | 
|---|
| 216 | hwnd = window->getWindowHandle(); | 
|---|
| 217 | RELEASE_WNDOBJ(window); | 
|---|
| 218 | return hwnd; | 
|---|
| 219 | } | 
|---|
| 220 | //****************************************************************************** | 
|---|
| 221 | //****************************************************************************** | 
|---|
| 222 | int WIN32API GetPriorityClipboardFormat( PUINT arg1, int arg2) | 
|---|
| 223 | { | 
|---|
| 224 | dprintf(("USER32:  GetPriorityClipboardFormat\n")); | 
|---|
| 225 | return O32_GetPriorityClipboardFormat(arg1, arg2); | 
|---|
| 226 | } | 
|---|
| 227 | //****************************************************************************** | 
|---|
| 228 | //****************************************************************************** | 
|---|
| 229 | BOOL WIN32API IsClipboardFormatAvailable( UINT arg1) | 
|---|
| 230 | { | 
|---|
| 231 | dprintf(("USER32: IsClipboardFormatAvailable %x", arg1)); | 
|---|
| 232 | return O32_IsClipboardFormatAvailable(arg1); | 
|---|
| 233 | } | 
|---|
| 234 | //****************************************************************************** | 
|---|
| 235 | //****************************************************************************** | 
|---|
| 236 | BOOL WIN32API OpenClipboard( HWND hwnd) | 
|---|
| 237 | { | 
|---|
| 238 | Win32BaseWindow *window; | 
|---|
| 239 |  | 
|---|
| 240 | if (hwnd) { | 
|---|
| 241 | window = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 242 | if(!window) { | 
|---|
| 243 | dprintf(("OpenClipboard, window %x not found", hwnd)); | 
|---|
| 244 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 245 | return 0; | 
|---|
| 246 | } | 
|---|
| 247 | hwnd = window->getOS2WindowHandle(); | 
|---|
| 248 | RELEASE_WNDOBJ(window); | 
|---|
| 249 | } | 
|---|
| 250 | dprintf(("USER32: OpenClipboard %x", hwnd)); | 
|---|
| 251 | return O32_OpenClipboard(hwnd); | 
|---|
| 252 | } | 
|---|
| 253 | //****************************************************************************** | 
|---|
| 254 | //****************************************************************************** | 
|---|
| 255 | UINT WIN32API RegisterClipboardFormatA( LPCSTR arg1) | 
|---|
| 256 | { | 
|---|
| 257 | dprintf(("USER32:  RegisterClipboardFormatA %s", arg1)); | 
|---|
| 258 | return O32_RegisterClipboardFormat(arg1); | 
|---|
| 259 | } | 
|---|
| 260 | //****************************************************************************** | 
|---|
| 261 | //****************************************************************************** | 
|---|
| 262 | UINT WIN32API RegisterClipboardFormatW(LPCWSTR arg1) | 
|---|
| 263 | { | 
|---|
| 264 | UINT  rc; | 
|---|
| 265 | char *astring = UnicodeToAsciiString((LPWSTR)arg1); | 
|---|
| 266 |  | 
|---|
| 267 | dprintf(("USER32:  RegisterClipboardFormatW %s\n", astring)); | 
|---|
| 268 | rc = O32_RegisterClipboardFormat(astring); | 
|---|
| 269 | FreeAsciiString(astring); | 
|---|
| 270 | dprintf(("USER32:  RegisterClipboardFormatW returned %d\n", rc)); | 
|---|
| 271 | return(rc); | 
|---|
| 272 | } | 
|---|
| 273 | //****************************************************************************** | 
|---|
| 274 | //****************************************************************************** | 
|---|
| 275 | HANDLE WIN32API SetClipboardData( UINT uFormat, HANDLE hClipObj) | 
|---|
| 276 | { | 
|---|
| 277 | #ifdef USING_OPEN32CLIPBOARD | 
|---|
| 278 | HANDLE hClipObjOpen32 = 0; | 
|---|
| 279 |  | 
|---|
| 280 | dprintf(("USER32: SetClipboardData %x %x", uFormat, hClipObj)); | 
|---|
| 281 | //memory leak | 
|---|
| 282 | if(hClipObj) { | 
|---|
| 283 | hClipObjOpen32 = GlobalCopy(NULL, hClipObj, FLAG_TO_OPEN32); | 
|---|
| 284 | } | 
|---|
| 285 | O32_SetClipboardData(uFormat, hClipObjOpen32); | 
|---|
| 286 |  | 
|---|
| 287 | return hClipObj; | 
|---|
| 288 | #else | 
|---|
| 289 | dprintf(("USER32: SetClipboardData %x %x", uFormat, hClipObj)); | 
|---|
| 290 | return O32_SetClipboardData(uFormat, hClipObj); | 
|---|
| 291 | #endif | 
|---|
| 292 | } | 
|---|
| 293 | //****************************************************************************** | 
|---|
| 294 | //****************************************************************************** | 
|---|
| 295 | HWND WIN32API SetClipboardViewer( HWND hwndNew) | 
|---|
| 296 | { | 
|---|
| 297 | Win32BaseWindow *wndnew, *wndold; | 
|---|
| 298 | HWND hwndOld; | 
|---|
| 299 | HWND hwndOS2New; | 
|---|
| 300 |  | 
|---|
| 301 | wndnew = Win32BaseWindow::GetWindowFromHandle(hwndNew); | 
|---|
| 302 | if(!wndnew) { | 
|---|
| 303 | dprintf(("SetClipboardViewer, window %x not found", hwndNew)); | 
|---|
| 304 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 305 | return 0; | 
|---|
| 306 | } | 
|---|
| 307 | dprintf(("USER32: SetClipboardViewer %x", hwndNew)); | 
|---|
| 308 | hwndOS2New = wndnew->getOS2WindowHandle(); | 
|---|
| 309 | RELEASE_WNDOBJ(wndnew); | 
|---|
| 310 |  | 
|---|
| 311 | hwndOld = O32_SetClipboardViewer(hwndOS2New); | 
|---|
| 312 |  | 
|---|
| 313 | wndold = Win32BaseWindow::GetWindowFromOS2Handle(hwndOld); | 
|---|
| 314 | if(!wndold) { | 
|---|
| 315 | //probably an OS/2 window, so pretend it's nobody | 
|---|
| 316 | return 0; | 
|---|
| 317 | } | 
|---|
| 318 | hwndOld = wndold->getWindowHandle(); | 
|---|
| 319 | RELEASE_WNDOBJ(wndold); | 
|---|
| 320 | return hwndOld; | 
|---|
| 321 | } | 
|---|
| 322 | //****************************************************************************** | 
|---|
| 323 | //****************************************************************************** | 
|---|