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