1 // PropTreeItemCheck.cpp : implementation file
3 // Copyright (C) 1998-2001 Scott Ramsay
5 // http://www.gonavi.com
7 // This material is provided "as is", with absolutely no warranty expressed
8 // or implied. Any use is at your own risk.
10 // Permission to use or copy this software for any purpose is hereby granted
11 // without fee, provided the above notices are retained on all copies.
12 // Permission to modify the code and to distribute modified code is granted,
13 // provided the above notices are retained, and a notice that the code was
14 // modified is included with the above copyright notice.
16 // If you use this code, drop me an email. I'd like to know if you find the code
20 #include "../../../idlib/precompiled.h"
24 #include "PropTreeItemCheck.h"
29 static char THIS_FILE[] = __FILE__;
32 #define CHECK_BOX_SIZE 14
34 /////////////////////////////////////////////////////////////////////////////
37 CPropTreeItemCheck::CPropTreeItemCheck()
42 CPropTreeItemCheck::~CPropTreeItemCheck()
47 BEGIN_MESSAGE_MAP(CPropTreeItemCheck, CButton)
48 //{{AFX_MSG_MAP(CPropTreeItemCheck)
50 ON_CONTROL_REFLECT(BN_KILLFOCUS, OnBnKillfocus)
51 ON_CONTROL_REFLECT(BN_CLICKED, OnBnClicked)
54 /////////////////////////////////////////////////////////////////////////////
55 // CPropTreeItemCheck message handlers
57 void CPropTreeItemCheck::DrawAttribute(CDC* pDC, const RECT& rc)
59 ASSERT(m_pProp!=NULL);
61 // verify the window has been created
62 if (!IsWindow(m_hWnd))
64 TRACE0("CPropTreeItemCombo::DrawAttribute() - The window has not been created\n");
68 checkRect.left = m_rc.left;
69 checkRect.top = m_rc.top + ((m_rc.bottom - m_rc.top)/2)-CHECK_BOX_SIZE/2;
70 checkRect.right = checkRect.left + CHECK_BOX_SIZE;
71 checkRect.bottom = checkRect.top + CHECK_BOX_SIZE;
74 pDC->DrawFrameControl(&checkRect, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_FLAT |(checkState ? DFCS_CHECKED : 0));
77 void CPropTreeItemCheck::SetCheckState(BOOL state)
81 SetCheck(checkState ? BST_CHECKED : BST_UNCHECKED);
85 LPARAM CPropTreeItemCheck::GetItemValue()
87 return (LPARAM)GetCheckState();
91 void CPropTreeItemCheck::SetItemValue(LPARAM lParam)
93 SetCheckState((BOOL)lParam);
97 void CPropTreeItemCheck::OnMove()
100 SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), SWP_NOZORDER|SWP_NOACTIVATE);
104 void CPropTreeItemCheck::OnRefresh()
109 void CPropTreeItemCheck::OnCommit()
115 void CPropTreeItemCheck::OnActivate(int activateType, CPoint point)
117 if(activateType == CPropTreeItem::ACTIVATE_TYPE_MOUSE) {
118 //Check where the user clicked
119 if(point.x < m_rc.left + CHECK_BOX_SIZE) {
120 SetCheckState(!GetCheckState());
123 SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), SWP_NOZORDER|SWP_SHOWWINDOW);
127 SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), SWP_NOZORDER|SWP_SHOWWINDOW);
133 bool CPropTreeItemCheck::CreateCheckBox() {
134 ASSERT(m_pProp!=NULL);
136 if (IsWindow(m_hWnd))
139 DWORD dwStyle = (WS_CHILD|BS_CHECKBOX|BS_NOTIFY|BS_FLAT );
141 if (!Create(NULL, dwStyle, CRect(0,0,0,0), m_pProp->GetCtrlParent(), GetCtrlID()))
143 TRACE0("CPropTreeItemCombo::CreateComboBox() - failed to create combo box\n");
150 void CPropTreeItemCheck::OnBnKillfocus()
155 void CPropTreeItemCheck::OnBnClicked()
157 int state = GetCheck();
159 SetCheckState(GetCheck() == BST_CHECKED ? FALSE : TRUE);