doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PropTreeItemCheck.cpp
Go to the documentation of this file.
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 "../../../idlib/precompiled.h"
21 #pragma hdrstop
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 
35 // CPropTreeItemCheck
36 
38 {
39  checkState = 0;
40 }
41 
43 {
44 }
45 
46 
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 
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 
78  {
79  checkState = state;
80 
81  SetCheck(checkState ? BST_CHECKED : BST_UNCHECKED);
82  }
83 
84 
86 {
87  return (LPARAM)GetCheckState();
88 }
89 
90 
92 {
93  SetCheckState((BOOL)lParam);
94 }
95 
96 
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 
105 {
106 }
107 
108 
110 {
111  ShowWindow(SW_HIDE);
112 }
113 
114 
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) {
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 
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 
151 {
152  CommitChanges();
153 }
154 
156 {
157  int state = GetCheck();
158 
159  SetCheckState(GetCheck() == BST_CHECKED ? FALSE : TRUE);
160  CommitChanges();
161 }
virtual void OnRefresh()
virtual LPARAM GetItemValue()
afx_msg void OnBnKillfocus()
#define const
Definition: getdate.c:251
DWORD
Definition: win_qgl.cpp:61
afx_msg void OnBnClicked()
#define BOOL
Definition: mprintf.c:71
virtual void SetItemValue(LPARAM lParam)
void CommitChanges()
#define NULL
Definition: Lib.h:88
CPropTree * m_pProp
Definition: PropTreeItem.h:147
virtual void OnActivate(int activateType, CPoint point)
CWnd * GetCtrlParent()
Definition: PropTree.cpp:180
#define FALSE
Definition: mprintf.c:70
#define TRUE
Definition: mprintf.c:69
void SetCheckState(BOOL state)
#define CHECK_BOX_SIZE