1 // PropTreeItemCheck.cpp : implementation file
2 //
3 // Copyright (C) 1998-2001 Scott Ramsay
4 // sramsay@gonavi.com
5 // http://www.gonavi.com
6 //
7 // This material is provided "as is", with absolutely no warranty expressed
8 // or implied. Any use is at your own risk.
9 //
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.
15 //
16 // If you use this code, drop me an email. I'd like to know if you find the code
17 // useful.
18
19 //#include "stdafx.h"
20 #include "tools/edit_gui_common.h"
21
22
23 #include "proptree.h"
24 #include "PropTreeItemCheck.h"
25
26 #ifdef _DEBUG
27 #define new DEBUG_NEW
28 #undef THIS_FILE
29 static char THIS_FILE[] = __FILE__;
30 #endif
31
32 #define CHECK_BOX_SIZE 14
33
34 /////////////////////////////////////////////////////////////////////////////
35 // CPropTreeItemCheck
36
CPropTreeItemCheck()37 CPropTreeItemCheck::CPropTreeItemCheck()
38 {
39 checkState = 0;
40 }
41
~CPropTreeItemCheck()42 CPropTreeItemCheck::~CPropTreeItemCheck()
43 {
44 }
45
46
BEGIN_MESSAGE_MAP(CPropTreeItemCheck,CButton)47 BEGIN_MESSAGE_MAP(CPropTreeItemCheck, CButton)
48 //{{AFX_MSG_MAP(CPropTreeItemCheck)
49 //}}AFX_MSG_MAP
50 ON_CONTROL_REFLECT(BN_KILLFOCUS, OnBnKillfocus)
51 ON_CONTROL_REFLECT(BN_CLICKED, OnBnClicked)
52 END_MESSAGE_MAP()
53
54 /////////////////////////////////////////////////////////////////////////////
55 // CPropTreeItemCheck message handlers
56
57 void CPropTreeItemCheck::DrawAttribute(CDC* pDC, const RECT& rc)
58 {
59 ASSERT(m_pProp!=NULL);
60
61 // verify the window has been created
62 if (!IsWindow(m_hWnd))
63 {
64 TRACE0("CPropTreeItemCombo::DrawAttribute() - The window has not been created\n");
65 return;
66 }
67
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;
72
73 if(!m_bActivated)
74 pDC->DrawFrameControl(&checkRect, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_FLAT |(checkState ? DFCS_CHECKED : 0));
75 }
76
SetCheckState(BOOL state)77 void CPropTreeItemCheck::SetCheckState(BOOL state)
78 {
79 checkState = state;
80
81 SetCheck(checkState ? BST_CHECKED : BST_UNCHECKED);
82 }
83
84
GetItemValue()85 LPARAM CPropTreeItemCheck::GetItemValue()
86 {
87 return (LPARAM)GetCheckState();
88 }
89
90
SetItemValue(LPARAM lParam)91 void CPropTreeItemCheck::SetItemValue(LPARAM lParam)
92 {
93 SetCheckState((BOOL)lParam);
94 }
95
96
OnMove()97 void CPropTreeItemCheck::OnMove()
98 {
99 if (IsWindow(m_hWnd))
100 SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), SWP_NOZORDER|SWP_NOACTIVATE);
101 }
102
103
OnRefresh()104 void CPropTreeItemCheck::OnRefresh()
105 {
106 }
107
108
OnCommit()109 void CPropTreeItemCheck::OnCommit()
110 {
111 ShowWindow(SW_HIDE);
112 }
113
114
OnActivate(int activateType,CPoint point)115 void CPropTreeItemCheck::OnActivate(int activateType, CPoint point)
116 {
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());
121 CommitChanges();
122 } else {
123 SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), SWP_NOZORDER|SWP_SHOWWINDOW);
124 SetFocus();
125 }
126 } else {
127 SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), SWP_NOZORDER|SWP_SHOWWINDOW);
128 SetFocus();
129 }
130 }
131
132
CreateCheckBox()133 bool CPropTreeItemCheck::CreateCheckBox() {
134 ASSERT(m_pProp!=NULL);
135
136 if (IsWindow(m_hWnd))
137 DestroyWindow();
138
139 DWORD dwStyle = (WS_CHILD|BS_CHECKBOX|BS_NOTIFY|BS_FLAT );
140
141 if (!Create(NULL, dwStyle, CRect(0,0,0,0), m_pProp->GetCtrlParent(), GetCtrlID()))
142 {
143 TRACE0("CPropTreeItemCombo::CreateComboBox() - failed to create combo box\n");
144 return FALSE;
145 }
146
147 return TRUE;
148 }
149
OnBnKillfocus()150 void CPropTreeItemCheck::OnBnKillfocus()
151 {
152 CommitChanges();
153 }
154
OnBnClicked()155 void CPropTreeItemCheck::OnBnClicked()
156 {
157 int state = GetCheck();
158
159 SetCheckState(GetCheck() == BST_CHECKED ? FALSE : TRUE);
160 CommitChanges();
161 }
162