-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAppDlg.cpp
311 lines (266 loc) · 8.87 KB
/
AppDlg.cpp
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/******************************************************************************
** (C) Chris Oldwood
**
** MODULE: APPDLG.CPP
** COMPONENT: The Application.
** DESCRIPTION: CAppDlg class definition.
**
*******************************************************************************
*/
#include "Common.hpp"
#include "AppDlg.hpp"
#include "UTCMGRApp.hpp"
#include <MDBL/ResultSet.hpp>
/******************************************************************************
** Method: Default constructor.
**
** Description: .
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
CAppDlg::CAppDlg()
: CMainDlg(IDD_MAIN)
, m_nSortColumn(CCache::FILE_DATE)
, m_eSortOrder(CSortColumns::DESC)
, m_bShowAllFiles(false)
{
DEFINE_CTRL_TABLE
CTRL(IDC_GRID, &m_lvGrid)
END_CTRL_TABLE
DEFINE_GRAVITY_TABLE
CTRLGRAV(IDC_GRID, LEFT_EDGE, TOP_EDGE, RIGHT_EDGE, BOTTOM_EDGE)
END_GRAVITY_TABLE
DEFINE_CTRLMSG_TABLE
NFY_CTRLMSG(IDC_GRID, LVN_ITEMCHANGED, &CAppDlg::OnGridSelchange)
NFY_CTRLMSG(IDC_GRID, NM_RCLICK, &CAppDlg::OnGridRightClick)
NFY_CTRLMSG(IDC_GRID, LVN_COLUMNCLICK, &CAppDlg::OnGridClickColumn)
END_CTRLMSG_TABLE
}
/******************************************************************************
** Method: OnInitDialog()
**
** Description: Initialise the dialog.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CAppDlg::OnInitDialog()
{
// Set grid style.
// m_lvGrid.Font(CFont(ANSI_FIXED_FONT));
m_lvGrid.FullRowSelect(true);
// m_lvGrid.GridLines(true);
// Set the ListView icons.
m_lvGrid.ImageList(LVSIL_SMALL, IDB_LIST_ICONS, 16, RGB(255, 0, 255));
int anColWidths[NUM_COLUMNS];
// Load the columns widths config.
anColWidths[FILE_COLUMN] = App.m_oIniFile.ReadInt(TXT("UI"), TXT("Column0"), 200);
anColWidths[TYPE_COLUMN] = App.m_oIniFile.ReadInt(TXT("UI"), TXT("Column1"), 50);
anColWidths[DATE_COLUMN] = App.m_oIniFile.ReadInt(TXT("UI"), TXT("Column2"), 125);
anColWidths[SIZE_COLUMN] = App.m_oIniFile.ReadInt(TXT("UI"), TXT("Column3"), 70);
anColWidths[STATUS_COLUMN] = App.m_oIniFile.ReadInt(TXT("UI"), TXT("Column4"), 55);
anColWidths[CACHE_COLUMN] = App.m_oIniFile.ReadInt(TXT("UI"), TXT("Column5"), 275);
// Create grid columns.
m_lvGrid.InsertColumn(FILE_COLUMN, TXT("File"), anColWidths[FILE_COLUMN], LVCFMT_LEFT );
m_lvGrid.InsertColumn(TYPE_COLUMN, TXT("Type"), anColWidths[TYPE_COLUMN], LVCFMT_LEFT );
m_lvGrid.InsertColumn(DATE_COLUMN, TXT("Date"), anColWidths[DATE_COLUMN], LVCFMT_LEFT );
m_lvGrid.InsertColumn(SIZE_COLUMN, TXT("Size"), anColWidths[SIZE_COLUMN], LVCFMT_RIGHT );
m_lvGrid.InsertColumn(STATUS_COLUMN, TXT("Status"), anColWidths[STATUS_COLUMN], LVCFMT_CENTER);
m_lvGrid.InsertColumn(CACHE_COLUMN, TXT("Cache Name"), anColWidths[CACHE_COLUMN], LVCFMT_LEFT );
}
/******************************************************************************
** Method: OnDestroy()
**
** Description: Dialog being destroyed, save the column widths.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CAppDlg::OnDestroy()
{
App.m_oIniFile.WriteInt(TXT("UI"), TXT("Column0"), static_cast<int>(m_lvGrid.ColumnWidth(FILE_COLUMN)));
App.m_oIniFile.WriteInt(TXT("UI"), TXT("Column1"), static_cast<int>(m_lvGrid.ColumnWidth(TYPE_COLUMN)));
App.m_oIniFile.WriteInt(TXT("UI"), TXT("Column2"), static_cast<int>(m_lvGrid.ColumnWidth(DATE_COLUMN)));
App.m_oIniFile.WriteInt(TXT("UI"), TXT("Column3"), static_cast<int>(m_lvGrid.ColumnWidth(SIZE_COLUMN)));
App.m_oIniFile.WriteInt(TXT("UI"), TXT("Column4"), static_cast<int>(m_lvGrid.ColumnWidth(STATUS_COLUMN)));
App.m_oIniFile.WriteInt(TXT("UI"), TXT("Column5"), static_cast<int>(m_lvGrid.ColumnWidth(CACHE_COLUMN)));
}
/******************************************************************************
** Method: RefreshView()
**
** Description: Load the grid with the cache details.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CAppDlg::RefreshView()
{
// Reset grid.
m_lvGrid.DeleteAllItems();
// Get the cache details and sort.
CResultSet oRS = App.m_oCache.SelectAll();
oRS.OrderBy(CSortColumns(m_nSortColumn, m_eSortOrder));
// For all rows.
for (size_t i = 0; i < oRS.Count(); ++i)
{
CRow& oRow = oRS[i];
// Check filter.
if ( (m_bShowAllFiles) || (oRow[CCache::STATUS] == NEW_FILE) )
{
size_t n = m_lvGrid.ItemCount();
// Add to the grid.
m_lvGrid.InsertItem(n, oRow[CCache::REAL_FILENAME], App.IconIndex(oRow[CCache::FILE_TYPE]));
m_lvGrid.ItemText (n, TYPE_COLUMN, App.FormatType(oRow[CCache::FILE_TYPE]));
m_lvGrid.ItemText (n, DATE_COLUMN, oRow[CCache::FILE_DATE].Format());
m_lvGrid.ItemText (n, SIZE_COLUMN, App.FormatSize(oRow[CCache::FILE_SIZE]));
m_lvGrid.ItemText (n, STATUS_COLUMN, App.FormatStatus(oRow[CCache::STATUS]));
m_lvGrid.ItemText (n, CACHE_COLUMN, oRow[CCache::CACHE_FILENAME]);
m_lvGrid.ItemPtr (n, &oRow);
}
}
}
/******************************************************************************
** Method: SelectNew()
**
** Description: Select all new files in the grid.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CAppDlg::SelectNew()
{
size_t nFiles = m_lvGrid.ItemCount();
for (size_t i = 0; i < nFiles; ++i)
m_lvGrid.Select(i, (GetRow(i)[CCache::STATUS] == NEW_FILE));
}
/******************************************************************************
** Method: SelectAll()
**
** Description: Select all files in the grid.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CAppDlg::SelectAll()
{
size_t nFiles = m_lvGrid.ItemCount();
for (size_t i = 0; i < nFiles; ++i)
m_lvGrid.Select(i);
}
/******************************************************************************
** Method: GetSelectedFiles()
**
** Description: Gets all the files selected in the grid.
**
** Parameters: oRS The collection for the selection.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CAppDlg::GetSelectedFiles(CResultSet& oRS)
{
size_t nFiles = m_lvGrid.ItemCount();
// For all rows.
for (size_t i = 0; i < nFiles; ++i)
{
if (m_lvGrid.IsSelected(i))
oRS.Add(GetRow(i));
}
}
/******************************************************************************
** Method: OnGridSelchange()
**
** Description: Grid item (de)selected, update the main UI.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
LRESULT CAppDlg::OnGridSelchange(NMHDR& oNMHdr)
{
NMLISTVIEW& oMsgHdr = reinterpret_cast<NMLISTVIEW&>(oNMHdr);
if (oMsgHdr.uChanged & LVIF_STATE)
App.m_AppCmds.UpdateUI();
return 0;
}
/******************************************************************************
** Method: OnGridRightClick()
**
** Description: Right click on the grid, show context menu.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
LRESULT CAppDlg::OnGridRightClick(NMHDR& /*oHdr*/)
{
// Only show menu, if a selection.
if (m_lvGrid.IsSelection())
{
CPopupMenu oMenu(IDR_GRIDMENU);
bool bReadOnly = App.m_pProfile->m_bReadOnly;
// Enable/Disable relevant menu commands.
oMenu.EnableCmd(ID_EDIT_MOVE, !bReadOnly);
oMenu.EnableCmd(ID_EDIT_DELETE, !bReadOnly);
oMenu.EnableCmd(ID_CACHE_PROPERTIES, true);
// Get co-ordinates of mouse click.
const MSG& oCurrMsg = App.m_MainThread.CurrentMsg();
// Show menu.
uint nCmdID = oMenu.TrackMenu(m_lvGrid, CPoint(oCurrMsg.pt.x, oCurrMsg.pt.y));
// Dispatch command.
if (nCmdID != 0)
App.m_AppWnd.PostCommand(nCmdID);
}
return 0;
}
/******************************************************************************
** Method: OnGridClickColumn()
**
** Description: Grid column clicked, resort the grid.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
LRESULT CAppDlg::OnGridClickColumn(NMHDR& oHdr)
{
NMLISTVIEW& oParam = (NMLISTVIEW&) oHdr;
// Decode column.
switch (oParam.iSubItem)
{
case FILE_COLUMN: App.m_AppCmds.OnViewSortByName(); break;
case TYPE_COLUMN: App.m_AppCmds.OnViewSortByType(); break;
case DATE_COLUMN: App.m_AppCmds.OnViewSortByDate(); break;
case SIZE_COLUMN: App.m_AppCmds.OnViewSortBySize(); break;
case STATUS_COLUMN: App.m_AppCmds.OnViewSortByStatus(); break;
case CACHE_COLUMN: App.m_AppCmds.OnViewSortByCache(); break;
default: ASSERT_FALSE(); break;
}
return 0;
}