Garmin Fleet Management Controller  2.19.0
CColoredListBox.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CColoredListBox.cpp
5 *
6 * Copyright 2008-2009 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 #include "CColoredListBox.h"
11 
12 //----------------------------------------------------------------------
21 //----------------------------------------------------------------------
23  (
24  LPDRAWITEMSTRUCT aDrawItem
25  )
26 {
27  CDC dc;
28  CRect rcItem( aDrawItem->rcItem );
29  UINT nIndex = aDrawItem->itemID;
30  if( (int)nIndex >= 0 )
31  {
32  COLORREF rgbBkGnd;
33  COLORREF rgbText;
34  CString itemText;
35  CString compareText;
36 
37  GetText( nIndex, itemText );
38  compareText = itemText;
39  compareText = compareText.MakeLower();
40 
41  if( aDrawItem->itemState & ODS_SELECTED )
42  {
43  rgbBkGnd = ::GetSysColor( COLOR_HIGHLIGHT );
44  rgbText = ::GetSysColor( COLOR_HIGHLIGHTTEXT );
45  }
46  else if( !mSearchString.IsEmpty() && compareText.Find( mSearchString, 0 ) != -1 )
47  {
48  rgbBkGnd = RGB( 255, 255, 0 ); // yellow
49  rgbText = RGB( 0, 0, 0 ); // black
50  }
51  else
52  {
53  rgbBkGnd = RGB( 255, 255, 255 ); // white
54  rgbText = RGB( 0, 0, 0 ); // black
55  }
56  dc.Attach( aDrawItem->hDC );
57 
58  if( aDrawItem->itemState & ODS_FOCUS )
59  dc.DrawFocusRect( rcItem );
60 
61  CBrush br( rgbBkGnd );
62  dc.FillRect( rcItem, &br );
63  dc.SetBkColor( rgbBkGnd );
64  dc.SetTextColor( rgbText );
65  dc.TextOut( rcItem.left + 2, rcItem.top + 2, itemText );
66 
67  dc.Detach();
68  }
69 }
70 
71 //----------------------------------------------------------------------
74 //----------------------------------------------------------------------
76 {
77  return mSearchString;
78 }
79 
80 //----------------------------------------------------------------------
83 //----------------------------------------------------------------------
84 void CColoredListBox::setSearchString( CString aSearchString )
85 {
86  mSearchString = aSearchString;
87  mSearchString.MakeLower();
88 }
void setSearchString(CString aSearchString)
Set the search string to use.
CString mSearchString
The search string to match.
CString getSearchString() const
Get the search string being used.
void DrawItem(LPDRAWITEMSTRUCT aDrawItem)
Draw the list item specified by aDrawItem.