ReactOS 0.4.15-dev-7842-g558ab78
clipboard.c File Reference
#include <win32k.h>
Include dependency graph for clipboard.c:

Go to the source code of this file.

Macros

#define DATA_DELAYED   (HANDLE)0
 
#define DATA_SYNTH_USER   (HANDLE)1
 
#define DATA_SYNTH_KRNL   (HANDLE)2
 
#define IS_DATA_DELAYED(ce)   ((ce)->hData == DATA_DELAYED)
 
#define IS_DATA_SYNTHESIZED(ce)   ((ce)->hData == DATA_SYNTH_USER || (ce)->hData == DATA_SYNTH_KRNL)
 

Functions

 DBG_DEFAULT_CHANNEL (UserClipbrd)
 
static PWINSTATION_OBJECT FASTCALL IntGetWinStaForCbAccess (VOID)
 
static PCLIP FASTCALL IntGetFormatElement (PWINSTATION_OBJECT pWinStaObj, UINT fmt)
 
static BOOL FASTCALL IntIsFormatAvailable (PWINSTATION_OBJECT pWinStaObj, UINT fmt)
 
static VOID FASTCALL IntFreeElementData (PCLIP pElement)
 
static PCLIP NTAPI IntAddFormatedData (PWINSTATION_OBJECT pWinStaObj, UINT fmt, HANDLE hData, BOOLEAN fGlobalHandle, BOOL bEnd)
 
static BOOL FASTCALL IntIsClipboardOpenByMe (PWINSTATION_OBJECT pWinSta)
 
static VOID NTAPI IntSynthesizeDib (PWINSTATION_OBJECT pWinStaObj, HBITMAP hbm)
 
static VOID WINAPI IntSynthesizeBitmap (PWINSTATION_OBJECT pWinStaObj, PCLIP pBmEl)
 
static VOID NTAPI IntAddSynthesizedFormats (PWINSTATION_OBJECT pWinStaObj)
 
VOID NTAPI UserEmptyClipboardData (PWINSTATION_OBJECT pWinSta)
 
VOID FASTCALL UserClipboardRelease (PWND pWindow)
 
VOID FASTCALL UserClipboardFreeWindow (PWND pWindow)
 
UINT APIENTRY UserEnumClipboardFormats (UINT fmt)
 
BOOL NTAPI UserOpenClipboard (HWND hWnd)
 
BOOL APIENTRY NtUserOpenClipboard (HWND hWnd, DWORD Unknown1)
 
BOOL NTAPI UserCloseClipboard (VOID)
 
BOOL APIENTRY NtUserCloseClipboard (VOID)
 
HWND APIENTRY NtUserGetOpenClipboardWindow (VOID)
 
BOOL APIENTRY NtUserChangeClipboardChain (HWND hWndRemove, HWND hWndNewNext)
 
DWORD APIENTRY NtUserCountClipboardFormats (VOID)
 
BOOL NTAPI UserEmptyClipboard (VOID)
 
BOOL APIENTRY NtUserEmptyClipboard (VOID)
 
INT APIENTRY NtUserGetClipboardFormatName (UINT fmt, LPWSTR lpszFormatName, INT cchMaxCount)
 
HWND APIENTRY NtUserGetClipboardOwner (VOID)
 
HWND APIENTRY NtUserGetClipboardViewer (VOID)
 
INT APIENTRY NtUserGetPriorityClipboardFormat (UINT *paFormatPriorityList, INT cFormats)
 
BOOL APIENTRY NtUserIsClipboardFormatAvailable (UINT fmt)
 
HANDLE APIENTRY NtUserGetClipboardData (UINT fmt, PGETCLIPBDATA pgcd)
 
HANDLE NTAPI UserSetClipboardData (UINT fmt, HANDLE hData, PSETCLIPBDATA scd)
 
HANDLE APIENTRY NtUserSetClipboardData (UINT fmt, HANDLE hData, PSETCLIPBDATA pUnsafeScd)
 
HWND APIENTRY NtUserSetClipboardViewer (HWND hWndNewViewer)
 
DWORD APIENTRY NtUserGetClipboardSequenceNumber (VOID)
 
HANDLE APIENTRY NtUserConvertMemHandle (PVOID pData, DWORD cbData)
 
NTSTATUS APIENTRY NtUserCreateLocalMemHandle (HANDLE hMem, PVOID pData, DWORD cbData, DWORD *pcbData)
 

Macro Definition Documentation

◆ DATA_DELAYED

#define DATA_DELAYED   (HANDLE)0

Definition at line 14 of file clipboard.c.

◆ DATA_SYNTH_KRNL

#define DATA_SYNTH_KRNL   (HANDLE)2

Definition at line 16 of file clipboard.c.

◆ DATA_SYNTH_USER

#define DATA_SYNTH_USER   (HANDLE)1

Definition at line 15 of file clipboard.c.

◆ IS_DATA_DELAYED

#define IS_DATA_DELAYED (   ce)    ((ce)->hData == DATA_DELAYED)

Definition at line 17 of file clipboard.c.

◆ IS_DATA_SYNTHESIZED

#define IS_DATA_SYNTHESIZED (   ce)    ((ce)->hData == DATA_SYNTH_USER || (ce)->hData == DATA_SYNTH_KRNL)

Definition at line 18 of file clipboard.c.

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( UserClipbrd  )

◆ IntAddFormatedData()

static PCLIP NTAPI IntAddFormatedData ( PWINSTATION_OBJECT  pWinStaObj,
UINT  fmt,
HANDLE  hData,
BOOLEAN  fGlobalHandle,
BOOL  bEnd 
)
static

Definition at line 84 of file clipboard.c.

85{
86 PCLIP pElement = NULL;
87
88 /* Use existing entry with specified format */
89 if (!bEnd)
90 pElement = IntGetFormatElement(pWinStaObj, fmt);
91
92 /* Put new entry at the end if nothing was found */
93 if (!pElement)
94 {
95 /* Allocate bigger clipboard if needed. We could use lists but Windows uses array */
96 if (pWinStaObj->cNumClipFormats % 4 == 0)
97 {
98 PCLIP pNewClip;
99
100 /* Allocate new clipboard */
102 (pWinStaObj->cNumClipFormats + 4) * sizeof(CLIP),
104 if (!pNewClip)
105 {
107 return NULL;
108 }
109
110 /* Copy data */
111 memcpy(pNewClip, pWinStaObj->pClipBase, pWinStaObj->cNumClipFormats * sizeof(CLIP));
112
113 /* Free old clipboard */
114 if (pWinStaObj->pClipBase)
116
117 /* Update WinSta */
118 pWinStaObj->pClipBase = pNewClip;
119 }
120
121 /* New element is at the end */
122 pElement = &pWinStaObj->pClipBase[pWinStaObj->cNumClipFormats];
123 pElement->fmt = fmt;
124 pWinStaObj->cNumClipFormats++;
125 }
126 else
127 IntFreeElementData(pElement);
128
129 pElement->hData = hData;
130 pElement->fGlobalHandle = fGlobalHandle;
131
132 return pElement;
133}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NULL
Definition: types.h:112
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
Definition: clipboard.h:4
HANDLE hData
Definition: clipboard.h:6
BOOL fGlobalHandle
Definition: clipboard.h:7
UINT fmt
Definition: clipboard.h:5
DWORD cNumClipFormats
Definition: winsta.h:30
PCLIP pClipBase
Definition: winsta.h:29
Definition: dsound.c:943
static PCLIP FASTCALL IntGetFormatElement(PWINSTATION_OBJECT pWinStaObj, UINT fmt)
Definition: clipboard.c:41
static VOID FASTCALL IntFreeElementData(PCLIP pElement)
Definition: clipboard.c:61
#define USERTAG_CLIPBOARD
Definition: tags.h:200
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:22

