123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- #include "stdafx.h"
- #include "TCHAR.h"
- #include "InPlaceEdit.h"
- #include "GridCtrl.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- CInPlaceEdit::CInPlaceEdit(CWnd* pParent, CRect& rect, DWORD dwStyle, UINT nID,
- int nRow, int nColumn, CString sInitText,
- UINT nFirstChar)
- {
- m_sInitText = sInitText;
- m_nRow = nRow;
- m_nColumn = nColumn;
- m_nLastChar = 0;
- m_bExitOnArrows = (nFirstChar != VK_LBUTTON);
-
- m_Rect = rect;
-
- DWORD dwEditStyle = WS_BORDER|WS_CHILD|WS_VISIBLE| ES_AUTOHSCROLL
- | dwStyle;
- if (!Create(dwEditStyle, rect, pParent, nID)) return;
-
- SetFont(pParent->GetFont());
-
- SetWindowText(sInitText);
- SetFocus();
-
- switch (nFirstChar){
- case VK_LBUTTON:
- case VK_RETURN: SetSel((int)_tcslen(m_sInitText), -1); return;
- case VK_BACK: SetSel((int)_tcslen(m_sInitText), -1); break;
- case VK_TAB:
- case VK_DOWN:
- case VK_UP:
- case VK_RIGHT:
- case VK_LEFT:
- case VK_NEXT:
- case VK_PRIOR:
- case VK_HOME:
- case VK_SPACE:
- case VK_END: SetSel(0,-1); return;
- default: SetSel(0,-1);
- }
-
- SendMessage(WM_CHAR, nFirstChar);
- }
- CInPlaceEdit::~CInPlaceEdit()
- {
- }
- BEGIN_MESSAGE_MAP(CInPlaceEdit, CEdit)
-
- ON_WM_KILLFOCUS()
- ON_WM_CHAR()
- ON_WM_KEYDOWN()
- ON_WM_GETDLGCODE()
- ON_WM_CREATE()
-
- END_MESSAGE_MAP()
- void CInPlaceEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- if ((nChar == VK_PRIOR || nChar == VK_NEXT ||
- nChar == VK_DOWN || nChar == VK_UP ||
- nChar == VK_RIGHT || nChar == VK_LEFT) &&
- (m_bExitOnArrows || GetKeyState(VK_CONTROL) < 0))
- {
- m_nLastChar = nChar;
- GetParent()->SetFocus();
- return;
- }
-
- CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- void CInPlaceEdit::OnKillFocus(CWnd* pNewWnd)
- {
- CEdit::OnKillFocus(pNewWnd);
- EndEdit();
- }
- void CInPlaceEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- if (nChar == VK_TAB || nChar == VK_RETURN)
- {
- m_nLastChar = nChar;
- GetParent()->SetFocus();
- return;
- }
- if (nChar == VK_ESCAPE)
- {
- SetWindowText(m_sInitText);
- m_nLastChar = nChar;
- GetParent()->SetFocus();
- return;
- }
-
- CEdit::OnChar(nChar, nRepCnt, nFlags);
-
-
-
-
- CString str;
- GetWindowText( str );
-
- str += _T(" ");
-
- CWindowDC dc(this);
- CFont *pFontDC = dc.SelectObject(GetFont());
- CSize size = dc.GetTextExtent( str );
- dc.SelectObject( pFontDC );
-
-
- CRect ParentRect;
- GetParent()->GetClientRect( &ParentRect );
-
-
-
- if (size.cx > m_Rect.Width())
- {
- if( size.cx + m_Rect.left < ParentRect.right )
- m_Rect.right = m_Rect.left + size.cx;
- else
- m_Rect.right = ParentRect.right;
- MoveWindow( &m_Rect );
- }
- }
- UINT CInPlaceEdit::OnGetDlgCode()
- {
- return DLGC_WANTALLKEYS;
- }
- BOOL CInPlaceEdit::PreTranslateMessage(MSG* pMsg)
- {
-
- if (pMsg->message == WM_SYSCHAR)
- return TRUE;
-
- return CWnd::PreTranslateMessage(pMsg);
- }
- void CInPlaceEdit::PostNcDestroy()
- {
- CEdit::PostNcDestroy();
-
- delete this;
- }
- void CInPlaceEdit::EndEdit()
- {
- CString str;
- GetWindowText(str);
-
-
- GV_DISPINFO dispinfo;
-
- dispinfo.hdr.hwndFrom = GetSafeHwnd();
- dispinfo.hdr.idFrom = GetDlgCtrlID();
- dispinfo.hdr.code = GVN_ENDLABELEDIT;
-
- dispinfo.item.mask = LVIF_TEXT|LVIF_PARAM;
- dispinfo.item.row = m_nRow;
- dispinfo.item.col = m_nColumn;
- dispinfo.item.szText = str;
- dispinfo.item.lParam = (LPARAM) m_nLastChar;
-
- CWnd* pOwner = GetOwner();
- if (pOwner)
- pOwner->SendMessage(WM_NOTIFY, GetDlgCtrlID(), (LPARAM)&dispinfo );
-
-
- PostMessage(WM_CLOSE, 0, 0);
- }
|