📄 bcgppropertysheet.cpp
字号:
//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This is a part of the BCGControlBar Library
// Copyright (C) 1998-2000 BCGSoft Ltd.
// All rights reserved.
//
// This source code can be used, distributed or modified
// only under terms and conditions
// of the accompanying license agreement.
//*******************************************************************************
// BCGPPropertySheet.cpp : implementation file
//
#include "stdafx.h"
#include "bcgcbpro.h"
#include "BCGPPropertyPage.h"
#include "BCGPInit.h"
#include "BCGPPropertySheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const int idTree = 101;
const int idTab = 102;
/////////////////////////////////////////////////////////////////////////////
// CBCGPPropSheetPane
BOOL CBCGPPropSheetPane::OnSendCommand (const CBCGPToolbarButton* pButton)
{
ASSERT_VALID (this);
ASSERT_VALID (m_pParent);
CWaitCursor wait;
m_pParent->SetActivePage (ButtonToIndex (pButton));
return TRUE;
}
//****************************************************************************************
void CBCGPPropSheetPane::EnsureVisible (int iButton)
{
ASSERT_VALID (this);
CBCGPToolbarButton* pButton = GetButton (iButton);
ASSERT_VALID (pButton);
CRect rectButton = pButton->Rect ();
CRect rectWork;
GetClientRect (rectWork);
if (rectButton.Height () >= rectWork.Height ())
{
// Work area is too small, nothing to do
return;
}
if (rectButton.top >= rectWork.top && rectButton.bottom <= rectWork.bottom)
{
// Already visible
return;
}
if (rectButton.top < rectWork.top)
{
while (pButton->Rect ().top < rectWork.top)
{
int iScrollOffset = m_iScrollOffset;
ScrollUp ();
if (iScrollOffset == m_iScrollOffset)
{
break;
}
}
}
else
{
while (pButton->Rect ().bottom > rectWork.bottom)
{
int iScrollOffset = m_iScrollOffset;
ScrollDown ();
if (iScrollOffset == m_iScrollOffset)
{
break;
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CBCGPPropSheetTab
CBCGPPropSheetTab::CBCGPPropSheetTab ()
{
m_bIsDlgControl = TRUE;
}
//*********************************************************************************
BOOL CBCGPPropSheetTab::SetActiveTab (int iTab)
{
ASSERT_VALID (this);
ASSERT_VALID (m_pParent);
CWaitCursor wait;
if (m_pParent->GetActiveIndex () != iTab)
{
if (!m_pParent->SetActivePage (iTab))
{
return FALSE;
}
}
CBCGPTabWnd::SetActiveTab (iTab);
CRect rectWndArea = m_rectWndArea;
MapWindowPoints (m_pParent, rectWndArea);
CPropertyPage* pPage = m_pParent->GetPage (iTab);
if (pPage != NULL)
{
pPage->SetWindowPos (NULL, rectWndArea.left, rectWndArea.top,
rectWndArea.Width (), rectWndArea.Height (),
SWP_NOACTIVATE | SWP_NOZORDER);
}
return TRUE;
}
//////////////////////////////////////////////////////////////////////////////
// CBCGPPropSheetCategory
IMPLEMENT_DYNAMIC(CBCGPPropSheetCategory, CObject)
CBCGPPropSheetCategory::CBCGPPropSheetCategory (LPCTSTR lpszName, int nIcon,
int nSelectedIcon,
const CBCGPPropSheetCategory* pParentCategory) :
m_strName (lpszName),
m_nIcon (nIcon),
m_nSelectedIcon (nSelectedIcon),
m_pParentCategory (pParentCategory)
{
m_hTreeItem = NULL;
if (pParentCategory != NULL)
{
ASSERT_VALID (pParentCategory);
((CBCGPPropSheetCategory*)pParentCategory)->m_lstSubCategories.AddTail (this);
}
}
CBCGPPropSheetCategory::~CBCGPPropSheetCategory()
{
while (!m_lstSubCategories.IsEmpty ())
{
delete m_lstSubCategories.RemoveHead ();
}
}
/////////////////////////////////////////////////////////////////////////////
// CBCGPPropertySheet
#define UM_AFTERACTIVATEPAGE (WM_USER + 1001)
IMPLEMENT_DYNAMIC(CBCGPPropertySheet, CPropertySheet)
#pragma warning (disable : 4355)
CBCGPPropertySheet::CBCGPPropertySheet() :
m_Impl (*this)
{
CommonInit ();
}
CBCGPPropertySheet::CBCGPPropertySheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage),
m_Impl (*this)
{
CommonInit ();
}
CBCGPPropertySheet::CBCGPPropertySheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage),
m_Impl (*this)
{
CommonInit ();
}
#pragma warning (default : 4355)
void CBCGPPropertySheet::SetLook (PropSheetLook look, int nNavBarWidth)
{
ASSERT (GetSafeHwnd () == NULL);
m_look = look;
m_nBarWidth = nNavBarWidth;
if (m_look != PropSheetLook_Tabs)
{
EnableStackedTabs (FALSE);
}
}
CBCGPPropertySheet::~CBCGPPropertySheet()
{
while (!m_lstTreeCategories.IsEmpty ())
{
delete m_lstTreeCategories.RemoveHead ();
}
}
void CBCGPPropertySheet::CommonInit ()
{
m_nBarWidth = 100;
m_nActivePage = -1;
m_look = PropSheetLook_Tabs;
m_bIsInSelectTree = FALSE;
BCGPInit ();
}
BEGIN_MESSAGE_MAP(CBCGPPropertySheet, CPropertySheet)
//{{AFX_MSG_MAP(CBCGPPropertySheet)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_MESSAGE(UM_AFTERACTIVATEPAGE, OnAfterActivatePage)
ON_NOTIFY(TVN_SELCHANGEDA, idTree, OnSelectTree)
ON_NOTIFY(TVN_SELCHANGEDW, idTree, OnSelectTree)
ON_NOTIFY(TVN_GETDISPINFOA, idTree, OnGetDispInfo)
ON_NOTIFY(TVN_GETDISPINFOW, idTree, OnGetDispInfo)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBCGPPropertySheet message handlers
void CBCGPPropertySheet::AddPage(CPropertyPage* pPage)
{
CPropertySheet::AddPage (pPage);
if (GetSafeHwnd () == NULL || m_look == PropSheetLook_Tabs)
{
return;
}
CTabCtrl* pTab = GetTabControl ();
ASSERT_VALID (pTab);
InternalAddPage (pTab->GetItemCount () - 1);
}
//****************************************************************************************
void CBCGPPropertySheet::InternalAddPage (int nTab)
{
CTabCtrl* pTab = GetTabControl ();
ASSERT_VALID (pTab);
TCHAR szTab [256];
TCITEM item;
item.mask = TCIF_TEXT;
item.cchTextMax = 255;
item.pszText = szTab;
pTab->GetItem (nTab, &item);
if (m_wndPane1.GetSafeHwnd () != NULL)
{
m_wndPane1.AddButton (m_Icons.ExtractIcon (nTab), szTab, 0);
}
if (m_wndTree.GetSafeHwnd () != NULL)
{
CBCGPPropertyPage* pPage = DYNAMIC_DOWNCAST (CBCGPPropertyPage, GetPage (nTab));
if (pPage == NULL)
{
ASSERT (FALSE);
return;
}
HTREEITEM hParent = NULL;
if (pPage->m_pCategory != NULL)
{
ASSERT_VALID (pPage->m_pCategory);
hParent = pPage->m_pCategory->m_hTreeItem;
}
HTREEITEM hTreeItem = m_wndTree.InsertItem (szTab,
I_IMAGECALLBACK, I_IMAGECALLBACK, hParent);
m_wndTree.SetItemData (hTreeItem, (DWORD) pPage);
pPage->m_hTreeNode = hTreeItem;
}
if (m_wndTab.GetSafeHwnd () != NULL)
{
CBCGPPropertyPage* pPage = DYNAMIC_DOWNCAST (CBCGPPropertyPage, GetPage (nTab));
if (pPage == NULL)
{
ASSERT (FALSE);
return;
}
UINT uiImage = m_Icons.GetSafeHandle () == NULL ? (UINT)-1 : nTab;
m_wndTab.AddTab (pPage, szTab, uiImage, FALSE);
}
}
//****************************************************************************************
void CBCGPPropertySheet::RemovePage(CPropertyPage* pPage)
{
int nPage = GetPageIndex (pPage);
ASSERT (nPage >= 0);
CPropertySheet::RemovePage (pPage);
if (m_wndPane1.GetSafeHwnd () != NULL)
{
m_wndPane1.RemoveButton (nPage);
}
if (m_wndTree.GetSafeHwnd () != NULL)
{
ASSERT (FALSE);
}
}
//****************************************************************************************
void CBCGPPropertySheet::RemovePage(int nPage)
{
CPropertySheet::RemovePage (nPage);
if (m_wndPane1.GetSafeHwnd () != NULL)
{
m_wndPane1.RemoveButton (nPage);
}
if (m_wndTree.GetSafeHwnd () != NULL)
{
ASSERT (FALSE);
}
}
//****************************************************************************************
CBCGPPropSheetCategory* CBCGPPropertySheet::AddTreeCategory (LPCTSTR lpszLabel,
int nIconNum, int nSelectedIconNum, const CBCGPPropSheetCategory* pParentCategory)
{
ASSERT_VALID (this);
ASSERT (m_look == PropSheetLook_Tree);
if (nSelectedIconNum == -1)
{
nSelectedIconNum = nIconNum;
}
CBCGPPropSheetCategory* pCategory = new CBCGPPropSheetCategory (
lpszLabel, nIconNum, nSelectedIconNum,
pParentCategory);
if (m_wndTree.GetSafeHwnd () != NULL)
{
HTREEITEM hParent = NULL;
if (pParentCategory != NULL)
{
hParent = pParentCategory->m_hTreeItem;
}
pCategory->m_hTreeItem = m_wndTree.InsertItem (
lpszLabel, I_IMAGECALLBACK, I_IMAGECALLBACK, hParent);
m_wndTree.SetItemData (pCategory->m_hTreeItem, (DWORD) pCategory);
}
if (pParentCategory == NULL)
{
m_lstTreeCategories.AddTail (pCategory);
}
return pCategory;
}
//***************************************************************************************
void CBCGPPropertySheet::AddPageToTree (CBCGPPropSheetCategory* pCategory,
CBCGPPropertyPage* pPage, int nIconNum,
int nSelIconNum)
{
ASSERT_VALID (this);
ASSERT_VALID (pPage);
ASSERT (m_look == PropSheetLook_Tree);
if (pCategory != NULL)
{
ASSERT_VALID (pCategory);
pCategory->m_lstPages.AddTail (pPage);
}
pPage->m_pCategory = pCategory;
pPage->m_nIcon = nIconNum;
pPage->m_nSelIconNum = nSelIconNum;
CPropertySheet::AddPage (pPage);
if (GetSafeHwnd () != NULL)
{
CTabCtrl* pTab = GetTabControl ();
ASSERT_VALID (pTab);
InternalAddPage (pTab->GetItemCount () - 1);
}
}
//****************************************************************************************
BOOL CBCGPPropertySheet::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();
CWnd* pWndNavigator = InitNavigationControl ();
if (m_wndTab.GetSafeHwnd () != NULL)
{
CTabCtrl* pTab = GetTabControl ();
ASSERT_VALID (pTab);
CRect rectTab;
pTab->GetWindowRect (rectTab);
ScreenToClient (rectTab);
rectTab.InflateRect (2, 0);
m_wndTab.MoveWindow (rectTab);
pTab->ModifyStyle (WS_TABSTOP, 0);
pTab->ShowWindow (SW_HIDE);
if (pTab->GetItemCount () > 0)
{
m_wndTab.SetActiveTab (0);
}
return bResult;
}
if (pWndNavigator != NULL)
{
CTabCtrl* pTab = GetTabControl ();
ASSERT_VALID (pTab);
pTab->ModifyStyle (WS_TABSTOP, 0);
CRect rectTabItem;
pTab->GetItemRect (0, rectTabItem);
pTab->MapWindowPoints (this, &rectTabItem);
const int nVertMargin = 5;
const int nHorzMargin = 5;
const int nTabsHeight = rectTabItem.Height () + nVertMargin;
CRect rectClient;
GetClientRect (rectClient);
SetWindowPos (NULL, -1, -1, rectClient.Width () + m_nBarWidth,
rectClient.Height () - nTabsHeight + 3 * nVertMargin,
SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
GetClientRect (rectClient);
pTab->MoveWindow (m_nBarWidth, -nTabsHeight, rectClient.right, rectClient.bottom - 2 * nVertMargin);
CRect rectTab;
pTab->GetWindowRect (rectTab);
ScreenToClient (rectTab);
CRect rectNavigator = rectClient;
rectNavigator.right = rectNavigator.left + m_nBarWidth;
rectNavigator.bottom = rectTab.bottom;
rectNavigator.DeflateRect (1, 1);
pWndNavigator->SetWindowPos (&wndTop,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -