-
Notifications
You must be signed in to change notification settings - Fork 1
/
ComboInListView.cpp
129 lines (109 loc) · 3.02 KB
/
ComboInListView.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
119
120
121
122
123
124
125
126
127
128
129
// ComboInListView.cpp : implementation file
//
// The code contained in this file is based on the original
// CInPlaceList from http://www.codeguru.com/listview
#include "stdafx.h"
#include "SuperGrid.h"
#include "ComboInListView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CComboInListView
CComboInListView::CComboInListView(int iItem, int iSubItem, CStringList *plstItems)
{
m_iItem = iItem;
m_iSubItem = iSubItem;
m_lstItems.AddTail(plstItems);
m_bVK_ESCAPE = 0;
}
CComboInListView::~CComboInListView()
{
}
BEGIN_MESSAGE_MAP(CComboInListView, CComboBox)
//{{AFX_MSG_MAP(CComboInListView)
ON_WM_CREATE()
ON_WM_KILLFOCUS()
ON_WM_CHAR()
ON_WM_NCDESTROY()
ON_CONTROL_REFLECT(CBN_CLOSEUP, OnCloseup)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//
int CComboInListView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CComboBox::OnCreate(lpCreateStruct) == -1)
return -1;
CFont* font = GetParent()->GetFont();
SetFont(font);
//add the items from CStringlist
POSITION pos = m_lstItems.GetHeadPosition();
while(pos != NULL)
AddString((LPCTSTR)(m_lstItems.GetNext(pos)));
SetFocus();
return 0;
}
BOOL CComboInListView::PreTranslateMessage(MSG* pMsg)
{
if( pMsg->message == WM_KEYDOWN )
{
if(pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)
{
::TranslateMessage(pMsg);
::DispatchMessage(pMsg);
return 1;
}
}
return CComboBox::PreTranslateMessage(pMsg);
}
void CComboInListView::OnKillFocus(CWnd* pNewWnd)
{
int nIndex = GetCurSel();
CComboBox::OnKillFocus(pNewWnd);
CString str;
GetWindowText(str);
// Send Notification to parent of ListView ctrl
LV_DISPINFO lvDispinfo;
lvDispinfo.hdr.hwndFrom = GetParent()->m_hWnd;
lvDispinfo.hdr.idFrom = GetDlgCtrlID();//that's us
lvDispinfo.hdr.code = LVN_ENDLABELEDIT;
lvDispinfo.item.mask = LVIF_TEXT | LVIF_PARAM;
lvDispinfo.item.iItem = m_iItem;
lvDispinfo.item.iSubItem = m_iSubItem;
lvDispinfo.item.pszText = m_bVK_ESCAPE ? NULL : LPTSTR((LPCTSTR)str);
lvDispinfo.item.cchTextMax = str.GetLength();
lvDispinfo.item.lParam = GetItemData(GetCurSel());
if(nIndex!=CB_ERR)
GetParent()->GetParent()->SendMessage(WM_NOTIFY, GetParent()->GetDlgCtrlID(), (LPARAM)&lvDispinfo);
PostMessage(WM_CLOSE);
}
//need to catch the VK_ESCAPE for the notification msg
void CComboInListView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(nChar == VK_ESCAPE || nChar == VK_RETURN)
{
if( nChar == VK_ESCAPE)
m_bVK_ESCAPE = 1;
GetParent()->SetFocus();
return;
}
CComboBox::OnChar(nChar, nRepCnt, nFlags);
}
//doing this hence we are "modaless" and need to clean up me self
void CComboInListView::OnNcDestroy()
{
CComboBox::OnNcDestroy();
delete this;
}
void CComboInListView::OnCloseup()
{
GetParent()->SetFocus();
}
void CComboInListView::OnSize(UINT nType, int cx, int cy)
{
CComboBox::OnSize(nType, cx, cy);
}