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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/winuser16.h"
27 #include "wine/server.h"
30 /* size of buffer needed to store an atom string */
31 #define ATOM_BUFFER_SIZE 256
34 /***********************************************************************
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
;
48 if (!(data
= HeapAlloc( GetProcessHeap(), 0, total
* sizeof(*data
) ))) break;
50 SERVER_START_REQ( get_window_properties
)
53 wine_server_add_data( req
, data
, total
* sizeof(*data
) );
54 if (!wine_server_call( req
)) res
= reply
->total
;
57 if (res
&& res
<= total
)
62 HeapFree( GetProcessHeap(), 0, data
);
63 total
= res
; /* restart with larger buffer */
69 /***********************************************************************
72 * relay to call the EnumProps callback function from EnumPropsEx
74 static BOOL CALLBACK
EnumPropsA_relay( HWND hwnd
, LPCSTR str
, HANDLE handle
, ULONG_PTR lparam
)
76 PROPENUMPROCA func
= (PROPENUMPROCA
)lparam
;
77 return func( hwnd
, str
, handle
);
81 /***********************************************************************
84 * relay to call the EnumProps callback function from EnumPropsEx
86 static BOOL CALLBACK
EnumPropsW_relay( HWND hwnd
, LPCWSTR 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
)
119 if (!HIWORD(str
)) atom
= LOWORD(str
);
120 else if (!(atom
= GlobalFindAtomA( str
))) return 0;
122 SERVER_START_REQ( get_window_property
)
126 if (!wine_server_call_err( req
)) ret
= reply
->handle
;
133 /***********************************************************************
134 * GetPropW (USER32.@)
136 HANDLE WINAPI
GetPropW( HWND hwnd
, LPCWSTR str
)
141 if (!HIWORD(str
)) atom
= LOWORD(str
);
142 else if (!(atom
= GlobalFindAtomW( str
))) return 0;
144 SERVER_START_REQ( get_window_property
)
148 if (!wine_server_call_err( req
)) ret
= reply
->handle
;
155 /***********************************************************************
156 * SetPropA (USER32.@)
158 BOOL WINAPI
SetPropA( HWND hwnd
, LPCSTR str
, HANDLE handle
)
163 if (!HIWORD(str
)) atom
= LOWORD(str
);
164 else if (!(atom
= GlobalAddAtomA( str
))) return FALSE
;
166 SERVER_START_REQ( set_window_property
)
170 req
->string
= (HIWORD(str
) != 0);
171 req
->handle
= handle
;
172 ret
= !wine_server_call_err( req
);
176 if (HIWORD(str
)) GlobalDeleteAtom( atom
);
181 /***********************************************************************
182 * SetPropW (USER32.@)
184 BOOL WINAPI
SetPropW( HWND hwnd
, LPCWSTR str
, HANDLE handle
)
189 if (!HIWORD(str
)) atom
= LOWORD(str
);
190 else if (!(atom
= GlobalAddAtomW( str
))) return FALSE
;
192 SERVER_START_REQ( set_window_property
)
196 req
->string
= (HIWORD(str
) != 0);
197 req
->handle
= handle
;
198 ret
= !wine_server_call_err( req
);
202 if (HIWORD(str
)) GlobalDeleteAtom( atom
);
207 /***********************************************************************
208 * RemovePropA (USER32.@)
210 HANDLE WINAPI
RemovePropA( HWND hwnd
, LPCSTR str
)
215 if (!HIWORD(str
)) return RemovePropW( hwnd
, MAKEINTATOMW(LOWORD(str
)) );
217 if ((atom
= GlobalAddAtomA( str
)))
219 ret
= RemovePropW( hwnd
, MAKEINTATOMW(atom
) );
220 GlobalDeleteAtom( atom
);
226 /***********************************************************************
227 * RemovePropW (USER32.@)
229 HANDLE WINAPI
RemovePropW( HWND hwnd
, LPCWSTR str
)
234 if (!HIWORD(str
)) atom
= LOWORD(str
);
235 else if (!(atom
= GlobalAddAtomW( str
))) return 0;
237 SERVER_START_REQ( remove_window_property
)
241 if (!wine_server_call_err( req
)) ret
= reply
->handle
;
245 if (HIWORD(str
)) GlobalDeleteAtom( atom
);
250 /***********************************************************************
251 * EnumPropsExA (USER32.@)
253 INT WINAPI
EnumPropsExA(HWND hwnd
, PROPENUMPROCEXA func
, LPARAM lParam
)
255 int ret
= -1, i
, count
;
256 property_data_t
*list
= get_properties( hwnd
, &count
);
260 for (i
= 0; i
< count
; i
++)
262 char string
[ATOM_BUFFER_SIZE
];
263 if (!GlobalGetAtomNameA( list
[i
].atom
, string
, ATOM_BUFFER_SIZE
)) continue;
264 if (!(ret
= func( hwnd
, string
, list
[i
].handle
, lParam
))) break;
266 HeapFree( GetProcessHeap(), 0, list
);
272 /***********************************************************************
273 * EnumPropsExW (USER32.@)
275 INT WINAPI
EnumPropsExW(HWND hwnd
, PROPENUMPROCEXW func
, LPARAM lParam
)
277 int ret
= -1, i
, count
;
278 property_data_t
*list
= get_properties( hwnd
, &count
);
282 for (i
= 0; i
< count
; i
++)
284 WCHAR string
[ATOM_BUFFER_SIZE
];
285 if (!GlobalGetAtomNameW( list
[i
].atom
, string
, ATOM_BUFFER_SIZE
)) continue;
286 if (!(ret
= func( hwnd
, string
, list
[i
].handle
, lParam
))) break;
288 HeapFree( GetProcessHeap(), 0, list
);
294 /***********************************************************************
295 * EnumProps (USER.27)
297 INT16 WINAPI
EnumProps16( HWND16 hwnd
, PROPENUMPROC16 func
)
299 int ret
= -1, i
, count
;
300 property_data_t
*list
= get_properties( HWND_32(hwnd
), &count
);
304 char string
[ATOM_BUFFER_SIZE
];
305 SEGPTR segptr
= MapLS( string
);
309 for (i
= 0; i
< count
; i
++)
311 if (list
[i
].string
) /* it was a string originally */
313 if (!GlobalGetAtomNameA( list
[i
].atom
, string
, ATOM_BUFFER_SIZE
)) continue;
315 args
[2] = SELECTOROF(segptr
);
316 args
[1] = OFFSETOF(segptr
);
317 args
[0] = LOWORD(list
[i
].handle
);
323 args
[1] = list
[i
].atom
;
324 args
[0] = LOWORD(list
[i
].handle
);
326 WOWCallback16Ex( (DWORD
)func
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
327 if (!(ret
= LOWORD(result
))) break;
330 HeapFree( GetProcessHeap(), 0, list
);