X64 transport [Part 5] (Update plugins.cpp)
[xy_vsfilter.git] / src / apps / mplayerc / ComPropertySheet.cpp
blob49cc664edfdd45e068b8ae29da68ee0973860f28
1 /*
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)
8 * any later version.
9 *
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
25 #include "stdafx.h"
26 #include "mplayerc.h"
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;
37 public:
38 CComPropertyPageSite(IComPropertyPageDirty* pPPD) : CUnknown(NAME("CComPropertyPageSite"), NULL), m_pPPD(pPPD) {}
40 DECLARE_IUNKNOWN
41 STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv)
43 return
44 QI(IPropertyPageSite)
45 __super::NonDelegatingQueryInterface(riid, ppv);
48 // IPropertyPageSite
49 STDMETHODIMP OnStatusChange(DWORD flags)
51 if(m_pPPD)
53 if(flags&PROPPAGESTATUS_DIRTY) m_pPPD->OnSetDirty(true);
54 if(flags&PROPPAGESTATUS_CLEAN) m_pPPD->OnSetDirty(false);
56 return S_OK;
58 STDMETHODIMP GetLocaleID(LCID* pLocaleID)
60 CheckPointer(pLocaleID, E_POINTER);
61 *pLocaleID = ::GetUserDefaultLCID();
62 return S_OK;
64 STDMETHODIMP GetPageContainer(IUnknown** ppUnk) {return E_NOTIMPL;}
65 STDMETHODIMP TranslateAccelerator(LPMSG pMsg) {return E_NOTIMPL;}
68 // CComPropertySheet
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);
75 m_size.SetSize(0, 0);
78 CComPropertySheet::CComPropertySheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
79 : CPropertySheet(pszCaption, pParentWnd, iSelectPage)
81 m_pSite = new CComPropertyPageSite(this);
82 m_size.SetSize(0, 0);
85 CComPropertySheet::~CComPropertySheet()
89 int CComPropertySheet::AddPages(CComPtr<ISpecifyPropertyPages> pSPP)
91 if(!pSPP) return(0);
93 CAUUID caGUID;
94 caGUID.pElems = NULL;
95 if(FAILED(pSPP->GetPages(&caGUID)))
96 return(0);
98 IUnknown* lpUnk = NULL;
99 if(FAILED(pSPP.QueryInterface(&lpUnk)))
100 return(0);
102 m_spp.AddTail(pSPP);
104 CComQIPtr<ISpecifyPropertyPages2> pSPP2 = pSPP;
105 CComQIPtr<IPersist> pPersist = pSPP;
107 ULONG nPages = 0;
108 for(ULONG i = 0; i < caGUID.cElems; i++)
110 CComPtr<IPropertyPage> pPage;
112 HRESULT hr = E_FAIL;
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);
129 if(SUCCEEDED(hr))
131 if(AddPage(pPage, lpUnk))
132 nPages++;
136 if(caGUID.pElems) CoTaskMemFree(caGUID.pElems);
137 lpUnk->Release();
139 return(nPages);
142 bool CComPropertySheet::AddPage(IPropertyPage* pPage, IUnknown* pUnk)
144 if(!pPage || !pUnk) return false;
146 HRESULT hr;
147 hr = pPage->SetPageSite(m_pSite);
148 hr = pPage->SetObjects(1, &pUnk);
149 PROPPAGEINFO ppi;
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));
154 __super::AddPage(p);
155 m_pages.AddTail(p);
157 return true;
160 void CComPropertySheet::OnActivated(CPropertyPage* pPage)
162 if(!pPage) return;
164 CRect bounds(30000,30000,-30000,-30000);
166 CRect wr, cr;
167 GetWindowRect(wr);
168 GetClientRect(cr);
169 CSize ws = wr.Size(), cs = cr.Size();
171 CRect twr, tcr;
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;
186 CRect r;
187 pGrandChild->GetWindowRect(&r);
188 pChild->ScreenToClient(r);
189 bounds |= 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());
199 ScreenToClient(r);
200 pTC->MoveWindow(r);
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);
209 CRect r = twr;
210 pTC->AdjustRect(FALSE, r);
211 ScreenToClient(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);
221 ScreenToClient(r);
222 pWnd->MoveWindow(CRect(r.TopLeft() + diff, r.Size()));
226 MoveWindow(CRect(wr.TopLeft(), ws + diff));
228 Invalidate();
232 BEGIN_MESSAGE_MAP(CComPropertySheet, CPropertySheet)
233 END_MESSAGE_MAP()
236 // CComPropertySheet message handlers
238 BOOL CComPropertySheet::OnInitDialog()
240 BOOL bResult = (BOOL)Default();//CPropertySheet::OnInitDialog();
242 if (!(GetStyle() & WS_CHILD))
243 CenterWindow();
245 return bResult;