Referenced by IntAddSynthesizedFormats(), IntSynthesizeDib(), and UserSetClipboardData().

◆ IntAddSynthesizedFormats()

static VOID NTAPI IntAddSynthesizedFormats ( PWINSTATION_OBJECT  pWinStaObj)
static

Definition at line 291 of file clipboard.c.

292{
293 BOOL bHaveText, bHaveUniText, bHaveOemText, bHaveLocale, bHaveBm, bHaveDib, bHaveMFP, bHaveEMF;
294
295 bHaveText = IntIsFormatAvailable(pWinStaObj, CF_TEXT);
296 bHaveOemText = IntIsFormatAvailable(pWinStaObj, CF_OEMTEXT);
297 bHaveUniText = IntIsFormatAvailable(pWinStaObj, CF_UNICODETEXT);
298 bHaveLocale = IntIsFormatAvailable(pWinStaObj, CF_LOCALE);
299 bHaveBm = IntIsFormatAvailable(pWinStaObj, CF_BITMAP);
300 bHaveDib = IntIsFormatAvailable(pWinStaObj, CF_DIB);
301 bHaveMFP = IntIsFormatAvailable(pWinStaObj, CF_METAFILEPICT);
302 bHaveEMF = IntIsFormatAvailable(pWinStaObj, CF_ENHMETAFILE);
303
304 /* Add CF_LOCALE format if we have CF_TEXT, CF_OEMTEXT or CF_UNICODETEXT */
305 if (!bHaveLocale && (bHaveText || bHaveOemText || bHaveUniText))
306 {
307 PCLIPBOARDDATA pMemObj;
308 HANDLE hMem;
309
311 sizeof(CLIPBOARDDATA) + sizeof(LCID));
312 if (pMemObj)
313 {
314 pMemObj->cbData = sizeof(LCID);
315 *((LCID*)pMemObj->Data) = NtCurrentTeb()->CurrentLocale;
316 IntAddFormatedData(pWinStaObj, CF_LOCALE, hMem, TRUE, TRUE);
317
318 /* Release the extra reference (UserCreateObject added 2 references) */
319 UserDereferenceObject(pMemObj);
320 }
321 }
322
323 /* Add CF_TEXT. Note: it is synthesized in user32.dll */
324 if (!bHaveText && (bHaveUniText || bHaveOemText))
326
327 /* Add CF_OEMTEXT. Note: it is synthesized in user32.dll */
328 if (!bHaveOemText && (bHaveUniText || bHaveText))
330
331 /* Add CF_UNICODETEXT. Note: it is synthesized in user32.dll */
332 if (!bHaveUniText && (bHaveText || bHaveOemText))
334
335 /* Add CF_BITMAP. Note: it is synthesized on demand */
336 if (!bHaveBm && bHaveDib)
338
339 /* Add CF_ENHMETAFILE. Note: it is synthesized in gdi32.dll */
340 if (bHaveMFP && !bHaveEMF)
342
343 /* Add CF_METAFILEPICT. Note: it is synthesized in gdi32.dll */
344 if (bHaveEMF && !bHaveMFP)
346
347 /* Note: We need to render the DIB or DIBV5 format as soon as possible
348 because palette information may change */
349 if (!bHaveDib && bHaveBm)
350 IntSynthesizeDib(pWinStaObj, IntGetFormatElement(pWinStaObj, CF_BITMAP)->hData);
351}
#define CF_UNICODETEXT
Definition: constants.h:408
#define CF_METAFILEPICT
Definition: constants.h:398
#define CF_BITMAP
Definition: constants.h:397
#define CF_LOCALE
Definition: constants.h:411
#define CF_ENHMETAFILE
Definition: constants.h:409
#define CF_TEXT
Definition: constants.h:396
#define CF_DIB
Definition: constants.h:403
#define CF_OEMTEXT
Definition: constants.h:402
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
struct tagCLIPBOARDDATA * PCLIPBOARDDATA
@ TYPE_CLIPDATA
Definition: ntuser.h:46
#define NtCurrentTeb
DWORD LCID
Definition: nls.h:13
BYTE Data[0]
Definition: ntuser.h:259
DWORD cbData
Definition: ntuser.h:258
static BOOL FASTCALL IntIsFormatAvailable(PWINSTATION_OBJECT pWinStaObj, UINT fmt)
Definition: clipboard.c:55
#define DATA_SYNTH_USER
Definition: clipboard.c:15
#define DATA_SYNTH_KRNL
Definition: clipboard.c:16
static VOID NTAPI IntSynthesizeDib(PWINSTATION_OBJECT pWinStaObj, HBITMAP hbm)
Definition: clipboard.c:144
static PCLIP NTAPI IntAddFormatedData(PWINSTATION_OBJECT pWinStaObj, UINT fmt, HANDLE hData, BOOLEAN fGlobalHandle, BOOL bEnd)
Definition: clipboard.c:84
BOOL FASTCALL UserDereferenceObject(PVOID Object)
Definition: object.c:644
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13
PVOID FASTCALL UserCreateObject(PUSER_HANDLE_TABLE ht, PDESKTOP pDesktop, PTHREADINFO pti, HANDLE *h, HANDLE_TYPE type, ULONG size)
Definition: object.c:568

Referenced by UserClipboardRelease(), and UserCloseClipboard().

◆ IntFreeElementData()

static VOID FASTCALL IntFreeElementData ( PCLIP  pElement)
static

Definition at line 61 of file clipboard.c.

62{
63 if (!IS_DATA_DELAYED(pElement) &&
64 !IS_DATA_SYNTHESIZED(pElement))
65 {
66 if (pElement->fGlobalHandle)
68 else if (pElement->fmt == CF_BITMAP ||
69 pElement->fmt == CF_PALETTE ||
70 pElement->fmt == CF_DSPBITMAP ||
71 pElement->fmt == CF_METAFILEPICT ||
72 pElement->fmt == CF_DSPMETAFILEPICT ||
73 pElement->fmt == CF_DSPENHMETAFILE ||
74 pElement->fmt == CF_ENHMETAFILE )
75 {
77 GreDeleteObject(pElement->hData);
78 }
79 }
80}
#define CF_PALETTE
Definition: constants.h:404
#define CF_DSPENHMETAFILE
Definition: constants.h:417
#define CF_DSPMETAFILEPICT
Definition: constants.h:416
#define CF_DSPBITMAP
Definition: constants.h:415
#define GDI_OBJ_HMGR_POWNED
Definition: ntgdihdl.h:117
BOOL NTAPI GreSetObjectOwner(HGDIOBJ hobj, ULONG ulOwner)
Definition: gdiobj.c:1255
BOOL NTAPI GreDeleteObject(HGDIOBJ hobj)
Definition: gdiobj.c:1158
#define IS_DATA_SYNTHESIZED(ce)
Definition: clipboard.c:18
#define IS_DATA_DELAYED(ce)
Definition: clipboard.c:17
BOOL FASTCALL UserDeleteObject(HANDLE h, HANDLE_TYPE type)
Definition: object.c:717

