OSDN Git Service

refactor
[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
14 class DIFFITEM;
15 class CDiffContext;
16
17 // DirViewColItems typedefs
18 typedef String (*ColGetFncPtrType)(const CDiffContext *, const void *, int);
19 typedef int (*ColSortFncPtrType)(const CDiffContext *, const void *, const void *, int);
20
21
22 /**
23  * @brief Information about one column of dirview list info
24  */
25 struct DirColInfo
26 {
27         enum ColAlign
28         {
29                 ALIGN_LEFT = 0,   // LVCFMT_LEFT
30                 ALIGN_RIGHT = 1,  // LVCFMT_RIGHT
31                 ALIGN_CENTER = 2  // LVCFMT_CENTER
32         };
33         const tchar_t *regName; /**< Internal name used for registry entries etc */
34         // localized string resources
35         const char *idNameContext; 
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;  /**< Offset into DIFFITEM::diffFileInfo[] */
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         int opt;
45         String GetDisplayName() const;
46         String GetDescription() const;
47 };
48
49 extern const int g_ncols;
50 extern const int g_ncols3;
51
52 class DirViewColItems
53 {
54 public:
55         explicit DirViewColItems(int nDirs, const std::vector<String>& additionalPropertyNames);
56         String GetColRegValueNameBase(int col) const;
57         int GetColDefaultOrder(int col) const;
58         const DirColInfo * GetDirColInfo(int col) const;
59         bool IsColById(int col, const char *idname) const;
60         bool IsColName(int col) const;
61         bool IsColLmTime(int col) const;
62         bool IsColMmTime(int col) const;
63         bool IsColRmTime(int col) const;
64         bool IsColStatus(int col) const;
65         bool IsColStatusAbbr(int col) const;
66         bool IsDefaultSortAscending(int col) const;
67         String GetColDisplayName(int col) const;
68         String GetColDescription(int col) const;
69         int     GetColCount() const { return m_numcols; };
70         int GetDispColCount() const { return m_dispcols; }
71         String ColGetTextToDisplay(const CDiffContext *pCtxt, int col, const DIFFITEM &di) const;
72         int ColSort(const CDiffContext *pCtxt, int col, const DIFFITEM &ldi, const DIFFITEM &rdi, bool bTreeMode) const;
73
74         int ColPhysToLog(int i) const { return m_invcolorder[i]; }
75         int ColLogToPhys(int i) const { return m_colorder[i]; } /**< -1 if not displayed */
76         void ClearColumnOrders();
77         void MoveColumn(int psrc, int pdest);
78         void ResetColumnOrdering();
79         void SetColumnOrdering(const int colorder[]);
80         String ResetColumnWidths(int defcolwidth);
81         void LoadColumnOrders(const String& colOrders);
82         String SaveColumnOrders();
83         const std::vector<String>& GetAdditionalPropertyNames() const { return m_additionalPropertyNames; }
84         void SetAdditionalPropertyNames(const std::vector<String>& propertyNames);
85
86         /// Update all column widths (from registry to screen)
87         // Necessary when user reorders columns
88         template<class SetColumnWidthFunc>
89         void LoadColumnWidths(String colwidths, SetColumnWidthFunc setcolwidth, int defcolwidth)
90         {
91                 std::basic_istringstream<tchar_t> ss(colwidths);
92                 for (int i = 0; i < m_numcols; ++i)
93                 {
94                         int phy = ColLogToPhys(i);
95                         if (phy >= 0)
96                         {
97                                 int w = defcolwidth;
98                                 ss >> w;
99                                 setcolwidth(phy, (std::max)(w, 10));
100                         }
101                 }
102         }
103
104         /** @brief store current column widths into registry */
105         template<class GetColumnWidthFunc>
106         String SaveColumnWidths(GetColumnWidthFunc getcolwidth)
107         {
108                 String result;
109                 for (int i = 0; i < m_numcols; i++)
110                 {
111                         int phy = ColLogToPhys(i);
112                         if (phy >= 0)
113                         {
114                                 if (!result.empty()) result += ' ';
115                                 result += strutils::to_str(getcolwidth(phy));
116                         }
117                 }
118                 return result;
119         }
120
121
122 private:
123         void AddAdditionalPropertyName(const String& propertyName);
124         void RemoveAdditionalPropertyName(const String& propertyName);
125
126         int m_nDirs;
127         int m_numcols;
128         int m_dispcols;
129         std::vector<int> m_colorder; /**< colorder[logical#]=physical# */
130         std::vector<int> m_invcolorder; /**< invcolorder[physical]=logical# */
131         std::vector<DirColInfo> m_cols;
132         std::vector<String> m_additionalPropertyNames;
133         std::list<String> m_strpool;
134 };