doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PropTreeItemCombo.cpp
Go to the documentation of this file.
1 // PropTreeItemCombo.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 "../../../sys/win32/rc/proptree_Resource.h"
25 
26 #include "PropTreeItemCombo.h"
27 
28 #ifdef _DEBUG
29 #define new DEBUG_NEW
30 #undef THIS_FILE
31 static char THIS_FILE[] = __FILE__;
32 #endif
33 
34 #define DROPDOWN_HEIGHT 100
35 
37 // CPropTreeItemCombo
38 
40  m_lComboData(0),
41  m_nDropHeight(DROPDOWN_HEIGHT)
42 {
43 }
44 
46 {
47 }
48 
49 
50 BEGIN_MESSAGE_MAP(CPropTreeItemCombo, CComboBox)
51  //{{AFX_MSG_MAP(CPropTreeItemCombo)
52  ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange)
53  ON_CONTROL_REFLECT(CBN_KILLFOCUS, OnKillfocus)
54  //}}AFX_MSG_MAP
55 END_MESSAGE_MAP()
56 
58 // CPropTreeItemCombo message handlers
59 
60 void CPropTreeItemCombo::DrawAttribute(CDC* pDC, const RECT& rc)
61 {
62  ASSERT(m_pProp!=NULL);
63 
64  // verify the window has been created
65  if (!IsWindow(m_hWnd))
66  {
67  TRACE0("CPropTreeItemCombo::DrawAttribute() - The window has not been created\n");
68  return;
69  }
70 
71  pDC->SelectObject(IsReadOnly() ? m_pProp->GetNormalFont() : m_pProp->GetBoldFont());
72  pDC->SetTextColor(RGB(0,0,0));
73  pDC->SetBkMode(TRANSPARENT);
74 
75  CRect r = rc;
76  CString s;
77  LONG idx;
78 
79  if ((idx = GetCurSel())!=CB_ERR)
80  GetLBText(idx, s);
81  else
82  s = _T("");
83 
84  pDC->DrawText(s, r, DT_SINGLELINE|DT_VCENTER);
85 }
86 
87 
89 {
90  return m_lComboData;
91 }
92 
93 
95 {
96  m_lComboData = lParam;
97  OnRefresh();
98 }
99 
100 
102 {
103  if (IsWindow(m_hWnd) && IsWindowVisible())
104  SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width() + 1, m_rc.Height(), SWP_NOZORDER|SWP_SHOWWINDOW);
105 }
106 
107 
109 {
111 
112  if (idx!=CB_ERR)
113  SetCurSel(idx);
114 }
115 
116 
118 {
119  LONG idx;
120 
121  // store combo box item data
122  if ((idx = GetCurSel())==CB_ERR)
123  m_lComboData = 0;
124  else
125  m_lComboData = (LPARAM)GetItemData(idx);
126 
127  ShowWindow(SW_HIDE);
128 }
129 
130 
131 void CPropTreeItemCombo::OnActivate(int activateType, CPoint point)
132 {
133  // activate the combo box
134  SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width() + 1, m_rc.Height() + m_nDropHeight, SWP_NOZORDER|SWP_SHOWWINDOW);
135  SetFocus();
136 
137  if (GetCount())
138  ShowDropDown(TRUE);
139 }
140 
141 
143 {
144  ASSERT(m_pProp!=NULL);
145 
146  if (IsWindow(m_hWnd))
147  DestroyWindow();
148 
149  // force as not visible child window
150  dwStyle = (WS_CHILD|WS_VSCROLL|dwStyle) & ~WS_VISIBLE;
151 
152  if (!Create(dwStyle, CRect(0,0,0,0), m_pProp->GetCtrlParent(), GetCtrlID()))
153  {
154  TRACE0("CPropTreeItemCombo::CreateComboBox() - failed to create combo box\n");
155  return FALSE;
156  }
157 
158  SendMessage(WM_SETFONT, (WPARAM)m_pProp->GetNormalFont()->m_hObject);
159 
160  return TRUE;
161 }
162 
163 
165 {
166  ASSERT(m_pProp!=NULL);
167 
168  if (IsWindow(m_hWnd))
169  DestroyWindow();
170 
171  // force as a non-visible child window
172  DWORD dwStyle = WS_CHILD|WS_VSCROLL|CBS_SORT|CBS_DROPDOWNLIST;
173 
174  if (!Create(dwStyle, CRect(0,0,0,0), m_pProp->GetCtrlParent(), GetCtrlID()))
175  {
176  TRACE0("CPropTreeItemCombo::CreateComboBoxBool() - failed to create combo box\n");
177  return FALSE;
178  }
179 
180  SendMessage(WM_SETFONT, (WPARAM)m_pProp->GetNormalFont()->m_hObject);
181 
182  // file the combo box
183  LONG idx;
184  CString s;
185 
186  s.LoadString(IDS_TRUE);
187  idx = AddString(s);
188  SetItemData(idx, TRUE);
189 
190  s.LoadString(IDS_FALSE);
191  idx = AddString(s);
192  SetItemData(idx, FALSE);
193 
194  return TRUE;
195 }
196 
197 
199 {
200  LONG idx;
201 
202  for (idx = 0; idx < GetCount(); idx++)
203  {
204  if (GetItemData(idx)==(DWORD)lParam)
205  return idx;
206  }
207 
208  return CB_ERR;
209 }
210 
211 
213 {
214  CommitChanges();
215 }
216 
217 
219 {
220  CommitChanges();
221 }
222 
223 
225 {
226  m_nDropHeight = nDropHeight;
227 }
228 
229 
231 {
232  return m_nDropHeight;
233 }
afx_msg void OnSelchange()
#define IDS_FALSE
static CFont * GetNormalFont()
Definition: PropTree.cpp:272
CPropTreeItem LPARAM
Definition: PropTree.h:70
#define const
Definition: getdate.c:251
#define DROPDOWN_HEIGHT
virtual void SetItemValue(LPARAM lParam)
DWORD
Definition: win_qgl.cpp:61
#define IDS_TRUE
virtual void OnActivate(int activateType, CPoint point)
GLdouble s
Definition: glext.h:2935
afx_msg void OnKillfocus()
#define BOOL
Definition: mprintf.c:71
void CommitChanges()
void SetDropDownHeight(LONG nDropHeight)
#define NULL
Definition: Lib.h:88
CPropTree * m_pProp
Definition: PropTreeItem.h:147
BOOL CreateComboBox(DWORD dwStyle=WS_CHILD|WS_VSCROLL|CBS_SORT|CBS_DROPDOWNLIST)
long LONG
GLdouble GLdouble GLdouble r
Definition: glext.h:2951
LONG FindCBData(LPARAM lParam)
CWnd * GetCtrlParent()
Definition: PropTree.cpp:180
#define FALSE
Definition: mprintf.c:70
virtual void OnRefresh()
#define TRUE
Definition: mprintf.c:69
virtual LPARAM GetItemValue()