doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PropTreeItemEdit.cpp
Go to the documentation of this file.
1 // PropTreeItemEdit.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 "PropTreeItemEdit.h"
25 
26 #ifdef _DEBUG
27 #define new DEBUG_NEW
28 #undef THIS_FILE
29 static char THIS_FILE[] = __FILE__;
30 #endif
31 
33 // CPropTreeItemEdit
34 
36  m_sEdit(_T("")),
37  m_nFormat(ValueFormatText),
38  m_bPassword(FALSE),
39  m_fValue(0.0f)
40 {
41 }
42 
44 {
45 }
46 
47 
48 BEGIN_MESSAGE_MAP(CPropTreeItemEdit, CEdit)
49  //{{AFX_MSG_MAP(CPropTreeItemEdit)
50  ON_WM_GETDLGCODE()
51  ON_WM_KEYDOWN()
52  ON_CONTROL_REFLECT(EN_KILLFOCUS, OnKillfocus)
53  //}}AFX_MSG_MAP
54 END_MESSAGE_MAP()
55 
57 // CPropTreeItemEdit message handlers
58 
59 void CPropTreeItemEdit::DrawAttribute(CDC* pDC, const RECT& rc)
60 {
61  ASSERT(m_pProp!=NULL);
62 
63  pDC->SelectObject(IsReadOnly() ? m_pProp->GetNormalFont() : m_pProp->GetBoldFont());
64  pDC->SetTextColor(RGB(0,0,0));
65  pDC->SetBkMode(TRANSPARENT);
66 
67  CRect r = rc;
68 
69  TCHAR ch;
70 
71  // can't use GetPasswordChar(), because window may not be created yet
72  ch = (m_bPassword) ? '*' : '\0';
73 
74  if (ch)
75  {
76  CString s;
77 
78  s = m_sEdit;
79  for (LONG i=0; i<s.GetLength();i++)
80  s.SetAt(i, ch);
81 
82  pDC->DrawText(s, r, DT_SINGLELINE|DT_VCENTER);
83  }
84  else
85  {
86  pDC->DrawText(m_sEdit, r, DT_SINGLELINE|DT_VCENTER);
87  }
88 }
89 
90 
91 
93 {
94  m_bPassword = bPassword;
95 }
96 
97 
99 {
100  m_nFormat = nFormat;
101 }
102 
103 
105 {
106  switch (m_nFormat)
107  {
108  case ValueFormatNumber:
109  return _ttoi(m_sEdit);
110 
112  _stscanf(m_sEdit, _T("%f"), &m_fValue);
113  return (LPARAM)&m_fValue;
114  }
115 
116  return (LPARAM)(LPCTSTR)m_sEdit;
117 }
118 
119 
121 {
122  switch (m_nFormat)
123  {
124  case ValueFormatNumber:
125  m_sEdit.Format(_T("%d"), lParam);
126  return;
127 
129  {
130  TCHAR tmp[MAX_PATH];
131  m_fValue = *(float*)lParam;
132  _stprintf(tmp, _T("%f"), m_fValue);
133  m_sEdit = tmp;
134  }
135  return;
136  }
137 
138  if (lParam==0L)
139  {
140  TRACE0("CPropTreeItemEdit::SetItemValue - Invalid lParam value\n");
141  return;
142  }
143 
144  m_sEdit = (LPCTSTR)lParam;
145 }
146 
147 
149 {
150  if (IsWindow(m_hWnd))
151  SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), SWP_NOZORDER|SWP_NOACTIVATE);
152 }
153 
154 
156 {
157  if (IsWindow(m_hWnd))
158  SetWindowText(m_sEdit);
159 }
160 
161 
163 {
164  // hide edit control
165  ShowWindow(SW_HIDE);
166 
167  // store edit text for GetItemValue
168  GetWindowText(m_sEdit);
169 }
170 
171 
172 void CPropTreeItemEdit::OnActivate(int activateType, CPoint point)
173 {
174  // Check if the edit control needs creation
175  if (!IsWindow(m_hWnd))
176  {
177  DWORD dwStyle;
178 
179  dwStyle = WS_CHILD|ES_AUTOHSCROLL;
180  Create(dwStyle, m_rc, m_pProp->GetCtrlParent(), GetCtrlID());
181  }
182 
183  SendMessage(WM_SETFONT, (WPARAM)m_pProp->GetNormalFont()->m_hObject);
184 
185  SetPasswordChar((TCHAR)(m_bPassword ? '*' : 0));
186  SetWindowText(m_sEdit);
187  SetSel(0, -1);
188 
189  SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), SWP_NOZORDER|SWP_SHOWWINDOW);
190  SetFocus();
191 }
192 
193 
195 {
196  return CEdit::OnGetDlgCode()|DLGC_WANTALLKEYS;
197 }
198 
199 
200 void CPropTreeItemEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
201 {
202  if (nChar==VK_RETURN)
203  CommitChanges();
204 
205  CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
206 }
207 
208 
210 {
211  CommitChanges();
212 }
virtual void OnRefresh()
static CFont * GetNormalFont()
Definition: PropTree.cpp:272
virtual void OnCommit()
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
#define const
Definition: getdate.c:251
DWORD
Definition: win_qgl.cpp:61
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
GLdouble s
Definition: glext.h:2935
int i
Definition: process.py:33
#define BOOL
Definition: mprintf.c:71
void CommitChanges()
virtual LPARAM GetItemValue()
void SetValueFormat(ValueFormat nFormat)
#define NULL
Definition: Lib.h:88
CPropTree * m_pProp
Definition: PropTreeItem.h:147
virtual void SetItemValue(LPARAM lParam)
Definition: eax4.h:1413
afx_msg void OnKillfocus()
long LONG
GLdouble GLdouble GLdouble r
Definition: glext.h:2951
virtual ~CPropTreeItemEdit()
tuple f
Definition: idal.py:89
CWnd * GetCtrlParent()
Definition: PropTree.cpp:180
afx_msg UINT OnGetDlgCode()
#define FALSE
Definition: mprintf.c:70
ValueFormat m_nFormat
void SetAsPassword(BOOL bPassword)
virtual void OnMove()
virtual void OnActivate(int activateType, CPoint point)