Referenced by IntAddFormatedData(), and UserEmptyClipboardData().

◆ IntGetFormatElement()

static PCLIP FASTCALL IntGetFormatElement ( PWINSTATION_OBJECT  pWinStaObj,
UINT  fmt 
)
static

Definition at line 41 of file clipboard.c.

42{
43 DWORD i;
44
45 for (i = 0; i < pWinStaObj->cNumClipFormats; ++i)
46 {
47 if (pWinStaObj->pClipBase[i].fmt == fmt)
48 return &pWinStaObj->pClipBase[i];
49 }
50
51 return NULL;
52}
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by IntAddFormatedData(), IntAddSynthesizedFormats(), IntIsFormatAvailable(), IntSynthesizeBitmap(), NtUserGetClipboardData(), and UserEnumClipboardFormats().

◆ IntGetWinStaForCbAccess()

static PWINSTATION_OBJECT FASTCALL IntGetWinStaForCbAccess ( VOID  )
static

Definition at line 21 of file clipboard.c.

22{
23 HWINSTA hWinSta;
24 PWINSTATION_OBJECT pWinStaObj;
26
29 if (!NT_SUCCESS(Status))
30 {
31 ERR("Cannot open winsta\n");
33 return NULL;
34 }
35
36 return pWinStaObj;
37}
LONG NTSTATUS
Definition: precomp.h:26
#define ERR(fmt,...)
Definition: debug.h:110
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
#define UserMode
Definition: asm.h:35
NTSTATUS FASTCALL IntValidateWindowStationHandle(HWINSTA WindowStation, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PWINSTATION_OBJECT *Object, POBJECT_HANDLE_INFORMATION pObjectHandleInfo)
Definition: winsta.c:232
HWINSTA FASTCALL UserGetProcessWindowStation(VOID)
Definition: winsta.c:1353
VOID FASTCALL SetLastNtError(_In_ NTSTATUS Status)
Definition: error.c:31
#define WINSTA_ACCESSCLIPBOARD
Definition: winuser.h:408

Referenced by NtUserChangeClipboardChain(), NtUserCountClipboardFormats(), NtUserGetClipboardData(), NtUserGetClipboardOwner(), NtUserGetClipboardSequenceNumber(), NtUserGetClipboardViewer(), NtUserGetOpenClipboardWindow(), NtUserGetPriorityClipboardFormat(), NtUserIsClipboardFormatAvailable(), NtUserSetClipboardViewer(), UserClipboardFreeWindow(), UserClipboardRelease(), UserCloseClipboard(), UserEmptyClipboard(), UserEnumClipboardFormats(), UserOpenClipboard(), and UserSetClipboardData().

◆ IntIsClipboardOpenByMe()

static BOOL FASTCALL IntIsClipboardOpenByMe ( PWINSTATION_OBJECT  pWinSta)
static

Definition at line 136 of file clipboard.c.

137{
138 /* Check if the current thread has opened the clipboard */
139 return (pWinSta->ptiClipLock &&
141}
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
PTHREADINFO ptiClipLock
Definition: winsta.h:24

Referenced by NtUserGetClipboardData(), UserCloseClipboard(), UserEmptyClipboard(), UserEnumClipboardFormats(), and UserOpenClipboard().

◆ IntIsFormatAvailable()

static BOOL FASTCALL IntIsFormatAvailable ( PWINSTATION_OBJECT  pWinStaObj,
UINT  fmt 
)
static

Definition at line 55 of file clipboard.c.

56{
57 return IntGetFormatElement(pWinStaObj, fmt) != NULL;
58}

Referenced by IntAddSynthesizedFormats(), NtUserGetPriorityClipboardFormat(), and NtUserIsClipboardFormatAvailable().

◆ IntSynthesizeBitmap()

static VOID WINAPI IntSynthesizeBitmap ( PWINSTATION_OBJECT  pWinStaObj,
PCLIP  pBmEl 
)
static

Definition at line 230 of file clipboard.c.

231{
232 HDC hdc = NULL;
233 PBITMAPINFO pBmi, pConvertedBmi = NULL;
234 HBITMAP hBm = NULL;
235 PCLIPBOARDDATA pMemObj;
236 PCLIP pDibEl;
238
239 TRACE("IntSynthesizeBitmap(%p, %p)\n", pWinStaObj, pBmEl);
240
241 pDibEl = IntGetFormatElement(pWinStaObj, CF_DIB);
242 ASSERT(pDibEl && !IS_DATA_SYNTHESIZED(pDibEl));
243 if (!pDibEl->fGlobalHandle)
244 return;
245
247 if (!pMemObj)
248 return;
249
250 pBmi = (BITMAPINFO*)pMemObj->Data;
251
252 if (pMemObj->cbData < sizeof(DWORD) && pMemObj->cbData < pBmi->bmiHeader.biSize)
253 goto cleanup;
254
255 pConvertedBmi = DIB_ConvertBitmapInfo(pBmi, DIB_RGB_COLORS);
256 if (!pConvertedBmi)
257 goto cleanup;
258
260
262 if (!hdc)
263 goto cleanup;
264
266 pConvertedBmi->bmiHeader.biWidth,
267 pConvertedBmi->bmiHeader.biHeight,
268 CBM_INIT,
269 pMemObj->Data + Offset,
270 pConvertedBmi,
272 0,
273 pMemObj->cbData - Offset,
274 0);
275
276 if (hBm)
277 {
279 pBmEl->hData = hBm;
280 }
281
282cleanup:
283 if (hdc)
285
286 if (pConvertedBmi)
287 DIB_FreeConvertedBitmapInfo(pConvertedBmi, pBmi, -1);
288}
#define DCX_USESTYLE
Definition: GetDCEx.c:10
HBITMAP NTAPI GreCreateDIBitmapInternal(IN HDC hDc, IN INT cx, IN INT cy, IN DWORD fInit, IN OPTIONAL LPBYTE pjInit, IN OPTIONAL PBITMAPINFO pbmi, IN DWORD iUsage, IN FLONG fl, IN UINT cjMaxBits, IN HANDLE hcmXform)
Definition: dibobj.c:1718
static void cleanup(void)
Definition: main.c:1335
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
#define TRACE(s)
Definition: solgame.cpp:4
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
uint32_t ULONG
Definition: typedefs.h:59
INT FASTCALL UserReleaseDC(PWND Window, HDC hDc, BOOL EndPaint)
Definition: windc.c:918
HDC FASTCALL UserGetDCEx(PWND Window OPTIONAL, HANDLE ClipRegion, ULONG Flags)
INT FASTCALL DIB_BitmapInfoSize(const BITMAPINFO *info, WORD coloruse, BOOL max)
Definition: bitmap.c:65
BITMAPINFO *FASTCALL DIB_ConvertBitmapInfo(CONST BITMAPINFO *bmi, DWORD Usage)
Definition: dibobj.c:2238
VOID FASTCALL DIB_FreeConvertedBitmapInfo(BITMAPINFO *converted, BITMAPINFO *orig, DWORD Usage)
Definition: dibobj.c:2302
PVOID UserGetObject(PUSER_HANDLE_TABLE ht, HANDLE handle, HANDLE_TYPE type)
Definition: object.c:495
#define DIB_RGB_COLORS
Definition: wingdi.h:367
#define CBM_INIT
Definition: wingdi.h:365

Referenced by NtUserGetClipboardData().

◆ IntSynthesizeDib()

