forked from Thomas-Mielke-Software/EasyCash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXFileOpenListView.cpp
More file actions
267 lines (235 loc) · 7.72 KB
/
XFileOpenListView.cpp
File metadata and controls
267 lines (235 loc) · 7.72 KB
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
// XFileOpenListView.cpp Version 1.0
//
// Diese Datei ist Bestandteil von EasyCash&Tax, der freien EÜR-Fibu
//
// Copyleft (GPLv3) 2020 Thomas Mielke
//
// Dies ist freie Software; Sie dürfen sie unter den Bedingungen der
// GNU General Public License, wie von der Free Software Foundation
// veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß
// Version 3 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
//
// Ein Verkauf dieser Quelldatei ist jedoch ausgeschlossen (siehe vorher-
// gehende Release-Info von Hans Dietrich).
//
// Diese Software wird in der Hoffnung weiterverbreitet, dass sie nützlich
// sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte
// Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK.
// Mehr Details finden Sie in der GNU Lesser General Public License.
//
// Sie sollten eine Kopie der GNU General Public License Version 3 zusammen mit
// dieser Software erhalten haben; falls nicht, schreiben Sie an die Free
// Software Foundation, Inc., 51 Franklin St, 5th Floor, Boston, MA 02110, USA.
// vorige Release-Informationen (credits):
// Author: Hans Dietrich
// hdietrich@gmail.com
//
// Description:
// XFileOpenListView implements CXFileOpenListView, a folder browsing
// dialog that uses the new Windows 2000-style dialog. Please see article
// at www.codeproject.com.
//
// History
// Version 1.0 - 2008 February 22
// - Initial public release
//
// License:
// This software is released into the public domain. You are free to use
// it in any way you like, except that you may not sell this source code.
//
// This software is provided "as is" with no expressed or implied warranty.
// I accept no liability for any damage or loss of business that this
// software may cause.
//
///////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "XFileOpenListView.h"
#include "winver.h"
// definitions from commctrl.h
#ifndef LV_VIEW_ICON
#define LV_VIEW_ICON 0x0000
#define LV_VIEW_DETAILS 0x0001
#define LV_VIEW_SMALLICON 0x0002
#define LV_VIEW_LIST 0x0003
#define LV_VIEW_TILE 0x0004
#define LV_VIEW_MAX 0x0004
#endif
#ifndef LVM_GETVIEW
#define LVM_GETVIEW (LVM_FIRST + 143)
#endif
#ifndef __noop
#if _MSC_VER < 1300
#define __noop ((void)0)
#endif
#endif
#undef TRACE
#define TRACE __noop
//=============================================================================
// if you want to see the TRACE output, uncomment this line:
//#include "XTrace.h"
//=============================================================================
//=============================================================================
//=============================================================================
// CXFileOpenListView - Used to subclass the "SHELLDLL_DefView" window in the
// file open dialog. This window contain the list view and processses
// commands to set different view modes.
//=============================================================================
//=============================================================================
//=============================================================================
// Set the list view to desired mode.
BOOL CXFileOpenListView::SetViewMode(int cmd)
//=============================================================================
{
TRACE(_T("in CXFileOpenListView::SetViewMode: 0x%X\n"), cmd);
if (IsWindow(m_hWnd))
{
// SHELLDLL_DefView window found: send it the command.
if (cmd == 0)
{
if (IsXP())
cmd = XLVM_XP_LIST;
else if (IsVista())
cmd = XLVM_VISTA_LIST;
}
SendMessage(WM_COMMAND, cmd);
// Send parent dialog a Refresh command (F5) to force repaint.
// The command ID value was obtained by inspection using Spy++.
const UINT CMD_REFRESH = 40966;
GetParent()->SendMessage(WM_COMMAND, CMD_REFRESH);
return TRUE;
}
else
{
TRACE(_T("ERROR - no m_hWnd\n"));
}
return FALSE;
}
//=============================================================================
// Get current list view mode in the form of WM_COMMAND code that can be
// passed to SetViewMode.
int CXFileOpenListView::GetViewMode()
//=============================================================================
{
TRACE(_T("in CXFileOpenListView::GetViewMode\n"));
int nViewMode = 0;
if (IsWindow(m_hWnd))
{
// Get the child list view window.
HWND hlc = ::FindWindowEx(m_hWnd, NULL, _T("SysListView32"), NULL);
if (hlc)
{
CListCtrl* plc = (CListCtrl*)CWnd::FromHandle(hlc);
if (plc)
{
long lView = (long)plc->SendMessage(LVM_GETVIEW);
TRACE(_T("lView=%X\n"), lView);
if (IsXP())
nViewMode = GetXpViewMode(lView, plc);
else if (IsVista())
nViewMode = GetVistaViewMode(lView, plc);
}
}
}
return nViewMode;
}
//=============================================================================
int CXFileOpenListView::GetXpViewMode(long lView, CListCtrl* plc)
//=============================================================================
{
int nViewMode = 0;
if (lView == LV_VIEW_ICON)
{
// If list view is in ICON mode, look at icon spacing to determine
// whether Thumbnail or Icon mode.
CSize sz(0, 0);
if (plc && IsWindow(plc->m_hWnd))
sz = CSize((DWORD)plc->SendMessage(LVM_GETITEMSPACING));
TRACE(_T("sz.cx = %d\n"), sz.cx);
if (sz.cx > GetSystemMetrics(SM_CXICONSPACING))
{
nViewMode = XLVM_XP_THUMBNAILS;
}
else
{
nViewMode = XLVM_XP_ICONS;
}
}
else if (lView == LV_VIEW_DETAILS)
{
nViewMode = XLVM_XP_DETAILS;
}
else if (lView == LV_VIEW_LIST)
{
nViewMode = XLVM_XP_LIST;
}
else if (lView == LV_VIEW_TILE)
{
nViewMode = XLVM_XP_TILES;
}
return nViewMode;
}
//=============================================================================
int CXFileOpenListView::GetVistaViewMode(long lView, CListCtrl* plc)
//=============================================================================
{
int nViewMode = 0;
if (lView == LV_VIEW_SMALLICON)
{
nViewMode = XLVM_VISTA_SMALL_ICONS;
}
else if (lView == LV_VIEW_ICON)
{
// If list view is in ICON mode, look at icon spacing to determine
// whether Thumbnail or Icon mode.
CSize sz(0, 0);
if (plc && IsWindow(plc->m_hWnd))
sz = CSize((DWORD)plc->SendMessage(LVM_GETITEMSPACING));
int nIconSpacing = GetSystemMetrics(SM_CXICONSPACING);
//CString s;
//s.Format(_T("item spacing = (%d, %d), nIconSpacing = %d"), sz.cx, sz.cy, nIconSpacing);
//::MessageBox(NULL, s, _T("item spacing"), MB_OK);
if (sz.cx == nIconSpacing)
{
nViewMode = XLVM_VISTA_MEDIUM_ICONS;
}
else if (sz.cx > nIconSpacing*2)
{
nViewMode = XLVM_VISTA_EXTRA_LARGE_ICONS;
}
else
{
nViewMode = XLVM_VISTA_LARGE_ICONS;
}
}
else if (lView == LV_VIEW_DETAILS)
{
nViewMode = XLVM_VISTA_DETAILS;
}
else if (lView == LV_VIEW_LIST)
{
nViewMode = XLVM_VISTA_LIST;
}
else if (lView == LV_VIEW_TILE)
{
nViewMode = XLVM_VISTA_TILES;
}
return nViewMode;
}
//=============================================================================
// Process window message from list view. Call default to bypass MFC
// entirely because MFC has all sorts of ASSERT checks that will bomb.
// The only message I care about is WM_DESTROY, to re-initialize myself.
//
// The original version in MSDN only overrode OnCommand; it's necessary to
// override WindowProc to completely bypass MFC.
//
LRESULT CXFileOpenListView::WindowProc(UINT msg, WPARAM, LPARAM)
//=============================================================================
{
if (msg == WM_DESTROY)
{
m_lastViewMode = GetViewMode(); // save current view mode
UnsubclassWindow(); // unsubclass myself
}
return Default(); // all message: pass to default WndProc, avoid MFC/CWnd
}