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/winuser16.h"
32 #include "wine/server.h"
34 /* size of buffer needed to store an atom string */
35 #define ATOM_BUFFER_SIZE 256
38 /***********************************************************************
41 * Retrieve the list of properties of a given window.
42 * Returned buffer must be freed by caller.
44 static property_data_t
*get_properties( HWND hwnd
, int *count
)
46 property_data_t
*data
;
52 if (!(data
= HeapAlloc( GetProcessHeap(), 0, total
* sizeof(*data
) ))) break;
54 SERVER_START_REQ( get_window_properties
)
56 req
->window
= wine_server_user_handle( hwnd
);
57 wine_server_set_reply( req
, data
, total
* sizeof(*data
) );
58 if (!wine_server_call( req
)) res
= reply
->total
;
61 if (res
&& res
<= total
)
66 HeapFree( GetProcessHeap(), 0, data
);
67 total
= res
; /* restart with larger buffer */
73 /***********************************************************************
76 * relay to call the EnumProps callback function from EnumPropsEx
78 static BOOL CALLBACK
EnumPropsA_relay( HWND hwnd
, LPSTR str
, HANDLE handle
, ULONG_PTR lparam
)
80 PROPENUMPROCA func
= (PROPENUMPROCA
)lparam
;
81 return func( hwnd
, str
, handle
);
85 /***********************************************************************
88 * relay to call the EnumProps callback function from EnumPropsEx
90 static BOOL CALLBACK
EnumPropsW_relay( HWND hwnd
, LPWSTR str
, HANDLE handle
, ULONG_PTR lparam
)
92 PROPENUMPROCW func
= (PROPENUMPROCW
)lparam
;
93 return func( hwnd
, str
, handle
);
97 /***********************************************************************
98 * EnumPropsA (USER32.@)
100 INT WINAPI
EnumPropsA( HWND hwnd
, PROPENUMPROCA func
)
102 return EnumPropsExA( hwnd
, EnumPropsA_relay
, (LPARAM
)func
);
106 /***********************************************************************
107 * EnumPropsW (USER32.@)
109 INT WINAPI
EnumPropsW( HWND hwnd
, PROPENUMPROCW func
)
111 return EnumPropsExW( hwnd
, EnumPropsW_relay
, (LPARAM
)func
);
115 /***********************************************************************
116 * GetPropA (USER32.@)
118 HANDLE WINAPI
GetPropA( HWND hwnd
, LPCSTR str
)
120 WCHAR buffer
[ATOM_BUFFER_SIZE
];
122 if (!HIWORD(str
)) return GetPropW( hwnd
, (LPCWSTR
)str
);
123 if (!MultiByteToWideChar( CP_ACP
, 0, str
, -1, buffer
, ATOM_BUFFER_SIZE
)) return 0;
124 return GetPropW( hwnd
, buffer
);
128 /***********************************************************************
129 * GetPropW (USER32.@)
131 HANDLE WINAPI
GetPropW( HWND hwnd
, LPCWSTR str
)
135 SERVER_START_REQ( get_window_property
)
137 req
->window
= wine_server_user_handle( hwnd
);
138 if (!HIWORD(str
)) req
->atom
= LOWORD(str
);
139 else wine_server_add_data( req
, str
, strlenW(str
) * sizeof(WCHAR
) );
140 if (!wine_server_call_err( req
)) ret
= reply
->data
;
147 /***********************************************************************
148 * SetPropA (USER32.@)
150 BOOL WINAPI
SetPropA( HWND hwnd
, LPCSTR str
, HANDLE handle
)
152 WCHAR buffer
[ATOM_BUFFER_SIZE
];
154 if (!HIWORD(str
)) return SetPropW( hwnd
, (LPCWSTR
)str
, handle
);
155 if (!MultiByteToWideChar( CP_ACP
, 0, str
, -1, buffer
, ATOM_BUFFER_SIZE
)) return FALSE
;
156 return SetPropW( hwnd
, buffer
, handle
);
160 /***********************************************************************
161 * SetPropW (USER32.@)
163 BOOL WINAPI
SetPropW( HWND hwnd
, LPCWSTR str
, HANDLE handle
)
167 SERVER_START_REQ( set_window_property
)
169 req
->window
= wine_server_user_handle( hwnd
);
170 req
->data
= (ULONG_PTR
)handle
;
171 if (!HIWORD(str
)) req
->atom
= LOWORD(str
);
172 else wine_server_add_data( req
, str
, strlenW(str
) * sizeof(WCHAR
) );
173 ret
= !wine_server_call_err( req
);
180 /***********************************************************************
181 * RemovePropA (USER32.@)
183 HANDLE WINAPI
RemovePropA( HWND hwnd
, LPCSTR str
)
185 WCHAR buffer
[ATOM_BUFFER_SIZE
];
187 if (!HIWORD(str
)) return RemovePropW( hwnd
, (LPCWSTR
)str
);
188 if (!MultiByteToWideChar( CP_ACP
, 0, str
, -1, buffer
, ATOM_BUFFER_SIZE
)) return 0;
189 return RemovePropW( hwnd
, buffer
);
193 /***********************************************************************
194 * RemovePropW (USER32.@)
196 HANDLE WINAPI
RemovePropW( HWND hwnd
, LPCWSTR str
)
200 SERVER_START_REQ( remove_window_property
)
202 req
->window
= wine_server_user_handle( hwnd
);
203 if (!HIWORD(str
)) req
->atom
= LOWORD(str
);
204 else wine_server_add_data( req
, str
, strlenW(str
) * sizeof(WCHAR
) );
205 if (!wine_server_call_err( req
)) ret
= reply
->data
;
213 /***********************************************************************
214 * EnumPropsExA (USER32.@)
216 INT WINAPI
EnumPropsExA(HWND hwnd
, PROPENUMPROCEXA func
, LPARAM lParam
)
218 int ret
= -1, i
, count
;
219 property_data_t
*list
= get_properties( hwnd
, &count
);
223 for (i
= 0; i
< count
; i
++)
225 char string
[ATOM_BUFFER_SIZE
];
226 if (!GlobalGetAtomNameA( list
[i
].atom
, string
, ATOM_BUFFER_SIZE
)) continue;
227 if (!(ret
= func( hwnd
, string
, (HANDLE
)(ULONG_PTR
)list
[i
].data
, lParam
))) break;
229 HeapFree( GetProcessHeap(), 0, list
);
235 /***********************************************************************
236 * EnumPropsExW (USER32.@)
238 INT WINAPI
EnumPropsExW(HWND hwnd
, PROPENUMPROCEXW func
, LPARAM lParam
)
240 int ret
= -1, i
, count
;
241 property_data_t
*list
= get_properties( hwnd
, &count
);
245 for (i
= 0; i
< count
; i
++)
247 WCHAR string
[ATOM_BUFFER_SIZE
];
248 if (!GlobalGetAtomNameW( list
[i
].atom
, string
, ATOM_BUFFER_SIZE
)) continue;
249 if (!(ret
= func( hwnd
, string
, (HANDLE
)(ULONG_PTR
)list
[i
].data
, lParam
))) break;
251 HeapFree( GetProcessHeap(), 0, list
);
257 /***********************************************************************
258 * EnumProps (USER.27)
260 INT16 WINAPI
EnumProps16( HWND16 hwnd
, PROPENUMPROC16 func
)
262 int ret
= -1, i
, count
;
263 property_data_t
*list
= get_properties( HWND_32(hwnd
), &count
);
267 char string
[ATOM_BUFFER_SIZE
];
268 SEGPTR segptr
= MapLS( string
);
272 for (i
= 0; i
< count
; i
++)
274 if (list
[i
].string
) /* it was a string originally */
276 if (!GlobalGetAtomNameA( list
[i
].atom
, string
, ATOM_BUFFER_SIZE
)) continue;
278 args
[2] = SELECTOROF(segptr
);
279 args
[1] = OFFSETOF(segptr
);
280 args
[0] = LOWORD(list
[i
].data
);
286 args
[1] = list
[i
].atom
;
287 args
[0] = LOWORD(list
[i
].data
);
289 WOWCallback16Ex( (DWORD
)func
, WCB16_PASCAL
, sizeof(args
), args
, &result
);
290 if (!(ret
= LOWORD(result
))) break;
293 HeapFree( GetProcessHeap(), 0, list
);