doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PropTreeItemEditButton.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 "PropTreeItemEditButton.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 BUTTON_SIZE 17
33 
35 // CPropTreeItemEditButton
36 
38 m_sEdit(_T("")),
39 m_nFormat(ValueFormatText),
40 m_bPassword(FALSE),
41 m_fValue(0.0f)
42 {
43  mouseDown = false;
44 }
45 
47 {
48 }
49 
50 
51 BEGIN_MESSAGE_MAP(CPropTreeItemEditButton, CEdit)
52  //{{AFX_MSG_MAP(CPropTreeItemEditButton)
53  ON_WM_GETDLGCODE()
54  ON_WM_KEYDOWN()
55  ON_CONTROL_REFLECT(EN_KILLFOCUS, OnKillfocus)
56  //}}AFX_MSG_MAP
57 END_MESSAGE_MAP()
58 
60 // CPropTreeItemEditButton message handlers
61 
62 LONG CPropTreeItemEditButton::DrawItem( CDC* pDC, const RECT& rc, LONG x, LONG y )
63 {
64  CSize textSize;
65  CRect textRect;
66  LONG nTotal = 0;
67 
68  nTotal = CPropTreeItemEdit::DrawItem( pDC, rc, x, y );
69 
70  textSize = pDC->GetOutputTextExtent( buttonText );
71 
72  buttonRect.left = m_rc.right - ( textSize.cx + 12 + 4);
73  buttonRect.top = m_rc.top + ((m_rc.bottom - m_rc.top)/2)-BUTTON_SIZE/2;
74  buttonRect.right = buttonRect.left + textSize.cx + 12;
75  buttonRect.bottom = buttonRect.top + BUTTON_SIZE;
76 
77  UINT buttonStyle;
78 
79  if ( (m_dwState & TreeItemChecked) ) {
80  buttonStyle = DFCS_BUTTONPUSH | DFCS_PUSHED;
81  } else {
82  buttonStyle = DFCS_BUTTONPUSH;
83  }
84  pDC->DrawFrameControl(&buttonRect, DFC_BUTTON, buttonStyle );
85 
86  textRect = buttonRect;
87  textRect.left += 4;
88  textRect.right -= 8;
89  pDC->DrawText( buttonText, textRect, DT_SINGLELINE|DT_VCENTER );
90 
91  //Adjust hit test rect to acount for window scrolling
92  hitTestRect = buttonRect;
93  hitTestRect.OffsetRect(0, m_pProp->GetOrigin().y);
94 
95  return nTotal;
96 }
97 
98 void CPropTreeItemEditButton::DrawAttribute(CDC* pDC, const RECT& rc)
99 {
100  ASSERT(m_pProp!=NULL);
101 
102  pDC->SelectObject(IsReadOnly() ? m_pProp->GetNormalFont() : m_pProp->GetBoldFont());
103  pDC->SetTextColor(RGB(0,0,0));
104  pDC->SetBkMode(TRANSPARENT);
105 
106  CRect r = rc;
107  r.right = buttonRect.left - 5;
108 
109  TCHAR ch;
110 
111  // can't use GetPasswordChar(), because window may not be created yet
112  ch = (m_bPassword) ? '*' : '\0';
113 
114  if (ch)
115  {
116  CString s;
117 
118  s = m_sEdit;
119  for (LONG i=0; i<s.GetLength();i++)
120  s.SetAt(i, ch);
121 
122  pDC->DrawText(s, r, DT_SINGLELINE|DT_VCENTER);
123  }
124  else
125  {
126  pDC->DrawText(m_sEdit, r, DT_SINGLELINE|DT_VCENTER);
127  }
128 }
129 
130 
131 
133 {
134  m_bPassword = bPassword;
135 }
136 
137 
139 {
140  m_nFormat = nFormat;
141 }
142 
143 
145 {
146  switch (m_nFormat)
147  {
148  case ValueFormatNumber:
149  return _ttoi(m_sEdit);
150 
152  _stscanf(m_sEdit, _T("%f"), &m_fValue);
153  return (LPARAM)&m_fValue;
154  }
155 
156  return (LPARAM)(LPCTSTR)m_sEdit;
157 }
158 
159 
161 {
162  switch (m_nFormat)
163  {
164  case ValueFormatNumber:
165  m_sEdit.Format(_T("%d"), lParam);
166  return;
167 
169  {
170  TCHAR tmp[MAX_PATH];
171  m_fValue = *(float*)lParam;
172  _stprintf(tmp, _T("%f"), m_fValue);
173  m_sEdit = tmp;
174  }
175  return;
176  }
177 
178  if (lParam==0L)
179  {
180  TRACE0("CPropTreeItemEditButton::SetItemValue - Invalid lParam value\n");
181  return;
182  }
183 
184  m_sEdit = (LPCTSTR)lParam;
185 }
186 
187 
189 {
190  if (IsWindow(m_hWnd))
191  SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), SWP_NOZORDER|SWP_NOACTIVATE);
192 }
193 
194 
196 {
197  if (IsWindow(m_hWnd))
198  SetWindowText(m_sEdit);
199 }
200 
201 
203 {
204  // hide edit control
205  ShowWindow(SW_HIDE);
206 
207  // store edit text for GetItemValue
208  GetWindowText(m_sEdit);
209 }
210 
211 
212 void CPropTreeItemEditButton::OnActivate(int activateType, CPoint point)
213 {
214  // Check if the edit control needs creation
215  if (!IsWindow(m_hWnd))
216  {
217  DWORD dwStyle;
218 
219  dwStyle = WS_CHILD|ES_AUTOHSCROLL;
220  Create(dwStyle, m_rc, m_pProp->GetCtrlParent(), GetCtrlID());
221  SendMessage(WM_SETFONT, (WPARAM)m_pProp->GetNormalFont()->m_hObject);
222  }
223 
224  SetPasswordChar((TCHAR)(m_bPassword ? '*' : 0));
225  SetWindowText(m_sEdit);
226  SetSel(0, -1);
227 
228  SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width() - buttonRect.Width() - 5, m_rc.Height(), SWP_NOZORDER|SWP_SHOWWINDOW);
229  SetFocus();
230 }
231 
232 
234 {
235  return CEdit::OnGetDlgCode()|DLGC_WANTALLKEYS;
236 }
237 
238 
239 void CPropTreeItemEditButton::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
240 {
241  if (nChar==VK_RETURN)
242  CommitChanges();
243 
244  CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
245 }
246 
247 
249 {
250  CommitChanges();
251 }
252 
254  return hitTestRect.PtInRect( pt );
255 }
256 
258  buttonText = text;
259 }
static CFont * GetNormalFont()
Definition: PropTree.cpp:272
#define BUTTON_SIZE
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
virtual LONG DrawItem(CDC *pDC, const RECT &rc, LONG x, LONG y)
#define const
Definition: getdate.c:251
DWORD
Definition: win_qgl.cpp:61
GLenum GLint GLint y
Definition: glext.h:2849
virtual void DrawAttribute(CDC *pDC, const RECT &rc)
static CFont * GetBoldFont()
Definition: PropTree.cpp:278
GLdouble s
Definition: glext.h:2935
GLenum GLint x
Definition: glext.h:2849
int i
Definition: process.py:33
#define BOOL
Definition: mprintf.c:71
virtual BOOL HitButton(const POINT &pt)
void CommitChanges()
#define NULL
Definition: Lib.h:88
CPropTree * m_pProp
Definition: PropTreeItem.h:147
Definition: eax4.h:1413
long LONG
GLdouble GLdouble GLdouble r
Definition: glext.h:2951
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
void SetValueFormat(ValueFormat nFormat)
tuple f
Definition: idal.py:89
CWnd * GetCtrlParent()
Definition: PropTree.cpp:180
void SetAsPassword(BOOL bPassword)
#define FALSE
Definition: mprintf.c:70
virtual void OnActivate(int activateType, CPoint point)
virtual void SetItemValue(LPARAM lParam)