| 1 | /* $Id: clipboard.cpp,v 1.1 2001-05-11 08:38:35 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 "win32wbase.h" | 
|---|
| 19 | #include <unicode.h> | 
|---|
| 20 |  | 
|---|
| 21 | #define DBG_LOCALLOG    DBG_clipboard | 
|---|
| 22 | #include "dbglocal.h" | 
|---|
| 23 |  | 
|---|
| 24 | //****************************************************************************** | 
|---|
| 25 | //****************************************************************************** | 
|---|
| 26 | BOOL WIN32API ChangeClipboardChain( HWND hwndRemove, HWND hwndNext) | 
|---|
| 27 | { | 
|---|
| 28 | Win32BaseWindow *wndRemove, *wndNext; | 
|---|
| 29 |  | 
|---|
| 30 | wndRemove = Win32BaseWindow::GetWindowFromHandle(hwndRemove); | 
|---|
| 31 | if(!wndRemove) { | 
|---|
| 32 | dprintf(("ChangeClipboardChain, window %x not found", hwndRemove)); | 
|---|
| 33 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 34 | return 0; | 
|---|
| 35 | } | 
|---|
| 36 | wndNext = Win32BaseWindow::GetWindowFromHandle(hwndNext); | 
|---|
| 37 | if(!wndNext) { | 
|---|
| 38 | dprintf(("ChangeClipboardChain, window %x not found", hwndNext)); | 
|---|
| 39 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 40 | return 0; | 
|---|
| 41 | } | 
|---|
| 42 | dprintf(("USER32:  ChangeClipboardChain\n")); | 
|---|
| 43 | return O32_ChangeClipboardChain(wndRemove->getOS2WindowHandle(), | 
|---|
| 44 | wndNext->getOS2WindowHandle()); | 
|---|
| 45 | } | 
|---|
| 46 | //****************************************************************************** | 
|---|
| 47 | //****************************************************************************** | 
|---|
| 48 | BOOL WIN32API CloseClipboard(void) | 
|---|
| 49 | { | 
|---|
| 50 | dprintf(("USER32:  CloseClipboard\n")); | 
|---|
| 51 | return O32_CloseClipboard(); | 
|---|
| 52 | } | 
|---|
| 53 | //****************************************************************************** | 
|---|
| 54 | //****************************************************************************** | 
|---|
| 55 | int WIN32API CountClipboardFormats(void) | 
|---|
| 56 | { | 
|---|
| 57 | dprintf(("USER32:  CountClipboardFormats\n")); | 
|---|
| 58 | return O32_CountClipboardFormats(); | 
|---|
| 59 | } | 
|---|
| 60 | //****************************************************************************** | 
|---|
| 61 | //****************************************************************************** | 
|---|
| 62 | BOOL WIN32API EmptyClipboard(void) | 
|---|
| 63 | { | 
|---|
| 64 | dprintf(("USER32:  EmptyClipboard\n")); | 
|---|
| 65 | return O32_EmptyClipboard(); | 
|---|
| 66 | } | 
|---|
| 67 | //****************************************************************************** | 
|---|
| 68 | //****************************************************************************** | 
|---|
| 69 | UINT WIN32API EnumClipboardFormats(UINT arg1) | 
|---|
| 70 | { | 
|---|
| 71 | dprintf(("USER32:  EnumClipboardFormats\n")); | 
|---|
| 72 | return O32_EnumClipboardFormats(arg1); | 
|---|
| 73 | } | 
|---|
| 74 | //****************************************************************************** | 
|---|
| 75 | //****************************************************************************** | 
|---|
| 76 | HANDLE WIN32API GetClipboardData( UINT arg1) | 
|---|
| 77 | { | 
|---|
| 78 | dprintf(("USER32:  GetClipboardData\n")); | 
|---|
| 79 | return O32_GetClipboardData(arg1); | 
|---|
| 80 | } | 
|---|
| 81 | //****************************************************************************** | 
|---|
| 82 | //****************************************************************************** | 
|---|
| 83 | int WIN32API GetClipboardFormatNameA(UINT format,LPSTR lpszFormatName,int cchMaxCount) | 
|---|
| 84 | { | 
|---|
| 85 | dprintf(("USER32:  GetClipboardFormatNameA %d\n",format)); | 
|---|
| 86 | return O32_GetClipboardFormatName(format,lpszFormatName,cchMaxCount); | 
|---|
| 87 | } | 
|---|
| 88 | //****************************************************************************** | 
|---|
| 89 | //****************************************************************************** | 
|---|
| 90 | int WIN32API GetClipboardFormatNameW(UINT format,LPWSTR lpszFormatName,int cchMaxCount) | 
|---|
| 91 | { | 
|---|
| 92 | int   rc; | 
|---|
| 93 | char *astring = (CHAR*)malloc(cchMaxCount); | 
|---|
| 94 |  | 
|---|
| 95 | dprintf(("USER32:  GetClipboardFormatNameW %d\n",format)); | 
|---|
| 96 | rc = O32_GetClipboardFormatName(format,astring,cchMaxCount); | 
|---|
| 97 | if (rc) AsciiToUnicode(astring,lpszFormatName); | 
|---|
| 98 | free(astring); | 
|---|
| 99 | return(rc); | 
|---|
| 100 | } | 
|---|
| 101 | //****************************************************************************** | 
|---|
| 102 | //****************************************************************************** | 
|---|
| 103 | HWND WIN32API GetClipboardOwner(void) | 
|---|
| 104 | { | 
|---|
| 105 | HWND hwndOwner; | 
|---|
| 106 | Win32BaseWindow *window; | 
|---|
| 107 |  | 
|---|
| 108 | dprintf(("USER32:  GetClipboardOwner\n")); | 
|---|
| 109 | hwndOwner = O32_GetClipboardOwner(); | 
|---|
| 110 |  | 
|---|
| 111 | window = Win32BaseWindow::GetWindowFromOS2Handle(hwndOwner); | 
|---|
| 112 | if(!window) { | 
|---|
| 113 | //an OS/2 window probably owns the clipboard, we pretend nobody owns it | 
|---|
| 114 | return NULL; | 
|---|
| 115 | } | 
|---|
| 116 | return window->getWindowHandle(); | 
|---|
| 117 | } | 
|---|
| 118 | //****************************************************************************** | 
|---|
| 119 | //****************************************************************************** | 
|---|
| 120 | HWND WIN32API GetClipboardViewer(void) | 
|---|
| 121 | { | 
|---|
| 122 | Win32BaseWindow *window; | 
|---|
| 123 | HWND hwndViewer; | 
|---|
| 124 |  | 
|---|
| 125 | dprintf(("USER32:  GetClipboardViewer\n")); | 
|---|
| 126 | hwndViewer = O32_GetClipboardViewer(); | 
|---|
| 127 |  | 
|---|
| 128 | window = Win32BaseWindow::GetWindowFromOS2Handle(hwndViewer); | 
|---|
| 129 | if(!window) { | 
|---|
| 130 | //probably an OS/2 window, we pretend it's nobody | 
|---|
| 131 | return NULL; | 
|---|
| 132 | } | 
|---|
| 133 | return window->getWindowHandle(); | 
|---|
| 134 | } | 
|---|
| 135 | //****************************************************************************** | 
|---|
| 136 | //****************************************************************************** | 
|---|
| 137 | HWND WIN32API GetOpenClipboardWindow(void) | 
|---|
| 138 | { | 
|---|
| 139 | Win32BaseWindow *window; | 
|---|
| 140 | HWND hwnd; | 
|---|
| 141 |  | 
|---|
| 142 | dprintf(("USER32:  GetOpenClipboardWindow\n")); | 
|---|
| 143 | hwnd = O32_GetOpenClipboardWindow(); | 
|---|
| 144 |  | 
|---|
| 145 | window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd); | 
|---|
| 146 | if(!window) { | 
|---|
| 147 | //probably an OS/2 window, we pretend it's nobody | 
|---|
| 148 | return NULL; | 
|---|
| 149 | } | 
|---|
| 150 | return window->getWindowHandle(); | 
|---|
| 151 | } | 
|---|
| 152 | //****************************************************************************** | 
|---|
| 153 | //****************************************************************************** | 
|---|
| 154 | int WIN32API GetPriorityClipboardFormat( PUINT arg1, int arg2) | 
|---|
| 155 | { | 
|---|
| 156 | dprintf(("USER32:  GetPriorityClipboardFormat\n")); | 
|---|
| 157 | return O32_GetPriorityClipboardFormat(arg1, arg2); | 
|---|
| 158 | } | 
|---|
| 159 | //****************************************************************************** | 
|---|
| 160 | //****************************************************************************** | 
|---|
| 161 | BOOL WIN32API IsClipboardFormatAvailable( UINT arg1) | 
|---|
| 162 | { | 
|---|
| 163 | dprintf(("USER32: IsClipboardFormatAvailable %x", arg1)); | 
|---|
| 164 | return O32_IsClipboardFormatAvailable(arg1); | 
|---|
| 165 | } | 
|---|
| 166 | //****************************************************************************** | 
|---|
| 167 | //****************************************************************************** | 
|---|
| 168 | BOOL WIN32API OpenClipboard( HWND hwnd) | 
|---|
| 169 | { | 
|---|
| 170 | Win32BaseWindow *window; | 
|---|
| 171 |  | 
|---|
| 172 | if (hwnd) { | 
|---|
| 173 | window = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 174 | if(!window) { | 
|---|
| 175 | dprintf(("OpenClipboard, window %x not found", hwnd)); | 
|---|
| 176 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 177 | return 0; | 
|---|
| 178 | } | 
|---|
| 179 | } | 
|---|
| 180 | dprintf(("USER32: OpenClipboard %x", hwnd)); | 
|---|
| 181 | return O32_OpenClipboard(hwnd ? window->getOS2WindowHandle() : NULL); | 
|---|
| 182 | } | 
|---|
| 183 | //****************************************************************************** | 
|---|
| 184 | //****************************************************************************** | 
|---|
| 185 | UINT WIN32API RegisterClipboardFormatA( LPCSTR arg1) | 
|---|
| 186 | { | 
|---|
| 187 | dprintf(("USER32:  RegisterClipboardFormatA %s", arg1)); | 
|---|
| 188 | return O32_RegisterClipboardFormat(arg1); | 
|---|
| 189 | } | 
|---|
| 190 | //****************************************************************************** | 
|---|
| 191 | //****************************************************************************** | 
|---|
| 192 | UINT WIN32API RegisterClipboardFormatW(LPCWSTR arg1) | 
|---|
| 193 | { | 
|---|
| 194 | UINT  rc; | 
|---|
| 195 | char *astring = UnicodeToAsciiString((LPWSTR)arg1); | 
|---|
| 196 |  | 
|---|
| 197 | dprintf(("USER32:  RegisterClipboardFormatW %s\n", astring)); | 
|---|
| 198 | rc = O32_RegisterClipboardFormat(astring); | 
|---|
| 199 | FreeAsciiString(astring); | 
|---|
| 200 | dprintf(("USER32:  RegisterClipboardFormatW returned %d\n", rc)); | 
|---|
| 201 | return(rc); | 
|---|
| 202 | } | 
|---|
| 203 | //****************************************************************************** | 
|---|
| 204 | //****************************************************************************** | 
|---|
| 205 | HANDLE WIN32API SetClipboardData( UINT arg1, HANDLE  arg2) | 
|---|
| 206 | { | 
|---|
| 207 | dprintf(("USER32:  SetClipboardData\n")); | 
|---|
| 208 | return O32_SetClipboardData(arg1, arg2); | 
|---|
| 209 | } | 
|---|
| 210 | //****************************************************************************** | 
|---|
| 211 | //****************************************************************************** | 
|---|
| 212 | HWND WIN32API SetClipboardViewer( HWND hwndNew) | 
|---|
| 213 | { | 
|---|
| 214 | Win32BaseWindow *wndnew, *wndold; | 
|---|
| 215 | HWND hwndOld; | 
|---|
| 216 |  | 
|---|
| 217 | wndnew = Win32BaseWindow::GetWindowFromHandle(hwndNew); | 
|---|
| 218 | if(!wndnew) { | 
|---|
| 219 | dprintf(("OpenClipboard, window %x not found", hwndNew)); | 
|---|
| 220 | SetLastError(ERROR_INVALID_WINDOW_HANDLE); | 
|---|
| 221 | return 0; | 
|---|
| 222 | } | 
|---|
| 223 | dprintf(("USER32:  SetClipboardViewer\n")); | 
|---|
| 224 | hwndOld = O32_SetClipboardViewer(wndnew->getOS2WindowHandle()); | 
|---|
| 225 |  | 
|---|
| 226 | wndold = Win32BaseWindow::GetWindowFromOS2Handle(hwndOld); | 
|---|
| 227 | if(!wndold) { | 
|---|
| 228 | //probably an OS/2 window, so pretend it's nobody | 
|---|
| 229 | return 0; | 
|---|
| 230 | } | 
|---|
| 231 | return wndold->getWindowHandle(); | 
|---|
| 232 | } | 
|---|
| 233 | //****************************************************************************** | 
|---|
| 234 | //****************************************************************************** | 
|---|