diff options
author | Stef Walter <stef@thewalter.net> | 2003-09-17 19:07:23 +0000 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2003-09-17 19:07:23 +0000 |
commit | 3f95d417d9e623ac0c74df8ef11d7a01846392dd (patch) | |
tree | 45ec73f2dc07eafd7f41a6f62a8cdfbaa279469f /Checklist/AdvancedPage.cpp |
Diffstat (limited to 'Checklist/AdvancedPage.cpp')
-rw-r--r-- | Checklist/AdvancedPage.cpp | 317 |
1 files changed, 317 insertions, 0 deletions
diff --git a/Checklist/AdvancedPage.cpp b/Checklist/AdvancedPage.cpp new file mode 100644 index 0000000..edef443 --- /dev/null +++ b/Checklist/AdvancedPage.cpp @@ -0,0 +1,317 @@ +// AdvancedPage.cpp : implementation file +// + +#include "stdafx.h" +#include "AdvancedPage.h" + +///////////////////////////////////////////////////////////////////////////// +// CAdvancedPage property page + +CAdvancedPage::CAdvancedPage(CNightSecWizard* pParent, UINT nType, UINT nIDD, UINT nPos /*= WIZPAGE_MIDDLE*/) + : CPropertyPage(nIDD), + + // Set const variables + m_nType(nType), // Either COMPONENT_WIN or COMPONENT_DOS + + m_nPos(nPos) // Position in the Wizard (WIZPAGE_FIRST, WIZPAGE_MIDDLE + // or WIZPAGE_LAST) + +{ + m_pCurPropPage = NULL; // NULL means no Proppage shown + m_pCurComponent = NULL; + + ASSERT(pParent != NULL); // Have to have a valid parent + m_pParentSheet = pParent; // or we can't survive + +} + +CAdvancedPage::~CAdvancedPage() +{ + m_pParentSheet = NULL; + m_pCurPropPage = NULL; + m_pCurComponent = NULL; +} + +///////////////////////////////////////////////////////////////////////////// +// CAdvancedPage message handlers + +////////////////////////////////////////////////////////////////// +// List box selection has changed + +LRESULT CAdvancedPage::OnComponentsSelChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) +{ + // Make sure we have a matching PropPage up + SetCurrentComponent(); + + return 1; +} + +LRESULT CAdvancedPage::OnPageSelChange(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) +{ + // Make sure we have a matching PropPage up + SetCurrentPage(); + + return 1; +} + +////////////////////////////////////////////////////////////////// +// InitDialog + +LRESULT CAdvancedPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + m_ctlDrag.SubclassWindow(GetDlgItem(IDC_COMPONENTS)); + m_ctlCheck.SubclassWindow(GetDlgItem(IDC_COMPONENTS)); +// m_ctlCheck = GetDlgItem(IDC_COMPONENTS); + + m_ctlTabs = GetDlgItem(IDC_PAGETABS); + + int nIndex = 0; + + // Loop through and Add Components to Box + for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++) + { + // Make sure it's our internal type (set from constructor) + if(g_aComponents[nCnt]->GetType() == m_nType) + { + // Add the Title + nIndex = m_ctlCheck.AddString(g_aComponents[nCnt]->GetName()); + + // Save a Pointer to the component in the Listbox Data + m_ctlCheck.SetItemDataPtr(nIndex, (void*)g_aComponents[nCnt]); + + + // Check if Enabled + m_ctlCheck.SetCheck(nIndex, g_aComponents[nCnt]->IsEnabled()); + + } + + } + + + // Set the Proppage Rectangle to the Place Holder + ::GetWindowRect(GetDlgItem(IDC_PROPHOLDER), &m_rcPropPage); + ScreenToClient(&m_rcPropPage); + +// m_ctlTabs.Set + + + // Remove Place Holder Control + ::DestroyWindow(GetDlgItem(IDC_PROPHOLDER)); + + + // Select first item and display prop page + m_ctlCheck.SetCurSel(0); + SetCurrentComponent(); + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +////////////////////////////////////////////////////////////////// +// When the Finish Button on Wizard is pressed + +LRESULT CAdvancedPage::OnWizFinish(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) +{ + // If we have a PropPage then Save it + if(m_pCurPropPage != NULL) + m_pCurPropPage->Apply(); + + // Save Pos and Enabled Status + SaveChanges(); + + return 0; +} + +////////////////////////////////////////////////////////////////// +// Basically saves Position of component and Enabled Status + +HRESULT CAdvancedPage::SaveChanges() +{ + HRESULT hrRet = S_OK; + CComponentHolder* pComponent; + + // Loop though and save Pos and Enabled Status + for(int nCnt = 0; nCnt < m_ctlCheck.GetCount(); nCnt++) + { + // Get the Pointer from Listbox Data + pComponent = (CComponentHolder*)m_ctlCheck.GetItemDataPtr(nCnt); + + if(pComponent) + { + // Save to Component Data + pComponent->Enable(m_ctlCheck.GetCheck(nCnt) ? true : false); + pComponent->SetPos((nCnt * 2) + m_nType - 1); // Need special calculations because we have a number of type sharing same position list + } + else + // Bummed out and don't know why + hrRet = E_UNEXPECTED; + } + + return hrRet; +} + +////////////////////////////////////////////////////////////////// +// Make sure our buttons are properly enabled based on our +// position (passed in constructor) + +LRESULT CAdvancedPage::OnSetActive(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) +{ + DWORD dwButtons; + + // Depening on our Position in the Wizard + // Set the Buttons at the bottom on and off + + switch(m_nPos) + { + case WIZPAGE_FIRST: + dwButtons = PSWIZB_NEXT; + break; + case WIZPAGE_LAST: + dwButtons = PSWIZB_BACK | PSWIZB_FINISH; + break; + default: + dwButtons = PSWIZB_BACK | PSWIZB_NEXT; + break; + } + + m_pParentSheet->SetWizardButtons(dwButtons); + + return 0; +} + +////////////////////////////////////////////////////////////////// +// Have to save our changes when focus changes cause +// OnWizardFinish doesn't get called for each sheet + +LRESULT CAdvancedPage::OnWizBack(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) +{ + // If we have a PropPage then Save it + if(m_pCurPropPage != NULL) + m_pCurPropPage->Apply(); + + SaveChanges(); + + return 0; +} + +////////////////////////////////////////////////////////////////// +// Have to save our changes when focus changes cause +// OnWizardFinish doesn't get called for each sheet + +LRESULT CAdvancedPage::OnWizNext(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) +{ + // If we have a PropPage then Save it + if(m_pCurPropPage != NULL) + m_pCurPropPage->Apply(); + + SaveChanges(); + + return 0; +} + +LRESULT CAdvancedPage::OnHelp(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) +{ + WinHelp(NS_HELP_FILE, HELP_FINDER, 0); + return 1; +} + +////////////////////////////////////////////////////////////////// +// Shows the appropriate Property sheet for the current component +// in List box + +void CAdvancedPage::SetCurrentComponent() +{ + // Get the selection + int nCurSel = m_ctlCheck.GetCurSel(); + + if(nCurSel == LB_ERR) + return; + + // Get current selection + CComponentHolder* pComponent = (CComponentHolder*)m_ctlCheck.GetItemDataPtr(nCurSel); + + // Only change if a different component + if(pComponent == NULL || pComponent == m_pCurComponent) + return; + + m_ctlTabs.DeleteAllItems(); + + PropertyPageMap::iterator iterPages = m_pParentSheet->m_mapPages.lower_bound(pComponent); + PropertyPageMap::iterator endPages = m_pParentSheet->m_mapPages.upper_bound(pComponent); + for( ; iterPages != endPages && iterPages != m_pParentSheet->m_mapPages.end(); iterPages++) + { + string sTitle = iterPages->second->GetTitle(); + TCITEM tci; + tci.mask = TCIF_TEXT | TCIF_PARAM; + tci.pszText = sTitle.get_buffer(); + tci.iImage = -1; + tci.lParam = (LPARAM)iterPages->second; + + m_ctlTabs.InsertItem(m_ctlTabs.GetItemCount(), &tci); + } + + m_pCurComponent = pComponent; + SetCurrentPage(); +} + + +void CAdvancedPage::SetCurrentPage() +{ + // Get the selection + int nCurSel = m_ctlTabs.GetCurSel(); + + CPropPageHolder* pPropPage = NULL; + + if(nCurSel != -1) + { + + // Get current selection + TCITEM tci; + memset(&tci, 0, sizeof(TCITEM)); + tci.mask = TCIF_PARAM; + + m_ctlTabs.GetItem(nCurSel, &tci); + + pPropPage = (CPropPageHolder*)tci.lParam; + ASSERT(pPropPage); + } + + // Only change if a different component + if(pPropPage != NULL && pPropPage != m_pCurPropPage) + { + // If it's already created then just show it + if(pPropPage->IsActivated()) + { + pPropPage->Show(SW_SHOW); + } + // Otherwise Create + else + { + pPropPage->Create(m_hWnd, m_rcPropPage, true); + pPropPage->Show(SW_SHOW); + } + + } + + // Now Hide Old One (Hide after show to avoid flicker) + if(m_pCurPropPage != NULL && m_pCurPropPage != pPropPage) + { + m_pCurPropPage->Show(SW_HIDE); + + // Save Changes before going out + m_pCurPropPage->Apply(); + + } + + // Current Selection Update + m_pCurPropPage = pPropPage; +} + +LRESULT CAdvancedPage::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + // If we have a PropPage then Destroy it + if(m_pCurPropPage != NULL) + m_pCurPropPage->Destroy(); + + return 0; +} |