/*
Module : TreeOptionsCtrl.cpp
Purpose: Implementation for an MFC class to implement a tree options control
similiar to the advanced tab as seen on the "Internet options" dialog in
Internet Explorer 4 and later
Created: PJN / 31-03-1999
History: PJN / 21-04-1999 Added full support for enabling / disabling all the item types
PJN / 05-10-1999 Made class more self contained by internally managing the image list
PJN / 07-10-1999 1. Added support for including combo boxes aswell as edit boxes into the
edit control.
2. Added support for customizing the image list to use
PJN / 29-02-2000 Removed a VC 6 level 4 warning
PJN / 03-04-2000 Added support for navigation into and out of the combo boxes and edit controls
inside the control
PJN / 10-05-2000 1. Fixed a bug where the text was not being transferred to the control when the
in inplace combo or edit box is active and the tree control gets destroyed.
2. Added support for having check box items as children of other check box items
3. Setting the check box state of a parent now also sets the check box state
for all child box children.
4. Setting the check box state afects the check box state of the parent if that
parent is also a check box.
PJN / 30-05-2000 Code now uses ON_NOTIFY_REFLECT_EX instead of ON_NOTIFY_REFLECT. This allows
derived classes to handle the reflected messages also.
PJN / 03-07-2000 Now includes support for edit boxes with accompanying spin controls
Copyright (c) 1999 - 2000 by PJ Naughter.
All rights reserved.
*/
//////////////// Includes ////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "TreeOptionsCtrl.h"
//////////////// Macros / Locals /////////////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const UINT TREE_OPTIONS_COMBOBOX_ID = 100;
const UINT TREE_OPTIONS_EDITBOX_ID = 100;
const UINT TREE_OPTIONS_SPINCTRL_ID = 100;
struct _TreeOptionsItemData
{
CRuntimeClass* m_pRuntimeClass1;
CRuntimeClass* m_pRuntimeClass2;
_TreeOptionsItemData()
{
m_pRuntimeClass1 = NULL;
m_pRuntimeClass2 = NULL;
}
};
//////////////// Implementation //////////////////////////////////////
IMPLEMENT_DYNAMIC(CTreeOptionsCtrl, CTreeCtrl)
BEGIN_MESSAGE_MAP(CTreeOptionsCtrl, CTreeCtrl)
//{{AFX_MSG_MAP(CTreeOptionsCtrl)
ON_WM_LBUTTONDOWN()
ON_WM_CHAR()
ON_WM_DESTROY()
ON_WM_VSCROLL()
ON_WM_HSCROLL()
ON_WM_KEYDOWN()
ON_WM_KILLFOCUS()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
ON_NOTIFY_REFLECT_EX(NM_CLICK, OnClick)
ON_NOTIFY_REFLECT_EX(TVN_SELCHANGED, OnSelchanged)
ON_NOTIFY_REFLECT_EX(TVN_DELETEITEM, OnDeleteItem)
END_MESSAGE_MAP()
BOOL CTreeOptionsCtrl::OnDeleteItem(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
*pResult = 0;
//Free up the memory we had allocated in the item data (if needed)
_TreeOptionsItemData* pItemData = (_TreeOptionsItemData*) GetItemData(pNMTreeView->itemOld.hItem);
if (pItemData)
delete pItemData;
return FALSE;
}
void CTreeOptionsCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags )
{
if (nChar==VK_RIGHT)
{
HTREEITEM hItem = GetSelectedItem();
if (GetItemData(hItem) && m_hControlItem != NULL)
{
// if we have a children and VK_RIGHT -> Focus on it !
_TreeOptionsItemData* pItemData = (_TreeOptionsItemData*) GetItemData(hItem);
if (pItemData->m_pRuntimeClass1->IsDerivedFrom(RUNTIME_CLASS(CTreeOptionsCombo)))
{
if (m_pCombo->IsWindowVisible())
m_pCombo->SetFocus();
}
else
{
if (pItemData->m_pRuntimeClass1->IsDerivedFrom(RUNTIME_CLASS(CTreeOptionsEdit)))
{
if (m_pEdit->IsWindowVisible())
m_pEdit->SetFocus();
}
else
{
//Pass on to the parent since we didn't handle it
CTreeCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}
}
}
else
{
//Pass on to the parent since we didn't handle it
CTreeCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}
}
else
//Pass on to the parent since we didn't handle it
CTreeCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}
CTreeOptionsCtrl::CTreeOptionsCtrl()
{
m_pCombo = NULL;
m_pEdit = NULL;
m_pSpin = NULL;
m_nilID = IDB_TREE_CTRL_OPTIONS;
m_hControlItem = NULL;
}
void CTreeOptionsCtrl::HandleCheckBox(HTREEITEM hItem, BOOL bCheck)
{
//Turn of redraw to Q all the changes we're going to make here
SetRedraw(FALSE);
//Toggle the state
VERIFY(SetCheckBox(hItem, !bCheck));
//If the item has children, then iterate through them and for all items
//which are check boxes set their state to be the same as the parent
HTREEITEM hChild = GetNextItem(hItem, TVGN_CHILD);
while (hChild)
{
if (IsCheckBox(hChild))
SetCheckBox(hChild, !bCheck);
//Move on to the next item
hChild = GetNextItem(hChild, TVGN_NEXT);
}
//Get the parent item and if it is a checkbox, then iterate through
//all its children and if all the checkboxes are checked, then also
//automatically check the parent. If no checkboxes are checked, then
//also automatically uncheck the parent.
HTREEITEM hParent = GetNextItem(hItem, TVGN_PARENT);
if (hParent && IsCheckBox(hParent))
{
BOOL bNoCheckBoxesChecked = TRUE;
BOOL bAllCheckBoxesChecked = TRUE;
hChild = GetNextItem(hParent, TVGN_CHILD);
while (hChild)
{
if (IsCheckBox(hChild))
{
BOOL bThisChecked;
VERIFY(GetCheckBox(hChild, bThisChecked));
bNoCheckBoxesChecked = bNoCheckBoxesChecked && !bThisChecked;
bAllCheckBoxesChecked = bAllCheckBoxesChecked && bThisChecked;
}
//Move on to the next item
hChild = GetNextItem(hChild, TVGN_NEXT);
}
if (bNoCheckBoxesChecked)
SetCheckBox(hParent, FALSE);
else if (bAllCheckBoxesChecked)
{
SetCheckBox(hParent, FALSE); //gets rid of the semi state
SetCheckBox(hParent, TRUE);
}
else
{
BOOL bEnable;
VERIFY(GetCheckBoxEnable(hParent, bEnable));
SetEnabledSemiCheckBox(hParent, bEnable);
}
}
//Reset the redraw flag
SetRedraw(TRUE);
}
void CTreeOptionsCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
UINT uFlags=0;
HTREEITEM hItem = HitTest(point, &uFlags);
//If the mouse was over the label, icon or to the left or right of the item ?
if ((uFlags & TVHT_ONITEM) || (uFlags & TVHT_ONITEMINDENT) || (uFlags & TVHT_ONITEMRIGHT))
{
if (IsCheckBox(hItem))
{
BOOL bEnable;
VERIFY(GetCheckBoxEnable(hItem, bEnable));
if (bEnable)
{
//Turn of redraw to Q all the changes we're going to make here
SetRedraw(FALSE);
//Toggle the state of check items
BOOL bCheck;
VERIFY(GetCheckBox(hItem, bCheck));
HandleCheckBox(hItem, bCheck);
}
}
else if (IsRadioButton(hItem))
{
BOOL bEnable;
VERIFY(GetRadioButtonEnable(hItem, bEnable));
if (bEnable)
{
//Check the radio button if not already checked
BOOL bCheck;
VERIFY(GetRadioButton(hItem, bCheck));
if (!bCheck)
VERIFY(SetRadioButton(hItem));
}
}
//Pass on to the parent now that we that we have done our stuff
CTreeCtrl::OnLButtonDown(nFlags, point);
}
else
{
//Pass on to the parent since we didn't handle it
CTreeCtrl::OnLButtonDown(nFlags, point);
}
}
void CTreeOptio
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
treeoptions.zip (24个子文件)
StdAfx.h 928B
APP.H 343B
DowComboBox.cpp 851B
TestTreeOptions.dsp 7KB
RESOURCE.H 1KB
appDlg.cpp 7KB
RES
tree_ctrl.bmp 2KB
APP.ICO 1KB
APP.RC2 395B
DemoEditBox.cpp 582B
TreeOptionsCtrl.gif 9KB
DemoEditBox.h 317B
DemoSpinCtrl.h 321B
TreeOptionsCtrl.cpp 36KB
DowComboBox.h 336B
TestTreeOptions.rc 6KB
TreeOptionsCtrl.h 7KB
TreeOptionsCtrl.htm 39KB
StdAfx.cpp 201B
appDlg.h 1KB
APP.CPP 540B
TestTreeOptions.dsw 555B
TestTreeOptions.aps 22KB
DemoSpinCtrl.cpp 595B
共 24 条
- 1
资源评论
普通网友
- 粉丝: 882
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功