2 * Copyright 2001 TAKESHIMA Hidenori <hidenori@a2.ctktv.ne.jp>
4 * FIXME - use PropertySheetW.
14 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(ole);
22 typedef struct CPropertyPageContainerImpl CPropertyPageContainerImpl;
34 WS_VISIBLE | WS_CHILD, /* style */
35 0, /* dwExtendedStyle */
45 typedef struct CPropertyPageSiteImpl
47 ICOM_VFIELD(IPropertyPageSite);
51 /* IPropertyPageSite fields */
52 CPropertyPageContainerImpl* pContainer;
55 BYTE templ[sizeof(propsite_dlg)];
58 } CPropertyPageSiteImpl;
60 struct CPropertyPageContainerImpl
62 ULONG ref; /* for IUnknown(not used now) */
65 CPropertyPageSiteImpl** m_ppSites;
66 PROPSHEETPAGEA* m_pPsp;
71 #define CPropertyPageContainerImpl_AddRef(pContainer) (++((pContainer)->ref))
72 #define CPropertyPageContainerImpl_Release(pContainer) (--((pContainer)->ref))
75 /***************************************************************************/
77 #define PropSiteDlg_Return(a) do{SetWindowLongA(hwnd,DWL_MSGRESULT,(LONG)a);return TRUE;}while(1)
78 static BOOL CALLBACK PropSiteDlgProc(
79 HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
81 CPropertyPageSiteImpl* This = (CPropertyPageSiteImpl*)GetWindowLongA( hwnd, DWL_USER );
89 This = (CPropertyPageSiteImpl*)(((PROPSHEETPAGEA*)lParam)->lParam);
90 SetWindowLongA( hwnd, DWL_USER, (LONG)This );
91 TRACE("WM_INITDIALOG (%p) hwnd = %08x\n", This, hwnd );
94 ZeroMemory( &rc, sizeof(rc) );
95 GetClientRect( hwnd, &rc );
96 hr = IPropertyPage_Activate(This->pPage,hwnd,&rc,TRUE);
99 This->bActivate = TRUE;
100 hr = IPropertyPage_Show(This->pPage,SW_SHOW);
103 This->pContainer->m_hr = hr;
106 TRACE("WM_DESTROY (%p)\n",This);
109 if ( This->bActivate )
111 IPropertyPage_Show(This->pPage,SW_HIDE);
112 IPropertyPage_Deactivate(This->pPage);
113 This->bActivate = FALSE;
115 This->hwnd = (HWND)NULL;
117 SetWindowLongA( hwnd, DWL_USER, (LONG)0 );
120 pnmh = (NMHDR*)lParam;
121 switch ( pnmh->code )
124 TRACE("PSN_APPLY (%p)\n",This);
125 hr = IPropertyPage_Apply(This->pPage);
127 PropSiteDlg_Return(PSNRET_INVALID_NOCHANGEPAGE);
128 PropSiteDlg_Return(PSNRET_NOERROR);
129 case PSN_QUERYCANCEL:
130 FIXME("PSN_QUERYCANCEL (%p)\n",This);
131 PropSiteDlg_Return(FALSE);
133 FIXME("PSN_RESET (%p)\n",This);
134 PropSiteDlg_Return(0);
136 TRACE("PSN_SETACTIVE (%p)\n",This);
137 PropSiteDlg_Return(0);
139 TRACE("PSN_KILLACTIVE (%p)\n",This);
140 PropSiteDlg_Return(FALSE);
148 /***************************************************************************/
150 static HRESULT WINAPI
151 CPropertyPageSiteImpl_fnQueryInterface(IPropertyPageSite* iface,REFIID riid,LPVOID *ppobj)
153 ICOM_THIS(CPropertyPageSiteImpl,iface);
155 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
161 if ( IsEqualGUID(riid,&IID_IUnknown) ||
162 IsEqualGUID(riid,&IID_IPropertyPageSite) )
164 *ppobj = (LPVOID)This;
165 IUnknown_AddRef((IUnknown*)(*ppobj));
169 return E_NOINTERFACE;
173 CPropertyPageSiteImpl_fnAddRef(IPropertyPageSite* iface)
175 ICOM_THIS(CPropertyPageSiteImpl,iface);
177 TRACE("(%p)->()\n",This);
179 return InterlockedExchangeAdd(&(This->ref),1) + 1;
183 CPropertyPageSiteImpl_fnRelease(IPropertyPageSite* iface)
185 ICOM_THIS(CPropertyPageSiteImpl,iface);
188 TRACE("(%p)->()\n",This);
189 ref = InterlockedExchangeAdd(&(This->ref),-1) - 1;
193 if ( This->pContainer != NULL )
194 CPropertyPageContainerImpl_Release(This->pContainer);
195 if ( This->pPage != NULL )
196 IPropertyPage_Release(This->pPage);
197 if ( This->info.pszTitle != NULL )
198 CoTaskMemFree( This->info.pszTitle );
199 if ( This->info.pszDocString != NULL )
200 CoTaskMemFree( This->info.pszDocString );
201 if ( This->info.pszHelpFile != NULL )
202 CoTaskMemFree( This->info.pszHelpFile );
204 HeapFree(GetProcessHeap(),0,This);
209 static HRESULT WINAPI
210 CPropertyPageSiteImpl_fnOnStatusChange(IPropertyPageSite* iface,DWORD dwFlags)
212 ICOM_THIS(CPropertyPageSiteImpl,iface);
214 TRACE("(%p,%08lx)\n",This,dwFlags);
216 if ( This->hwnd == (HWND)NULL )
221 case PROPPAGESTATUS_DIRTY:
223 SendMessageA(GetParent(This->hwnd),PSM_CHANGED,(WPARAM)(This->hwnd),0);
225 case PROPPAGESTATUS_VALIDATE:
227 SendMessageA(GetParent(This->hwnd),PSM_UNCHANGED,(WPARAM)(This->hwnd),0);
230 FIXME("(%p,%08lx) unknown flags\n",This,dwFlags);
237 static HRESULT WINAPI
238 CPropertyPageSiteImpl_fnGetLocaleID(IPropertyPageSite* iface,LCID* pLocaleID)
240 ICOM_THIS(CPropertyPageSiteImpl,iface);
242 TRACE("(%p,%p)\n",This,pLocaleID);
244 if ( pLocaleID == NULL )
247 *pLocaleID = This->pContainer->lcid;
252 static HRESULT WINAPI
253 CPropertyPageSiteImpl_fnGetPageContainer(IPropertyPageSite* iface,IUnknown** ppUnk)
255 ICOM_THIS(CPropertyPageSiteImpl,iface);
257 FIXME("(%p,%p) - Win95 returns E_NOTIMPL\n",This,ppUnk);
267 static HRESULT WINAPI
268 CPropertyPageSiteImpl_fnTranslateAccelerator(IPropertyPageSite* iface,MSG* pMsg)
270 ICOM_THIS(CPropertyPageSiteImpl,iface);
272 FIXME("(%p,%p) - Win95 returns E_NOTIMPL\n",This,pMsg);
280 static ICOM_VTABLE(IPropertyPageSite) iproppagesite =
282 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
283 /* IUnknown fields */
284 CPropertyPageSiteImpl_fnQueryInterface,
285 CPropertyPageSiteImpl_fnAddRef,
286 CPropertyPageSiteImpl_fnRelease,
287 /* IPropertyPageSite fields */
288 CPropertyPageSiteImpl_fnOnStatusChange,
289 CPropertyPageSiteImpl_fnGetLocaleID,
290 CPropertyPageSiteImpl_fnGetPageContainer,
291 CPropertyPageSiteImpl_fnTranslateAccelerator,
294 /***************************************************************************/
297 HRESULT OLEPRO32_CreatePropertyPageSite(
298 CPropertyPageContainerImpl* pContainer,
299 IPropertyPage* pPage,
300 CPropertyPageSiteImpl** ppSite,
301 PROPSHEETPAGEA* pPspReturned )
303 CPropertyPageSiteImpl* This = NULL;
308 ZeroMemory( pPspReturned, sizeof(PROPSHEETPAGEA) );
310 This = (CPropertyPageSiteImpl*)HeapAlloc( GetProcessHeap(), 0,
311 sizeof(CPropertyPageSiteImpl) );
313 return E_OUTOFMEMORY;
314 ZeroMemory( This, sizeof(CPropertyPageSiteImpl) );
316 ICOM_VTBL(This) = &iproppagesite;
318 This->pContainer = pContainer; CPropertyPageContainerImpl_AddRef(pContainer);
319 This->pPage = pPage; IPropertyPage_AddRef(pPage);
320 This->hwnd = (HWND)NULL;
321 memcpy( &This->templ, &propsite_dlg, sizeof(propsite_dlg) );
322 This->info.cb = sizeof(PROPPAGEINFO);
323 This->bActivate = FALSE;
324 ptempl = (DLGTEMPLATE*)&This->templ;
327 hr = IPropertyPage_SetPageSite(pPage,(IPropertyPageSite*)This);
331 hr = IPropertyPage_GetPageInfo(pPage,&This->info);
335 ptempl->cx = This->info.size.cx;
336 ptempl->cy = This->info.size.cy;
338 pPspReturned->dwSize = sizeof(PROPSHEETPAGEA);
339 pPspReturned->dwFlags = PSP_DLGINDIRECT;
340 pPspReturned->u.pResource = ptempl;
341 if ( This->info.pszTitle != NULL );
343 pPspReturned->dwFlags |= PSP_USETITLE;
344 pPspReturned->pszTitle = "Title";/*FIXME - This->info.pszTitle;*/
346 pPspReturned->pfnDlgProc = PropSiteDlgProc;
347 pPspReturned->lParam = (LONG)This;
352 IUnknown_Release((IUnknown*)This);
360 /***************************************************************************/
363 void OLEPRO32_DestroyPropertyPageContainer(
364 CPropertyPageContainerImpl* This )
368 if ( This->m_ppSites != NULL )
370 for ( nIndex = 0; nIndex < This->m_cSites; nIndex++ )
372 if ( This->m_ppSites[nIndex] != NULL )
374 IPropertyPage_SetPageSite(This->m_ppSites[nIndex]->pPage,NULL);
375 IUnknown_Release((IUnknown*)This->m_ppSites[nIndex]);
378 HeapFree( GetProcessHeap(), 0, This->m_ppSites );
379 This->m_ppSites = NULL;
381 if ( This->m_pPsp != NULL )
383 HeapFree( GetProcessHeap(), 0, This->m_pPsp );
386 HeapFree( GetProcessHeap(), 0, This );
390 HRESULT OLEPRO32_CreatePropertyPageContainer(
391 CPropertyPageContainerImpl** ppContainer,
392 ULONG cPages, const CLSID* pclsidPages,
395 CPropertyPageContainerImpl* This = NULL;
397 IPropertyPage* pPage;
400 This = (CPropertyPageContainerImpl*)HeapAlloc( GetProcessHeap(), 0,
401 sizeof(CPropertyPageContainerImpl) );
403 return E_OUTOFMEMORY;
404 ZeroMemory( This, sizeof(CPropertyPageContainerImpl) );
407 This->m_cSites = cPages;
408 This->m_ppSites = NULL;
412 This->m_ppSites = (CPropertyPageSiteImpl**)HeapAlloc( GetProcessHeap(), 0, sizeof(CPropertyPageSiteImpl*) * cPages );
413 if ( This->m_ppSites == NULL )
418 ZeroMemory( This->m_ppSites, sizeof(CPropertyPageSiteImpl*) * cPages );
420 This->m_pPsp = (PROPSHEETPAGEA*)HeapAlloc( GetProcessHeap(), 0, sizeof(PROPSHEETPAGEA) * cPages );
421 if ( This->m_pPsp == NULL )
426 ZeroMemory( This->m_pPsp, sizeof(PROPSHEETPAGEA) * cPages );
428 for ( nIndex = 0; nIndex < cPages; nIndex ++ )
430 hr = CoCreateInstance(
431 &pclsidPages[nIndex], NULL, CLSCTX_SERVER,
432 &IID_IPropertyPage, (void**)&pPage );
435 hr = OLEPRO32_CreatePropertyPageSite(
436 This, pPage, &This->m_ppSites[nIndex], &This->m_pPsp[nIndex] );
437 IPropertyPage_Release(pPage);
446 OLEPRO32_DestroyPropertyPageContainer( This );
455 HRESULT OLEPRO32_SetObjectsToPropertyPages(
456 CPropertyPageContainerImpl* This,
457 ULONG cObjects, IUnknown** ppunk )
462 for ( nIndex = 0; nIndex < This->m_cSites; nIndex ++ )
464 if ( This->m_ppSites[nIndex] == NULL )
466 hr = IPropertyPage_SetObjects(This->m_ppSites[nIndex]->pPage,cObjects,ppunk);
475 /***********************************************************************
477 * OleCreatePropertyFrameIndirect (OLEAUT32.416)(OLEPRO32.249)
481 HRESULT WINAPI OleCreatePropertyFrameIndirect( LPOCPFIPARAMS lpParams )
483 CPropertyPageContainerImpl* pContainer = NULL;
485 PROPSHEETHEADERA psh;
488 TRACE("(%p)\n",lpParams);
490 if ( lpParams == NULL )
492 if ( lpParams->cbStructSize != sizeof(OCPFIPARAMS) )
494 FIXME("lpParams->cbStructSize(%lu) != sizeof(OCPFIPARAMS)(%lu)\n",lpParams->cbStructSize,(unsigned long)sizeof(OCPFIPARAMS));
498 hr = OLEPRO32_CreatePropertyPageContainer(
500 lpParams->cPages, lpParams->lpPages,
504 TRACE( "OLEPRO32_CreatePropertyPageContainer returns %08lx\n",hr);
508 hr = OLEPRO32_SetObjectsToPropertyPages(
510 lpParams->cObjects, lpParams->lplpUnk );
513 TRACE("OLEPRO32_SetObjectsToPropertyPages returns %08lx\n",hr);
514 OLEPRO32_DestroyPropertyPageContainer(pContainer);
518 /* FIXME - use lpParams.x / lpParams.y */
520 ZeroMemory( &psh, sizeof(psh) );
521 psh.dwSize = sizeof(PROPSHEETHEADERA);
522 psh.dwFlags = PSH_PROPSHEETPAGE;
523 psh.hwndParent = lpParams->hWndOwner;
524 psh.pszCaption = "Caption"; /* FIXME - lpParams->lpszCaption; */
525 psh.nPages = pContainer->m_cSites;
526 psh.u2.nStartPage = lpParams->dispidInitialProperty;
527 psh.u3.ppsp = pContainer->m_pPsp;
529 ret = PropertySheetA( &psh );
530 OLEPRO32_DestroyPropertyPageContainer(pContainer);
539 /***********************************************************************
541 * OleCreatePropertyFrame (OLEAUT32.417)(OLEPRO32.250)
545 HRESULT WINAPI OleCreatePropertyFrame(
546 HWND hwndOwner, UINT x, UINT y, LPCOLESTR lpszCaption,ULONG cObjects,
547 LPUNKNOWN* lplpUnk, ULONG cPages, LPCLSID pPageClsID, LCID lcid,
548 DWORD dwReserved, LPVOID pvReserved )
552 TRACE("(%x,%d,%d,%s,%ld,%p,%ld,%p,%x,%ld,%p)\n",
553 hwndOwner,x,y,debugstr_w(lpszCaption),cObjects,lplpUnk,cPages,
554 pPageClsID, (int)lcid,dwReserved,pvReserved);
556 if ( dwReserved != 0 || pvReserved != NULL )
558 FIXME("(%x,%d,%d,%s,%ld,%p,%ld,%p,%x,%ld,%p) - E_INVALIDARG\n",
559 hwndOwner,x,y,debugstr_w(lpszCaption),cObjects,lplpUnk,cPages,
560 pPageClsID, (int)lcid,dwReserved,pvReserved);
564 ZeroMemory( ¶ms, sizeof(params) );
565 params.cbStructSize = sizeof(OCPFIPARAMS);
566 params.hWndOwner = hwndOwner;
569 params.lpszCaption = lpszCaption;
570 params.cObjects = cObjects;
571 params.lplpUnk = lplpUnk;
572 params.cPages = cPages;
573 params.lpPages = pPageClsID;
575 params.dispidInitialProperty = 0;
577 return OleCreatePropertyFrameIndirect( ¶ms );