Added the DFCS_{HOT,TRANSPARENT} definitions.
[wine/gsoc_dplay.git] / dlls / oleaut32 / propertyframe.c
blob1ad7b50ced7c35173850778dd0fb4a0fe61ae913
1 /*
2 * Copyright 2001 TAKESHIMA Hidenori <hidenori@a2.ctktv.ne.jp>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * FIXME - use PropertySheetW.
19 * FIXME - not tested.
22 #include "config.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "wine/debug.h"
29 #include "ole2.h"
30 #include "olectl.h"
31 #include "oleauto.h"
32 #include "commctrl.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(ole);
36 typedef struct CPropertyPageContainerImpl CPropertyPageContainerImpl;
38 static const struct
40 DLGTEMPLATE templ;
41 WORD wMenuName;
42 WORD wClassName;
43 WCHAR wDummyCaption;
44 BYTE padding[4];
45 } propsite_dlg =
48 WS_VISIBLE | WS_CHILD, /* style */
49 0, /* dwExtendedStyle */
50 0, /* cdit */
51 0, /* x */
52 0, /* y */
53 0, /* cx */
54 0, /* cy */
56 0, 0, 0,
59 typedef struct CPropertyPageSiteImpl
61 ICOM_VFIELD(IPropertyPageSite);
62 /* IUnknown fields */
63 ULONG ref;
65 /* IPropertyPageSite fields */
66 CPropertyPageContainerImpl* pContainer;
67 IPropertyPage* pPage;
68 HWND hwnd;
69 BYTE templ[sizeof(propsite_dlg)];
70 PROPPAGEINFO info;
71 BOOL bActivate;
72 } CPropertyPageSiteImpl;
74 struct CPropertyPageContainerImpl
76 ULONG ref; /* for IUnknown(not used now) */
77 LCID lcid;
78 DWORD m_cSites;
79 CPropertyPageSiteImpl** m_ppSites;
80 PROPSHEETPAGEA* m_pPsp;
81 HRESULT m_hr;
84 /* for future use. */
85 #define CPropertyPageContainerImpl_AddRef(pContainer) (++((pContainer)->ref))
86 #define CPropertyPageContainerImpl_Release(pContainer) (--((pContainer)->ref))
89 /***************************************************************************/
91 #define PropSiteDlg_Return(a) do{SetWindowLongA(hwnd,DWL_MSGRESULT,(LONG)a);return TRUE;}while(1)
92 static BOOL CALLBACK PropSiteDlgProc(
93 HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
95 CPropertyPageSiteImpl* This = (CPropertyPageSiteImpl*)GetWindowLongA( hwnd, DWL_USER );
96 HRESULT hr;
97 RECT rc;
98 NMHDR* pnmh;
100 switch ( msg )
102 case WM_INITDIALOG:
103 This = (CPropertyPageSiteImpl*)(((PROPSHEETPAGEA*)lParam)->lParam);
104 SetWindowLongA( hwnd, DWL_USER, (LONG)This );
105 TRACE("WM_INITDIALOG (%p) hwnd = %08x\n", This, hwnd );
107 This->hwnd = hwnd;
108 ZeroMemory( &rc, sizeof(rc) );
109 GetClientRect( hwnd, &rc );
110 hr = IPropertyPage_Activate(This->pPage,hwnd,&rc,TRUE);
111 if ( SUCCEEDED(hr) )
113 This->bActivate = TRUE;
114 hr = IPropertyPage_Show(This->pPage,SW_SHOW);
116 if ( FAILED(hr) )
117 This->pContainer->m_hr = hr;
118 break;
119 case WM_DESTROY:
120 TRACE("WM_DESTROY (%p)\n",This);
121 if ( This != NULL )
123 if ( This->bActivate )
125 IPropertyPage_Show(This->pPage,SW_HIDE);
126 IPropertyPage_Deactivate(This->pPage);
127 This->bActivate = FALSE;
129 This->hwnd = (HWND)NULL;
131 SetWindowLongA( hwnd, DWL_USER, (LONG)0 );
132 break;
133 case WM_NOTIFY:
134 pnmh = (NMHDR*)lParam;
135 switch ( pnmh->code )
137 case PSN_APPLY:
138 TRACE("PSN_APPLY (%p)\n",This);
139 hr = IPropertyPage_Apply(This->pPage);
140 if ( FAILED(hr) )
141 PropSiteDlg_Return(PSNRET_INVALID_NOCHANGEPAGE);
142 PropSiteDlg_Return(PSNRET_NOERROR);
143 case PSN_QUERYCANCEL:
144 FIXME("PSN_QUERYCANCEL (%p)\n",This);
145 PropSiteDlg_Return(FALSE);
146 case PSN_RESET:
147 FIXME("PSN_RESET (%p)\n",This);
148 PropSiteDlg_Return(0);
149 case PSN_SETACTIVE:
150 TRACE("PSN_SETACTIVE (%p)\n",This);
151 PropSiteDlg_Return(0);
152 case PSN_KILLACTIVE:
153 TRACE("PSN_KILLACTIVE (%p)\n",This);
154 PropSiteDlg_Return(FALSE);
156 break;
159 return FALSE;
162 /***************************************************************************/
164 static HRESULT WINAPI
165 CPropertyPageSiteImpl_fnQueryInterface(IPropertyPageSite* iface,REFIID riid,LPVOID *ppobj)
167 ICOM_THIS(CPropertyPageSiteImpl,iface);
169 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
171 if ( ppobj == NULL )
172 return E_POINTER;
173 *ppobj = NULL;
175 if ( IsEqualGUID(riid,&IID_IUnknown) ||
176 IsEqualGUID(riid,&IID_IPropertyPageSite) )
178 *ppobj = (LPVOID)This;
179 IUnknown_AddRef((IUnknown*)(*ppobj));
180 return S_OK;
183 return E_NOINTERFACE;
186 static ULONG WINAPI
187 CPropertyPageSiteImpl_fnAddRef(IPropertyPageSite* iface)
189 ICOM_THIS(CPropertyPageSiteImpl,iface);
191 TRACE("(%p)->()\n",This);
193 return InterlockedExchangeAdd(&(This->ref),1) + 1;
196 static ULONG WINAPI
197 CPropertyPageSiteImpl_fnRelease(IPropertyPageSite* iface)
199 ICOM_THIS(CPropertyPageSiteImpl,iface);
200 LONG ref;
202 TRACE("(%p)->()\n",This);
203 ref = InterlockedExchangeAdd(&(This->ref),-1) - 1;
204 if ( ref > 0 )
205 return (ULONG)ref;
207 if ( This->pContainer != NULL )
208 CPropertyPageContainerImpl_Release(This->pContainer);
209 if ( This->pPage != NULL )
210 IPropertyPage_Release(This->pPage);
211 if ( This->info.pszTitle != NULL )
212 CoTaskMemFree( This->info.pszTitle );
213 if ( This->info.pszDocString != NULL )
214 CoTaskMemFree( This->info.pszDocString );
215 if ( This->info.pszHelpFile != NULL )
216 CoTaskMemFree( This->info.pszHelpFile );
218 HeapFree(GetProcessHeap(),0,This);
220 return 0;
223 static HRESULT WINAPI
224 CPropertyPageSiteImpl_fnOnStatusChange(IPropertyPageSite* iface,DWORD dwFlags)
226 ICOM_THIS(CPropertyPageSiteImpl,iface);
228 TRACE("(%p,%08lx)\n",This,dwFlags);
230 if ( This->hwnd == (HWND)NULL )
231 return E_UNEXPECTED;
233 switch ( dwFlags )
235 case PROPPAGESTATUS_DIRTY:
236 /* dirty */
237 SendMessageA(GetParent(This->hwnd),PSM_CHANGED,(WPARAM)(This->hwnd),0);
238 break;
239 case PROPPAGESTATUS_VALIDATE:
240 /* validate */
241 SendMessageA(GetParent(This->hwnd),PSM_UNCHANGED,(WPARAM)(This->hwnd),0);
242 break;
243 default:
244 FIXME("(%p,%08lx) unknown flags\n",This,dwFlags);
245 return E_INVALIDARG;
248 return NOERROR;
251 static HRESULT WINAPI
252 CPropertyPageSiteImpl_fnGetLocaleID(IPropertyPageSite* iface,LCID* pLocaleID)
254 ICOM_THIS(CPropertyPageSiteImpl,iface);
256 TRACE("(%p,%p)\n",This,pLocaleID);
258 if ( pLocaleID == NULL )
259 return E_POINTER;
261 *pLocaleID = This->pContainer->lcid;
263 return NOERROR;
266 static HRESULT WINAPI
267 CPropertyPageSiteImpl_fnGetPageContainer(IPropertyPageSite* iface,IUnknown** ppUnk)
269 ICOM_THIS(CPropertyPageSiteImpl,iface);
271 FIXME("(%p,%p) - Win95 returns E_NOTIMPL\n",This,ppUnk);
273 if ( ppUnk == NULL )
274 return E_POINTER;
276 *ppUnk = NULL;
278 return E_NOTIMPL;
281 static HRESULT WINAPI
282 CPropertyPageSiteImpl_fnTranslateAccelerator(IPropertyPageSite* iface,MSG* pMsg)
284 ICOM_THIS(CPropertyPageSiteImpl,iface);
286 FIXME("(%p,%p) - Win95 returns E_NOTIMPL\n",This,pMsg);
288 if ( pMsg == NULL )
289 return E_POINTER;
291 return E_NOTIMPL;
294 static ICOM_VTABLE(IPropertyPageSite) iproppagesite =
296 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
297 /* IUnknown fields */
298 CPropertyPageSiteImpl_fnQueryInterface,
299 CPropertyPageSiteImpl_fnAddRef,
300 CPropertyPageSiteImpl_fnRelease,
301 /* IPropertyPageSite fields */
302 CPropertyPageSiteImpl_fnOnStatusChange,
303 CPropertyPageSiteImpl_fnGetLocaleID,
304 CPropertyPageSiteImpl_fnGetPageContainer,
305 CPropertyPageSiteImpl_fnTranslateAccelerator,
308 /***************************************************************************/
310 static
311 HRESULT OLEPRO32_CreatePropertyPageSite(
312 CPropertyPageContainerImpl* pContainer,
313 IPropertyPage* pPage,
314 CPropertyPageSiteImpl** ppSite,
315 PROPSHEETPAGEA* pPspReturned )
317 CPropertyPageSiteImpl* This = NULL;
318 HRESULT hr;
319 DLGTEMPLATE* ptempl;
321 *ppSite = NULL;
322 ZeroMemory( pPspReturned, sizeof(PROPSHEETPAGEA) );
324 This = (CPropertyPageSiteImpl*)HeapAlloc( GetProcessHeap(), 0,
325 sizeof(CPropertyPageSiteImpl) );
326 if ( This == NULL )
327 return E_OUTOFMEMORY;
328 ZeroMemory( This, sizeof(CPropertyPageSiteImpl) );
330 ICOM_VTBL(This) = &iproppagesite;
331 This->ref = 1;
332 This->pContainer = pContainer; CPropertyPageContainerImpl_AddRef(pContainer);
333 This->pPage = pPage; IPropertyPage_AddRef(pPage);
334 This->hwnd = (HWND)NULL;
335 memcpy( &This->templ, &propsite_dlg, sizeof(propsite_dlg) );
336 This->info.cb = sizeof(PROPPAGEINFO);
337 This->bActivate = FALSE;
338 ptempl = (DLGTEMPLATE*)&This->templ;
340 /* construct */
341 hr = IPropertyPage_SetPageSite(pPage,(IPropertyPageSite*)This);
342 if ( FAILED(hr) )
343 goto end;
345 hr = IPropertyPage_GetPageInfo(pPage,&This->info);
346 if ( FAILED(hr) )
347 goto end;
349 ptempl->cx = This->info.size.cx;
350 ptempl->cy = This->info.size.cy;
352 pPspReturned->dwSize = sizeof(PROPSHEETPAGEA);
353 pPspReturned->dwFlags = PSP_DLGINDIRECT;
354 pPspReturned->u.pResource = ptempl;
355 if ( This->info.pszTitle != NULL );
357 pPspReturned->dwFlags |= PSP_USETITLE;
358 pPspReturned->pszTitle = "Title";/*FIXME - This->info.pszTitle;*/
360 pPspReturned->pfnDlgProc = PropSiteDlgProc;
361 pPspReturned->lParam = (LONG)This;
363 end:
364 if ( FAILED(hr) )
366 IUnknown_Release((IUnknown*)This);
367 return hr;
370 *ppSite = This;
371 return NOERROR;
374 /***************************************************************************/
376 static
377 void OLEPRO32_DestroyPropertyPageContainer(
378 CPropertyPageContainerImpl* This )
380 DWORD nIndex;
382 if ( This->m_ppSites != NULL )
384 for ( nIndex = 0; nIndex < This->m_cSites; nIndex++ )
386 if ( This->m_ppSites[nIndex] != NULL )
388 IPropertyPage_SetPageSite(This->m_ppSites[nIndex]->pPage,NULL);
389 IUnknown_Release((IUnknown*)This->m_ppSites[nIndex]);
392 HeapFree( GetProcessHeap(), 0, This->m_ppSites );
393 This->m_ppSites = NULL;
395 if ( This->m_pPsp != NULL )
397 HeapFree( GetProcessHeap(), 0, This->m_pPsp );
398 This->m_pPsp = NULL;
400 HeapFree( GetProcessHeap(), 0, This );
403 static
404 HRESULT OLEPRO32_CreatePropertyPageContainer(
405 CPropertyPageContainerImpl** ppContainer,
406 ULONG cPages, const CLSID* pclsidPages,
407 LCID lcid )
409 CPropertyPageContainerImpl* This = NULL;
410 DWORD nIndex;
411 IPropertyPage* pPage;
412 HRESULT hr;
414 This = (CPropertyPageContainerImpl*)HeapAlloc( GetProcessHeap(), 0,
415 sizeof(CPropertyPageContainerImpl) );
416 if ( This == NULL )
417 return E_OUTOFMEMORY;
418 ZeroMemory( This, sizeof(CPropertyPageContainerImpl) );
419 This->ref = 1;
420 This->lcid = lcid;
421 This->m_cSites = cPages;
422 This->m_ppSites = NULL;
423 This->m_pPsp = NULL;
424 This->m_hr = S_OK;
426 This->m_ppSites = (CPropertyPageSiteImpl**)HeapAlloc( GetProcessHeap(), 0, sizeof(CPropertyPageSiteImpl*) * cPages );
427 if ( This->m_ppSites == NULL )
429 hr = E_OUTOFMEMORY;
430 goto end;
432 ZeroMemory( This->m_ppSites, sizeof(CPropertyPageSiteImpl*) * cPages );
434 This->m_pPsp = (PROPSHEETPAGEA*)HeapAlloc( GetProcessHeap(), 0, sizeof(PROPSHEETPAGEA) * cPages );
435 if ( This->m_pPsp == NULL )
437 hr = E_OUTOFMEMORY;
438 goto end;
440 ZeroMemory( This->m_pPsp, sizeof(PROPSHEETPAGEA) * cPages );
442 for ( nIndex = 0; nIndex < cPages; nIndex ++ )
444 hr = CoCreateInstance(
445 &pclsidPages[nIndex], NULL, CLSCTX_SERVER,
446 &IID_IPropertyPage, (void**)&pPage );
447 if ( FAILED(hr) )
448 goto end;
449 hr = OLEPRO32_CreatePropertyPageSite(
450 This, pPage, &This->m_ppSites[nIndex], &This->m_pPsp[nIndex] );
451 IPropertyPage_Release(pPage);
452 if ( FAILED(hr) )
453 goto end;
456 hr = NOERROR;
457 end:
458 if ( FAILED(hr) )
460 OLEPRO32_DestroyPropertyPageContainer( This );
461 return hr;
464 *ppContainer = This;
465 return NOERROR;
468 static
469 HRESULT OLEPRO32_SetObjectsToPropertyPages(
470 CPropertyPageContainerImpl* This,
471 ULONG cObjects, IUnknown** ppunk )
473 DWORD nIndex;
474 HRESULT hr;
476 for ( nIndex = 0; nIndex < This->m_cSites; nIndex ++ )
478 if ( This->m_ppSites[nIndex] == NULL )
479 return E_UNEXPECTED;
480 hr = IPropertyPage_SetObjects(This->m_ppSites[nIndex]->pPage,cObjects,ppunk);
481 if ( FAILED(hr) )
482 return hr;
485 return NOERROR;
489 /***********************************************************************
491 * OleCreatePropertyFrameIndirect (OLEAUT32.416)(OLEPRO32.249)
495 HRESULT WINAPI OleCreatePropertyFrameIndirect( LPOCPFIPARAMS lpParams )
497 CPropertyPageContainerImpl* pContainer = NULL;
498 HRESULT hr;
499 PROPSHEETHEADERA psh;
500 int ret;
502 TRACE("(%p)\n",lpParams);
504 if ( lpParams == NULL )
505 return E_POINTER;
506 if ( lpParams->cbStructSize != sizeof(OCPFIPARAMS) )
508 FIXME("lpParams->cbStructSize(%lu) != sizeof(OCPFIPARAMS)(%lu)\n",lpParams->cbStructSize,(unsigned long)sizeof(OCPFIPARAMS));
509 return E_INVALIDARG;
512 hr = OLEPRO32_CreatePropertyPageContainer(
513 &pContainer,
514 lpParams->cPages, lpParams->lpPages,
515 lpParams->lcid );
516 if ( FAILED(hr) )
518 TRACE( "OLEPRO32_CreatePropertyPageContainer returns %08lx\n",hr);
519 return hr;
522 hr = OLEPRO32_SetObjectsToPropertyPages(
523 pContainer,
524 lpParams->cObjects, lpParams->lplpUnk );
525 if ( FAILED(hr) )
527 TRACE("OLEPRO32_SetObjectsToPropertyPages returns %08lx\n",hr);
528 OLEPRO32_DestroyPropertyPageContainer(pContainer);
529 return hr;
532 /* FIXME - use lpParams.x / lpParams.y */
534 ZeroMemory( &psh, sizeof(psh) );
535 psh.dwSize = sizeof(PROPSHEETHEADERA);
536 psh.dwFlags = PSH_PROPSHEETPAGE;
537 psh.hwndParent = lpParams->hWndOwner;
538 psh.pszCaption = "Caption"; /* FIXME - lpParams->lpszCaption; */
539 psh.nPages = pContainer->m_cSites;
540 psh.u2.nStartPage = lpParams->dispidInitialProperty;
541 psh.u3.ppsp = pContainer->m_pPsp;
543 ret = PropertySheetA( &psh );
544 OLEPRO32_DestroyPropertyPageContainer(pContainer);
546 if ( ret == -1 )
547 return E_FAIL;
549 return S_OK;
553 /***********************************************************************
555 * OleCreatePropertyFrame (OLEAUT32.417)(OLEPRO32.250)
559 HRESULT WINAPI OleCreatePropertyFrame(
560 HWND hwndOwner, UINT x, UINT y, LPCOLESTR lpszCaption,ULONG cObjects,
561 LPUNKNOWN* lplpUnk, ULONG cPages, LPCLSID pPageClsID, LCID lcid,
562 DWORD dwReserved, LPVOID pvReserved )
564 OCPFIPARAMS params;
566 TRACE("(%x,%d,%d,%s,%ld,%p,%ld,%p,%x,%ld,%p)\n",
567 hwndOwner,x,y,debugstr_w(lpszCaption),cObjects,lplpUnk,cPages,
568 pPageClsID, (int)lcid,dwReserved,pvReserved);
570 if ( dwReserved != 0 || pvReserved != NULL )
572 FIXME("(%x,%d,%d,%s,%ld,%p,%ld,%p,%x,%ld,%p) - E_INVALIDARG\n",
573 hwndOwner,x,y,debugstr_w(lpszCaption),cObjects,lplpUnk,cPages,
574 pPageClsID, (int)lcid,dwReserved,pvReserved);
575 return E_INVALIDARG;
578 ZeroMemory( &params, sizeof(params) );
579 params.cbStructSize = sizeof(OCPFIPARAMS);
580 params.hWndOwner = hwndOwner;
581 params.x = x;
582 params.y = y;
583 params.lpszCaption = lpszCaption;
584 params.cObjects = cObjects;
585 params.lplpUnk = lplpUnk;
586 params.cPages = cPages;
587 params.lpPages = pPageClsID;
588 params.lcid = lcid;
589 params.dispidInitialProperty = 0;
591 return OleCreatePropertyFrameIndirect( &params );