forked from sabrogden/Ditto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComboBoxSearch.cpp
128 lines (113 loc) · 2.5 KB
/
ComboBoxSearch.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
// ComboBoxSearch.cpp : implementation file
//
#include "stdafx.h"
#include "CP_Main.h"
#include "ComboBoxSearch.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CComboBoxSearch
CComboBoxSearch::CComboBoxSearch()
{
m_bShowingDropDown = FALSE;
}
CComboBoxSearch::~CComboBoxSearch()
{
}
BEGIN_MESSAGE_MAP(CComboBoxSearch, CComboBox)
//{{AFX_MSG_MAP(CComboBoxSearch)
ON_CONTROL_REFLECT(CBN_DROPDOWN, OnDropdown)
ON_CONTROL_REFLECT(CBN_SELENDCANCEL, OnSelendcancel)
ON_CONTROL_REFLECT(CBN_SELENDOK, OnSelendok)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CComboBoxSearch message handlers
void CComboBoxSearch::OnDropdown()
{
m_bShowingDropDown = TRUE;
SetCurSel(0);
}
void CComboBoxSearch::OnSelendcancel()
{
m_bShowingDropDown = FALSE;
}
void CComboBoxSearch::OnSelendok()
{
m_bShowingDropDown = FALSE;
}
BOOL CComboBoxSearch::PreTranslateMessage(MSG* pMsg)
{
switch(pMsg->message)
{
case WM_KEYDOWN:
{
if(pMsg->wParam == VK_RETURN && m_bShowingDropDown == FALSE)
{
CWnd *pWnd = GetParent();
if(pWnd)
{
if(GetCurSel() == -1)
{
//Add the text to the combo
CString csText;
GetWindowText(csText);
int nRet = InsertString(0, csText);
SetCurSel(nRet);
}
if(g_Opt.m_bFindAsYouType)
{
pWnd->SendMessage(NM_SELECT, 0, 0);
}
else
{
//Send a message to the parent to refill the lb from the search
pWnd->PostMessage(CB_SEARCH, 0, 0);
}
}
return TRUE;
}
else if (pMsg->wParam == VK_DOWN ||
pMsg->wParam == VK_UP ||
pMsg->wParam == VK_F3)
{
if(g_Opt.m_bFindAsYouType)
{
CWnd *pWnd = GetParent();
if(pWnd)
{
pWnd->SendMessage(CB_UPDOWN, pMsg->wParam, pMsg->lParam);
return TRUE;
}
}
// if(!m_bShowingDropDown)
// {
// ShowDropDown();
// return TRUE;
// }
}
else if(pMsg->wParam == 'C' &&
GetKeyState(VK_CONTROL) & 0x8000 ||
pMsg->wParam == 'X' &&
GetKeyState(VK_CONTROL) & 0x8000 ||
pMsg->wParam == VK_DELETE)
{
LONG lEditSel = GetEditSel();
if(LOWORD(lEditSel) == HIWORD(lEditSel))
{
CWnd *pWnd = GetParent();
if(pWnd)
{
pWnd->SendMessage(CB_UPDOWN, pMsg->wParam, pMsg->lParam);
return TRUE;
}
}
}
break;
}
}
return CComboBox::PreTranslateMessage(pMsg);
}