Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
EGPropertyGridItemEdit.cpp
Package: solidgraph_sources.zip [view]
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 4k
Category:
Graph program
Development Platform:
Visual C++
- // PropTreeItemEdit.cpp : implementation file
- //
- // Copyright (C) 1998-2001 Scott Ramsay
- // sramsay@gonavi.com
- // http://www.gonavi.com
- //
- // This material is provided "as is", with absolutely no warranty expressed
- // or implied. Any use is at your own risk.
- //
- // Permission to use or copy this software for any purpose is hereby granted
- // without fee, provided the above notices are retained on all copies.
- // Permission to modify the code and to distribute modified code is granted,
- // provided the above notices are retained, and a notice that the code was
- // modified is included with the above copyright notice.
- //
- // If you use this code, drop me an email. I'd like to know if you find the code
- // useful.
- #include "stdafx.h"
- #include "EGPropertyGrid.h"
- #include "EGPropertyGridItemEdit.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CEGPropertyGridItemEdit
- CEGPropertyGridItemEdit::CEGPropertyGridItemEdit() :
- m_sEdit(_T("")),
- m_nFormat(ValueFormatText),
- m_bPassword(FALSE),
- m_fValue(0.0f)
- {
- }
- CEGPropertyGridItemEdit::~CEGPropertyGridItemEdit()
- {
- }
- BEGIN_MESSAGE_MAP(CEGPropertyGridItemEdit, CEdit)
- //{{AFX_MSG_MAP(CEGPropertyGridItemEdit)
- ON_WM_GETDLGCODE()
- ON_WM_KEYDOWN()
- ON_CONTROL_REFLECT(EN_KILLFOCUS, OnKillfocus)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CEGPropertyGridItemEdit message handlers
- void CEGPropertyGridItemEdit::DrawAttribute(CDC* pDC, const RECT& rc)
- {
- ASSERT(m_pProp!=NULL);
- pDC->SelectObject(IsReadOnly() ? m_pProp->GetNormalFont() : m_pProp->GetBoldFont());
- pDC->SetTextColor(RGB(0,0,0));
- pDC->SetBkMode(TRANSPARENT);
- CRect r = rc;
- TCHAR ch;
- // can't use GetPasswordChar(), because window may not be created yet
- ch = (m_bPassword) ? '*' : '';
- if (ch)
- {
- CString s;
- s = m_sEdit;
- for (LONG i=0; i<s.GetLength();i++)
- s.SetAt(i, ch);
- pDC->DrawText(s, r, DT_SINGLELINE|DT_VCENTER);
- }
- else
- {
- pDC->DrawText(m_sEdit, r, DT_SINGLELINE|DT_VCENTER);
- }
- }
- void CEGPropertyGridItemEdit::SetAsPassword(BOOL bPassword)
- {
- m_bPassword = bPassword;
- }
- void CEGPropertyGridItemEdit::SetValueFormat(ValueFormat nFormat)
- {
- m_nFormat = nFormat;
- }
- LPARAM CEGPropertyGridItemEdit::GetItemValue()
- {
- switch (m_nFormat)
- {
- case ValueFormatNumber:
- return _ttoi(m_sEdit);
- case ValueFormatFloatPointer:
- _stscanf(m_sEdit, _T("%f"), &m_fValue);
- return (LPARAM)&m_fValue;
- }
- return (LPARAM)(LPCTSTR)m_sEdit;
- }
- void CEGPropertyGridItemEdit::SetItemValue(LPARAM lParam)
- {
- switch (m_nFormat)
- {
- case ValueFormatNumber:
- m_sEdit.Format(_T("%d"), lParam);
- return;
- case ValueFormatFloatPointer:
- {
- TCHAR tmp[MAX_PATH];
- m_fValue = *(float*)lParam;
- _stprintf(tmp, _T("%f"), m_fValue);
- m_sEdit = tmp;
- }
- return;
- }
- if (lParam==0L)
- {
- TRACE0("CEGPropertyGridItemEdit::SetItemValue - Invalid lParam valuen");
- return;
- }
- m_sEdit = (LPCTSTR)lParam;
- }
- void CEGPropertyGridItemEdit::OnMove()
- {
- if (IsWindow(m_hWnd))
- SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), SWP_NOZORDER|SWP_NOACTIVATE);
- }
- void CEGPropertyGridItemEdit::OnRefresh()
- {
- if (IsWindow(m_hWnd))
- SetWindowText(m_sEdit);
- }
- void CEGPropertyGridItemEdit::OnCommit()
- {
- // hide edit control
- ShowWindow(SW_HIDE);
- // store edit text for GetItemValue
- GetWindowText(m_sEdit);
- }
- void CEGPropertyGridItemEdit::OnActivate()
- {
- // Check if the edit control needs creation
- if (!IsWindow(m_hWnd))
- {
- DWORD dwStyle;
- dwStyle = WS_CHILD|ES_AUTOHSCROLL;
- Create(dwStyle, m_rc, m_pProp->GetCtrlParent(), GetCtrlID());
- SendMessage(WM_SETFONT, (WPARAM)m_pProp->GetNormalFont()->m_hObject);
- }
- SetPasswordChar((TCHAR)(m_bPassword ? '*' : 0));
- SetWindowText(m_sEdit);
- SetSel(0, -1);
- SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), SWP_NOZORDER|SWP_SHOWWINDOW);
- SetFocus();
- }
- UINT CEGPropertyGridItemEdit::OnGetDlgCode()
- {
- return CEdit::OnGetDlgCode()|DLGC_WANTALLKEYS;
- }
- void CEGPropertyGridItemEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- if (nChar==VK_RETURN)
- CommitChanges();
- CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- void CEGPropertyGridItemEdit::OnKillfocus()
- {
- CommitChanges();
- }