diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2021-12-27 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-03-18 15:35:13 +0500 |
commit | f19f813537c7aea1c20749c914e756b54a9c3cf5 (patch) | |
tree | 816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Windows/CommonDialog.cpp | |
parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
download | 7zip-21.07.tar.gz 7zip-21.07.tar.bz2 7zip-21.07.zip |
'21.07'21.07
Diffstat (limited to 'CPP/Windows/CommonDialog.cpp')
-rw-r--r-- | CPP/Windows/CommonDialog.cpp | 208 |
1 files changed, 208 insertions, 0 deletions
diff --git a/CPP/Windows/CommonDialog.cpp b/CPP/Windows/CommonDialog.cpp new file mode 100644 index 0000000..eaaecad --- /dev/null +++ b/CPP/Windows/CommonDialog.cpp | |||
@@ -0,0 +1,208 @@ | |||
1 | // Windows/CommonDialog.cpp | ||
2 | |||
3 | #include "StdAfx.h" | ||
4 | |||
5 | #include "../Common/MyWindows.h" | ||
6 | |||
7 | #ifdef UNDER_CE | ||
8 | #include <commdlg.h> | ||
9 | #endif | ||
10 | |||
11 | #ifndef _UNICODE | ||
12 | #include "../Common/StringConvert.h" | ||
13 | #endif | ||
14 | |||
15 | #include "CommonDialog.h" | ||
16 | #include "Defs.h" | ||
17 | |||
18 | #ifndef _UNICODE | ||
19 | extern bool g_IsNT; | ||
20 | #endif | ||
21 | |||
22 | namespace NWindows { | ||
23 | |||
24 | #ifndef _UNICODE | ||
25 | |||
26 | class CDoubleZeroStringListA | ||
27 | { | ||
28 | LPTSTR Buf; | ||
29 | unsigned Size; | ||
30 | public: | ||
31 | CDoubleZeroStringListA(LPSTR buf, unsigned size): Buf(buf), Size(size) {} | ||
32 | bool Add(LPCSTR s) throw(); | ||
33 | void Finish() { *Buf = 0; } | ||
34 | }; | ||
35 | |||
36 | bool CDoubleZeroStringListA::Add(LPCSTR s) throw() | ||
37 | { | ||
38 | unsigned len = MyStringLen(s) + 1; | ||
39 | if (len >= Size) | ||
40 | return false; | ||
41 | MyStringCopy(Buf, s); | ||
42 | Buf += len; | ||
43 | Size -= len; | ||
44 | return true; | ||
45 | } | ||
46 | |||
47 | #endif | ||
48 | |||
49 | class CDoubleZeroStringListW | ||
50 | { | ||
51 | LPWSTR Buf; | ||
52 | unsigned Size; | ||
53 | public: | ||
54 | CDoubleZeroStringListW(LPWSTR buf, unsigned size): Buf(buf), Size(size) {} | ||
55 | bool Add(LPCWSTR s) throw(); | ||
56 | void Finish() { *Buf = 0; } | ||
57 | }; | ||
58 | |||
59 | bool CDoubleZeroStringListW::Add(LPCWSTR s) throw() | ||
60 | { | ||
61 | unsigned len = MyStringLen(s) + 1; | ||
62 | if (len >= Size) | ||
63 | return false; | ||
64 | MyStringCopy(Buf, s); | ||
65 | Buf += len; | ||
66 | Size -= len; | ||
67 | return true; | ||
68 | } | ||
69 | |||
70 | |||
71 | #ifdef UNDER_CE | ||
72 | #define MY__OFN_PROJECT 0x00400000 | ||
73 | #define MY__OFN_SHOW_ALL 0x01000000 | ||
74 | #endif | ||
75 | |||
76 | /* if (lpstrFilter == NULL && nFilterIndex == 0) | ||
77 | MSDN : "the system doesn't show any files", | ||
78 | but WinXP-64 shows all files. Why ??? */ | ||
79 | |||
80 | /* | ||
81 | structures | ||
82 | OPENFILENAMEW | ||
83 | OPENFILENAMEA | ||
84 | contain additional members: | ||
85 | #if (_WIN32_WINNT >= 0x0500) | ||
86 | void *pvReserved; | ||
87 | DWORD dwReserved; | ||
88 | DWORD FlagsEx; | ||
89 | #endif | ||
90 | |||
91 | If we compile the source code with (_WIN32_WINNT >= 0x0500), some functions | ||
92 | will not work at NT 4.0, if we use sizeof(OPENFILENAME*). | ||
93 | So we use size of old version of structure. */ | ||
94 | |||
95 | #if defined(UNDER_CE) || defined(_WIN64) || (_WIN32_WINNT < 0x0500) | ||
96 | // || !defined(WINVER) | ||
97 | #ifndef _UNICODE | ||
98 | #define my_compatib_OPENFILENAMEA_size sizeof(OPENFILENAMEA) | ||
99 | #endif | ||
100 | #define my_compatib_OPENFILENAMEW_size sizeof(OPENFILENAMEW) | ||
101 | #else | ||
102 | |||
103 | // MinGW doesn't support some required macros. So we define them here: | ||
104 | #ifndef CDSIZEOF_STRUCT | ||
105 | #define CDSIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member)) | ||
106 | #endif | ||
107 | #ifndef _UNICODE | ||
108 | #ifndef OPENFILENAME_SIZE_VERSION_400A | ||
109 | #define OPENFILENAME_SIZE_VERSION_400A CDSIZEOF_STRUCT(OPENFILENAMEA,lpTemplateName) | ||
110 | #endif | ||
111 | #endif | ||
112 | #ifndef OPENFILENAME_SIZE_VERSION_400W | ||
113 | #define OPENFILENAME_SIZE_VERSION_400W CDSIZEOF_STRUCT(OPENFILENAMEW,lpTemplateName) | ||
114 | #endif | ||
115 | |||
116 | #ifndef _UNICODE | ||
117 | #define my_compatib_OPENFILENAMEA_size OPENFILENAME_SIZE_VERSION_400A | ||
118 | #endif | ||
119 | #define my_compatib_OPENFILENAMEW_size OPENFILENAME_SIZE_VERSION_400W | ||
120 | #endif | ||
121 | |||
122 | #ifndef _UNICODE | ||
123 | #define CONV_U_To_A(dest, src, temp) AString temp; if (src) { temp = GetSystemString(src); dest = temp; } | ||
124 | #endif | ||
125 | |||
126 | bool MyGetOpenFileName(HWND hwnd, LPCWSTR title, | ||
127 | LPCWSTR initialDir, | ||
128 | LPCWSTR filePath, | ||
129 | LPCWSTR filterDescription, | ||
130 | LPCWSTR filter, | ||
131 | UString &resPath | ||
132 | #ifdef UNDER_CE | ||
133 | , bool openFolder | ||
134 | #endif | ||
135 | ) | ||
136 | { | ||
137 | const unsigned kBufSize = MAX_PATH * 2; | ||
138 | const unsigned kFilterBufSize = MAX_PATH; | ||
139 | if (!filter) | ||
140 | filter = L"*.*"; | ||
141 | #ifndef _UNICODE | ||
142 | if (!g_IsNT) | ||
143 | { | ||
144 | CHAR buf[kBufSize]; | ||
145 | MyStringCopy(buf, (const char *)GetSystemString(filePath)); | ||
146 | // OPENFILENAME_NT4A | ||
147 | OPENFILENAMEA p; | ||
148 | memset(&p, 0, sizeof(p)); | ||
149 | p.lStructSize = my_compatib_OPENFILENAMEA_size; | ||
150 | p.hwndOwner = hwnd; | ||
151 | CHAR filterBuf[kFilterBufSize]; | ||
152 | { | ||
153 | CDoubleZeroStringListA dz(filterBuf, kFilterBufSize); | ||
154 | dz.Add(GetSystemString(filterDescription ? filterDescription : filter)); | ||
155 | dz.Add(GetSystemString(filter)); | ||
156 | dz.Finish(); | ||
157 | p.lpstrFilter = filterBuf; | ||
158 | p.nFilterIndex = 1; | ||
159 | } | ||
160 | |||
161 | p.lpstrFile = buf; | ||
162 | p.nMaxFile = kBufSize; | ||
163 | CONV_U_To_A(p.lpstrInitialDir, initialDir, initialDirA); | ||
164 | CONV_U_To_A(p.lpstrTitle, title, titleA); | ||
165 | p.Flags = OFN_EXPLORER | OFN_HIDEREADONLY; | ||
166 | |||
167 | bool res = BOOLToBool(::GetOpenFileNameA(&p)); | ||
168 | resPath = GetUnicodeString(buf); | ||
169 | return res; | ||
170 | } | ||
171 | else | ||
172 | #endif | ||
173 | { | ||
174 | WCHAR buf[kBufSize]; | ||
175 | MyStringCopy(buf, filePath); | ||
176 | // OPENFILENAME_NT4W | ||
177 | OPENFILENAMEW p; | ||
178 | memset(&p, 0, sizeof(p)); | ||
179 | p.lStructSize = my_compatib_OPENFILENAMEW_size; | ||
180 | p.hwndOwner = hwnd; | ||
181 | |||
182 | WCHAR filterBuf[kFilterBufSize]; | ||
183 | { | ||
184 | CDoubleZeroStringListW dz(filterBuf, kFilterBufSize); | ||
185 | dz.Add(filterDescription ? filterDescription : filter); | ||
186 | dz.Add(filter); | ||
187 | dz.Finish(); | ||
188 | p.lpstrFilter = filterBuf; | ||
189 | p.nFilterIndex = 1; | ||
190 | } | ||
191 | |||
192 | p.lpstrFile = buf; | ||
193 | p.nMaxFile = kBufSize; | ||
194 | p.lpstrInitialDir = initialDir; | ||
195 | p.lpstrTitle = title; | ||
196 | p.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | ||
197 | #ifdef UNDER_CE | ||
198 | | (openFolder ? (MY__OFN_PROJECT | MY__OFN_SHOW_ALL) : 0) | ||
199 | #endif | ||
200 | ; | ||
201 | |||
202 | bool res = BOOLToBool(::GetOpenFileNameW(&p)); | ||
203 | resPath = buf; | ||
204 | return res; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | } | ||