2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 // ComPropertySheet.cpp : implementation file
27 #include "ComPropertySheet.h"
28 #include "..\..\DSUtil\DSUtil.h"
29 #include "..\..\filters\InternalPropertyPage.h"
31 // CComPropertyPageSite
33 class CComPropertyPageSite
: public CUnknown
, public IPropertyPageSite
35 IComPropertyPageDirty
* m_pPPD
;
38 CComPropertyPageSite(IComPropertyPageDirty
* pPPD
) : CUnknown(NAME("CComPropertyPageSite"), NULL
), m_pPPD(pPPD
) {}
41 STDMETHODIMP
NonDelegatingQueryInterface(REFIID riid
, void** ppv
)
45 __super::NonDelegatingQueryInterface(riid
, ppv
);
49 STDMETHODIMP
OnStatusChange(DWORD flags
)
53 if(flags
&PROPPAGESTATUS_DIRTY
) m_pPPD
->OnSetDirty(true);
54 if(flags
&PROPPAGESTATUS_CLEAN
) m_pPPD
->OnSetDirty(false);
58 STDMETHODIMP
GetLocaleID(LCID
* pLocaleID
)
60 CheckPointer(pLocaleID
, E_POINTER
);
61 *pLocaleID
= ::GetUserDefaultLCID();
64 STDMETHODIMP
GetPageContainer(IUnknown
** ppUnk
) {return E_NOTIMPL
;}
65 STDMETHODIMP
TranslateAccelerator(LPMSG pMsg
) {return E_NOTIMPL
;}
70 IMPLEMENT_DYNAMIC(CComPropertySheet
, CPropertySheet
)
71 CComPropertySheet::CComPropertySheet(UINT nIDCaption
, CWnd
* pParentWnd
, UINT iSelectPage
)
72 : CPropertySheet(nIDCaption
, pParentWnd
, iSelectPage
)
74 m_pSite
= new CComPropertyPageSite(this);
78 CComPropertySheet::CComPropertySheet(LPCTSTR pszCaption
, CWnd
* pParentWnd
, UINT iSelectPage
)
79 : CPropertySheet(pszCaption
, pParentWnd
, iSelectPage
)
81 m_pSite
= new CComPropertyPageSite(this);
85 CComPropertySheet::~CComPropertySheet()
89 int CComPropertySheet::AddPages(CComPtr
<ISpecifyPropertyPages
> pSPP
)
95 if(FAILED(pSPP
->GetPages(&caGUID
)))
98 IUnknown
* lpUnk
= NULL
;
99 if(FAILED(pSPP
.QueryInterface(&lpUnk
)))
104 CComQIPtr
<ISpecifyPropertyPages2
> pSPP2
= pSPP
;
105 CComQIPtr
<IPersist
> pPersist
= pSPP
;
108 for(ULONG i
= 0; i
< caGUID
.cElems
; i
++)
110 CComPtr
<IPropertyPage
> pPage
;
114 if(FAILED(hr
) && !pPage
&& pSPP2
)
116 hr
= pSPP2
->CreatePage(caGUID
.pElems
[i
], &pPage
);
119 if(FAILED(hr
) && !pPage
)
121 hr
= pPage
.CoCreateInstance(caGUID
.pElems
[i
]);
124 if(FAILED(hr
) && !pPage
&& pPersist
)
126 hr
= LoadExternalPropertyPage(pPersist
, caGUID
.pElems
[i
], &pPage
);
131 if(AddPage(pPage
, lpUnk
))
136 if(caGUID
.pElems
) CoTaskMemFree(caGUID
.pElems
);
142 bool CComPropertySheet::AddPage(IPropertyPage
* pPage
, IUnknown
* pUnk
)
144 if(!pPage
|| !pUnk
) return false;
147 hr
= pPage
->SetPageSite(m_pSite
);
148 hr
= pPage
->SetObjects(1, &pUnk
);
150 hr
= pPage
->GetPageInfo(&ppi
);
151 m_size
.cx
= max(m_size
.cx
, ppi
.size
.cx
);
152 m_size
.cy
= max(m_size
.cy
, ppi
.size
.cy
);
153 CAutoPtr
<CComPropertyPage
> p(new CComPropertyPage(pPage
));
160 void CComPropertySheet::OnActivated(CPropertyPage
* pPage
)
164 CRect
bounds(30000,30000,-30000,-30000);
169 CSize ws
= wr
.Size(), cs
= cr
.Size();
172 CTabCtrl
* pTC
= (CTabCtrl
*)GetDlgItem(AFX_IDC_TAB_CONTROL
);
173 pTC
->GetWindowRect(twr
);
174 pTC
->GetClientRect(tcr
);
175 CSize tws
= twr
.Size(), tcs
= tcr
.Size();
177 if(CWnd
* pChild
= pPage
->GetWindow(GW_CHILD
))
179 pChild
->ModifyStyle(WS_CAPTION
|WS_THICKFRAME
, 0);
180 pChild
->ModifyStyleEx(WS_EX_DLGMODALFRAME
, WS_EX_CONTROLPARENT
);
182 for(CWnd
* pGrandChild
= pChild
->GetWindow(GW_CHILD
); pGrandChild
; pGrandChild
= pGrandChild
->GetNextWindow())
184 if(!(pGrandChild
->GetStyle()&WS_VISIBLE
)) continue;
187 pGrandChild
->GetWindowRect(&r
);
188 pChild
->ScreenToClient(r
);
193 bounds
|= CRect(0,0,0,0);
194 bounds
.SetRect(0, 0, bounds
.right
+ max(bounds
.left
, 4), bounds
.bottom
+ max(bounds
.top
, 4));
196 CRect r
= CRect(CPoint(0,0), bounds
.Size());
197 pTC
->AdjustRect(TRUE
, r
);
198 r
.SetRect(twr
.TopLeft(), twr
.TopLeft() + r
.Size());
201 pTC
->ModifyStyle(TCS_MULTILINE
, TCS_SINGLELINE
);
203 CSize diff
= r
.Size() - tws
;
205 if(!bounds
.IsRectEmpty())
207 if(CWnd
* pChild
= pPage
->GetWindow(GW_CHILD
))
208 pChild
->MoveWindow(bounds
);
210 pTC
->AdjustRect(FALSE
, r
);
212 pPage
->MoveWindow(CRect(r
.TopLeft(), bounds
.Size()));
215 int _afxPropSheetButtons
[] = { IDOK
, IDCANCEL
, ID_APPLY_NOW
, IDHELP
};
216 for(int i
= 0; i
< countof(_afxPropSheetButtons
); i
++)
218 if(CWnd
* pWnd
= GetDlgItem(_afxPropSheetButtons
[i
]))
220 pWnd
->GetWindowRect(r
);
222 pWnd
->MoveWindow(CRect(r
.TopLeft() + diff
, r
.Size()));
226 MoveWindow(CRect(wr
.TopLeft(), ws
+ diff
));
232 BEGIN_MESSAGE_MAP(CComPropertySheet
, CPropertySheet
)
236 // CComPropertySheet message handlers
238 BOOL
CComPropertySheet::OnInitDialog()
240 BOOL bResult
= (BOOL
)Default();//CPropertySheet::OnInitDialog();
242 if (!(GetStyle() & WS_CHILD
))