static VOID NTAPI IntSynthesizeDib ( PWINSTATION_OBJECT  pWinStaObj,
HBITMAP  hbm 
)
static

Definition at line 144 of file clipboard.c.

147{
148 HDC hdc;
149 ULONG cjInfoSize, cjDataSize;
150 PCLIPBOARDDATA pClipboardData;
151 HANDLE hMem;
152 INT iResult;
153 struct
154 {
155 BITMAPINFOHEADER bmih;
156 RGBQUAD rgbColors[256];
157 } bmiBuffer;
158 PBITMAPINFO pbmi = (PBITMAPINFO)&bmiBuffer;
159
160 /* Get the display DC */
162 if (!hdc)
163 {
164 return;
165 }
166
167 /* Get information about the bitmap format */
168 memset(&bmiBuffer, 0, sizeof(bmiBuffer));
169 pbmi->bmiHeader.biSize = sizeof(bmiBuffer.bmih);
170 iResult = GreGetDIBitsInternal(hdc,
171 hbm,
172 0,
173 0,
174 NULL,
175 pbmi,
177 0,
178 sizeof(bmiBuffer));
179 if (iResult == 0)
180 {
181 goto cleanup;
182 }
183
184 /* Get the size for a full BITMAPINFO */
186
187 /* Calculate the size of the clipboard data, which is a packed DIB */
188 cjDataSize = cjInfoSize + pbmi->bmiHeader.biSizeImage;
189
190 /* Create the clipboard data */
192 NULL,
193 NULL,
194 &hMem,
196 sizeof(CLIPBOARDDATA) + cjDataSize);
197 if (!pClipboardData)
198 {
199 goto cleanup;
200 }
201
202 /* Set the data size */
203 pClipboardData->cbData = cjDataSize;
204
205 /* Copy the BITMAPINFOHEADER */
206 memcpy(pClipboardData->Data, pbmi, sizeof(BITMAPINFOHEADER));
207
208 /* Get the bitmap bits and the color table */
209 iResult = GreGetDIBitsInternal(hdc,
210 hbm,
211 0,
213 (LPBYTE)pClipboardData->Data + cjInfoSize,
214 (LPBITMAPINFO)pClipboardData->Data,
217 cjInfoSize);
218
219 /* Add the clipboard data */
220 IntAddFormatedData(pWinStaObj, CF_DIB, hMem, TRUE, TRUE);
221
222 /* Release the extra reference (UserCreateObject added 2 references) */
223 UserDereferenceObject(pClipboardData);
224
225cleanup:
227}
ULONG RGBQUAD
Definition: precomp.h:59
#define abs(i)
Definition: fconv.c:206
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
#define memset(x, y, z)
Definition: compat.h:39
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
_In_z_ PCWSTR _In_ ULONG _Post_z_ PVOID _In_ ULONG cjDataSize
Definition: ntuser.h:45
INT APIENTRY GreGetDIBitsInternal(HDC hDC, HBITMAP hBitmap, UINT StartScan, UINT ScanLines, LPBYTE Bits, LPBITMAPINFO Info, UINT Usage, UINT MaxBits, UINT MaxInfo)
Definition: dibobj.c:717
struct tagBITMAPINFO * PBITMAPINFO

Referenced by IntAddSynthesizedFormats().

◆ NtUserChangeClipboardChain()

BOOL APIENTRY NtUserChangeClipboardChain ( HWND  hWndRemove,
HWND  hWndNewNext 
)

Definition at line 624 of file clipboard.c.

625{
626 BOOL bRet = FALSE;
627 PWND pWindowRemove;
628 PWINSTATION_OBJECT pWinStaObj;
629
630 TRACE("NtUserChangeClipboardChain(%p, %p)\n", hWndRemove, hWndNewNext);
631
633
634 pWinStaObj = IntGetWinStaForCbAccess();
635 if (!pWinStaObj)
636 goto cleanup;
637
638 pWindowRemove = UserGetWindowObject(hWndRemove);
639
640 if (pWindowRemove && pWinStaObj->spwndClipViewer)
641 {
642 if (pWindowRemove == pWinStaObj->spwndClipViewer)
643 pWinStaObj->spwndClipViewer = UserGetWindowObject(hWndNewNext);
644
645 if (pWinStaObj->spwndClipViewer)
646 bRet = (BOOL)co_IntSendMessage(UserHMGetHandle(pWinStaObj->spwndClipViewer), WM_CHANGECBCHAIN, (WPARAM)hWndRemove, (LPARAM)hWndNewNext);
647 }
648
649 ObDereferenceObject(pWinStaObj);
650
651cleanup:
652 UserLeave();
653
654 return bRet;
655}
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
#define BOOL
Definition: nt_native.h:43
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:251
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:242
PWND spwndClipViewer
Definition: winsta.h:27
Definition: ntuser.h:694
PWND FASTCALL UserGetWindowObject(HWND hWnd)
Definition: window.c:122
static PWINSTATION_OBJECT FASTCALL IntGetWinStaForCbAccess(VOID)
Definition: clipboard.c:21
LRESULT FASTCALL co_IntSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1445
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define WM_CHANGECBCHAIN
Definition: winuser.h:1874
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by ChangeClipboardChain().

◆ NtUserCloseClipboard()

BOOL APIENTRY NtUserCloseClipboard ( VOID  )

Definition at line 589 of file clipboard.c.

590{
591 BOOL bRet;
592
594 bRet = UserCloseClipboard();
595 UserLeave();
596
597 return bRet;
598}
BOOL NTAPI UserCloseClipboard(VOID)
Definition: clipboard.c:545

Referenced by CloseClipboard().

◆ NtUserConvertMemHandle()

HANDLE APIENTRY NtUserConvertMemHandle ( PVOID  pData,
DWORD  cbData 
)

Definition at line 1187 of file clipboard.c.

1190{
1191 HANDLE hMem = NULL;
1192 PCLIPBOARDDATA pMemObj;
1193
1195
1196 /* Create Clipboard data object */
1197 pMemObj = UserCreateObject(gHandleTable, NULL, NULL, &hMem, TYPE_CLIPDATA, sizeof(CLIPBOARDDATA) + cbData);
1198 if (!pMemObj)
1199 goto cleanup;
1200
1201 pMemObj->cbData = cbData;
1202
1203 /* Copy data */
1204 _SEH2_TRY
1205 {
1206 ProbeForRead(pData, cbData, 1);
1207 memcpy(pMemObj->Data, pData, cbData);
1208 }
1210 {
1211 pMemObj = NULL;
1212 }
1213 _SEH2_END;
1214
1215 /* Release the extra reference (UserCreateObject added 2 references) */
1216 UserDereferenceObject(pMemObj);
1217
1218 /* If we failed to copy data, remove handle */
1219 if (!pMemObj)
1220 {
1222 hMem = NULL;
1223 }
1224
1225cleanup:
1226 UserLeave();
1227
1228 return hMem;
1229}
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830

Referenced by GetClipboardData(), and SetClipboardData().

◆ NtUserCountClipboardFormats()

DWORD APIENTRY NtUserCountClipboardFormats ( VOID  )

Definition at line 658 of file clipboard.c.

