2 * Copyright 1999 Corel Corporation
4 * Copyright 2010 Geoffrey Hausheer
5 * Copyright 2010 Piotr Caban for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
36 IPropertyPageSite IPropertyPageSite_iface
;
41 static inline PropertyPageSite
*impl_from_IPropertyPageSite(IPropertyPageSite
*iface
)
43 return CONTAINING_RECORD(iface
, PropertyPageSite
, IPropertyPageSite_iface
);
46 static INT_PTR CALLBACK
property_sheet_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
48 IPropertyPage
*property_page
= (IPropertyPage
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
54 property_page
= (IPropertyPage
*)((LPPROPSHEETPAGEW
)lparam
)->lParam
;
56 GetClientRect(hwnd
, &rect
);
57 IPropertyPage_Activate(property_page
, hwnd
, &rect
, TRUE
);
58 IPropertyPage_Show(property_page
, SW_SHOW
);
60 SetWindowLongPtrW(hwnd
, DWLP_USER
, (LONG_PTR
)property_page
);
64 IPropertyPage_Show(property_page
, SW_HIDE
);
65 IPropertyPage_Deactivate(property_page
);
72 static HRESULT WINAPI
PropertyPageSite_QueryInterface(IPropertyPageSite
* iface
,
73 REFIID riid
, void** ppv
)
75 TRACE("(%p riid: %s)\n",iface
, debugstr_guid(riid
));
77 if(IsEqualGUID(&IID_IUnknown
, riid
)
78 || IsEqualGUID(&IID_IPropertyPageSite
, riid
))
85 IUnknown_AddRef((IUnknown
*)*ppv
);
89 static ULONG WINAPI
PropertyPageSite_AddRef(IPropertyPageSite
* iface
)
91 PropertyPageSite
*this = impl_from_IPropertyPageSite(iface
);
92 LONG ref
= InterlockedIncrement(&this->ref
);
94 TRACE("%p, refcount %ld.\n", iface
, ref
);
98 static ULONG WINAPI
PropertyPageSite_Release(IPropertyPageSite
* iface
)
100 PropertyPageSite
*this = impl_from_IPropertyPageSite(iface
);
101 LONG ref
= InterlockedDecrement(&this->ref
);
103 TRACE("%p, refcount %ld.\n", iface
, ref
);
105 HeapFree(GetProcessHeap(), 0, this);
109 static HRESULT WINAPI
PropertyPageSite_OnStatusChange(
110 IPropertyPageSite
*iface
, DWORD dwFlags
)
112 TRACE("%p, %lx.\n", iface
, dwFlags
);
116 static HRESULT WINAPI
PropertyPageSite_GetLocaleID(
117 IPropertyPageSite
*iface
, LCID
*pLocaleID
)
119 PropertyPageSite
*this = impl_from_IPropertyPageSite(iface
);
121 TRACE("(%p, %p)\n", iface
, pLocaleID
);
122 *pLocaleID
= this->lcid
;
126 static HRESULT WINAPI
PropertyPageSite_GetPageContainer(
127 IPropertyPageSite
* iface
, IUnknown
** ppUnk
)
129 FIXME("(%p, %p)\n", iface
, ppUnk
);
133 static HRESULT WINAPI
PropertyPageSite_TranslateAccelerator(
134 IPropertyPageSite
* iface
, MSG
*pMsg
)
136 FIXME("(%p, %p)\n", iface
, pMsg
);
140 static IPropertyPageSiteVtbl PropertyPageSiteVtbl
= {
141 PropertyPageSite_QueryInterface
,
142 PropertyPageSite_AddRef
,
143 PropertyPageSite_Release
,
144 PropertyPageSite_OnStatusChange
,
145 PropertyPageSite_GetLocaleID
,
146 PropertyPageSite_GetPageContainer
,
147 PropertyPageSite_TranslateAccelerator
150 /***********************************************************************
151 * OleCreatePropertyFrameIndirect (OLEAUT32.416)
153 HRESULT WINAPI
OleCreatePropertyFrameIndirect(LPOCPFIPARAMS lpParams
)
155 PROPSHEETHEADERW property_sheet
;
156 PROPSHEETPAGEW property_sheet_page
;
158 DLGTEMPLATE
template;
163 IPropertyPage
**property_page
;
164 PropertyPageSite
*property_page_site
;
168 HRSRC property_sheet_dialog_find
= NULL
;
169 HGLOBAL property_sheet_dialog_load
= NULL
;
170 WCHAR
*property_sheet_dialog_data
= NULL
;
174 LONG font_width
= 4, font_height
= 8;
179 TRACE("%ld, %p, %d, %d, %s, %ld, %p, %ld, %p, %ld, %ld.\n", lpParams
->cbStructSize
,
180 lpParams
->hWndOwner
, lpParams
->x
, lpParams
->y
,
181 debugstr_w(lpParams
->lpszCaption
), lpParams
->cObjects
,
182 lpParams
->lplpUnk
, lpParams
->cPages
, lpParams
->lpPages
,
183 lpParams
->lcid
, lpParams
->dispidInitialProperty
);
185 if(!lpParams
->lpPages
)
188 if(lpParams
->cbStructSize
!= sizeof(OCPFIPARAMS
)) {
189 WARN("incorrect structure size\n");
193 if(lpParams
->dispidInitialProperty
)
194 FIXME("dispidInitialProperty not yet implemented\n");
197 hcomctl
= LoadLibraryW(L
"comctl32.dll");
199 property_sheet_dialog_find
= FindResourceW(hcomctl
,
200 MAKEINTRESOURCEW(1006 /*IDD_PROPSHEET*/), (LPWSTR
)RT_DIALOG
);
201 if(property_sheet_dialog_find
)
202 property_sheet_dialog_load
= LoadResource(hcomctl
, property_sheet_dialog_find
);
203 if(property_sheet_dialog_load
)
204 property_sheet_dialog_data
= LockResource(property_sheet_dialog_load
);
206 if(property_sheet_dialog_data
) {
207 if(property_sheet_dialog_data
[1] == 0xffff) {
208 ERR("Expected DLGTEMPLATE structure\n");
209 FreeLibrary(hcomctl
);
210 return E_OUTOFMEMORY
;
213 property_sheet_dialog_data
+= sizeof(DLGTEMPLATE
)/sizeof(WCHAR
);
214 /* Skip menu, class and title */
215 property_sheet_dialog_data
+= lstrlenW(property_sheet_dialog_data
)+1;
216 property_sheet_dialog_data
+= lstrlenW(property_sheet_dialog_data
)+1;
217 property_sheet_dialog_data
+= lstrlenW(property_sheet_dialog_data
)+1;
219 memset(&font_desc
, 0, sizeof(LOGFONTW
));
220 /* Calculate logical height */
221 font_desc
.lfHeight
= -MulDiv(property_sheet_dialog_data
[0],
222 GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
223 font_desc
.lfCharSet
= DEFAULT_CHARSET
;
224 memcpy(font_desc
.lfFaceName
, property_sheet_dialog_data
+1,
225 sizeof(WCHAR
)*(lstrlenW(property_sheet_dialog_data
+1)+1));
226 hfont
= CreateFontIndirectW(&font_desc
);
229 hfont
= SelectObject(hdc
, hfont
);
230 font_width
= GdiGetCharDimensions(hdc
, NULL
, &font_height
);
231 SelectObject(hdc
, hfont
);
235 FreeLibrary(hcomctl
);
236 ReleaseDC(NULL
, hdc
);
238 memset(&property_sheet
, 0, sizeof(property_sheet
));
239 property_sheet
.dwSize
= sizeof(property_sheet
);
240 if(lpParams
->lpszCaption
) {
241 property_sheet
.dwFlags
= PSH_PROPTITLE
;
242 property_sheet
.pszCaption
= lpParams
->lpszCaption
;
245 property_sheet
.phpage
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
246 lpParams
->cPages
*sizeof(HPROPSHEETPAGE
));
247 property_page
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
248 lpParams
->cPages
*sizeof(IPropertyPage
*));
249 dialogs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
250 lpParams
->cPages
*sizeof(*dialogs
));
251 if(!property_sheet
.phpage
|| !property_page
|| !dialogs
) {
252 HeapFree(GetProcessHeap(), 0, property_sheet
.phpage
);
253 HeapFree(GetProcessHeap(), 0, property_page
);
254 HeapFree(GetProcessHeap(), 0, dialogs
);
255 return E_OUTOFMEMORY
;
258 memset(&property_sheet_page
, 0, sizeof(PROPSHEETPAGEW
));
259 property_sheet_page
.dwSize
= sizeof(PROPSHEETPAGEW
);
260 property_sheet_page
.dwFlags
= PSP_DLGINDIRECT
|PSP_USETITLE
;
261 property_sheet_page
.pfnDlgProc
= property_sheet_proc
;
263 for(i
=0; i
<lpParams
->cPages
; i
++) {
264 PROPPAGEINFO page_info
;
266 res
= CoCreateInstance(&lpParams
->lpPages
[i
], NULL
, CLSCTX_INPROC_SERVER
,
267 &IID_IPropertyPage
, (void**)&property_page
[i
]);
271 property_page_site
= HeapAlloc(GetProcessHeap(), 0, sizeof(PropertyPageSite
));
272 if(!property_page_site
)
274 property_page_site
->IPropertyPageSite_iface
.lpVtbl
= &PropertyPageSiteVtbl
;
275 property_page_site
->ref
= 1;
276 property_page_site
->lcid
= lpParams
->lcid
;
278 res
= IPropertyPage_SetPageSite(property_page
[i
],
279 &property_page_site
->IPropertyPageSite_iface
);
280 IPropertyPageSite_Release(&property_page_site
->IPropertyPageSite_iface
);
284 res
= IPropertyPage_SetObjects(property_page
[i
],
285 lpParams
->cObjects
, lpParams
->lplpUnk
);
287 WARN("SetObjects() failed, hr %#lx.\n", res
);
289 res
= IPropertyPage_GetPageInfo(property_page
[i
], &page_info
);
293 dialogs
[i
].template.cx
= MulDiv(page_info
.size
.cx
, 4, font_width
);
294 dialogs
[i
].template.cy
= MulDiv(page_info
.size
.cy
, 8, font_height
);
296 property_sheet_page
.pResource
= &dialogs
[i
].template;
297 property_sheet_page
.lParam
= (LPARAM
)property_page
[i
];
298 property_sheet_page
.pszTitle
= page_info
.pszTitle
;
300 property_sheet
.phpage
[property_sheet
.nPages
++] =
301 CreatePropertySheetPageW(&property_sheet_page
);
304 PropertySheetW(&property_sheet
);
306 for(i
=0; i
<lpParams
->cPages
; i
++) {
308 IPropertyPage_Release(property_page
[i
]);
311 HeapFree(GetProcessHeap(), 0, dialogs
);
312 HeapFree(GetProcessHeap(), 0, property_page
);
313 HeapFree(GetProcessHeap(), 0, property_sheet
.phpage
);
317 /***********************************************************************
318 * OleCreatePropertyFrame (OLEAUT32.417)
320 HRESULT WINAPI
OleCreatePropertyFrame(
321 HWND hwndOwner
, UINT x
, UINT y
, LPCOLESTR lpszCaption
, ULONG cObjects
,
322 LPUNKNOWN
* ppUnk
, ULONG cPages
, LPCLSID pPageClsID
, LCID lcid
,
323 DWORD dwReserved
, LPVOID pvReserved
)
327 ocpf
.cbStructSize
= sizeof(OCPFIPARAMS
);
328 ocpf
.hWndOwner
= hwndOwner
;
331 ocpf
.lpszCaption
= lpszCaption
;
332 ocpf
.cObjects
= cObjects
;
333 ocpf
.lplpUnk
= ppUnk
;
334 ocpf
.cPages
= cPages
;
335 ocpf
.lpPages
= pPageClsID
;
337 ocpf
.dispidInitialProperty
= 0;
339 return OleCreatePropertyFrameIndirect(&ocpf
);