Small cleanups
[TortoiseGit.git] / src / TortoiseProc / UpdateListCtrl.cpp
blob0ccb30a85810e7c19e6770ce649a870e45b2f899
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2012 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // CUpdateListCtrl
21 #include "stdafx.h"
22 #include "UpdateListCtrl.h"
24 IMPLEMENT_DYNAMIC(CUpdateListCtrl, CListCtrl)
26 CUpdateListCtrl::CUpdateListCtrl()
28 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
29 LOGFONT lf = {0};
30 GetObject(hFont, sizeof(LOGFONT), &lf);
31 lf.lfWeight = FW_BOLD;
32 m_boldFont = CreateFontIndirect(&lf);
35 CUpdateListCtrl::~CUpdateListCtrl()
37 if (m_boldFont)
38 DeleteObject(m_boldFont);
41 BEGIN_MESSAGE_MAP(CUpdateListCtrl, CListCtrl)
42 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, &CUpdateListCtrl::OnNMCustomdraw)
43 END_MESSAGE_MAP()
47 // CUpdateListCtrl message handlers
48 void CUpdateListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
50 NMLVCUSTOMDRAW *pNMCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
52 *pResult = 0;
55 switch (pNMCD->nmcd.dwDrawStage)
57 case CDDS_PREPAINT:
59 *pResult = CDRF_NOTIFYITEMDRAW;
60 return;
62 break;
63 case CDDS_ITEMPREPAINT:
65 // This is the prepaint stage for an item. Here's where we set the
66 // item's text color.
68 // Tell Windows to send draw notifications for each subitem.
69 *pResult = CDRF_NOTIFYSUBITEMDRAW;
71 CUpdateListCtrl::Entry *data = (CUpdateListCtrl::Entry *)this->GetItemData((int)pNMCD->nmcd.dwItemSpec);
72 switch(data->m_status & STATUS_MASK)
74 case STATUS_SUCCESS:
75 pNMCD->clrText = RGB(0,128,0);
76 break;
77 case STATUS_FAIL:
78 pNMCD->clrText = RGB(255,0,0);
79 break;
80 case STATUS_IGNORE:
81 pNMCD->clrText = RGB(128,128,128);
82 break;
85 if(data->m_status & STATUS_DOWNLOADING)
87 SelectObject(pNMCD->nmcd.hdc, m_boldFont);
88 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
92 break;
94 *pResult = CDRF_DODEFAULT;