659{
660 DWORD cFormats = 0;
661 PWINSTATION_OBJECT pWinStaObj;
662
664
665 pWinStaObj = IntGetWinStaForCbAccess();
666 if (!pWinStaObj)
667 goto cleanup;
668
669 cFormats = pWinStaObj->cNumClipFormats;
670
671 ObDereferenceObject(pWinStaObj);
672
673cleanup:
674 UserLeave();
675
676 return cFormats;
677}
VOID FASTCALL UserEnterShared(VOID)
Definition: ntuser.c:235

Referenced by CountClipboardFormats(), and START_TEST().

◆ NtUserCreateLocalMemHandle()

NTSTATUS APIENTRY NtUserCreateLocalMemHandle ( HANDLE  hMem,
PVOID  pData,
DWORD  cbData,
DWORD pcbData 
)

Definition at line 1232 of file clipboard.c.

1237{
1238 PCLIPBOARDDATA pMemObj;
1240
1242
1243 /* Get Clipboard data object */
1245 if (!pMemObj)
1246 {
1248 goto cleanup;
1249 }
1250
1251 /* Don't overrun */
1252 if (cbData > pMemObj->cbData)
1253 cbData = pMemObj->cbData;
1254
1255 /* Copy data to usermode */
1256 _SEH2_TRY
1257 {
1258 if (pcbData)
1259 {
1260 ProbeForWrite(pcbData, sizeof(*pcbData), 1);
1261 *pcbData = pMemObj->cbData;
1262 }
1263
1264 ProbeForWrite(pData, cbData, 1);
1265 memcpy(pData, pMemObj->Data, cbData);
1266 }
1268 {
1270 }
1271 _SEH2_END;
1272
1273cleanup:
1274 UserLeave();
1275
1276 return Status;
1277}
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define STATUS_SUCCESS
Definition: shellext.h:65
_In_ DWORD _Out_writes_bytes_to_opt_ pcbData void _Inout_ DWORD * pcbData
Definition: wincrypt.h:4950

Referenced by GetClipboardData().

◆ NtUserEmptyClipboard()

BOOL APIENTRY NtUserEmptyClipboard ( VOID  )

Definition at line 722 of file clipboard.c.

723{
724 BOOL bRet;
725
726 TRACE("NtUserEmptyClipboard()\n");
727
729 bRet = UserEmptyClipboard();
730 UserLeave();
731
732 return bRet;
733}
BOOL NTAPI UserEmptyClipboard(VOID)
Definition: clipboard.c:680

Referenced by EmptyClipboard().

◆ NtUserGetClipboardData()

HANDLE APIENTRY NtUserGetClipboardData ( UINT  fmt,
PGETCLIPBDATA  pgcd 
)

Definition at line 897 of file clipboard.c.

898{
899 HANDLE hRet = NULL;
900 PCLIP pElement;
901 PWINSTATION_OBJECT pWinStaObj;
902 UINT uSourceFmt = fmt;
903
904 TRACE("NtUserGetClipboardData(%x, %p)\n", fmt, pgcd);
905
907
908 pWinStaObj = IntGetWinStaForCbAccess();
909 if (!pWinStaObj)
910 goto cleanup;
911
912 /* Check if the clipboard has been opened */
913 if (!IntIsClipboardOpenByMe(pWinStaObj))
914 {
916 goto cleanup;
917 }
918
919 pElement = IntGetFormatElement(pWinStaObj, fmt);
920 if (!pElement)
921 goto cleanup;
922
923 if (IS_DATA_SYNTHESIZED(pElement))
924 {
925 /* Note: Data is synthesized in usermode */
926 /* TODO: Add more formats */
927 switch (fmt)
928 {
929 case CF_UNICODETEXT:
930 case CF_TEXT:
931 case CF_OEMTEXT:
932 uSourceFmt = CF_UNICODETEXT;
933 pElement = IntGetFormatElement(pWinStaObj, uSourceFmt);
934 if (IS_DATA_SYNTHESIZED(pElement))
935 {
936 uSourceFmt = CF_TEXT;
937 pElement = IntGetFormatElement(pWinStaObj, uSourceFmt);
938 }
939 if (IS_DATA_SYNTHESIZED(pElement))
940 {
941 uSourceFmt = CF_OEMTEXT;
942 pElement = IntGetFormatElement(pWinStaObj, uSourceFmt);
943 }
944 break;
945
946 case CF_BITMAP:
947 IntSynthesizeBitmap(pWinStaObj, pElement);
948 break;
949
950 case CF_METAFILEPICT:
951 uSourceFmt = CF_ENHMETAFILE;
952 pElement = IntGetFormatElement(pWinStaObj, uSourceFmt);
953 break;
954
955 case CF_ENHMETAFILE:
956 uSourceFmt = CF_METAFILEPICT;
957 pElement = IntGetFormatElement(pWinStaObj, uSourceFmt);
958 break;
959
960 default:
961 ASSERT(FALSE);
962 }
963 }
964
965 if (pElement && IS_DATA_DELAYED(pElement) && pWinStaObj->spwndClipOwner)
966 {
967 /* Send WM_RENDERFORMAT message */
968 pWinStaObj->fInDelayedRendering = TRUE;
970 pWinStaObj->fInDelayedRendering = FALSE;
971
972 /* Data should be in clipboard now */
973 pElement = IntGetFormatElement(pWinStaObj, uSourceFmt);
974 }
975
976 if (!pElement || IS_DATA_DELAYED(pElement))
977 goto cleanup;
978
980 {
981 ProbeForWrite(pgcd, sizeof(*pgcd), 1);
982 pgcd->uFmtRet = pElement->fmt;
983 pgcd->fGlobalHandle = pElement->fGlobalHandle;
984
985 /* Text and bitmap needs more data */
986 if (fmt == CF_TEXT)
987 {
988 PCLIP pLocaleEl;
989
990 pLocaleEl = IntGetFormatElement(pWinStaObj, CF_LOCALE);
991 if (pLocaleEl && !IS_DATA_DELAYED(pLocaleEl))
992 pgcd->hLocale = pLocaleEl->hData;
993 }
994 else if (fmt == CF_BITMAP)
995 {
996 PCLIP pPaletteEl;
997
998 pPaletteEl = IntGetFormatElement(pWinStaObj, CF_PALETTE);
999 if (pPaletteEl && !IS_DATA_DELAYED(pPaletteEl))
1000 pgcd->hPalette = pPaletteEl->hData;
1001 }
1002
1003 hRet = pElement->hData;
1004 }
1006 {
1008 }
1009 _SEH2_END;
1010
1011cleanup:
1012 if (pWinStaObj)
1013 ObDereferenceObject(pWinStaObj);
1014
1015 UserLeave();
1016
1017 TRACE("NtUserGetClipboardData returns %p\n", hRet);
1018
1019 return hRet;
1020}
unsigned int UINT
Definition: ndis.h:50
INT fInDelayedRendering
Definition: winsta.h:34
PWND spwndClipOwner
Definition: winsta.h:28
BOOL fGlobalHandle
Definition: ntuser.h:1158
HANDLE hPalette
Definition: ntuser.h:1162
HANDLE hLocale
Definition: ntuser.h:1161
static BOOL FASTCALL IntIsClipboardOpenByMe(PWINSTATION_OBJECT pWinSta)
Definition: clipboard.c:136
static VOID WINAPI IntSynthesizeBitmap(PWINSTATION_OBJECT pWinStaObj, PCLIP pBmEl)
Definition: clipboard.c:230
#define ERROR_CLIPBOARD_NOT_OPEN
Definition: winerror.h:899
#define WM_RENDERFORMAT
Definition: winuser.h:1866

