d2d1: Create feature level 10.0 device context state objects.
[wine.git] / dlls / user32 / property.c
blob4d55c4dfac8dc57cf9a9270b08a2cd40ba13e91b
1 /*
2 * Window properties
4 * Copyright 1995, 1996, 2001 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <string.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winnls.h"
27 #include "ntuser.h"
28 #include "wine/server.h"
30 /* size of buffer needed to store an atom string */
31 #define ATOM_BUFFER_SIZE 256
34 /***********************************************************************
35 * get_properties
37 * Retrieve the list of properties of a given window.
38 * Returned buffer must be freed by caller.
40 static property_data_t *get_properties( HWND hwnd, int *count )
42 property_data_t *data;
43 int total = 32;
45 while (total)
47 int res = 0;
48 if (!(data = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*data) ))) break;
49 *count = 0;
50 SERVER_START_REQ( get_window_properties )
52 req->window = wine_server_user_handle( hwnd );
53 wine_server_set_reply( req, data, total * sizeof(*data) );
54 if (!wine_server_call( req )) res = reply->total;
56 SERVER_END_REQ;
57 if (res && res <= total)
59 *count = res;
60 return data;
62 HeapFree( GetProcessHeap(), 0, data );
63 total = res; /* restart with larger buffer */
65 return NULL;
69 /***********************************************************************
70 * EnumPropsA_relay
72 * relay to call the EnumProps callback function from EnumPropsEx
74 static BOOL CALLBACK EnumPropsA_relay( HWND hwnd, LPSTR str, HANDLE handle, ULONG_PTR lparam )
76 PROPENUMPROCA func = (PROPENUMPROCA)lparam;
77 return func( hwnd, str, handle );
81 /***********************************************************************
82 * EnumPropsW_relay
84 * relay to call the EnumProps callback function from EnumPropsEx
86 static BOOL CALLBACK EnumPropsW_relay( HWND hwnd, LPWSTR str, HANDLE handle, ULONG_PTR lparam )
88 PROPENUMPROCW func = (PROPENUMPROCW)lparam;
89 return func( hwnd, str, handle );
93 /***********************************************************************
94 * EnumPropsA (USER32.@)
96 INT WINAPI EnumPropsA( HWND hwnd, PROPENUMPROCA func )
98 return EnumPropsExA( hwnd, EnumPropsA_relay, (LPARAM)func );
102 /***********************************************************************
103 * EnumPropsW (USER32.@)
105 INT WINAPI EnumPropsW( HWND hwnd, PROPENUMPROCW func )
107 return EnumPropsExW( hwnd, EnumPropsW_relay, (LPARAM)func );
111 /***********************************************************************
112 * GetPropA (USER32.@)
114 HANDLE WINAPI GetPropA( HWND hwnd, LPCSTR str )
116 WCHAR buffer[ATOM_BUFFER_SIZE];
118 if (IS_INTRESOURCE(str)) return GetPropW( hwnd, (LPCWSTR)str );
119 if (!MultiByteToWideChar( CP_ACP, 0, str, -1, buffer, ATOM_BUFFER_SIZE )) return 0;
120 return GetPropW( hwnd, buffer );
124 /***********************************************************************
125 * GetPropW (USER32.@)
127 HANDLE WINAPI GetPropW( HWND hwnd, LPCWSTR str )
129 return NtUserGetProp( hwnd, str );
133 /***********************************************************************
134 * SetPropA (USER32.@)
136 BOOL WINAPI SetPropA( HWND hwnd, LPCSTR str, HANDLE handle )
138 WCHAR buffer[ATOM_BUFFER_SIZE];
140 if (IS_INTRESOURCE(str)) return SetPropW( hwnd, (LPCWSTR)str, handle );
141 if (!MultiByteToWideChar( CP_ACP, 0, str, -1, buffer, ATOM_BUFFER_SIZE )) return FALSE;
142 return SetPropW( hwnd, buffer, handle );
146 /***********************************************************************
147 * SetPropW (USER32.@)
149 BOOL WINAPI SetPropW( HWND hwnd, LPCWSTR str, HANDLE handle )
151 return NtUserSetProp( hwnd, str, handle );
155 /***********************************************************************
156 * RemovePropA (USER32.@)
158 HANDLE WINAPI RemovePropA( HWND hwnd, LPCSTR str )
160 WCHAR buffer[ATOM_BUFFER_SIZE];
162 if (IS_INTRESOURCE(str)) return RemovePropW( hwnd, (LPCWSTR)str );
163 if (!MultiByteToWideChar( CP_ACP, 0, str, -1, buffer, ATOM_BUFFER_SIZE )) return 0;
164 return RemovePropW( hwnd, buffer );
168 /***********************************************************************
169 * RemovePropW (USER32.@)
171 HANDLE WINAPI RemovePropW( HWND hwnd, LPCWSTR str )
173 return NtUserRemoveProp( hwnd, str );
177 /***********************************************************************
178 * EnumPropsExA (USER32.@)
180 INT WINAPI EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
182 int ret = -1, i, count;
183 property_data_t *list = get_properties( hwnd, &count );
185 if (list)
187 for (i = 0; i < count; i++)
189 char string[ATOM_BUFFER_SIZE];
190 if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
191 if (!(ret = func( hwnd, string, (HANDLE)(ULONG_PTR)list[i].data, lParam ))) break;
193 HeapFree( GetProcessHeap(), 0, list );
195 return ret;
199 /***********************************************************************
200 * EnumPropsExW (USER32.@)
202 INT WINAPI EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
204 int ret = -1, i, count;
205 property_data_t *list = get_properties( hwnd, &count );
207 if (list)
209 for (i = 0; i < count; i++)
211 WCHAR string[ATOM_BUFFER_SIZE];
212 if (!GlobalGetAtomNameW( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
213 if (!(ret = func( hwnd, string, (HANDLE)(ULONG_PTR)list[i].data, lParam ))) break;
215 HeapFree( GetProcessHeap(), 0, list );
217 return ret;