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
22 #include "wine/port.h"
30 #include "wine/unicode.h"
31 #include "wine/server.h"
33 /* size of buffer needed to store an atom string */
34 #define ATOM_BUFFER_SIZE 256
37 /***********************************************************************
40 * Retrieve the list of properties of a given window.
41 * Returned buffer must be freed by caller.
43 static property_data_t *get_properties( HWND hwnd, int *count )
45 property_data_t *data;
51 if (!(data = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*data) ))) break;
53 SERVER_START_REQ( get_window_properties )
55 req->window = wine_server_user_handle( hwnd );
56 wine_server_set_reply( req, data, total * sizeof(*data) );
57 if (!wine_server_call( req )) res = reply->total;
60 if (res && res <= total)
65 HeapFree( GetProcessHeap(), 0, data );
66 total = res; /* restart with larger buffer */
72 /***********************************************************************
75 * relay to call the EnumProps callback function from EnumPropsEx
77 static BOOL CALLBACK EnumPropsA_relay( HWND hwnd, LPSTR str, HANDLE handle, ULONG_PTR lparam )
79 PROPENUMPROCA func = (PROPENUMPROCA)lparam;
80 return func( hwnd, str, handle );
84 /***********************************************************************
87 * relay to call the EnumProps callback function from EnumPropsEx
89 static BOOL CALLBACK EnumPropsW_relay( HWND hwnd, LPWSTR str, HANDLE handle, ULONG_PTR lparam )
91 PROPENUMPROCW func = (PROPENUMPROCW)lparam;
92 return func( hwnd, str, handle );
96 /***********************************************************************
97 * EnumPropsA (USER32.@)
99 INT WINAPI EnumPropsA( HWND hwnd, PROPENUMPROCA func )
101 return EnumPropsExA( hwnd, EnumPropsA_relay, (LPARAM)func );
105 /***********************************************************************
106 * EnumPropsW (USER32.@)
108 INT WINAPI EnumPropsW( HWND hwnd, PROPENUMPROCW func )
110 return EnumPropsExW( hwnd, EnumPropsW_relay, (LPARAM)func );
114 /***********************************************************************
115 * GetPropA (USER32.@)
117 HANDLE WINAPI GetPropA( HWND hwnd, LPCSTR str )
119 WCHAR buffer[ATOM_BUFFER_SIZE];
121 if (IS_INTRESOURCE(str)) return GetPropW( hwnd, (LPCWSTR)str );
122 if (!MultiByteToWideChar( CP_ACP, 0, str, -1, buffer, ATOM_BUFFER_SIZE )) return 0;
123 return GetPropW( hwnd, buffer );
127 /***********************************************************************
128 * GetPropW (USER32.@)
130 HANDLE WINAPI GetPropW( HWND hwnd, LPCWSTR str )
134 SERVER_START_REQ( get_window_property )
136 req->window = wine_server_user_handle( hwnd );
137 if (IS_INTRESOURCE(str)) req->atom = LOWORD(str);
138 else wine_server_add_data( req, str, strlenW(str) * sizeof(WCHAR) );
139 if (!wine_server_call_err( req )) ret = reply->data;
146 /***********************************************************************
147 * SetPropA (USER32.@)
149 BOOL WINAPI SetPropA( HWND hwnd, LPCSTR str, HANDLE handle )
151 WCHAR buffer[ATOM_BUFFER_SIZE];
153 if (IS_INTRESOURCE(str)) return SetPropW( hwnd, (LPCWSTR)str, handle );
154 if (!MultiByteToWideChar( CP_ACP, 0, str, -1, buffer, ATOM_BUFFER_SIZE )) return FALSE;
155 return SetPropW( hwnd, buffer, handle );
159 /***********************************************************************
160 * SetPropW (USER32.@)
162 BOOL WINAPI SetPropW( HWND hwnd, LPCWSTR str, HANDLE handle )
166 SERVER_START_REQ( set_window_property )
168 req->window = wine_server_user_handle( hwnd );
169 req->data = (ULONG_PTR)handle;
170 if (IS_INTRESOURCE(str)) req->atom = LOWORD(str);
171 else wine_server_add_data( req, str, strlenW(str) * sizeof(WCHAR) );
172 ret = !wine_server_call_err( req );
179 /***********************************************************************
180 * RemovePropA (USER32.@)
182 HANDLE WINAPI RemovePropA( HWND hwnd, LPCSTR str )
184 WCHAR buffer[ATOM_BUFFER_SIZE];
186 if (IS_INTRESOURCE(str)) return RemovePropW( hwnd, (LPCWSTR)str );
187 if (!MultiByteToWideChar( CP_ACP, 0, str, -1, buffer, ATOM_BUFFER_SIZE )) return 0;
188 return RemovePropW( hwnd, buffer );
192 /***********************************************************************
193 * RemovePropW (USER32.@)
195 HANDLE WINAPI RemovePropW( HWND hwnd, LPCWSTR str )
199 SERVER_START_REQ( remove_window_property )
201 req->window = wine_server_user_handle( hwnd );
202 if (IS_INTRESOURCE(str)) req->atom = LOWORD(str);
203 else wine_server_add_data( req, str, strlenW(str) * sizeof(WCHAR) );
204 if (!wine_server_call_err( req )) ret = reply->data;
212 /***********************************************************************
213 * EnumPropsExA (USER32.@)
215 INT WINAPI EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
217 int ret = -1, i, count;
218 property_data_t *list = get_properties( hwnd, &count );
222 for (i = 0; i < count; i++)
224 char string[ATOM_BUFFER_SIZE];
225 if (!GlobalGetAtomNameA( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
226 if (!(ret = func( hwnd, string, (HANDLE)(ULONG_PTR)list[i].data, lParam ))) break;
228 HeapFree( GetProcessHeap(), 0, list );
234 /***********************************************************************
235 * EnumPropsExW (USER32.@)
237 INT WINAPI EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
239 int ret = -1, i, count;
240 property_data_t *list = get_properties( hwnd, &count );
244 for (i = 0; i < count; i++)
246 WCHAR string[ATOM_BUFFER_SIZE];
247 if (!GlobalGetAtomNameW( list[i].atom, string, ATOM_BUFFER_SIZE )) continue;
248 if (!(ret = func( hwnd, string, (HANDLE)(ULONG_PTR)list[i].data, lParam ))) break;
250 HeapFree( GetProcessHeap(), 0, list );