Referenced by GetClipboardData().

◆ NtUserGetClipboardFormatName()

INT APIENTRY NtUserGetClipboardFormatName ( UINT  fmt,
LPWSTR  lpszFormatName,
INT  cchMaxCount 
)

Definition at line 736 of file clipboard.c.

737{
738 INT iRet = 0;
739
741
742 /* If the format is built-in we fail */
743 if (fmt < 0xc000 || fmt > 0xffff)
744 {
745 /* Registetrated formats are >= 0xc000 */
746 goto cleanup;
747 }
748
749 if (cchMaxCount < 1 || !lpszFormatName)
750 {
752 goto cleanup;
753 }
754
756 {
757 ProbeForWrite(lpszFormatName, cchMaxCount * sizeof(WCHAR), 1);
758
760 lpszFormatName,
761 cchMaxCount * sizeof(WCHAR));
762 iRet /= sizeof(WCHAR);
763 }
765 {
767 }
768 _SEH2_END;
769
770cleanup:
771 UserLeave();
772
773 return iRet;
774}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
unsigned short RTL_ATOM
Definition: atom.c:42
ULONG FASTCALL IntGetAtomName(RTL_ATOM nAtom, LPWSTR lpBuffer, ULONG cjBufSize)
Definition: useratom.c:37
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by GetClipboardFormatNameA(), and GetClipboardFormatNameW().

◆ NtUserGetClipboardOwner()

HWND APIENTRY NtUserGetClipboardOwner ( VOID  )

Definition at line 777 of file clipboard.c.

778{
779 HWND hWnd = NULL;
780 PWINSTATION_OBJECT pWinStaObj;
781
783
784 pWinStaObj = IntGetWinStaForCbAccess();
785 if (!pWinStaObj)
786 goto cleanup;
787
788 if (pWinStaObj->spwndClipOwner)
789 hWnd = UserHMGetHandle(pWinStaObj->spwndClipOwner);
790
791 ObDereferenceObject(pWinStaObj);
792
793cleanup:
794 UserLeave();
795
796 return hWnd;
797}
HWND hWnd
Definition: settings.c:17

Referenced by GetClipboardOwner().

◆ NtUserGetClipboardSequenceNumber()

DWORD APIENTRY NtUserGetClipboardSequenceNumber ( VOID  )

Definition at line 1164 of file clipboard.c.

1165{
1166 DWORD dwRet = 0;
1167 PWINSTATION_OBJECT pWinStaObj;
1168
1170
1171 pWinStaObj = IntGetWinStaForCbAccess();
1172 if (!pWinStaObj)
1173 goto cleanup;
1174
1175 /* Get windowstation sequence number */
1176 dwRet = (DWORD)pWinStaObj->iClipSequenceNumber;
1177
1178 ObDereferenceObject(pWinStaObj);
1179
1180cleanup:
1181 UserLeave();
1182
1183 return dwRet;
1184}
#define DWORD
Definition: nt_native.h:44
INT iClipSequenceNumber
Definition: winsta.h:32

Referenced by GetClipboardSequenceNumber().

◆ NtUserGetClipboardViewer()

HWND APIENTRY NtUserGetClipboardViewer ( VOID  )

Definition at line 800 of file clipboard.c.

801{
802 HWND hWnd = NULL;
803 PWINSTATION_OBJECT pWinStaObj;
804
806
807 pWinStaObj = IntGetWinStaForCbAccess();
808 if (!pWinStaObj)
809 goto cleanup;
810
811 if (pWinStaObj->spwndClipViewer)
812 hWnd = UserHMGetHandle(pWinStaObj->spwndClipViewer);
813
814 ObDereferenceObject(pWinStaObj);
815
816cleanup:
817 UserLeave();
818
819 return hWnd;
820}

Referenced by GetClipboardViewer().

◆ NtUserGetOpenClipboardWindow()

HWND APIENTRY NtUserGetOpenClipboardWindow ( VOID  )

Definition at line 601 of file clipboard.c.

602{
603 HWND hWnd = NULL;
604 PWINSTATION_OBJECT pWinStaObj;
605
607
608 pWinStaObj = IntGetWinStaForCbAccess();
609 if (!pWinStaObj)
610 goto cleanup;
611
612 if (pWinStaObj->spwndClipOpen)
613 hWnd = UserHMGetHandle(pWinStaObj->spwndClipOpen);
614
615 ObDereferenceObject(pWinStaObj);
616
617cleanup:
618 UserLeave();
619
620 return hWnd;
621}
PWND spwndClipOpen
Definition: winsta.h:26

Referenced by GetOpenClipboardWindow().

◆ NtUserGetPriorityClipboardFormat()

INT APIENTRY NtUserGetPriorityClipboardFormat ( UINT paFormatPriorityList,
INT  cFormats 
)

Definition at line 823 of file clipboard.c.

824{
825 INT i, iRet = 0;
826 PWINSTATION_OBJECT pWinStaObj;
827
829
830 pWinStaObj = IntGetWinStaForCbAccess();
831 if (!pWinStaObj)
832 goto cleanup;
833
834 if (pWinStaObj->pClipBase == NULL)
835 {
836 iRet = 0;
837 }
838 else
839 {
841 {
842 ProbeForRead(paFormatPriorityList, cFormats * sizeof(UINT), sizeof(UINT));
843
844 iRet = -1;
845
846 for (i = 0; i < cFormats; ++i)
847 {
848 if (IntIsFormatAvailable(pWinStaObj, paFormatPriorityList[i]))
849 {
850 iRet = paFormatPriorityList[i];
851 break;
852 }
853 }
854 }
856 {
858 }
859 _SEH2_END;
860 }
861
862 ObDereferenceObject(pWinStaObj);
863
864cleanup:
865 UserLeave();
866
867 return iRet;
868
869}

Referenced by GetPriorityClipboardFormat().

◆ NtUserIsClipboardFormatAvailable()

BOOL APIENTRY NtUserIsClipboardFormatAvailable ( UINT  fmt)

Definition at line 872 of file clipboard.c.

873{
874 BOOL bRet = FALSE;
875 PWINSTATION_OBJECT pWinStaObj;
876
877 TRACE("NtUserIsClipboardFormatAvailable(%x)\n", fmt);
878
880
881 pWinStaObj = IntGetWinStaForCbAccess();
882 if (!pWinStaObj)
883 goto cleanup;
884
885 if (IntIsFormatAvailable(pWinStaObj, fmt))
886 bRet = TRUE;
887
888 ObDereferenceObject(pWinStaObj);
889
890cleanup:
891 UserLeave();
892
893 return bRet;
894}

Referenced by IsClipboardFormatAvailable().

◆ NtUserOpenClipboard()

BOOL APIENTRY NtUserOpenClipboard ( HWND  hWnd,
DWORD  Unknown1 
)

Definition at line 533 of file clipboard.c.

534{
535 BOOL bRet;
536
538 bRet = UserOpenClipboard(hWnd);
539 UserLeave();
540
541 return bRet;
542}
BOOL NTAPI UserOpenClipboard(HWND hWnd)
Definition: clipboard.c:488

Referenced by OpenClipboard().

◆ NtUserSetClipboardData()

HANDLE APIENTRY NtUserSetClipboardData ( UINT  fmt,
HANDLE  hData,
PSETCLIPBDATA  pUnsafeScd 
)

Definition at line 1084 of file clipboard.c.

