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
129
|
// ownerdrawnlistcontrol.h - Declaration of COwnerDrawnListControl and COwnerDrawnListItem
//
// WinDirStat - Directory Statistics
// Copyright (C) 2003-2005 Bernhard Seifert
// Copyright (C) 2004-2016 WinDirStat team (windirstat.info)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#ifndef __WDS_OWNERDRAWNLISTCONTROL_H__
#define __WDS_OWNERDRAWNLISTCONTROL_H__
#pragma once
#include "sortinglistcontrol.h"
class COwnerDrawnListItem;
class COwnerDrawnListControl;
//
// COwnerDrawnListItem. An item in a COwnerDrawnListControl.
// Some columns (subitems) may be owner drawn (DrawSubitem() returns true),
// COwnerDrawnListControl draws the texts (GetText()) of all others.
// DrawLabel() draws a standard label (width image, text, selection and focus rect)
//
class COwnerDrawnListItem: public CSortingListItem
{
public:
COwnerDrawnListItem();
virtual ~COwnerDrawnListItem();
// This text is drawn, if DrawSubitem returns false
virtual CString GetText(int subitem) const = 0;
// This color is used for the current item
virtual COLORREF GetItemTextColor() const { return ::GetSysColor(COLOR_WINDOWTEXT); }
// Return value is true, if the item draws itself.
// width != NULL -> only determine width, do not draw.
// If focus rectangle shall not begin leftmost, set *focusLeft
// to the left edge of the desired focus rectangle.
virtual bool DrawSubitem(int subitem, CDC *pdc, CRect rc, UINT state, int *width, int *focusLeft) const =0;
virtual void DrawAdditionalState(CDC * /*pdc*/, const CRect& /*rcLabel*/) const {}
void DrawSelection(COwnerDrawnListControl *list, CDC *pdc, CRect rc, UINT state) const;
protected:
void DrawLabel(COwnerDrawnListControl *list, CImageList *il, CDC *pdc, CRect& rc, UINT state, int *width, int *focusLeft, bool indent = true) const;
void DrawPercentage(CDC *pdc, CRect rc, double fraction, COLORREF color) const;
};
//
// COwnerDrawnListControl. Must be report view. Deals with COwnerDrawnListItems.
// Can have a grid or not (own implementation, don't set LVS_EX_GRIDLINES). Flicker-free.
//
class COwnerDrawnListControl: public CSortingListControl
{
DECLARE_DYNAMIC(COwnerDrawnListControl)
public:
COwnerDrawnListControl(LPCTSTR name, int rowHeight);
virtual ~COwnerDrawnListControl();
void OnColumnsInserted();
virtual void SysColorChanged();
int GetRowHeight();
void ShowGrid(bool show);
void ShowStripes(bool show);
void ShowFullRowSelection(bool show);
bool IsFullRowSelection();
COLORREF GetWindowColor();
COLORREF GetStripeColor();
COLORREF GetNonFocusHighlightColor();
COLORREF GetNonFocusHighlightTextColor();
COLORREF GetHighlightColor();
COLORREF GetHighlightTextColor();
bool IsItemStripeColor(int i);
bool IsItemStripeColor(const COwnerDrawnListItem *item);
COLORREF GetItemBackgroundColor(int i);
COLORREF GetItemBackgroundColor(const COwnerDrawnListItem *item);
COLORREF GetItemSelectionBackgroundColor(int i);
COLORREF GetItemSelectionBackgroundColor(const COwnerDrawnListItem *item);
COLORREF GetItemSelectionTextColor(int i);
COwnerDrawnListItem *GetItem(int i);
int FindListItem(const COwnerDrawnListItem *item);
int GetTextXMargin();
int GetGeneralLeftIndent();
void AdjustColumnWidth(int col);
CRect GetWholeSubitemRect(int item, int subitem);
bool HasFocus();
bool IsShowSelectionAlways();
protected:
void InitializeColors();
virtual void DrawItem(LPDRAWITEMSTRUCT pdis);
int GetSubItemWidth(COwnerDrawnListItem *item, int subitem);
bool IsColumnRightAligned(int col);
int m_rowHeight; // Height of an item
bool m_showGrid; // Whether to draw a grid
bool m_showStripes; // Whether to show stripes
bool m_showFullRowSelection; // Whether to draw full row selection
int m_yFirstItem; // Top of a first list item
COLORREF m_windowColor; // The default background color if !m_showStripes
COLORREF m_stripeColor; // The stripe color, used for every other item if m_showStripes
DECLARE_MESSAGE_MAP()
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnHdnDividerdblclick(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult);
};
#endif // __WDS_OWNERDRAWNLISTCONTROL_H__
|