ComPropertySheet.cpp

00001 /* 
00002  *      Copyright (C) 2003-2005 Gabest
00003  *      http://www.gabest.org
00004  *
00005  *  This Program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2, or (at your option)
00008  *  any later version.
00009  *   
00010  *  This Program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  *  GNU General Public License for more details.
00014  *   
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with GNU Make; see the file COPYING.  If not, write to
00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
00018  *  http://www.gnu.org/copyleft/gpl.html
00019  *
00020  */
00021 
00022 // ComPropertySheet.cpp : implementation file
00023 //
00024 
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "ComPropertySheet.h"
00028 #include "..\..\DSUtil\DSUtil.h"
00029 
00030 // CComPropertyPageSite
00031 
00032 class CComPropertyPageSite : public CUnknown, public IPropertyPageSite
00033 {
00034         IComPropertyPageDirty* m_pPPD;
00035 
00036 public:
00037         CComPropertyPageSite(IComPropertyPageDirty* pPPD) : CUnknown(NAME("CComPropertyPageSite"), NULL), m_pPPD(pPPD) {}
00038 
00039         DECLARE_IUNKNOWN
00040         STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv)
00041         {
00042                 return 
00043                         QI(IPropertyPageSite)
00044                         __super::NonDelegatingQueryInterface(riid, ppv);
00045         }
00046 
00047         // IPropertyPageSite
00048         STDMETHODIMP OnStatusChange(DWORD flags)
00049         {
00050                 if(m_pPPD)
00051                 {
00052                         if(flags&PROPPAGESTATUS_DIRTY) m_pPPD->OnSetDirty(true); 
00053                         if(flags&PROPPAGESTATUS_CLEAN) m_pPPD->OnSetDirty(false);
00054                 }
00055                 return S_OK;
00056         }
00057         STDMETHODIMP GetLocaleID(LCID* pLocaleID)
00058         {
00059                 CheckPointer(pLocaleID, E_POINTER);
00060                 *pLocaleID = ::GetUserDefaultLCID();
00061                 return S_OK;
00062         }
00063         STDMETHODIMP GetPageContainer(IUnknown** ppUnk) {return E_NOTIMPL;}
00064         STDMETHODIMP TranslateAccelerator(LPMSG pMsg) {return E_NOTIMPL;}
00065 };
00066 
00067 // CComPropertySheet
00068 
00069 IMPLEMENT_DYNAMIC(CComPropertySheet, CPropertySheet)
00070 CComPropertySheet::CComPropertySheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
00071         : CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
00072 {
00073         m_pSite = new CComPropertyPageSite(this);
00074         m_size.SetSize(0, 0);
00075 }
00076 
00077 CComPropertySheet::CComPropertySheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
00078         : CPropertySheet(pszCaption, pParentWnd, iSelectPage)
00079 {
00080         m_pSite = new CComPropertyPageSite(this);
00081         m_size.SetSize(0, 0);
00082 }
00083 
00084 CComPropertySheet::~CComPropertySheet()
00085 {
00086 }
00087 
00088 int CComPropertySheet::AddPages(CComPtr<ISpecifyPropertyPages> pSPP)
00089 {
00090         if(!pSPP) return(0);
00091 
00092         CAUUID caGUID;
00093         caGUID.pElems = NULL;
00094         if(FAILED(pSPP->GetPages(&caGUID)))
00095                 return(0);
00096 
00097         IUnknown* lpUnk = NULL;
00098         if(FAILED(pSPP.QueryInterface(&lpUnk)))
00099                 return(0);
00100 
00101         m_spp.AddTail(pSPP);
00102 
00103         ULONG nPages = 0;
00104         for(ULONG i = 0; i < caGUID.cElems; i++)
00105         {
00106                 CComPtr<IPropertyPage> pPage;
00107 
00108                 HRESULT hr = pPage.CoCreateInstance(caGUID.pElems[i]);
00109 
00110                 if(FAILED(hr))
00111                 {
00112                         if(CComQIPtr<IPersist> pP = pSPP)
00113                                 hr = LoadExternalPropertyPage(pP, caGUID.pElems[i], &pPage);
00114                 }
00115 
00116                 if(SUCCEEDED(hr))
00117                 {
00118                         HRESULT hr;
00119                         hr = pPage->SetPageSite(m_pSite);
00120                         hr = pPage->SetObjects(1, &lpUnk);
00121                         PROPPAGEINFO ppi;
00122                         hr = pPage->GetPageInfo(&ppi);
00123                         m_size.cx = max(m_size.cx, ppi.size.cx);
00124                         m_size.cy = max(m_size.cy, ppi.size.cy);
00125                         CAutoPtr<CComPropertyPage> p(new CComPropertyPage(pPage));
00126                         AddPage(p);
00127                         m_pages.AddTail(p);
00128                         nPages++;
00129                 }
00130         }
00131 
00132         if(caGUID.pElems) CoTaskMemFree(caGUID.pElems);
00133         lpUnk->Release();
00134 
00135         return(nPages);
00136 }
00137 
00138 void CComPropertySheet::OnActivated(CPropertyPage* pPage)
00139 {
00140         if(!pPage) return;
00141 
00142         CRect bounds(30000,30000,-30000,-30000);
00143 
00144         CRect wr, cr;
00145         GetWindowRect(wr);
00146         GetClientRect(cr);
00147         CSize ws = wr.Size(), cs = cr.Size();
00148 
00149         CRect twr, tcr;
00150         CTabCtrl* pTC = (CTabCtrl*)GetDlgItem(AFX_IDC_TAB_CONTROL);
00151         pTC->GetWindowRect(twr);
00152         pTC->GetClientRect(tcr);
00153         CSize tws = twr.Size(), tcs = tcr.Size();
00154 
00155         if(CWnd* pChild = pPage->GetWindow(GW_CHILD))
00156         {
00157                 pChild->ModifyStyle(WS_CAPTION|WS_THICKFRAME, 0);
00158                 pChild->ModifyStyleEx(WS_EX_DLGMODALFRAME, 0);
00159 
00160                 for(CWnd* pGrandChild = pChild->GetWindow(GW_CHILD); pGrandChild; pGrandChild = pGrandChild->GetNextWindow())
00161                 {
00162                         if(!(pGrandChild->GetStyle()&WS_VISIBLE)) continue;
00163 
00164                         CRect r;
00165                         pGrandChild->GetWindowRect(&r);
00166                         pChild->ScreenToClient(r);
00167                         bounds |= r;
00168                 }
00169         }
00170 
00171         bounds |= CRect(0,0,0,0);
00172         bounds.SetRect(0, 0, bounds.right + max(bounds.left, 4), bounds.bottom + max(bounds.top, 4));
00173 
00174         CRect r = CRect(CPoint(0,0), bounds.Size());
00175         pTC->AdjustRect(TRUE, r);
00176         r.SetRect(twr.TopLeft(), twr.TopLeft() + r.Size());
00177         ScreenToClient(r);
00178         pTC->MoveWindow(r);
00179         pTC->ModifyStyle(TCS_MULTILINE, TCS_SINGLELINE);
00180 
00181         CSize diff = r.Size() - tws;
00182 
00183         if(!bounds.IsRectEmpty())
00184         {
00185                 if(CWnd* pChild = pPage->GetWindow(GW_CHILD))
00186                         pChild->MoveWindow(bounds);
00187                 CRect r = twr;
00188                 pTC->AdjustRect(FALSE, r);
00189                 ScreenToClient(r);
00190                 pPage->MoveWindow(CRect(r.TopLeft(), bounds.Size()));
00191         }
00192 
00193         int _afxPropSheetButtons[] = { IDOK, IDCANCEL, ID_APPLY_NOW, IDHELP };
00194         for(int i = 0; i < countof(_afxPropSheetButtons); i++)
00195         {
00196                 if(CWnd* pWnd = GetDlgItem(_afxPropSheetButtons[i]))
00197                 {
00198                         pWnd->GetWindowRect(r);
00199                         ScreenToClient(r);
00200                         pWnd->MoveWindow(CRect(r.TopLeft() + diff, r.Size()));
00201                 }
00202         }
00203 
00204         MoveWindow(CRect(wr.TopLeft(), ws + diff));
00205 
00206         Invalidate();
00207 }
00208 
00209 
00210 BEGIN_MESSAGE_MAP(CComPropertySheet, CPropertySheet)
00211 END_MESSAGE_MAP()
00212 
00213 
00214 // CComPropertySheet message handlers
00215 
00216 BOOL CComPropertySheet::OnInitDialog()
00217 {
00218         BOOL bResult = (BOOL)Default();//CPropertySheet::OnInitDialog();
00219 
00220         if (!(GetStyle() & WS_CHILD))
00221                 CenterWindow();
00222 
00223         return bResult;
00224 }

Generated on Tue Dec 13 14:46:47 2005 for guliverkli by  doxygen 1.4.5