ReactOS  0.4.14-dev-593-g1793dcc
prop.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * PURPOSE: Window properties
5  * FILE: win32ss/user/ntuser/prop.c
6  * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
7  */
8 
9 #include <win32k.h>
10 DBG_DEFAULT_CHANNEL(UserProp);
11 
12 /* STATIC FUNCTIONS **********************************************************/
13 
18  _In_ ATOM Atom,
20 {
21  PLIST_ENTRY ListEntry;
23  UINT i;
24  WORD SystemFlag = SystemProp ? PROPERTY_FLAG_SYSTEM : 0;
25 
27  ListEntry = Window->PropListHead.Flink;
28 
29  for (i = 0; i < Window->PropListItems; i++)
30  {
31  Property = CONTAINING_RECORD(ListEntry, PROPERTY, PropListEntry);
32  ListEntry = ListEntry->Flink;
33 
34  if (Property->Atom == Atom &&
35  (Property->fs & PROPERTY_FLAG_SYSTEM) == SystemFlag)
36  {
37  return Property;
38  }
39  }
40  NT_ASSERT(ListEntry == &Window->PropListHead);
41  return NULL;
42 }
43 
44 HANDLE
48  _In_ ATOM Atom,
50 {
51  PPROPERTY Prop;
52 
54  Prop = IntGetProp(Window, Atom, SystemProp);
55  return Prop ? Prop->Data : NULL;
56 }
57 
58 _Success_(return)
59 HANDLE
63  _In_ ATOM Atom,
65 {
66  PPROPERTY Prop;
67  HANDLE Data;
68 
70  Prop = IntGetProp(Window, Atom, SystemProp);
71  if (Prop == NULL)
72  {
73  return NULL;
74  }
75 
76  Data = Prop->Data;
78  UserHeapFree(Prop);
79  Window->PropListItems--;
80  return Data;
81 }
82 
83 _Success_(return)
84 BOOL
86 UserSetProp(
88  _In_ ATOM Atom,
91 {
92  PPROPERTY Prop;
93 
95  Prop = IntGetProp(Window, Atom, SystemProp);
96  if (Prop == NULL)
97  {
98  Prop = UserHeapAlloc(sizeof(PROPERTY));
99  if (Prop == NULL)
100  {
101  return FALSE;
102  }
103  Prop->Atom = Atom;
104  Prop->fs = SystemProp ? PROPERTY_FLAG_SYSTEM : 0;
105  InsertTailList(&Window->PropListHead, &Prop->PropListEntry);
106  Window->PropListItems++;
107  }
108 
109  Prop->Data = Data;
110  return TRUE;
111 }
112 
113 VOID
114 FASTCALL
116  _In_ PWND Window)
117 {
118  PLIST_ENTRY ListEntry;
120 
122  while (!IsListEmpty(&Window->PropListHead))
123  {
124  ListEntry = Window->PropListHead.Flink;
125  Property = CONTAINING_RECORD(ListEntry, PROPERTY, PropListEntry);
126  RemoveEntryList(&Property->PropListEntry);
128  Window->PropListItems--;
129  }
130  return;
131 }
132 
133 /* FUNCTIONS *****************************************************************/
134 
135 NTSTATUS
136 APIENTRY
138  _In_ HWND hWnd,
142 {
143  PWND Window;
145  PLIST_ENTRY ListEntry;
146  PROPLISTITEM listitem, *li;
148  DWORD Cnt = 0;
149 
150  TRACE("Enter NtUserBuildPropList\n");
151  UserEnterShared();
152 
154  if (Window == NULL)
155  {
157  goto Exit;
158  }
159 
160  if (Buffer)
161  {
162  if (!BufferSize || (BufferSize % sizeof(PROPLISTITEM) != 0))
163  {
165  goto Exit;
166  }
167 
168  /* Copy list */
169  li = (PROPLISTITEM *)Buffer;
170  ListEntry = Window->PropListHead.Flink;
171  while ((BufferSize >= sizeof(PROPLISTITEM)) &&
172  (ListEntry != &Window->PropListHead))
173  {
174  Property = CONTAINING_RECORD(ListEntry, PROPERTY, PropListEntry);
175  ListEntry = ListEntry->Flink;
176  if (!(Property->fs & PROPERTY_FLAG_SYSTEM))
177  {
178  listitem.Atom = Property->Atom;
179  listitem.Data = Property->Data;
180 
181  Status = MmCopyToCaller(li, &listitem, sizeof(PROPLISTITEM));
182  if (!NT_SUCCESS(Status))
183  {
184  goto Exit;
185  }
186 
187  BufferSize -= sizeof(PROPLISTITEM);
188  Cnt++;
189  li++;
190  }
191  }
192 
193  }
194  else
195  {
196  /* FIXME: This counts user and system props */
197  Cnt = Window->PropListItems * sizeof(PROPLISTITEM);
198  }
199 
200  if (Count)
201  {
202  Status = MmCopyToCaller(Count, &Cnt, sizeof(DWORD));
203  if (!NT_SUCCESS(Status))
204  {
205  goto Exit;
206  }
207  }
208 
210 
211 Exit:
212  TRACE("Leave NtUserBuildPropList, ret=%lx\n", Status);
213  UserLeave();
214 
215  return Status;
216 }
217 
218 HANDLE
219 APIENTRY
221  _In_ HWND hWnd,
222  _In_ ATOM Atom)
223 {
224  PWND Window;
225  HANDLE Data = NULL;
226 
227  TRACE("Enter NtUserRemoveProp\n");
229 
231  if (Window == NULL)
232  {
233  goto Exit;
234  }
235 
237 
238 Exit:
239  TRACE("Leave NtUserRemoveProp, ret=%p\n", Data);
240  UserLeave();
241 
242  return Data;
243 }
244 
245 BOOL
246 APIENTRY
248  _In_ HWND hWnd,
249  _In_ ATOM Atom,
250  _In_ HANDLE Data)
251 {
252  PWND Window;
253  BOOL Ret;
254 
255  TRACE("Enter NtUserSetProp\n");
257 
259  if (Window == NULL)
260  {
261  Ret = FALSE;
262  goto Exit;
263  }
264 
265  Ret = UserSetProp(Window, Atom, Data, FALSE);
266 
267 Exit:
268  TRACE("Leave NtUserSetProp, ret=%i\n", Ret);
269  UserLeave();
270 
271  return Ret;
272 }
273 
274 /* EOF */
VOID FASTCALL UserEnterShared(VOID)
Definition: ntuser.c:241
#define TRUE
Definition: types.h:120
BOOL FASTCALL UserIsEntered(VOID)
Definition: ntuser.c:225
#define _Out_writes_bytes_to_opt_(size, count)
Definition: no_sal2.h:375
WORD ATOM
Definition: dimm.idl:113
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ ATOM _In_ HANDLE _In_ BOOLEAN SystemProp
Definition: prop.h:22
LONG NTSTATUS
Definition: precomp.h:26
HWND hWnd
Definition: settings.c:17
static __inline BOOL UserHeapFree(PVOID lpMem)
Definition: usrheap.h:42
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
NTSTATUS APIENTRY NtUserBuildPropList(_In_ HWND hWnd, _Out_writes_bytes_to_opt_(BufferSize, *Count *sizeof(PROPLISTITEM)) LPVOID Buffer, _In_ DWORD BufferSize, _Out_opt_ DWORD *Count)
Definition: prop.c:137
#define MmCopyToCaller(x, y, z)
Definition: mmcopy.h:19
#define InsertTailList(ListHead, Entry)
static __inline PVOID UserHeapAlloc(SIZE_T Bytes)
Definition: usrheap.h:34
_Out_ RTL_ATOM * Atom
Definition: class.h:54
BOOL APIENTRY NtUserSetProp(_In_ HWND hWnd, _In_ ATOM Atom, _In_ HANDLE Data)
Definition: prop.c:247
#define FASTCALL
Definition: nt_native.h:50
_Success_(return)
Definition: prop.c:58
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
#define PROPERTY_FLAG_SYSTEM
Definition: ntuser.h:1049
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
Definition: window.c:28
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
HANDLE Data
Definition: ntuser.h:1054
unsigned int BOOL
Definition: ntddk_ex.h:94
LIST_ENTRY PropListEntry
Definition: ntuser.h:1053
HANDLE APIENTRY NtUserRemoveProp(_In_ HWND hWnd, _In_ ATOM Atom)
Definition: prop.c:220
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
Definition: bufpool.h:45
PWND FASTCALL UserGetWindowObject(HWND hWnd)
Definition: window.c:103
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:247
#define _Out_opt_
Definition: no_sal2.h:339
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
VOID FASTCALL UserRemoveWindowProps(_In_ PWND Window)
Definition: prop.c:115
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PPROPERTY FASTCALL IntGetProp(_In_ PWND Window, _In_ ATOM Atom, _In_ BOOLEAN SystemProp)
Definition: prop.c:16
static void Exit(void)
Definition: sock.c:1331
HANDLE FASTCALL UserGetProp(_In_ PWND Window, _In_ ATOM Atom, _In_ BOOLEAN SystemProp)
Definition: prop.c:46
#define BufferSize
Definition: classpnp.h:419
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
int Window
Definition: x11stubs.h:26
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
_In_ DWORD Property
Definition: setupapi.h:1545
Definition: ntuser.h:657
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:255
unsigned int UINT
Definition: ndis.h:50
DBG_DEFAULT_CHANNEL(UserProp)
BOOL FASTCALL UserIsEnteredExclusive(VOID)
Definition: ntuser.c:231
ATOM Atom
Definition: ntuser.h:1055
HANDLE Data
Definition: ntuser.h:1046
return STATUS_SUCCESS
Definition: btrfs.c:2938
HANDLE FASTCALL UserRemoveProp(_In_ PWND Window, _In_ ATOM Atom, _In_ BOOLEAN SystemProp)
struct _PROPLISTITEM PROPLISTITEM
#define APIENTRY
Definition: api.h:79
#define NT_ASSERT
Definition: rtlfuncs.h:3312
WORD fs
Definition: ntuser.h:1056