Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sortinglistcontrol.h « Controls « windirstat - github.com/windirstat/windirstat.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3a2c82ffee5f0fd547b6e36e1dea729fb6da8900 (plain)
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
// sortinglistcontrol.h - Declaration of CSortingListItem and CSortingListControl
//
// 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_SORTINGLISTCONTROL_H__
#define __WDS_SORTINGLISTCONTROL_H__
#pragma once

//
// SSorting. A sorting specification. We sort by column1, and if two items
// equal in column1, we sort them by column2.
//
struct SSorting
{
    SSorting() { column1 = column2 = 0; ascending1 = ascending2 = true; }
    int  column1;
    bool ascending1;
    int  column2;
    bool ascending2;
};

//
// CSortingListItem. An item in a CSortingListControl.
//
class CSortingListItem
{
public:
    virtual CString GetText(int subitem) const;
    virtual int GetImage() const;
    virtual int Compare(const CSortingListItem *other, int subitem) const;
    int CompareS(const CSortingListItem *other, const SSorting& sorting) const;
};


//
// CSortingListControl. The base class for all our ListControls.
// The lParams of the items are pointers to CSortingListItems.
// The items use LPSTR_TEXTCALLBACK and I_IMAGECALLBACK.
// And the items can compare to one another.
// CSortingListControl maintains a SSorting and handles clicks
// on the header items. It also indicates the sorting to the user
// by adding a "<" or ">" to the header items.
//
class CSortingListControl: public CListCtrl
{
    DECLARE_DYNAMIC(CSortingListControl)
public:
    // Construction
    CSortingListControl(LPCTSTR name);
    virtual ~CSortingListControl();

    // Public methods
    void LoadPersistentAttributes();

    void AddExtendedStyle(DWORD exStyle);
    void RemoveExtendedStyle(DWORD exStyle);

    const SSorting& GetSorting();
    void GetSorting(int& sortColumn1, bool& ascending1, int& sortColumn2, bool& ascending2);

    void SetSorting(const SSorting& sorting);
    void SetSorting(int sortColumn1, bool ascending1, int sortColumn2, bool ascending2);
    void SetSorting(int sortColumn, bool ascending);

    void InsertListItem(int i, CSortingListItem *item);
    CSortingListItem *GetSortingListItem(int i);

    // Overridables
    virtual void SortItems();
    virtual bool GetAscendingDefault(int column);
    virtual bool HasImages();

#   if (_MFC_VER <=0x0800)
    BOOL GetColumnOrderArray(LPINT piArray, INT_PTR iCount = -1);
#   endif

private:
    void SavePersistentAttributes();
    static int CALLBACK _CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);

    CString m_name; // for persistence
    SSorting m_sorting;

    int m_indicatedColumn;

    DECLARE_MESSAGE_MAP()
    afx_msg void OnLvnGetdispinfo(NMHDR *pNMHDR, LRESULT *pResult);
    afx_msg void OnHdnItemclick(NMHDR *pNMHDR, LRESULT *pResult);
    afx_msg void OnHdnItemdblclick(NMHDR *pNMHDR, LRESULT *pResult);
    afx_msg void OnDestroy();
};

#endif // __WDS_SORTINGLISTCONTROL_H__