source: trunk/src/user32/oslibclipbrd.cpp

Last change on this file was 10578, checked in by sandervl, 21 years ago

KSO: clipboard rewrite

File size: 8.6 KB
Line 
1/* $Id: oslibclipbrd.cpp,v 1.1 2004-04-13 14:17:01 sandervl Exp $ */
2/** @file
3 *
4 * OSLIB Clipboard
5 *
6 * InnoTek Systemberatung GmbH confidential
7 *
8 * Copyright (c) 2004 InnoTek Systemberatung GmbH
9 * Author: knut st. osmundsen <bird-srcspam@anduin.net>
10 *
11 * All Rights Reserved
12 *
13 */
14
15
16/*******************************************************************************
17* Header Files *
18*******************************************************************************/
19#define INCL_WIN
20#define INCL_WINSTDDRAG
21#define INCL_PM
22#include <os2wrap.h>
23#include <stdlib.h>
24#include <string.h>
25#include <stdio.h>
26
27#include <dbglog.h>
28#include <winconst.h>
29#include <win32api.h>
30#include <winuser32.h>
31
32#include "oslibutil.h"
33#include "oslibclipbrd.h"
34
35
36/*******************************************************************************
37* Defined Constants And Macros *
38*******************************************************************************/
39/**
40 * Debug assertion macro.
41 * @param expr Assert that this expression is true.
42 * @param msg Message to print if expr isn't true. It's given to dprintf,
43 * and must be inclosed in paratheses.
44 * @todo move this to some header in /include.
45 */
46#ifdef DEBUG
47 #define DebugAssert(expr, msg) \
48 do { if (expr) break; \
49 dprintf(("!!!ASSERTION FAILED!!!\nFILE=%s\nLINE=%d\nFUNCTION=%s\n", __FILE__, __LINE__, __FUNCTION__)); \
50 dprintf(msg); DebugInt3(); \
51 } while (0)
52#else
53 #define DebugAssert(expr, msg) do {} while (0)
54#endif
55
56/**
57 * Debug assertion failed macro.
58 * @param msg Message to print if expr isn't true. It's given to dprintf,
59 * and must be inclosed in paratheses.
60 * @todo move this to some header in /include.
61 */
62#ifdef DEBUG
63 #define DebugAssertFailed(msg) \
64 do { dprintf(("!!!ASSERTION FAILED!!!\nFILE=%s\nLINE=%d\nFUNCTION=%s\n", __FILE__, __LINE__, __FUNCTION__)); \
65 dprintf(msg); DebugInt3(); \
66 } while (0)
67#else
68 #define DebugAssertFailed(msg) do {} while (0)
69#endif
70
71
72/**
73 * Duplicates a PM bitmap.
74 *
75 * @returns Handle to duplicated PM bitmap.
76 * @returns NULL on failure.
77 * @param hbmp Handle to the bitmap.
78 */
79HANDLE OSLibClipboardPMBitmapDuplicate(HANDLE hbmp)
80{
81 HAB hab = GetThreadHAB();
82 HBITMAP hbmpRet = NULLHANDLE;
83
84 /*
85 * Create a PS.
86 */
87 HDC hdc = DevOpenDC(hab, OD_MEMORY, (PSZ)"*", 0L, NULL, NULLHANDLE);
88 if (!hdc)
89 return NULL;
90 SIZEL sizl = { WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN), WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN) };
91 HPS hps = GpiCreatePS(hab, hdc, &sizl, GPIA_ASSOC | PU_PELS);
92
93 /*
94 * Select the bitmap into the PS.
95 */
96 if (GpiSetBitmap(hps, hbmp) != HBM_ERROR)
97 {
98 /*
99 * Get the bitmap header.
100 */
101 BITMAPINFOHEADER2 bih2;
102 bih2.cbFix = sizeof(bih2);
103 if (GpiQueryBitmapInfoHeader(hbmp, &bih2))
104 {
105 /*
106 * Calc bitmap size.
107 */
108 unsigned cbColorTable = 0;
109 switch (bih2.cBitCount)
110 {
111 case 1:
112 case 2:
113 case 4:
114 case 8:
115 cbColorTable = (1 << bih2.cBitCount) * sizeof(RGB2);
116 break;
117 }
118
119 unsigned cbBits = bih2.cbImage;
120 if (!cbBits)
121 {
122 cbBits = ((bih2.cx * bih2.cBitCount + 31) >> 5) << 2;
123 cbBits *= bih2.cy * bih2.cPlanes;
124 }
125
126 unsigned cbTotal = sizeof(bih2) + cbColorTable + cbBits;
127
128 /*
129 * Allocate temporary storage.
130 */
131 void * pv = malloc(cbTotal);
132 if (pv)
133 {
134 /*
135 * Get the bitmap bits.
136 */
137 void *pvBits = (char*)pv + sizeof(bih2) + cbColorTable;
138 memcpy(pv, &bih2, sizeof(bih2));
139 if (GpiQueryBitmapBits(hps, 0, bih2.cy, (PBYTE)pvBits, (PBITMAPINFO2)pv))
140 {
141 if (GpiSetBitmap(hps, NULLHANDLE) != HBM_ERROR)
142 {
143 hbmpRet = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2)pv, CBM_INIT, (PBYTE)pvBits,
144 (PBITMAPINFO2)pv);
145 DebugAssert(hbmpRet, ("GpiCreateBitmap failed lasterr=%#x\n", WinGetLastError(GetThreadHAB())));
146 }
147 }
148 free(pv);
149 }
150 }
151
152 }
153
154 GpiDestroyPS(hps);
155 DevCloseDC(hdc);
156
157 dprintf(("OSLibClipboardPMBitmapDuplicate: returning %#x\n", hbmpRet));
158 return hbmpRet;
159}
160
161
162/**
163 * Destroys a PM bitmap.
164 *
165 * @param hbmp Handle to the bitmap.
166 */
167void OSLibClipboardPMBitmapDelete(HANDLE hbmp)
168{
169 if (!GpiDeleteBitmap(hbmp))
170 DebugAssertFailed(("GpiDeleteBitmap failed lasterr=%#x\n", WinGetLastError(GetThreadHAB())));
171}
172
173
174/**
175 * Duplicates a PM palette.
176 *
177 * @returns Handle to duplicated PM palette.
178 * @returns NULL on failure.
179 * @param hpal Handle to the palette.
180 */
181HANDLE OSLibClipboardPMPaletteDuplicate(HANDLE hpal)
182{
183 HANDLE hpalRet = NULL;
184 HAB hab = GetThreadHAB();
185
186 /*
187 * Query data from hpal.
188 */
189 LONG cEntries = GpiQueryPaletteInfo(hpal, NULLHANDLE, 0, 0, 0, NULL);
190 if (cEntries > 0)
191 {
192 PULONG paulRGB = (PULONG)malloc(cEntries * sizeof(ULONG));
193 if (paulRGB)
194 {
195 cEntries = GpiQueryPaletteInfo(hab, NULLHANDLE, 0, 0, cEntries, paulRGB);
196 if (cEntries != PAL_ERROR)
197 {
198 hpalRet = GpiCreatePalette(hab, LCOL_PURECOLOR, LCOLF_CONSECRGB, cEntries, paulRGB);
199 DebugAssert(hpalRet != GPI_ERROR, ("GpiQueryPaletteInfo failed returning %d. lasterr=%#x\n", cEntries, WinGetLastError(hab)));
200 }
201 else
202 DebugAssertFailed(("GpiQueryPaletteInfo failed returning %d. lasterr=%#x\n", cEntries, WinGetLastError(hab)));
203 free(paulRGB);
204 }
205 }
206 else
207 DebugAssertFailed(("GpiQueryPaletteInfo failed returning %d. lasterr=%#x\n", cEntries, WinGetLastError(hab)));
208
209 return hpalRet;
210}
211
212
213/**
214 * Destroys a PM palette.
215 *
216 * @param hpal Handle to the palette.
217 */
218void OSLibClipboardPMPaletteDelete(HANDLE hpal)
219{
220 if (!GpiDeletePalette(hpal))
221 DebugAssertFailed(("GpiDeletePalette failed lasterr=%#x\n", WinGetLastError(GetThreadHAB())));
222}
223
224
225BOOL OSLib_OpenClipbrd(HANDLE hab, HWND hwndOpenWindow)
226{ return _OpenClipbrd(hab, hwndOpenWindow); }
227
228HWND OSLibWin32QueryOpenClipbrdWindow(void)
229{ return Win32QueryOpenClipbrdWindow(); }
230
231BOOL OSLibWinEmptyClipbrd(HANDLE hab)
232{ return WinEmptyClipbrd(hab); }
233
234BOOL OSLibWinSetClipbrdOwner(HANDLE hab, HWND hwndOwner)
235{ return WinSetClipbrdOwner(hab, hwndOwner); }
236
237HWND OSLibWinQueryClipbrdOwner(HANDLE hab)
238{ return WinQueryClipbrdOwner(hab); }
239
240HWND OSLibWin32QueryClipbrdViewerChain(void)
241{ return Win32QueryClipbrdViewerChain(); }
242
243BOOL OSLibWin32AddClipbrdViewer(HWND hwndNewViewer)
244{ return Win32AddClipbrdViewer(hwndNewViewer); }
245
246BOOL OSLibWin32RemoveClipbrdViewer(HWND hwndRemove)
247{ return Win32RemoveClipbrdViewer(hwndRemove); }
248
249BOOL OSLibWinQueryClipbrdFmtInfo(HANDLE hab, ULONG ulFormat, PULONG pfl)
250{ return WinQueryClipbrdFmtInfo(hab, ulFormat, pfl); }
251
252BOOL OSLibWinSetClipbrdData(HANDLE hab, ULONG ulData, ULONG ulFormat, ULONG ulFlags)
253{ return WinSetClipbrdData(hab, ulData, ulFormat, ulFlags); }
254
255ULONG OSLibWinQueryClipbrdData(HANDLE hab, ULONG ulFormat)
256{ return WinQueryClipbrdData(hab, ulFormat); }
257
258BOOL OSLibWinCloseClipbrd(HANDLE hab)
259{ return WinCloseClipbrd(hab); }
260
261ULONG OSLibWinEnumClipbrdFmts(HANDLE hab, ULONG ulFmt)
262{ return WinEnumClipbrdFmts(hab, ulFmt); }
263
264ULONG OSLibWinAddAtom(HANDLE hAtomTable, const char *pszAtomName)
265{ return WinAddAtom(hAtomTable, pszAtomName); }
266
267ULONG OSLibWinQueryAtomName(HANDLE hAtomTable, ULONG ulFormat, char *pszNameBuf, ULONG cchNameBuf)
268{ return WinQueryAtomName(hAtomTable, (ATOM)ulFormat, pszNameBuf, cchNameBuf); }
269
270HANDLE OSLibWinQuerySystemAtomTable(void)
271{ return WinQuerySystemAtomTable(); }
272
273ULONG OSLibWinSetErrorInfo(ULONG ulError, ULONG ulFlags, ...)
274{ return WinSetErrorInfo(ulError, ulFlags); }
275
276ULONG OSLibDosAllocSharedMem(void **ppv, const char *psz, ULONG cb, ULONG flFlags)
277{ return DosAllocSharedMem(ppv, psz, cb, flFlags); }
278
279ULONG OSLibDosFreeMem(void *pv)
280{ return DosFreeMem(pv); }
281
282ULONG OSLibDosQueryMem(PVOID pvAddr, PULONG pcb, PULONG pfl)
283{ return DosQueryMem(pvAddr, pcb, pfl); }
284
Note: See TracBrowser for help on using the repository browser.