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