summaryrefslogtreecommitdiff
path: root/Common/PropPageHolder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Common/PropPageHolder.cpp')
-rw-r--r--Common/PropPageHolder.cpp317
1 files changed, 317 insertions, 0 deletions
diff --git a/Common/PropPageHolder.cpp b/Common/PropPageHolder.cpp
new file mode 100644
index 0000000..cd14ff8
--- /dev/null
+++ b/Common/PropPageHolder.cpp
@@ -0,0 +1,317 @@
+// PropPageHolder.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "PropPageHolder.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// CPropPageHolder
+
+CPropPageHolder::CPropPageHolder()
+{
+ m_pSite = NULL;
+ m_pPropPage = NULL;
+ m_bActivated = false;
+ memset(&m_PageInfo, 0, sizeof(PROPPAGEINFO));
+}
+
+/*CPropPageHolder::CPropPageHolder(IPropertyPage* pPage, IUnknown* pSite)
+{
+ m_pSite = NULL;
+ m_pPropPage = NULL;
+ m_bActivated = false;
+ memset(&m_PageInfo, 0, sizeof(PROPPAGEINFO));
+
+ // We were passed a IUnknown, so Initialize from there
+ Initialize(pPage, pSite);
+}
+*/
+
+CPropPageHolder::~CPropPageHolder()
+{
+ // Just in case
+ if(m_pPropPage != NULL)
+ Destroy();
+
+ if(m_PageInfo.cb != 0)
+ {
+ CoTaskMemFree(m_PageInfo.pszDocString);
+ CoTaskMemFree(m_PageInfo.pszHelpFile);
+ CoTaskMemFree(m_PageInfo.pszTitle);
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// CPropPageHolder message handlers
+
+//////////////////////////////////////////////////////////////////
+// Loads Prop Page if it has one
+
+HRESULT CPropPageHolder::Initialize(IPropertyPage* pPage, IUnknown* pSite)
+{
+ // Can't Reinitialize
+ ASSERT(!m_pPropPage);
+ ASSERT(pSite);
+ ASSERT(pPage);
+
+ // This is the Container site
+ // (Returned from IPropertyPageSite::GetPageContainer)
+ m_pSite = pSite;
+
+ m_pPropPage = pPage;
+ pPage->AddRef();
+
+ // Get a IPropertyPageSite Pointer to ourselves
+ // for the new Proppage
+ IPropertyPageSite* pPageSite = NULL;
+ QueryInterface(IID_IPropertyPageSite, (void**)&pPageSite);
+ ASSERT(pPageSite);
+
+
+ // Set Page Site
+ HRESULT hr = m_pPropPage->SetPageSite(pPageSite);
+
+ // Make sure to reset to null if failed
+ if(FAILED(hr))
+ {
+ m_pPropPage->Release();
+ m_pPropPage = NULL;
+ }
+ else
+ {
+ // Property page should have AddRef'ed,
+ // So release our pointer
+ Release();
+ }
+
+ return hr;
+
+}
+
+//////////////////////////////////////////////////////////////////
+// Creates and shows PropPage
+
+HRESULT CPropPageHolder::Create(HWND hwndParent, const RECT& rect, bool bModalParent /*= true*/)
+{
+ // Need to Initialize First
+ ASSERT(m_pPropPage);
+
+
+ // If we're already activated then just
+ // move to new coordinates
+ if(m_bActivated)
+ return Move(rect);
+
+
+ HRESULT hr;
+
+
+ // Activate the Page
+ hr = m_pPropPage->Activate(hwndParent, &rect, true);
+
+
+ if(!FAILED(hr))
+ {
+ m_bActivated = true;
+
+ // Make sure it's visible
+ m_pPropPage->Show(SW_SHOW);
+ }
+
+
+ return hr;
+}
+
+//////////////////////////////////////////////////////////////////
+// Destroys and Releases PropPage
+
+HRESULT CPropPageHolder::Destroy()
+{
+ // Can't destroy NULL object
+ if(m_pPropPage == NULL)
+ return S_OK;
+
+
+ Close();
+
+ // Make it let go of our IPropertyPageSite Pointer
+ HRESULT hr = m_pPropPage->SetPageSite(NULL);
+
+
+ // Then release it
+ m_pPropPage->Release();
+
+
+ m_pPropPage = NULL;
+
+ return hr;
+}
+
+HRESULT CPropPageHolder::Close()
+{
+ // Need to Initialize
+ // and create first
+ ASSERT(m_pPropPage);
+
+ if(m_bActivated)
+ {
+
+ m_bActivated = false;
+
+ // Deactivate page
+ return m_pPropPage->Deactivate();
+
+ }
+
+ // It went okay but didn't do anything so...
+ return S_FALSE;
+
+}
+
+//////////////////////////////////////////////////////////////////
+// Calls IPropPage Show
+
+HRESULT CPropPageHolder::Show(UINT nCmdShow)
+{
+ // Need to Initialize
+ // and create first
+ ASSERT(m_pPropPage);
+ ASSERT(m_bActivated);
+
+ return m_pPropPage->Show(nCmdShow);
+
+}
+
+//////////////////////////////////////////////////////////////////
+// Calls IPropPage Move
+
+HRESULT CPropPageHolder::Move(const RECT& rect)
+{
+ // Need to Initialize
+ // and create first
+ ASSERT(m_pPropPage);
+ ASSERT(m_bActivated);
+
+ return m_pPropPage->Move(&rect);
+
+}
+
+//////////////////////////////////////////////////////////////////
+// PropPage is inited properly if pointer not null
+
+bool CPropPageHolder::IsInitialized()
+{
+ return !(m_pPropPage == NULL);
+}
+
+//////////////////////////////////////////////////////////////////
+// Calls IPropPage Apply (results in a call to OnStatusChanged
+// in our IPropPageSite)
+
+HRESULT CPropPageHolder::Apply()
+{
+ // Need to Initialize First
+ ASSERT(m_pPropPage);
+
+ return m_pPropPage->Apply();
+}
+
+//////////////////////////////////////////////////////////////////
+// Is it Created?
+
+bool CPropPageHolder::IsActivated()
+ { return m_bActivated; }
+
+
+
+/////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+// PropertyPageSite
+
+STDMETHODIMP CPropPageHolder::OnStatusChange(DWORD dwFlags)
+{
+ TRACE("CPropPageHolder::XPropertyPageSite::OnStatusChange\n");
+
+ // We don't need to implement any of this
+ // as we use delayed saving
+ return S_OK;
+}
+
+STDMETHODIMP CPropPageHolder::GetLocaleID(LCID* pLocaleID)
+{
+ TRACE("CPropPageHolder::XPropertyPageSite::GetLocaleID\n");
+
+ // Just give'm a default language
+ *pLocaleID = LOCALE_SYSTEM_DEFAULT;
+ return S_OK;
+}
+
+STDMETHODIMP CPropPageHolder::GetPageContainer(IUnknown** ppUnk)
+{
+ TRACE("CPropPageHolder::XPropertyPageSite::GetPageContainer\n");
+
+ // If Error we need to set to NULL
+ // This takes care of that cuz NULL is the only error around
+ *ppUnk = m_pSite;
+
+ if(!m_pSite)
+ return E_UNEXPECTED;
+
+ m_pSite->AddRef();
+
+ // Sorry
+ return S_OK;
+}
+
+STDMETHODIMP CPropPageHolder::TranslateAccelerator(LPMSG pMsg)
+{
+ TRACE("CPropPageHolder::XPropertyPageSite::TranslateAccelerator\n");
+
+ // Sorry
+ return E_NOTIMPL;
+}
+
+string CPropPageHolder::GetTitle()
+{
+ USES_CONVERSION;
+ LoadInfo();
+
+ if(m_PageInfo.pszTitle)
+ return OLE2T(m_PageInfo.pszTitle);
+
+ return _T("");
+}
+
+string CPropPageHolder::GetHelpFile()
+{
+ USES_CONVERSION;
+ LoadInfo();
+
+ if(m_PageInfo.pszHelpFile)
+ return OLE2T(m_PageInfo.pszHelpFile);
+
+ return _T("");
+}
+
+DWORD CPropPageHolder::GetHelpContext()
+{
+ LoadInfo();
+ return m_PageInfo.dwHelpContext;
+}
+
+
+HRESULT CPropPageHolder::LoadInfo()
+{
+ if(m_PageInfo.cb != 0)
+ return S_OK;
+
+ ASSERT(m_pPropPage);
+ m_PageInfo.cb = sizeof(PROPPAGEINFO);
+ return m_pPropPage->GetPageInfo(&m_PageInfo);
+}