| 1 | /* $Id: clipboard.cpp,v 1.17 2003-07-31 16:07:56 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 | return O32_CountClipboardFormats();
|
|---|
| 60 | }
|
|---|
| 61 | //******************************************************************************
|
|---|
| 62 | //******************************************************************************
|
|---|
| 63 | BOOL WIN32API EmptyClipboard(void)
|
|---|
| 64 | {
|
|---|
| 65 | return O32_EmptyClipboard();
|
|---|
| 66 | }
|
|---|
| 67 | //******************************************************************************
|
|---|
| 68 | //******************************************************************************
|
|---|
| 69 | UINT WIN32API EnumClipboardFormats(UINT uFormat)
|
|---|
| 70 | {
|
|---|
| 71 | return O32_EnumClipboardFormats(uFormat);
|
|---|
| 72 | }
|
|---|
| 73 | //******************************************************************************
|
|---|
| 74 | //******************************************************************************
|
|---|
| 75 | int WIN32API GetClipboardFormatNameA(UINT format,LPSTR lpszFormatName,int cchMaxCount)
|
|---|
| 76 | {
|
|---|
| 77 | dprintf(("USER32: GetClipboardFormatNameA %d\n",format));
|
|---|
| 78 | return O32_GetClipboardFormatName(format,lpszFormatName,cchMaxCount);
|
|---|
| 79 | }
|
|---|
| 80 | //******************************************************************************
|
|---|
| 81 | //******************************************************************************
|
|---|
| 82 | int WIN32API GetClipboardFormatNameW(UINT format,LPWSTR lpszFormatName,int cchMaxCount)
|
|---|
| 83 | {
|
|---|
| 84 | int rc;
|
|---|
| 85 | char *astring = (CHAR*)malloc(cchMaxCount);
|
|---|
| 86 |
|
|---|
| 87 | rc = GetClipboardFormatNameA(format,astring,cchMaxCount);
|
|---|
| 88 | if (rc) AsciiToUnicode(astring,lpszFormatName);
|
|---|
| 89 | free(astring);
|
|---|
| 90 | return(rc);
|
|---|
| 91 | }
|
|---|
| 92 | //******************************************************************************
|
|---|
| 93 | //******************************************************************************
|
|---|
| 94 | HWND WIN32API GetClipboardOwner(void)
|
|---|
| 95 | {
|
|---|
| 96 | HWND hwndOwner;
|
|---|
| 97 | Win32BaseWindow *window;
|
|---|
| 98 |
|
|---|
| 99 | dprintf(("USER32: GetClipboardOwner\n"));
|
|---|
| 100 | hwndOwner = O32_GetClipboardOwner();
|
|---|
| 101 |
|
|---|
| 102 | window = Win32BaseWindow::GetWindowFromOS2Handle(hwndOwner);
|
|---|
| 103 | if(!window) {
|
|---|
| 104 | //an OS/2 window probably owns the clipboard, we pretend nobody owns it
|
|---|
| 105 | return NULL;
|
|---|
| 106 | }
|
|---|
| 107 | hwndOwner = window->getWindowHandle();
|
|---|
| 108 | RELEASE_WNDOBJ(window);
|
|---|
| 109 | return hwndOwner;
|
|---|
| 110 | }
|
|---|
| 111 | //******************************************************************************
|
|---|
| 112 | //******************************************************************************
|
|---|
| 113 | HWND WIN32API GetClipboardViewer(void)
|
|---|
| 114 | {
|
|---|
| 115 | Win32BaseWindow *window;
|
|---|
| 116 | HWND hwndViewer;
|
|---|
| 117 |
|
|---|
| 118 | dprintf(("USER32: GetClipboardViewer"));
|
|---|
| 119 | hwndViewer = O32_GetClipboardViewer();
|
|---|
| 120 |
|
|---|
| 121 | window = Win32BaseWindow::GetWindowFromOS2Handle(hwndViewer);
|
|---|
| 122 | if(!window) {
|
|---|
| 123 | //probably an OS/2 window, we pretend it's nobody
|
|---|
| 124 | return NULL;
|
|---|
| 125 | }
|
|---|
| 126 | hwndViewer = window->getWindowHandle();
|
|---|
| 127 | RELEASE_WNDOBJ(window);
|
|---|
| 128 | return hwndViewer;
|
|---|
| 129 | }
|
|---|
| 130 | //******************************************************************************
|
|---|
| 131 | //******************************************************************************
|
|---|
| 132 | HWND WIN32API SetClipboardViewer( HWND hwndNew)
|
|---|
| 133 | {
|
|---|
| 134 | Win32BaseWindow *wndnew, *wndold;
|
|---|
| 135 | HWND hwndOld;
|
|---|
| 136 | HWND hwndOS2New;
|
|---|
| 137 |
|
|---|
| 138 | wndnew = Win32BaseWindow::GetWindowFromHandle(hwndNew);
|
|---|
| 139 | if(!wndnew) {
|
|---|
| 140 | dprintf(("SetClipboardViewer, window %x not found", hwndNew));
|
|---|
| 141 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
|---|
| 142 | return 0;
|
|---|
| 143 | }
|
|---|
| 144 | dprintf(("USER32: SetClipboardViewer %x", hwndNew));
|
|---|
| 145 | hwndOS2New = wndnew->getOS2WindowHandle();
|
|---|
| 146 | RELEASE_WNDOBJ(wndnew);
|
|---|
| 147 |
|
|---|
| 148 | hwndOld = O32_SetClipboardViewer(hwndOS2New);
|
|---|
| 149 |
|
|---|
| 150 | wndold = Win32BaseWindow::GetWindowFromOS2Handle(hwndOld);
|
|---|
| 151 | if(!wndold) {
|
|---|
| 152 | //probably an OS/2 window, so pretend it's nobody
|
|---|
| 153 | return 0;
|
|---|
| 154 | }
|
|---|
| 155 | hwndOld = wndold->getWindowHandle();
|
|---|
| 156 | RELEASE_WNDOBJ(wndold);
|
|---|
| 157 | return hwndOld;
|
|---|
| 158 | }
|
|---|
| 159 | //******************************************************************************
|
|---|
| 160 | //******************************************************************************
|
|---|
| 161 | HWND WIN32API GetOpenClipboardWindow(void)
|
|---|
| 162 | {
|
|---|
| 163 | Win32BaseWindow *window;
|
|---|
| 164 | HWND hwnd;
|
|---|
| 165 |
|
|---|
| 166 | hwnd = O32_GetOpenClipboardWindow();
|
|---|
| 167 |
|
|---|
| 168 | window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
|
|---|
| 169 | if(!window) {
|
|---|
| 170 | //probably an OS/2 window, we pretend it's nobody
|
|---|
| 171 | return NULL;
|
|---|
| 172 | }
|
|---|
| 173 | hwnd = window->getWindowHandle();
|
|---|
| 174 | RELEASE_WNDOBJ(window);
|
|---|
| 175 | return hwnd;
|
|---|
| 176 | }
|
|---|
| 177 | //******************************************************************************
|
|---|
| 178 | //******************************************************************************
|
|---|
| 179 | int WIN32API GetPriorityClipboardFormat( PUINT arg1, int arg2)
|
|---|
| 180 | {
|
|---|
| 181 | dprintf(("USER32: GetPriorityClipboardFormat"));
|
|---|
| 182 | return O32_GetPriorityClipboardFormat(arg1, arg2);
|
|---|
| 183 | }
|
|---|
| 184 | //******************************************************************************
|
|---|
| 185 | //******************************************************************************
|
|---|
| 186 | BOOL WIN32API IsClipboardFormatAvailable( UINT arg1)
|
|---|
| 187 | {
|
|---|
| 188 | dprintf(("USER32: IsClipboardFormatAvailable %x", arg1));
|
|---|
| 189 | return O32_IsClipboardFormatAvailable(arg1);
|
|---|
| 190 | }
|
|---|
| 191 | //******************************************************************************
|
|---|
| 192 | //******************************************************************************
|
|---|
| 193 | BOOL WIN32API OpenClipboard( HWND hwnd)
|
|---|
| 194 | {
|
|---|
| 195 | Win32BaseWindow *window;
|
|---|
| 196 |
|
|---|
| 197 | if (hwnd) {
|
|---|
| 198 | window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
|---|
| 199 | if(!window) {
|
|---|
| 200 | dprintf(("OpenClipboard, window %x not found", hwnd));
|
|---|
| 201 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
|---|
| 202 | return 0;
|
|---|
| 203 | }
|
|---|
| 204 | hwnd = window->getOS2WindowHandle();
|
|---|
| 205 | RELEASE_WNDOBJ(window);
|
|---|
| 206 | }
|
|---|
| 207 | dprintf(("USER32: OpenClipboard %x", hwnd));
|
|---|
| 208 | return O32_OpenClipboard(hwnd);
|
|---|
| 209 | }
|
|---|
| 210 | //******************************************************************************
|
|---|
| 211 | //******************************************************************************
|
|---|
| 212 | BOOL WIN32API CloseClipboard(void)
|
|---|
| 213 | {
|
|---|
| 214 | return O32_CloseClipboard();
|
|---|
| 215 | }
|
|---|
| 216 | //******************************************************************************
|
|---|
| 217 | //******************************************************************************
|
|---|
| 218 | UINT WIN32API RegisterClipboardFormatA( LPCSTR arg1)
|
|---|
| 219 | {
|
|---|
| 220 | dprintf(("USER32: RegisterClipboardFormatA %s", arg1));
|
|---|
| 221 | return O32_RegisterClipboardFormat(arg1);
|
|---|
| 222 | }
|
|---|
| 223 | //******************************************************************************
|
|---|
| 224 | //******************************************************************************
|
|---|
| 225 | UINT WIN32API RegisterClipboardFormatW(LPCWSTR arg1)
|
|---|
| 226 | {
|
|---|
| 227 | UINT rc;
|
|---|
| 228 | char *astring = UnicodeToAsciiString((LPWSTR)arg1);
|
|---|
| 229 |
|
|---|
| 230 | dprintf(("USER32: RegisterClipboardFormatW %s\n", astring));
|
|---|
| 231 | rc = O32_RegisterClipboardFormat(astring);
|
|---|
| 232 | FreeAsciiString(astring);
|
|---|
| 233 | dprintf(("USER32: RegisterClipboardFormatW returned %d\n", rc));
|
|---|
| 234 | return(rc);
|
|---|
| 235 | }
|
|---|
| 236 | //******************************************************************************
|
|---|
| 237 | //******************************************************************************
|
|---|
| 238 | HANDLE WIN32API GetClipboardData(UINT uFormat)
|
|---|
| 239 | {
|
|---|
| 240 | HANDLE hRet = O32_GetClipboardData(uFormat);
|
|---|
| 241 | dprintf(("GetClipboardData %x returned %x", uFormat, hRet));
|
|---|
| 242 | #ifdef DEBUG
|
|---|
| 243 | if(hRet) {
|
|---|
| 244 | if(uFormat == CF_TEXT || uFormat == CF_DSPTEXT) {
|
|---|
| 245 | char *lpszText = (char *)GlobalLock(hRet);
|
|---|
| 246 | if(lpszText) dprintf(("GetClipboardData %s", lpszText));
|
|---|
| 247 | GlobalUnlock(hRet);
|
|---|
| 248 | }
|
|---|
| 249 | if(uFormat == CF_UNICODETEXT) {
|
|---|
| 250 | LPWSTR lpszText = (LPWSTR)GlobalLock(hRet);
|
|---|
| 251 | if(lpszText) dprintf(("GetClipboardData %ls", lpszText));
|
|---|
| 252 | GlobalUnlock(hRet);
|
|---|
| 253 | }
|
|---|
| 254 | }
|
|---|
| 255 | #endif
|
|---|
| 256 | return hRet;
|
|---|
| 257 | }
|
|---|
| 258 | //******************************************************************************
|
|---|
| 259 | //******************************************************************************
|
|---|
| 260 | HANDLE WIN32API SetClipboardData( UINT uFormat, HANDLE hClipObj)
|
|---|
| 261 | {
|
|---|
| 262 | dprintf(("SetClipboardData %x %x", uFormat, hClipObj));
|
|---|
| 263 | #ifdef DEBUG
|
|---|
| 264 | if(hClipObj) {
|
|---|
| 265 | if(uFormat == CF_TEXT || uFormat == CF_DSPTEXT) {
|
|---|
| 266 | char *lpszText = (char *)GlobalLock(hClipObj);
|
|---|
| 267 | if(lpszText) dprintf(("SetClipboardData %s", lpszText));
|
|---|
| 268 | GlobalUnlock(hClipObj);
|
|---|
| 269 | }
|
|---|
| 270 | if(uFormat == CF_UNICODETEXT) {
|
|---|
| 271 | LPWSTR lpszText = (LPWSTR)GlobalLock(hClipObj);
|
|---|
| 272 | if(lpszText) dprintf(("SetClipboardData %ls", lpszText));
|
|---|
| 273 | GlobalUnlock(hClipObj);
|
|---|
| 274 | }
|
|---|
| 275 | }
|
|---|
| 276 | #endif
|
|---|
| 277 | return O32_SetClipboardData(uFormat, hClipObj);
|
|---|
| 278 | }
|
|---|
| 279 | //******************************************************************************
|
|---|
| 280 | //******************************************************************************
|
|---|