OSDN Git Service

Merge with stable
[winmerge-jp/winmerge-jp.git] / Src / DirViewColItems.h
1 /** 
2  * @file  DirViewColItems.h
3  *
4  * @brief Declaration file for DirColInfo
5  *
6  * @date  Created: 2003-08-19
7  */
8 #pragma once
9
10 #include "UnicodeString.h"
11 #include <vector>
12 #include <sstream>
13 #include <cassert>
14
15 struct DIFFITEM;
16 class CDiffContext;
17
18 // DirViewColItems typedefs
19 typedef String (*ColGetFncPtrType)(const CDiffContext *, const void *);
20 typedef int (*ColSortFncPtrType)(const CDiffContext *, const void *, const void *);
21
22
23 /**
24  * @brief Information about one column of dirview list info
25  */
26 struct DirColInfo
27 {
28         enum ColAlign
29         {
30                 ALIGN_LEFT = 0,   // LVCFMT_LEFT
31                 ALIGN_RIGHT = 1,  // LVCFMT_RIGHT
32                 ALIGN_CENTER = 2  // LVCFMT_CENTER
33         };
34         const TCHAR *regName; /**< Internal name used for registry entries etc */
35         // localized string resources
36         const char *idName; /**< Displayed name, ID of string resource */
37         const char *idDesc; /**< Description, ID of string resource */
38         ColGetFncPtrType getfnc; /**< Handler giving display string */
39         ColSortFncPtrType sortfnc; /**< Handler for sorting this column */
40         size_t offset;
41         int physicalIndex; /**< Current physical index, -1 if not displayed */
42         bool defSortUp; /**< Does column start with ascending sort (most do) */
43         int alignment; /**< Column alignment */
44 };
45
46 extern const int g_ncols;
47 extern const int g_ncols3;
48
49 class DirViewColItems
50 {
51 public:
52         DirViewColItems(int nDirs):
53           m_nDirs(nDirs), m_numcols(-1), m_dispcols(-1) {}
54         String GetColRegValueNameBase(int col) const;
55         int GetColDefaultOrder(int col) const;
56         const DirColInfo * GetDirColInfo(int col) const;
57         bool IsColById(int col, const char *idname) const;
58         bool IsColName(int col) const;
59         bool IsColLmTime(int col) const;
60         bool IsColMmTime(int col) const;
61         bool IsColRmTime(int col) const;
62         bool IsColStatus(int col) const;
63         bool IsColStatusAbbr(int col) const;
64         bool IsDefaultSortAscending(int col) const;
65         String GetColDisplayName(int col) const;
66         String GetColDescription(int col) const;
67         int     GetColCount() const;
68         int GetDispColCount() const { return m_dispcols; }
69         String ColGetTextToDisplay(const CDiffContext *pCtxt, int col, const DIFFITEM & di) const;
70         int ColSort(const CDiffContext *pCtxt, int col, const DIFFITEM & ldi, const DIFFITEM &rdi, bool bTreeMode) const;
71
72         int ColPhysToLog(int i) const { return m_invcolorder[i]; }
73         int ColLogToPhys(int i) const { return m_colorder[i]; } /**< -1 if not displayed */
74         void ClearColumnOrders();
75         void MoveColumn(int psrc, int pdest);
76         void ResetColumnOrdering();
77         void SetColumnOrdering(const int colorder[]);
78         String ResetColumnWidths(int defcolwidth);
79         void LoadColumnOrders(String colorders);
80         String SaveColumnOrders();
81
82         /// Update all column widths (from registry to screen)
83         // Necessary when user reorders columns
84         template<class SetColumnWidthFunc>
85         void LoadColumnWidths(String colwidths, SetColumnWidthFunc setcolwidth, int defcolwidth)
86         {
87                 std::basic_istringstream<TCHAR> ss(colwidths);
88                 for (int i = 0; i < m_numcols; ++i)
89                 {
90                         int phy = ColLogToPhys(i);
91                         if (phy >= 0)
92                         {
93                                 int w = defcolwidth;
94                                 ss >> w;
95                                 setcolwidth(phy, max(w, 10));
96                         }
97                 }
98         }
99
100         /** @brief store current column widths into registry */
101         template<class GetColumnWidthFunc>
102         String SaveColumnWidths(GetColumnWidthFunc getcolwidth)
103         {
104                 String result;
105                 for (int i = 0; i < m_numcols; i++)
106                 {
107                         int phy = ColLogToPhys(i);
108                         if (phy >= 0)
109                         {
110                                 if (!result.empty()) result += ' ';
111                                 result += string_to_str(getcolwidth(phy));
112                         }
113                 }
114                 return result;
115         }
116
117
118 private:
119         int m_nDirs;
120         int m_numcols;
121         int m_dispcols;
122         std::vector<int> m_colorder; /**< colorder[logical#]=physical# */
123         std::vector<int> m_invcolorder; /**< invcolorder[physical]=logical# */
124 };