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
28 #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
)
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
;
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
, LPSTR 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
, 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
)
131 SERVER_START_REQ( get_window_property
)
133 req
->window
= wine_server_user_handle( hwnd
);
134 if (IS_INTRESOURCE(str
)) req
->atom
= LOWORD(str
);
135 else wine_server_add_data( req
, str
, lstrlenW(str
) * sizeof(WCHAR
) );
136 if (!wine_server_call_err( req
)) ret
= reply
->data
;
143 /***********************************************************************
144 * SetPropA (USER32.@)
146 BOOL WINAPI
SetPropA( HWND hwnd
, LPCSTR str
, HANDLE handle
)
148 WCHAR buffer
[ATOM_BUFFER_SIZE
];
150 if (IS_INTRESOURCE(str
)) return SetPropW( hwnd
, (LPCWSTR
)str
, handle
);
151 if (!MultiByteToWideChar( CP_ACP
, 0, str
, -1, buffer
, ATOM_BUFFER_SIZE
)) return FALSE
;
152 return SetPropW( hwnd
, buffer
, handle
);
156 /***********************************************************************
157 * SetPropW (USER32.@)
159 BOOL WINAPI
SetPropW( HWND hwnd
, LPCWSTR str
, HANDLE handle
)
163 SERVER_START_REQ( set_window_property
)
165 req
->window
= wine_server_user_handle( hwnd
);
166 req
->data
= (ULONG_PTR
)handle
;
167 if (IS_INTRESOURCE(str
)) req
->atom
= LOWORD(str
);
168 else wine_server_add_data( req
, str
, lstrlenW(str
) * sizeof(WCHAR
) );
169 ret
= !wine_server_call_err( req
);
176 /***********************************************************************
177 * RemovePropA (USER32.@)
179 HANDLE WINAPI
RemovePropA( HWND hwnd
, LPCSTR str
)
181 WCHAR buffer
[ATOM_BUFFER_SIZE
];
183 if (IS_INTRESOURCE(str
)) return RemovePropW( hwnd
, (LPCWSTR
)str
);
184 if (!MultiByteToWideChar( CP_ACP
, 0, str
, -1, buffer
, ATOM_BUFFER_SIZE
)) return 0;
185 return RemovePropW( hwnd
, buffer
);
189 /***********************************************************************
190 * RemovePropW (USER32.@)
192 HANDLE WINAPI
RemovePropW( HWND hwnd
, LPCWSTR str
)
196 SERVER_START_REQ( remove_window_property
)
198 req
->window
= wine_server_user_handle( hwnd
);
199 if (IS_INTRESOURCE(str
)) req
->atom
= LOWORD(str
);
200 else wine_server_add_data( req
, str
, lstrlenW(str
) * sizeof(WCHAR
) );
201 if (!wine_server_call_err( req
)) ret
= reply
->data
;
209 /***********************************************************************
210 * EnumPropsExA (USER32.@)
212 INT WINAPI
EnumPropsExA(HWND hwnd
, PROPENUMPROCEXA func
, LPARAM lParam
)
214 int ret
= -1, i
, count
;
215 property_data_t
*list
= get_properties( hwnd
, &count
);
219 for (i
= 0; i
< count
; i
++)
221 char string
[ATOM_BUFFER_SIZE
];
222 if (!GlobalGetAtomNameA( list
[i
].atom
, string
, ATOM_BUFFER_SIZE
)) continue;
223 if (!(ret
= func( hwnd
, string
, (HANDLE
)(ULONG_PTR
)list
[i
].data
, lParam
))) break;
225 HeapFree( GetProcessHeap(), 0, list
);
231 /***********************************************************************
232 * EnumPropsExW (USER32.@)
234 INT WINAPI
EnumPropsExW(HWND hwnd
, PROPENUMPROCEXW func
, LPARAM lParam
)
236 int ret
= -1, i
, count
;
237 property_data_t
*list
= get_properties( hwnd
, &count
);
241 for (i
= 0; i
< count
; i
++)
243 WCHAR string
[ATOM_BUFFER_SIZE
];
244 if (!GlobalGetAtomNameW( list
[i
].atom
, string
, ATOM_BUFFER_SIZE
)) continue;
245 if (!(ret
= func( hwnd
, string
, (HANDLE
)(ULONG_PTR
)list
[i
].data
, lParam
))) break;
247 HeapFree( GetProcessHeap(), 0, list
);