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.
28 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
36 typedef struct CPropertyPageContainerImpl CPropertyPageContainerImpl
;
48 WS_VISIBLE
| WS_CHILD
, /* style */
49 0, /* dwExtendedStyle */
59 typedef struct CPropertyPageSiteImpl
61 ICOM_VFIELD(IPropertyPageSite
);
65 /* IPropertyPageSite fields */
66 CPropertyPageContainerImpl
* pContainer
;
69 BYTE templ
[sizeof(propsite_dlg
)];
72 } CPropertyPageSiteImpl
;
74 struct CPropertyPageContainerImpl
76 ULONG ref
; /* for IUnknown(not used now) */
79 CPropertyPageSiteImpl
** m_ppSites
;
80 PROPSHEETPAGEA
* m_pPsp
;
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
);
103 This
= (CPropertyPageSiteImpl
*)(((PROPSHEETPAGEA
*)lParam
)->lParam
);
104 SetWindowLongA( hwnd
, DWL_USER
, (LONG
)This
);
105 TRACE("WM_INITDIALOG (%p) hwnd = %08x\n", This
, hwnd
);
108 ZeroMemory( &rc
, sizeof(rc
) );
109 GetClientRect( hwnd
, &rc
);
110 hr
= IPropertyPage_Activate(This
->pPage
,hwnd
,&rc
,TRUE
);
113 This
->bActivate
= TRUE
;
114 hr
= IPropertyPage_Show(This
->pPage
,SW_SHOW
);
117 This
->pContainer
->m_hr
= hr
;
120 TRACE("WM_DESTROY (%p)\n",This
);
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 );
134 pnmh
= (NMHDR
*)lParam
;
135 switch ( pnmh
->code
)
138 TRACE("PSN_APPLY (%p)\n",This
);
139 hr
= IPropertyPage_Apply(This
->pPage
);
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
);
147 FIXME("PSN_RESET (%p)\n",This
);
148 PropSiteDlg_Return(0);
150 TRACE("PSN_SETACTIVE (%p)\n",This
);
151 PropSiteDlg_Return(0);
153 TRACE("PSN_KILLACTIVE (%p)\n",This
);
154 PropSiteDlg_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
);
175 if ( IsEqualGUID(riid
,&IID_IUnknown
) ||
176 IsEqualGUID(riid
,&IID_IPropertyPageSite
) )
178 *ppobj
= (LPVOID
)This
;
179 IUnknown_AddRef((IUnknown
*)(*ppobj
));
183 return E_NOINTERFACE
;
187 CPropertyPageSiteImpl_fnAddRef(IPropertyPageSite
* iface
)
189 ICOM_THIS(CPropertyPageSiteImpl
,iface
);
191 TRACE("(%p)->()\n",This
);
193 return InterlockedExchangeAdd(&(This
->ref
),1) + 1;
197 CPropertyPageSiteImpl_fnRelease(IPropertyPageSite
* iface
)
199 ICOM_THIS(CPropertyPageSiteImpl
,iface
);
202 TRACE("(%p)->()\n",This
);
203 ref
= InterlockedExchangeAdd(&(This
->ref
),-1) - 1;
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
);
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
)
235 case PROPPAGESTATUS_DIRTY
:
237 SendMessageA(GetParent(This
->hwnd
),PSM_CHANGED
,(WPARAM
)(This
->hwnd
),0);
239 case PROPPAGESTATUS_VALIDATE
:
241 SendMessageA(GetParent(This
->hwnd
),PSM_UNCHANGED
,(WPARAM
)(This
->hwnd
),0);
244 FIXME("(%p,%08lx) unknown flags\n",This
,dwFlags
);
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
)
261 *pLocaleID
= This
->pContainer
->lcid
;
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
);
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
);
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 /***************************************************************************/
311 HRESULT
OLEPRO32_CreatePropertyPageSite(
312 CPropertyPageContainerImpl
* pContainer
,
313 IPropertyPage
* pPage
,
314 CPropertyPageSiteImpl
** ppSite
,
315 PROPSHEETPAGEA
* pPspReturned
)
317 CPropertyPageSiteImpl
* This
= NULL
;
322 ZeroMemory( pPspReturned
, sizeof(PROPSHEETPAGEA
) );
324 This
= (CPropertyPageSiteImpl
*)HeapAlloc( GetProcessHeap(), 0,
325 sizeof(CPropertyPageSiteImpl
) );
327 return E_OUTOFMEMORY
;
328 ZeroMemory( This
, sizeof(CPropertyPageSiteImpl
) );
330 ICOM_VTBL(This
) = &iproppagesite
;
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
;
341 hr
= IPropertyPage_SetPageSite(pPage
,(IPropertyPageSite
*)This
);
345 hr
= IPropertyPage_GetPageInfo(pPage
,&This
->info
);
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
;
366 IUnknown_Release((IUnknown
*)This
);
374 /***************************************************************************/
377 void OLEPRO32_DestroyPropertyPageContainer(
378 CPropertyPageContainerImpl
* This
)
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
);
400 HeapFree( GetProcessHeap(), 0, This
);
404 HRESULT
OLEPRO32_CreatePropertyPageContainer(
405 CPropertyPageContainerImpl
** ppContainer
,
406 ULONG cPages
, const CLSID
* pclsidPages
,
409 CPropertyPageContainerImpl
* This
= NULL
;
411 IPropertyPage
* pPage
;
414 This
= (CPropertyPageContainerImpl
*)HeapAlloc( GetProcessHeap(), 0,
415 sizeof(CPropertyPageContainerImpl
) );
417 return E_OUTOFMEMORY
;
418 ZeroMemory( This
, sizeof(CPropertyPageContainerImpl
) );
421 This
->m_cSites
= cPages
;
422 This
->m_ppSites
= NULL
;
426 This
->m_ppSites
= (CPropertyPageSiteImpl
**)HeapAlloc( GetProcessHeap(), 0, sizeof(CPropertyPageSiteImpl
*) * cPages
);
427 if ( This
->m_ppSites
== NULL
)
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
)
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
);
449 hr
= OLEPRO32_CreatePropertyPageSite(
450 This
, pPage
, &This
->m_ppSites
[nIndex
], &This
->m_pPsp
[nIndex
] );
451 IPropertyPage_Release(pPage
);
460 OLEPRO32_DestroyPropertyPageContainer( This
);
469 HRESULT
OLEPRO32_SetObjectsToPropertyPages(
470 CPropertyPageContainerImpl
* This
,
471 ULONG cObjects
, IUnknown
** ppunk
)
476 for ( nIndex
= 0; nIndex
< This
->m_cSites
; nIndex
++ )
478 if ( This
->m_ppSites
[nIndex
] == NULL
)
480 hr
= IPropertyPage_SetObjects(This
->m_ppSites
[nIndex
]->pPage
,cObjects
,ppunk
);
489 /***********************************************************************
491 * OleCreatePropertyFrameIndirect (OLEAUT32.416)(OLEPRO32.249)
495 HRESULT WINAPI
OleCreatePropertyFrameIndirect( LPOCPFIPARAMS lpParams
)
497 CPropertyPageContainerImpl
* pContainer
= NULL
;
499 PROPSHEETHEADERA psh
;
502 TRACE("(%p)\n",lpParams
);
504 if ( lpParams
== NULL
)
506 if ( lpParams
->cbStructSize
!= sizeof(OCPFIPARAMS
) )
508 FIXME("lpParams->cbStructSize(%lu) != sizeof(OCPFIPARAMS)(%lu)\n",lpParams
->cbStructSize
,(unsigned long)sizeof(OCPFIPARAMS
));
512 hr
= OLEPRO32_CreatePropertyPageContainer(
514 lpParams
->cPages
, lpParams
->lpPages
,
518 TRACE( "OLEPRO32_CreatePropertyPageContainer returns %08lx\n",hr
);
522 hr
= OLEPRO32_SetObjectsToPropertyPages(
524 lpParams
->cObjects
, lpParams
->lplpUnk
);
527 TRACE("OLEPRO32_SetObjectsToPropertyPages returns %08lx\n",hr
);
528 OLEPRO32_DestroyPropertyPageContainer(pContainer
);
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
);
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
)
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
);
578 ZeroMemory( ¶ms
, sizeof(params
) );
579 params
.cbStructSize
= sizeof(OCPFIPARAMS
);
580 params
.hWndOwner
= hwndOwner
;
583 params
.lpszCaption
= lpszCaption
;
584 params
.cObjects
= cObjects
;
585 params
.lplpUnk
= lplpUnk
;
586 params
.cPages
= cPages
;
587 params
.lpPages
= pPageClsID
;
589 params
.dispidInitialProperty
= 0;
591 return OleCreatePropertyFrameIndirect( ¶ms
);