-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCInPlaceList.cpp
executable file
·118 lines (94 loc) · 2.52 KB
/
CInPlaceList.cpp
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
#include "stdafx.h"
#include "InPlaceList.h"
/////////////////////////////////////////////////////////////////////////////
// CInPlaceList
CInPlaceList::CInPlaceList(int iItem, int iSubItem, CStringList *plstItems, int nSel)
{
m_iItem = iItem;
m_iSubItem = iSubItem;
m_lstItems.AddTail( plstItems );
m_nSel = nSel;
m_bESC = FALSE;
}
CInPlaceList::~CInPlaceList()
{
}
BEGIN_MESSAGE_MAP(CInPlaceList, CComboBox)
//{{AFX_MSG_MAP(CInPlaceList)
ON_WM_CREATE()
ON_WM_KILLFOCUS()
ON_WM_CHAR()
ON_WM_NCDESTROY()
ON_CONTROL_REFLECT(CBN_CLOSEUP, OnCloseup)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInPlaceList message handlers
int CInPlaceList::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CComboBox::OnCreate(lpCreateStruct) == -1)
return -1;
// Set the proper font
CFont* font = GetParent()->GetFont();
SetFont(font);
for( POSITION pos = m_lstItems.GetHeadPosition(); pos != NULL; )
{
AddString( (LPCTSTR) (m_lstItems.GetNext( pos )) );
}
SetCurSel( m_nSel );
SetFocus();
return 0;
}
BOOL CInPlaceList::PreTranslateMessage(MSG* pMsg)
{
if( pMsg->message == WM_KEYDOWN )
{
if(pMsg->wParam == VK_RETURN
|| pMsg->wParam == VK_ESCAPE
)
{
::TranslateMessage(pMsg);
::DispatchMessage(pMsg);
return TRUE; // DO NOT process further
}
}
return CComboBox::PreTranslateMessage(pMsg);
}
void CInPlaceList::OnKillFocus(CWnd* pNewWnd)
{
CComboBox::OnKillFocus(pNewWnd);
CString str;
GetWindowText(str);
// Send Notification to parent of ListView ctrl
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();
GetParent()->GetParent()->SendMessage( WM_NOTIFY, GetParent()->GetDlgCtrlID(), (LPARAM)&dispinfo );
PostMessage( WM_CLOSE );
}
void CInPlaceList::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if( nChar == VK_ESCAPE || nChar == VK_RETURN)
{
if( nChar == VK_ESCAPE )
m_bESC = TRUE;
GetParent()->SetFocus();
return;
}
CComboBox::OnChar(nChar, nRepCnt, nFlags);
}
void CInPlaceList::OnNcDestroy()
{
CComboBox::OnNcDestroy();
delete this;
}
void CInPlaceList::OnCloseup()
{
GetParent()->SetFocus();
}