forked from ddehilster/visualtext3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListCtrlF.cpp
127 lines (107 loc) · 2.87 KB
/
ListCtrlF.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
/*******************************************************************************
Copyright (c) 1999-2010 by Text Analysis International, Inc.
All rights reserved.
*******************************************************************************/
// ListCtrlF.cpp : implementation file
//
#include "stdafx.h"
#include "kb.h"
#include "Utils.h"
#include "VisualText.h"
#include "ListCtrlF.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CListCtrlF
CListCtrlF::CListCtrlF()
{
}
CListCtrlF::~CListCtrlF()
{
}
BOOL CListCtrlF::AutoLoad(UINT nID, CWnd* pParent, UINT nIDCR, int nCharCol)
{
if (!SubclassDlgItem(nID, pParent))
return false;
m_nIDCR = nIDCR;
m_nCharCol = nCharCol;
return true;
}
BEGIN_MESSAGE_MAP(CListCtrlF, CListCtrl)
//{{AFX_MSG_MAP(CListCtrlF)
ON_WM_CHAR()
ON_WM_KEYDOWN()
ON_WM_GETDLGCODE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListCtrlF message handlers
void CListCtrlF::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
int nStart;
nStart = GetCurSel();
// In a multiple-selection List control, unselect all entries
int max = GetItemCount();
for (int i = max (0, nStart); i < max; i++)
SetItemState(i, 0, LVIS_SELECTED);
int index = -1;
for (int nLoop = 0; -1 == index && nLoop < 2; nLoop++) {
int start = 0 == nLoop ? nStart + 1 : 0;
int end = 0 == nLoop ? max : nStart;
for (int n = start; n < min(end,max); n++) {
CString strText = GetItemText(n,m_nCharCol);
if (strText.GetLength() && to_upper(strText[0]) == to_upper(nChar)) {
index = n;
break;
}
}
}
if (index != -1) {
SetItemState(index, LVIS_SELECTED, LVIS_SELECTED);
EnsureVisible(index, FALSE);
}
CListCtrl::OnChar(nChar, nRepCnt, nFlags);
}
void CListCtrlF::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CWnd *pParent = GetParent();
CWnd *pBtn;
if (pParent) {
BOOL bShift;
switch (nChar) {
case VK_ESCAPE:
pParent->SendMessage(WM_COMMAND, IDCANCEL, 0L);
return;
case VK_RETURN:
pBtn = pParent->GetDlgItem(m_nIDCR);
if (pBtn) {
pParent->SendMessage(WM_COMMAND,
(WPARAM)MAKELONG(m_nIDCR, BN_CLICKED),
(LPARAM)pBtn->m_hWnd);
}
return;
case VK_TAB:
bShift = ISKEYPRESSED(VK_SHIFT);
pParent->SendMessage(WM_NEXTDLGCTL, bShift, 0);
return;
default:
break;
}
}
CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}
UINT CListCtrlF::OnGetDlgCode()
{
return (DLGC_WANTCHARS | DLGC_WANTALLKEYS);
// return CListCtrl::OnGetDlgCode();
}
int CListCtrlF::GetCurSel (void)
{
POSITION pos = GetFirstSelectedItemPosition();
if (pos)
return GetNextSelectedItem(pos);
return -1;
}