Repository navigation
Expand file tree
/
Copy pathInPlaceEdit.cpp
More file actions
183 lines (163 loc) · 5.09 KB
/
Copy pathInPlaceEdit.cpp
File metadata and controls
183 lines (163 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "StdAfx.h"
#include "InPlaceEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Construction
CInPlaceEdit::CInPlaceEdit(int iItem, int iSubItem, CString sInitText, DWORD dwWM_APP_LISTCTRL_IPEDIT ):m_sInitText( sInitText )
{
m_iItem = iItem;
m_iSubItem = iSubItem;
m_dwWM_APP_LISTCTRL_IPEDIT = dwWM_APP_LISTCTRL_IPEDIT;
m_bESC = FALSE;
}
CInPlaceEdit::~CInPlaceEdit(){}
BEGIN_MESSAGE_MAP(CInPlaceEdit, CEdit)
//{{AFX_MSG_MAP(CInPlaceEdit)
ON_WM_KILLFOCUS()
ON_WM_NCDESTROY()
ON_WM_CHAR()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//CInPlaceEdit message handlers
// Translate window messages before they are dispatched to the TranslateMessage and DispatchMessage Windows functions.
BOOL
CInPlaceEdit::PreTranslateMessage ( MSG *pMsg )
{
if ( pMsg->message == WM_KEYDOWN )
{
if ( pMsg->wParam == VK_RETURN ||
pMsg->wParam == VK_DELETE ||
pMsg->wParam == VK_ESCAPE ||
GetKeyState(VK_CONTROL) )
{
::TranslateMessage(pMsg);
::DispatchMessage(pMsg);
return TRUE;
// DO NOT process further
}
}
return CEdit::PreTranslateMessage(pMsg);
}
// Called immediately before losing the input focus
void
CInPlaceEdit::OnKillFocus ( CWnd *pNewWnd )
{
CEdit::OnKillFocus(pNewWnd);
CString str;
GetWindowText(str);
DestroyWindow();
}
// Called when nonclient area is being destroyed
void
CInPlaceEdit::OnNcDestroy()
{
CEdit::OnNcDestroy();
delete this;
}
// Called for nonsystem character keystrokes
void
CInPlaceEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// Abandon editing
// NOTES: Changes still locked in this instance, no need
// to reset
if ( nChar == VK_ESCAPE /*|| nChar == VK_RETURN*/ )
{
if ( nChar == VK_ESCAPE )
m_bESC = TRUE;
GetParent()->SetFocus();
return;
}
// Termination of field edit
// NOTES: Perform single complete notification at end of edit
// : Build and send LV_DISPINFO structure
if ( nChar == VK_RETURN )
{
CString str; GetWindowText ( str );
LV_DISPINFO dispinfo;
dispinfo.hdr.hwndFrom = GetParent()->m_hWnd;
dispinfo.hdr.idFrom = GetDlgCtrlID();
dispinfo.hdr.code = LVN_ENDLABELEDIT;
dispinfo.item.mask = LVIF_TEXT;
dispinfo.item.iItem = m_iItem;
dispinfo.item.iSubItem = m_iSubItem;
dispinfo.item.pszText = m_bESC ? NULL : LPTSTR((LPCTSTR)str);
dispinfo.item.cchTextMax = str.GetLength();
// Send this Notification to parent of ListView ctrl
CWnd *pWndViewAttachmentsDlg = GetParent()->GetParent();
if ( pWndViewAttachmentsDlg )
{
ASSERT(m_dwWM_APP_LISTCTRL_IPEDIT);
pWndViewAttachmentsDlg->SendMessage( m_dwWM_APP_LISTCTRL_IPEDIT,
GetParent()->GetDlgCtrlID(),
(LPARAM)&dispinfo );
}
GetParent()->SetFocus();
return;
}
// Delegate
CEdit::OnChar(nChar, nRepCnt, nFlags);
// Progressive inplace edit housekeeping
CString str; GetWindowText( str );
CWindowDC dc(this);
CFont *pFont = GetParent()->GetFont();
CFont *pFontDC = dc.SelectObject( pFont );
CSize size = dc.GetTextExtent( str );
dc.SelectObject( pFontDC );
size.cx += 5;
// Get the client rectangle
CRect rect, parentrect;
GetClientRect( &rect );
GetParent()->GetClientRect( &parentrect );
// Transform rectangle to parent coordinates
ClientToScreen( &rect );
GetParent()->ScreenToClient( &rect );
// Check whether control needs resizing and if sufficient space to grow
if( size.cx > rect.Width() )
{
if( size.cx + rect.left < parentrect.right )
rect.right = rect.left + size.cx;
else
rect.right = parentrect.right;
MoveWindow( &rect );
}
// Construct list control item data
//LV_DISPINFO dispinfo;
//dispinfo.hdr.hwndFrom = GetParent()->m_hWnd;
//dispinfo.hdr.idFrom = GetDlgCtrlID();
//dispinfo.hdr.code = LVN_ENDLABELEDIT;
//dispinfo.item.mask = LVIF_TEXT;
//dispinfo.item.iItem = m_iItem;
//dispinfo.item.iSubItem = m_iSubItem;
//dispinfo.item.pszText = m_bESC ? NULL : LPTSTR((LPCTSTR)str);
//dispinfo.item.cchTextMax = str.GetLength();
// // Send this Notification to parent of ListView ctrl
// CWnd *pWndViewAttachmentsDlg = GetParent()->GetParent();
//if ( pWndViewAttachmentsDlg )
//{
// ASSERT(m_dwWM_APP_LISTCTRL_IPEDIT);
// pWndViewAttachmentsDlg->SendMessage( m_dwWM_APP_LISTCTRL_IPEDIT,
// GetParent()->GetDlgCtrlID(),
// (LPARAM)&dispinfo );
//}
}
// Called when application requests the Windows window be created by calling the Create/CreateEx member function.
int
CInPlaceEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CEdit::OnCreate(lpCreateStruct) == -1)
{
return -1;
}
// Set the proper font
CFont* font = GetParent()->GetFont();
SetFont( font );
SetWindowText( m_sInitText );
SetFocus();
SetSel( 0, -1 );
return 0;
}