OSDN Git Service

Merged in Timon34/winmerge-4/Timon34/russianpo-edited-online-with-bitbucket-m-1547616...
[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 *);
19 typedef int (*ColSortFncPtrType)(const CDiffContext *, const void *, const void *);
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 *regName; /**< Internal name used for registry entries etc */
34         // localized string resources
35         const char *idName; /**< Displayed name, ID of string resource */
36         const char *idDesc; /**< Description, ID of string resource */
37         ColGetFncPtrType getfnc; /**< Handler giving display string */
38         ColSortFncPtrType sortfnc; /**< Handler for sorting this column */
39         size_t offset;  /**< Offset into DIFFITEM::diffFileInfo[] */
40         int physicalIndex; /**< Current physical index, -1 if not displayed */
41         bool defSortUp; /**< Does column start with ascending sort (most do) */
42         int alignment; /**< Column alignment */
43 };
44
45 extern const int g_ncols;
46 extern const int g_ncols3;
47
48 class DirViewColItems
49 {
50 public:
51         explicit DirViewColItems(int nDirs):
52           m_nDirs(nDirs), m_numcols(-1), m_dispcols(-1) {}
53         String GetColRegValueNameBase(int col) const;
54         int GetColDefaultOrder(int col) const;
55         const DirColInfo * GetDirColInfo(int col) const;
56         bool IsColById(int col, const char *idname) const;
57         bool IsColName(int col) const;
58         bool IsColLmTime(int col) const;
59         bool IsColMmTime(int col) const;
60         bool IsColRmTime(int col) const;
61         bool IsColStatus(int col) const;
62         bool IsColStatusAbbr(int col) const;
63         bool IsDefaultSortAscending(int col) const;
64         String GetColDisplayName(int col) const;
65         String GetColDescription(int col) const;
66         int     GetColCount() const;
67         int GetDispColCount() const { return m_dispcols; }
68         String ColGetTextToDisplay(const CDiffContext *pCtxt, int col, const DIFFITEM &di) const;
69         int ColSort(const CDiffContext *pCtxt, int col, const DIFFITEM &ldi, const DIFFITEM &rdi, bool bTreeMode) const;
70
71         int ColPhysToLog(int i) const { return m_invcolorder[i]; }
72         int ColLogToPhys(int i) const { return m_colorder[i]; } /**< -1 if not displayed */
73         void ClearColumnOrders();
74         void MoveColumn(int psrc, int pdest);
75         void ResetColumnOrdering();
76         void SetColumnOrdering(const int colorder[]);
77         String ResetColumnWidths(int defcolwidth);
78         void LoadColumnOrders(String colorders);
79         String SaveColumnOrders();
80
81         /// Update all column widths (from registry to screen)
82         // Necessary when user reorders columns
83         template<class SetColumnWidthFunc>
84         void LoadColumnWidths(String colwidths, SetColumnWidthFunc setcolwidth, int defcolwidth)
85         {
86                 std::basic_istringstream<TCHAR> ss(colwidths);
87                 for (int i = 0; i < m_numcols; ++i)
88                 {
89                         int phy = ColLogToPhys(i);
90                         if (phy >= 0)
91                         {
92                                 int w = defcolwidth;
93                                 ss >> w;
94                                 setcolwidth(phy, max(w, 10));
95                         }
96                 }
97         }
98
99         /** @brief store current column widths into registry */
100         template<class GetColumnWidthFunc>
101         String SaveColumnWidths(GetColumnWidthFunc getcolwidth)
102         {
103                 String result;
104                 for (int i = 0; i < m_numcols; i++)
105                 {
106                         int phy = ColLogToPhys(i);
107                         if (phy >= 0)
108                         {
109                                 if (!result.empty()) result += ' ';
110                                 result += strutils::to_str(getcolwidth(phy));
111                         }
112                 }
113                 return result;
114         }
115
116
117 private:
118         int m_nDirs;
119         int m_numcols;
120         int m_dispcols;
121         std::vector<int> m_colorder; /**< colorder[logical#]=physical# */
122         std::vector<int> m_invcolorder; /**< invcolorder[physical]=logical# */
123 };