[994dbc]: PWListCtrl.cpp Maximize Restore History

Download this file

PWListCtrl.cpp    127 lines (110 with data), 3.1 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
/*
* Copyright (c) 2003-2007 Rony Shapiro <ronys@users.sourceforge.net>.
* All rights reserved. Use of the code is allowed under the
* Artistic License 2.0 terms, as specified in the LICENSE file
* distributed with this code, or available from
* http://www.opensource.org/licenses/artistic-license-2.0.php
*/
#include "stdafx.h"
#include "PWListCtrl.h"
#include "DboxMain.h"
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CPWListCtrl::CPWListCtrl()
: m_FindTimerID(0), m_csFind(_T(""))
{
}
CPWListCtrl::~CPWListCtrl()
{
}
BEGIN_MESSAGE_MAP(CPWListCtrl, CListCtrl)
//{{AFX_MSG_MAP(CPWListCtrl)
ON_MESSAGE(WM_CHAR, OnCharItemlist)
ON_WM_DESTROY()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
LRESULT CPWListCtrl::OnCharItemlist(WPARAM wParam, LPARAM /* lParam */)
{
const int iSubItem = m_pDbx->IsImageVisible() ? 1 : 0;
bool bFirst;
if (m_FindTimerID != 0) {
KillTimer(TIMER_FIND);
m_csFind += (TCHAR)wParam;
bFirst = false;
} else {
m_csFind = (TCHAR)wParam;
bFirst = true;
}
if (!FindNext(m_csFind, iSubItem) && !bFirst) {
// Didn't find a match when more than one character
// Emulate CListCtrl and try again (once) with this matching the first character
m_csFind = (TCHAR)wParam;
FindNext(m_csFind, iSubItem);
}
// Set timer going again
m_FindTimerID = SetTimer(TIMER_FIND, 1000, NULL);
return 0L;
}
void CPWListCtrl::OnDestroy()
{
// Remove dummy ImageList. PWTreeCtrl removes the real one!
m_pDbx->m_pImageList0->DeleteImageList();
delete m_pDbx->m_pImageList0;
}
void CPWListCtrl::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == TIMER_FIND) {
KillTimer(TIMER_FIND);
m_FindTimerID = 0;
}
}
bool
CPWListCtrl::FindNext(const CString &cs_find, const int iSubItem)
{
int iItem;
bool bFound(false);
CString cs_text;
const int iNum = GetItemCount();
const int iFindLen = cs_find.GetLength();
// Get selected item, if any
POSITION pos = GetFirstSelectedItemPosition();
// First search down.
if (pos == NULL)
iItem = 0;
else
iItem = (int)pos;
do {
cs_text = GetItemText(iItem, iSubItem);
cs_text = cs_text.Mid(0, iFindLen);
if (cs_text.GetLength() > 0 && cs_find.CompareNoCase(cs_text) == 0) {
bFound = true;
break;
}
iItem++;
} while (iItem <= iNum);
// Not found searching down and we didn't start from the top, now start from the top until
// we get to where we started!
if (!bFound && pos != NULL) {
iItem = 0;
do {
cs_text = GetItemText(iItem, iSubItem);
cs_text = cs_text.Mid(0, iFindLen);
if (cs_text.GetLength() > 0 && cs_find.CompareNoCase(cs_text) == 0) {
bFound = true;
break;
}
iItem++;
} while (iItem != (int)pos);
}
if (bFound) {
SetItemState(iItem, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
EnsureVisible(iItem, FALSE);
Invalidate();
}
return bFound;
}