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
25 #include "wine/winuser16.h"
26 #include "wine/server.h"
29 /* size of buffer needed to store an atom string */
30 #define ATOM_BUFFER_SIZE 256
32 /* ### start build ### */
33 extern WORD CALLBACK
PROP_CallTo16_word_wlw(PROPENUMPROC16
,WORD
,LONG
,WORD
);
34 /* ### stop build ### */
36 /***********************************************************************
39 * Retrieve the list of properties of a given window.
40 * Returned buffer must be freed by caller.
42 static property_data_t
*get_properties( HWND hwnd
, int *count
)
44 property_data_t
*data
;
50 if (!(data
= HeapAlloc( GetProcessHeap(), 0, total
* sizeof(*data
) ))) break;
52 SERVER_START_REQ( get_window_properties
)
55 wine_server_add_data( req
, data
, total
* sizeof(*data
) );
56 if (!wine_server_call( req
)) res
= reply
->total
;
59 if (res
&& res
<= total
)
64 HeapFree( GetProcessHeap(), 0, data
);
65 total
= res
; /* restart with larger buffer */
71 /***********************************************************************
74 * relay to call the EnumProps callback function from EnumPropsEx
76 static BOOL CALLBACK
EnumPropsA_relay( HWND hwnd
, LPCSTR str
, HANDLE handle
, ULONG_PTR lparam
)
78 PROPENUMPROCA func
= (PROPENUMPROCA
)lparam
;
79 return func( hwnd
, str
, handle
);
83 /***********************************************************************
86 * relay to call the EnumProps callback function from EnumPropsEx
88 static BOOL CALLBACK
EnumPropsW_relay( HWND hwnd
, LPCWSTR str
, HANDLE handle
, ULONG_PTR lparam
)
90 PROPENUMPROCW func
= (PROPENUMPROCW
)lparam
;
91 return func( hwnd
, str
, handle
);
95 /***********************************************************************
96 * EnumPropsA (USER32.@)
98 INT WINAPI
EnumPropsA( HWND hwnd
, PROPENUMPROCA func
)
100 return EnumPropsExA( hwnd
, EnumPropsA_relay
, (LPARAM
)func
);
104 /***********************************************************************
105 * EnumPropsW (USER32.@)
107 INT WINAPI
EnumPropsW( HWND hwnd
, PROPENUMPROCW func
)
109 return EnumPropsExW( hwnd
, EnumPropsW_relay
, (LPARAM
)func
);
113 /***********************************************************************
114 * GetPropA (USER32.@)
116 HANDLE WINAPI
GetPropA( HWND hwnd
, LPCSTR str
)
121 if (!HIWORD(str
)) atom
= LOWORD(str
);
122 else if (!(atom
= GlobalFindAtomA( str
))) return 0;
124 SERVER_START_REQ( get_window_property
)
128 if (!wine_server_call_err( req
)) ret
= reply
->handle
;
135 /***********************************************************************
136 * GetPropW (USER32.@)
138 HANDLE WINAPI
GetPropW( HWND hwnd
, LPCWSTR str
)
143 if (!HIWORD(str
)) atom
= LOWORD(str
);
144 else if (!(atom
= GlobalFindAtomW( str
))) return 0;
146 SERVER_START_REQ( get_window_property
)
150 if (!wine_server_call_err( req
)) ret
= reply
->handle
;
157 /***********************************************************************
158 * SetPropA (USER32.@)
160 BOOL WINAPI
SetPropA( HWND hwnd
, LPCSTR str
, HANDLE handle
)
165 if (!HIWORD(str
)) atom
= LOWORD(str
);
166 else if (!(atom
= GlobalAddAtomA( str
))) return FALSE
;
168 SERVER_START_REQ( set_window_property
)
172 req
->string
= (HIWORD(str
) != 0);
173 req
->handle
= handle
;
174 ret
= !wine_server_call_err( req
);
178 if (HIWORD(str
)) GlobalDeleteAtom( atom
);
183 /***********************************************************************
184 * SetPropW (USER32.@)
186 BOOL WINAPI
SetPropW( HWND hwnd
, LPCWSTR str
, HANDLE handle
)
191 if (!HIWORD(str
)) atom
= LOWORD(str
);
192 else if (!(atom
= GlobalAddAtomW( str
))) return FALSE
;
194 SERVER_START_REQ( set_window_property
)
198 req
->string
= (HIWORD(str
) != 0);
199 req
->handle
= handle
;
200 ret
= !wine_server_call_err( req
);
204 if (HIWORD(str
)) GlobalDeleteAtom( atom
);
209 /***********************************************************************
210 * RemovePropA (USER32.@)
212 HANDLE WINAPI
RemovePropA( HWND hwnd
, LPCSTR str
)
217 if (!HIWORD(str
)) return RemovePropW( hwnd
, MAKEINTATOMW(LOWORD(str
)) );
219 if ((atom
= GlobalAddAtomA( str
)))
221 ret
= RemovePropW( hwnd
, MAKEINTATOMW(atom
) );
222 GlobalDeleteAtom( atom
);
228 /***********************************************************************
229 * RemovePropW (USER32.@)
231 HANDLE WINAPI
RemovePropW( HWND hwnd
, LPCWSTR str
)
236 if (!HIWORD(str
)) atom
= LOWORD(str
);
237 else if (!(atom
= GlobalAddAtomW( str
))) return 0;
239 SERVER_START_REQ( remove_window_property
)
243 if (!wine_server_call_err( req
)) ret
= reply
->handle
;
247 if (HIWORD(str
)) GlobalDeleteAtom( atom
);
252 /***********************************************************************
253 * EnumPropsExA (USER32.@)
255 INT WINAPI
EnumPropsExA(HWND hwnd
, PROPENUMPROCEXA func
, LPARAM lParam
)
257 int ret
= -1, i
, count
;
258 property_data_t
*list
= get_properties( hwnd
, &count
);
262 for (i
= 0; i
< count
; i
++)
264 char string
[ATOM_BUFFER_SIZE
];
265 if (!GlobalGetAtomNameA( list
[i
].atom
, string
, ATOM_BUFFER_SIZE
)) continue;
266 if (!(ret
= func( hwnd
, string
, list
[i
].handle
, lParam
))) break;
268 HeapFree( GetProcessHeap(), 0, list
);
274 /***********************************************************************
275 * EnumPropsExW (USER32.@)
277 INT WINAPI
EnumPropsExW(HWND hwnd
, PROPENUMPROCEXW func
, LPARAM lParam
)
279 int ret
= -1, i
, count
;
280 property_data_t
*list
= get_properties( hwnd
, &count
);
284 for (i
= 0; i
< count
; i
++)
286 WCHAR string
[ATOM_BUFFER_SIZE
];
287 if (!GlobalGetAtomNameW( list
[i
].atom
, string
, ATOM_BUFFER_SIZE
)) continue;
288 if (!(ret
= func( hwnd
, string
, list
[i
].handle
, lParam
))) break;
290 HeapFree( GetProcessHeap(), 0, list
);
296 /***********************************************************************
297 * EnumProps (USER.27)
299 INT16 WINAPI
EnumProps16( HWND16 hwnd
, PROPENUMPROC16 func
)
301 int ret
= -1, i
, count
;
302 property_data_t
*list
= get_properties( HWND_32(hwnd
), &count
);
306 char string
[ATOM_BUFFER_SIZE
];
307 SEGPTR segptr
= MapLS( string
);
308 for (i
= 0; i
< count
; i
++)
310 if (list
[i
].string
) /* it was a string originally */
312 if (!GlobalGetAtomNameA( list
[i
].atom
, string
, ATOM_BUFFER_SIZE
)) continue;
313 ret
= PROP_CallTo16_word_wlw( func
, hwnd
, segptr
, list
[i
].handle
);
316 ret
= PROP_CallTo16_word_wlw( func
, hwnd
, list
[i
].atom
, list
[i
].handle
);
320 HeapFree( GetProcessHeap(), 0, list
);