Mercurial > vba-linux
comparison src/win32/FileDlg.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 // FileDlg.cpp: implementation of the FileDlg class. | |
2 // | |
3 ////////////////////////////////////////////////////////////////////// | |
4 //#define WINVER 0x0410 // windows 98 - just for this 1 file - just in case | |
5 #include "stdafx.h" | |
6 #include <commdlg.h> | |
7 #include <dlgs.h> | |
8 #include "resource.h" | |
9 #include "FileDlg.h" | |
10 #include "Sound.h" | |
11 #include "VBA.h" | |
12 | |
13 static FileDlg *instance = NULL; | |
14 | |
15 static UINT_PTR CALLBACK HookFunc(HWND hwnd, | |
16 UINT msg, | |
17 WPARAM wParam, | |
18 LPARAM lParam) | |
19 { | |
20 if (instance) | |
21 { | |
22 if (msg == WM_NOTIFY) | |
23 { | |
24 OFNOTIFY *notify = (OFNOTIFY *)lParam; | |
25 if (notify) | |
26 { | |
27 if (notify->hdr.code == CDN_TYPECHANGE) | |
28 { | |
29 instance->OnTypeChange(hwnd); | |
30 return 1; | |
31 } | |
32 } | |
33 } | |
34 } | |
35 return 0; | |
36 } | |
37 | |
38 static UINT_PTR CALLBACK HookFuncOldStyle(HWND hwnd, | |
39 UINT msg, | |
40 WPARAM wParam, | |
41 LPARAM lParam) | |
42 { | |
43 if (instance) | |
44 { | |
45 if (msg == WM_COMMAND) | |
46 { | |
47 if (HIWORD(wParam) == CBN_SELCHANGE) | |
48 { | |
49 if (LOWORD(wParam) == cmb1) | |
50 { | |
51 // call method with combobox handle to keep | |
52 // behaviour there | |
53 instance->OnTypeChange((HWND)lParam); | |
54 return 1; | |
55 } | |
56 } | |
57 } | |
58 } | |
59 return 0; | |
60 } | |
61 | |
62 ///////////////////////////////////////////////////////////////////////////// | |
63 // FileDlg | |
64 | |
65 ////////////////////////////////////////////////////////////////////// | |
66 // Construction/Destruction | |
67 ////////////////////////////////////////////////////////////////////// | |
68 | |
69 FileDlg::FileDlg(CWnd *parent, LPCTSTR file, LPCTSTR filter, | |
70 int filterIndex, LPCTSTR ext, LPCTSTR *exts, LPCTSTR initialDir, | |
71 LPCTSTR title, bool save, bool noReadOnly) | |
72 { | |
73 OSVERSIONINFO info; | |
74 info.dwOSVersionInfoSize = sizeof(info); | |
75 GetVersionEx(&info); | |
76 m_file = file; | |
77 int size = sizeof(OPENFILENAME); | |
78 | |
79 // avoid problems if OPENFILENAME is already defined with the extended fields | |
80 // needed for the enhanced open/save dialog | |
81 #if _WIN32_WINNT < 0x0500 | |
82 if (info.dwPlatformId == VER_PLATFORM_WIN32_NT) | |
83 { | |
84 if (info.dwMajorVersion >= 5) | |
85 size = sizeof(OPENFILENAMEEX); | |
86 } | |
87 #endif | |
88 | |
89 ZeroMemory(&m_ofn, sizeof(m_ofn)); | |
90 m_ofn.lpstrFile = m_file.GetBuffer(MAX_PATH); | |
91 m_ofn.nMaxFile = MAX_PATH; | |
92 m_ofn.lStructSize = size; | |
93 m_ofn.hwndOwner = parent ? parent->GetSafeHwnd() : NULL; | |
94 m_ofn.nFilterIndex = filterIndex; | |
95 m_ofn.lpstrInitialDir = initialDir; | |
96 m_ofn.lpstrTitle = title; | |
97 m_ofn.lpstrDefExt = ext; | |
98 m_ofn.lpfnHook = HookFunc; | |
99 m_ofn.Flags = OFN_PATHMUSTEXIST | OFN_ENABLESIZING | OFN_ENABLEHOOK; | |
100 m_ofn.Flags |= OFN_EXPLORER; | |
101 if (noReadOnly) | |
102 m_ofn.Flags |= OFN_HIDEREADONLY; | |
103 m_filter = filter; | |
104 | |
105 char *p = m_filter.GetBuffer(0); | |
106 | |
107 while ((p = strchr(p, '|')) != NULL) | |
108 *p++ = 0; | |
109 m_ofn.lpstrFilter = m_filter; | |
110 | |
111 if (theApp.videoOption == VIDEO_320x240) | |
112 { | |
113 m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_OPENDLG); | |
114 m_ofn.lpfnHook = HookFuncOldStyle; | |
115 m_ofn.Flags |= OFN_ENABLETEMPLATE; | |
116 m_ofn.Flags &= ~OFN_EXPLORER; | |
117 } | |
118 | |
119 isSave = save; | |
120 extensions = exts; | |
121 | |
122 instance = this; | |
123 } | |
124 | |
125 FileDlg::~FileDlg() | |
126 { | |
127 instance = NULL; | |
128 } | |
129 | |
130 void FileDlg::OnTypeChange(HWND hwnd) | |
131 { | |
132 HWND parent = GetParent(hwnd); | |
133 | |
134 HWND fileNameControl = ::GetDlgItem(parent, cmb13); | |
135 | |
136 if (fileNameControl == NULL) | |
137 fileNameControl = ::GetDlgItem(parent, edt1); | |
138 | |
139 if (fileNameControl == NULL) | |
140 return; | |
141 | |
142 CString filename; | |
143 GetWindowText(fileNameControl, filename.GetBuffer(MAX_PATH), MAX_PATH); | |
144 filename.ReleaseBuffer(); | |
145 | |
146 HWND typeControl = ::GetDlgItem(parent, cmb1); | |
147 | |
148 ASSERT(typeControl != NULL); | |
149 | |
150 int sel = ::SendMessage(typeControl, CB_GETCURSEL, 0, 0); | |
151 | |
152 ASSERT(sel != -1); | |
153 | |
154 LPCTSTR typeName = extensions[sel]; | |
155 | |
156 // sel could easily be an invalid index of extensions, so check for null guard | |
157 for(int i = 0; i <= sel; i++) | |
158 if(extensions[i] == NULL) | |
159 typeName = ""; | |
160 | |
161 if (filename.GetLength() == 0) | |
162 { | |
163 if(*typeName) | |
164 filename.Format("*%s", typeName); | |
165 } | |
166 else | |
167 { | |
168 int index = filename.Find('.'); | |
169 if (index == -1) | |
170 { | |
171 filename = filename + typeName; | |
172 } | |
173 else | |
174 { | |
175 filename = filename.Left(index) + typeName; | |
176 } | |
177 } | |
178 SetWindowText(fileNameControl, filename); | |
179 } | |
180 | |
181 int FileDlg::getFilterIndex() | |
182 { | |
183 return m_ofn.nFilterIndex; | |
184 } | |
185 | |
186 int FileDlg::DoModal() | |
187 { | |
188 systemSoundClearBuffer(); | |
189 BOOL res = isSave ? GetSaveFileName(&m_ofn) : | |
190 GetOpenFileName(&m_ofn); | |
191 | |
192 return res ? IDOK : IDCANCEL; | |
193 } | |
194 | |
195 LPCTSTR FileDlg::GetPathName() | |
196 { | |
197 return (LPCTSTR)m_file; | |
198 } | |
199 |