1085{
1086 SETCLIPBDATA scd;
1087 HANDLE hRet;
1088
1089 TRACE("NtUserSetClipboardData(%x %p %p)\n", fmt, hData, pUnsafeScd);
1090
1091 _SEH2_TRY
1092 {
1093 ProbeForRead(pUnsafeScd, sizeof(*pUnsafeScd), 1);
1094 RtlCopyMemory(&scd, pUnsafeScd, sizeof(scd));
1095 }
1097 {
1099 _SEH2_YIELD(return NULL;)
1100 }
1101 _SEH2_END
1102
1104
1105 /* Call internal function */
1106 hRet = UserSetClipboardData(fmt, hData, &scd);
1107
1108 UserLeave();
1109
1110 return hRet;
1111}
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:162
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
HANDLE NTAPI UserSetClipboardData(UINT fmt, HANDLE hData, PSETCLIPBDATA scd)
Definition: clipboard.c:1023

Referenced by GetClipboardData(), and SetClipboardData().

◆ NtUserSetClipboardViewer()

HWND APIENTRY NtUserSetClipboardViewer ( HWND  hWndNewViewer)

Definition at line 1114 of file clipboard.c.

1115{
1116 HWND hWndNext = NULL;
1117 PWINSTATION_OBJECT pWinStaObj;
1118 PWND pWindow;
1119
1121
1122 pWinStaObj = IntGetWinStaForCbAccess();
1123 if (!pWinStaObj)
1124 goto cleanup;
1125
1126 pWindow = UserGetWindowObject(hWndNewViewer);
1127 if (!pWindow)
1128 {
1130 goto cleanup;
1131 }
1132
1133 /* Return previous viewer. New viever window should
1134 send messages to rest of the chain */
1135 if (pWinStaObj->spwndClipViewer)
1136 hWndNext = UserHMGetHandle(pWinStaObj->spwndClipViewer);
1137
1138 /* Set new viewer window */
1139 pWinStaObj->spwndClipViewer = pWindow;
1140
1141 /* Notify viewer windows in chain */
1142 pWinStaObj->fClipboardChanged = FALSE;
1143 if (pWinStaObj->spwndClipViewer)
1144 {
1145 TRACE("Clipboard: sending WM_DRAWCLIPBOARD to %p\n", UserHMGetHandle(pWinStaObj->spwndClipViewer));
1146 // For 32-bit applications this message is sent as a notification
1148 }
1149
1150cleanup:
1151 if (pWinStaObj)
1152 ObDereferenceObject(pWinStaObj);
1153
1154 UserLeave();
1155
1156 return hWndNext;
1157}
INT fClipboardChanged
Definition: winsta.h:33
LRESULT FASTCALL co_IntSendMessageNoWait(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1713
#define ERROR_INVALID_WINDOW_HANDLE
Definition: winerror.h:881
#define WM_DRAWCLIPBOARD
Definition: winuser.h:1869

Referenced by SetClipboardViewer().

◆ UserClipboardFreeWindow()

VOID FASTCALL UserClipboardFreeWindow ( PWND  pWindow)

Definition at line 414 of file clipboard.c.

415{
416 PWINSTATION_OBJECT pWinStaObj;
417
418 pWinStaObj = IntGetWinStaForCbAccess();
419 if (!pWinStaObj)
420 return;
421
422 if (pWindow == pWinStaObj->spwndClipOwner)
423 {
424 /* The owner window was destroyed */
425 pWinStaObj->spwndClipOwner = NULL;
426 }
427
428 /* Check if clipboard is not locked by this window, if yes, unlock it */
429 if (pWindow == pWinStaObj->spwndClipOpen)
430 {
431 /* The window that opens the clipboard was destroyed */
432 pWinStaObj->spwndClipOpen = NULL;
433 pWinStaObj->ptiClipLock = NULL;
434 }
435 /* Remove window from window chain */
436 if (pWindow == pWinStaObj->spwndClipViewer)
437 pWinStaObj->spwndClipViewer = NULL;
438
439 ObDereferenceObject(pWinStaObj);
440}

Referenced by co_UserFreeWindow().

◆ UserClipboardRelease()

VOID FASTCALL UserClipboardRelease ( PWND  pWindow)

Definition at line 374 of file clipboard.c.

375{
376 PWINSTATION_OBJECT pWinStaObj;
377
378 if (!pWindow)
379 return;
380
381 pWinStaObj = IntGetWinStaForCbAccess();
382 if (!pWinStaObj)
383 return;
384
386
387 /* If the window being destroyed is the current clipboard owner... */
388 if (pWindow == pWinStaObj->spwndClipOwner)
389 {
390 /* ... make it release the clipboard */
391 pWinStaObj->spwndClipOwner = NULL;
392 }
393
394 if (pWinStaObj->fClipboardChanged)
395 {
396 /* Add synthesized formats - they are rendered later */
397 IntAddSynthesizedFormats(pWinStaObj);
398
399 /* Notify viewer windows in chain */
400 pWinStaObj->fClipboardChanged = FALSE;
401 if (pWinStaObj->spwndClipViewer)
402 {
403 TRACE("Clipboard: sending WM_DRAWCLIPBOARD to %p\n", UserHMGetHandle(pWinStaObj->spwndClipViewer));
404 // For 32-bit applications this message is sent as a notification
406 }
407 }
408
409 ObDereferenceObject(pWinStaObj);
410}
static VOID NTAPI IntAddSynthesizedFormats(PWINSTATION_OBJECT pWinStaObj)
Definition: clipboard.c:291
#define WM_RENDERALLFORMATS
Definition: winuser.h:1867

Referenced by IntSendDestroyMsg().

◆ UserCloseClipboard()

BOOL NTAPI UserCloseClipboard ( VOID  )

Definition at line 545 of file clipboard.c.

546{
547 BOOL bRet = FALSE;
548 PWINSTATION_OBJECT pWinStaObj;
549
550 pWinStaObj = IntGetWinStaForCbAccess();
551 if (!pWinStaObj)
552 goto cleanup;
553
554 /* Check if the clipboard has been opened */
555 if (!IntIsClipboardOpenByMe(pWinStaObj))
556 {
558 goto cleanup;
559 }
560
561 /* Clipboard is no longer open */
562 pWinStaObj->spwndClipOpen = NULL;
563 pWinStaObj->ptiClipLock = NULL;
564 bRet = TRUE;
565
566 if (pWinStaObj->fClipboardChanged)
567 {
568 /* Add synthesized formats - they are rendered later */
569 IntAddSynthesizedFormats(pWinStaObj);
570
571 /* Notify viewer windows in chain */
572 pWinStaObj->fClipboardChanged = FALSE;
573 if (pWinStaObj->spwndClipViewer)
574 {
575 TRACE("Clipboard: sending WM_DRAWCLIPBOARD to %p\n", UserHMGetHandle(pWinStaObj->spwndClipViewer));
576 // For 32-bit applications this message is sent as a notification
578 }
579 }
580
581cleanup:
582 if (pWinStaObj)
583 ObDereferenceObject(pWinStaObj);
584
585 return bRet;
586}

Referenced by DefWndScreenshot(), ExitThreadCallback(), NtUserCloseClipboard(), and SnapWindow().

◆ UserEmptyClipboard()

BOOL NTAPI UserEmptyClipboard ( VOID  )

Definition at line 680 of file clipboard.c.

681{
682 BOOL bRet = FALSE;
683 PWINSTATION_OBJECT pWinStaObj;
684
685 pWinStaObj = IntGetWinStaForCbAccess();
686 if (!pWinStaObj)
687 return FALSE;
688
689 /* Check if the clipboard has been opened */
690 if (!IntIsClipboardOpenByMe(pWinStaObj))
691 {
693 goto cleanup;
694 }
695
696 UserEmptyClipboardData(pWinStaObj);
697
698 if (pWinStaObj->spwndClipOwner)
699 {
700 TRACE("Clipboard: WM_DESTROYCLIPBOARD to %p\n", UserHMGetHandle(pWinStaObj->spwndClipOwner));
701 // For 32-bit applications this message is sent as a notification
703 }
704
705 pWinStaObj->spwndClipOwner = pWinStaObj->spwndClipOpen;
706
707 pWinStaObj->iClipSerialNumber++;
708 pWinStaObj->iClipSequenceNumber++;
709 pWinStaObj->fClipboardChanged = TRUE;
710 pWinStaObj->fInDelayedRendering = FALSE;
711
712 bRet = TRUE;
713
714cleanup:
715 if (pWinStaObj)
716 ObDereferenceObject(pWinStaObj);
717
718 return bRet;
719}
INT iClipSerialNumber
Definition: winsta.h:31
VOID NTAPI UserEmptyClipboardData(PWINSTATION_OBJECT pWinSta)
Definition: clipboard.c:354
#define WM_DESTROYCLIPBOARD
Definition: winuser.h:1868

Referenced by DefWndScreenshot(), NtUserEmptyClipboard(), and SnapWindow().

◆ UserEmptyClipboardData()

VOID NTAPI UserEmptyClipboardData ( PWINSTATION_OBJECT  pWinSta)

Definition at line 354 of file clipboard.c.

355{
356 DWORD i;
357 PCLIP pElement;
358
359 for (i = 0; i < pWinSta->cNumClipFormats; ++i)
360 {
361 pElement = &pWinSta->pClipBase[i];
362 IntFreeElementData(pElement);
363 }
364
365 if (pWinSta->pClipBase)
367
368 pWinSta->pClipBase = NULL;
369 pWinSta->cNumClipFormats = 0;
370}

Referenced by IntWinStaObjectDelete(), and UserEmptyClipboard().

◆ UserEnumClipboardFormats()

UINT APIENTRY UserEnumClipboardFormats ( UINT  fmt)

Definition at line 443 of file clipboard.c.

444{
445 UINT Ret = 0;
446 PCLIP pElement;
447 PWINSTATION_OBJECT pWinStaObj;
448
449 pWinStaObj = IntGetWinStaForCbAccess();
450 if (!pWinStaObj)
451 goto cleanup;
452
453 /* Check if the clipboard has been opened */
454 if (!IntIsClipboardOpenByMe(pWinStaObj))
455 {
457 goto cleanup;
458 }
459
460 if (fmt == 0)
461 {
462 /* Return first format */
463 if (pWinStaObj->pClipBase)
464 Ret = pWinStaObj->pClipBase[0].fmt;
465 }
466 else
467 {
468 /* Return next format */
469 pElement = IntGetFormatElement(pWinStaObj, fmt);
470 if (pElement != NULL)
471 {
472 ++pElement;
473 if (pElement < &pWinStaObj->pClipBase[pWinStaObj->cNumClipFormats])
474 {
475 Ret = pElement->fmt;
476 }
477 }
478 }
479
480cleanup:
481 if (pWinStaObj)
482 ObDereferenceObject(pWinStaObj);
483
484 return Ret;
485}

Referenced by NtUserCallOneParam().

◆ UserOpenClipboard()

BOOL NTAPI UserOpenClipboard ( HWND  hWnd)

Definition at line 488 of file clipboard.c.

489{
490 PWND pWindow = NULL;
491 BOOL bRet = FALSE;
492 PWINSTATION_OBJECT pWinStaObj = NULL;
493
494 if (hWnd)
495 {
496 pWindow = UserGetWindowObject(hWnd);
497 if (!pWindow)
498 goto cleanup;
499 }
500
501 pWinStaObj = IntGetWinStaForCbAccess();
502 if (!pWinStaObj)
503 goto cleanup;
504
505 /* Check if we already opened the clipboard */
506 if ((pWindow == pWinStaObj->spwndClipOpen) && IntIsClipboardOpenByMe(pWinStaObj))
507 {
508 bRet = TRUE;
509 goto cleanup;
510 }
511
512 /* If the clipboard was already opened by somebody else, bail out */
513 if ((pWindow != pWinStaObj->spwndClipOpen) && pWinStaObj->ptiClipLock)
514 {
515 ERR("Access denied!\n");
517 goto cleanup;
518 }
519
520 /* Open the clipboard */
521 pWinStaObj->spwndClipOpen = pWindow;
523 bRet = TRUE;
524
525cleanup:
526 if (pWinStaObj)
527 ObDereferenceObject(pWinStaObj);
528
529 return bRet;
530}
#define ERROR_ACCESS_DENIED
Definition: compat.h:97

Referenced by DefWndScreenshot(), NtUserOpenClipboard(), and SnapWindow().

◆ UserSetClipboardData()

HANDLE NTAPI UserSetClipboardData ( UINT  fmt,
HANDLE  hData,
PSETCLIPBDATA  scd 
)

Definition at line 1023 of file clipboard.c.

1024{
1025 HANDLE hRet = NULL;
1026 PWINSTATION_OBJECT pWinStaObj;
1027
1028 pWinStaObj = IntGetWinStaForCbAccess();
1029 if (!pWinStaObj)
1030 goto cleanup;
1031
1032 if (!fmt || !pWinStaObj->ptiClipLock)
1033 {
1034 ERR("Access denied!\n");
1036 goto cleanup;
1037 }
1038
1039 if (scd->fIncSerialNumber)
1040 pWinStaObj->iClipSerialNumber++;
1041
1042 /* Is it a delayed rendering? */
1043 if (hData)
1044 {
1045 /* Is it a bitmap? */
1046 if (fmt == CF_BITMAP)
1047 {
1048 /* Make bitmap public */
1050 }
1051
1052 /* Save data in the clipboard */
1053 IntAddFormatedData(pWinStaObj, fmt, hData, scd->fGlobalHandle, FALSE);
1054 TRACE("hData stored\n");
1055
1056 /* If the serial number was increased, increase also the sequence number */
1057 if (scd->fIncSerialNumber)
1058 pWinStaObj->iClipSequenceNumber++;
1059
1060 pWinStaObj->fClipboardChanged = TRUE;
1061
1062 /* Note: Synthesized formats are added in NtUserCloseClipboard */
1063 }
1064 else
1065 {
1066 /* This is a delayed rendering */
1068 TRACE("SetClipboardData delayed format: %u\n", fmt);
1069 }
1070
1071 /* Return hData on success */
1072 hRet = hData;
1073
1074cleanup:
1075 TRACE("NtUserSetClipboardData returns: %p\n", hRet);
1076
1077 if (pWinStaObj)
1078 ObDereferenceObject(pWinStaObj);
1079
1080 return hRet;
1081}
BOOL fIncSerialNumber
Definition: ntuser.h:1169
BOOL fGlobalHandle
Definition: ntuser.h:1168
#define DATA_DELAYED
Definition: clipboard.c:14

Referenced by DefWndScreenshot(), NtUserSetClipboardData(), and SnapWindow().