]> git.saurik.com Git - wxWidgets.git/blame - src/os2/filedlg.cpp
Remove DoSetSizeHints() call from Create()
[wxWidgets.git] / src / os2 / filedlg.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
e031f1df 2// Name: src/os2/filedlg.cpp
0e320a79 3// Purpose: wxFileDialog
f0a56ab0 4// Author: David Webster
0e320a79 5// Modified by:
f0a56ab0 6// Created: 10/05/99
f0a56ab0 7// Copyright: (c) David Webster
65571936 8// Licence: wxWindows licence
0e320a79
DW
9/////////////////////////////////////////////////////////////////////////////
10
fb46a9a6
DW
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
6670f564
WS
18#if wxUSE_FILEDLG
19
949c9f74
WS
20#include "wx/filedlg.h"
21
fb46a9a6 22#ifndef WX_PRECOMP
fb46a9a6
DW
23 #include "wx/utils.h"
24 #include "wx/msgdlg.h"
e39b5fa4 25 #include "wx/filename.h"
fb46a9a6
DW
26 #include "wx/intl.h"
27 #include "wx/log.h"
4efd4259 28 #include "wx/app.h"
463c4d71 29 #include "wx/math.h"
fb46a9a6
DW
30#endif
31
32#define INCL_PM
33#include <os2.h>
34
35#include "wx/os2/private.h"
36
fb46a9a6
DW
37#include <stdlib.h>
38#include <string.h>
0e320a79 39
4efd4259 40#include "wx/tokenzr.h"
691745ab 41#include "wx/modalhook.h"
4efd4259
DW
42
43#define wxMAXPATH 1024
44#define wxMAXFILE 1024
45#define wxMAXEXT 5
46
47#ifndef MAXPATH
48# define MAXPATH 400
49#endif
50
51#ifndef MAXDRIVE
52# define MAXDRIVE 3
53#endif
54
55#ifndef MAXFILE
56# define MAXFILE 9
57#endif
58
59#ifndef MAXEXT
60# define MAXEXT 5
61#endif
6670f564 62
f74172ab 63IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase)
0e320a79 64
4efd4259
DW
65// ----------------------------------------------------------------------------
66// CLASS wxFileDialog
67// ----------------------------------------------------------------------------
68
69wxFileDialog::wxFileDialog (
70 wxWindow* pParent
71, const wxString& rsMessage
72, const wxString& rsDefaultDir
73, const wxString& rsDefaultFileName
74, const wxString& rsWildCard
75, long lStyle
ff3e84ff
VZ
76, const wxPoint& rPos,
77 const wxSize& sz,
78 const wxString& name
4efd4259 79)
ff3e84ff 80 :wxFileDialogBase(pParent, rsMessage, rsDefaultDir, rsDefaultFileName, rsWildCard, lStyle, rPos, sz, name)
f74172ab 81
0e320a79 82{
556151f5 83 // NB: all style checks are done by wxFileDialogBase::Create
f74172ab
VZ
84
85 m_filterIndex = 1;
4efd4259
DW
86} // end of wxFileDialog::wxFileDialog
87
88void wxFileDialog::GetPaths (
89 wxArrayString& rasPaths
90) const
91{
f74172ab
VZ
92 wxString sDir(m_dir);
93 size_t nCount = m_fileNames.GetCount();
4efd4259
DW
94
95 rasPaths.Empty();
9a83f860
VZ
96 if (m_dir.Last() != wxT('\\'))
97 sDir += wxT('\\');
4efd4259
DW
98
99 for ( size_t n = 0; n < nCount; n++ )
100 {
f74172ab 101 rasPaths.Add(sDir + m_fileNames[n]);
4efd4259
DW
102 }
103} // end of wxFileDialog::GetPaths
0e320a79
DW
104
105int wxFileDialog::ShowModal()
106{
691745ab 107 WX_HOOK_MODAL_DIALOG();
643e9cf9 108
4efd4259
DW
109 wxString sTheFilter;
110 wxString sFilterBuffer;
b93f4bb9 111 wxChar* pzFilterBuffer;
4efd4259
DW
112 static wxChar zFileNameBuffer[wxMAXPATH]; // the file-name
113 HWND hWnd = 0;
114 wxChar zTitleBuffer[wxMAXFILE + 1 + wxMAXEXT]; // the file-name, without path
b93f4bb9
DW
115 wxString sDir;
116 size_t i;
f74172ab 117 size_t nLen = m_dir.length();
b93f4bb9 118 int nCount = 0;
4efd4259
DW
119 FILEDLG vFileDlg;
120 ULONG lFlags = 0L;
121
122 memset(&vFileDlg, '\0', sizeof(FILEDLG));
f74172ab
VZ
123 if (m_parent)
124 hWnd = (HWND) m_parent->GetHWND();
4efd4259
DW
125 if (!hWnd && wxTheApp->GetTopWindow())
126 hWnd = (HWND) wxTheApp->GetTopWindow()->GetHWND();
127
128
129 *zFileNameBuffer = wxT('\0');
130 *zTitleBuffer = wxT('\0');
131
e031f1df 132 if (m_windowStyle & wxFD_SAVE)
b93f4bb9
DW
133 lFlags = FDS_SAVEAS_DIALOG;
134 else
135 lFlags = FDS_OPEN_DIALOG;
136
e031f1df 137 if (m_windowStyle & wxFD_SAVE)
4efd4259 138 lFlags |= FDS_SAVEAS_DIALOG;
e031f1df 139 if (m_windowStyle & wxFD_MULTIPLE)
4efd4259
DW
140 lFlags |= FDS_OPEN_DIALOG | FDS_MULTIPLESEL;
141
142 vFileDlg.cbSize = sizeof(FILEDLG);
143 vFileDlg.fl = lFlags;
0fba44b4 144 vFileDlg.pszTitle = (PSZ)zTitleBuffer;
4efd4259
DW
145
146 //
147 // Convert forward slashes to backslashes (file selector doesn't like
148 // forward slashes) and also squeeze multiple consecutive slashes into one
149 // as it doesn't like two backslashes in a row neither
150 //
151 sDir.reserve(nLen);
152 for ( i = 0; i < nLen; i++ )
153 {
f74172ab 154 wxChar ch = m_dir[i];
4efd4259
DW
155
156 switch (ch)
157 {
9a83f860 158 case wxT('/'):
4efd4259
DW
159 //
160 // Convert to backslash
161 //
9a83f860 162 ch = wxT('\\');
4efd4259
DW
163
164 //
165 // Fall through
166 //
9a83f860 167 case wxT('\\'):
4efd4259
DW
168 while (i < nLen - 1)
169 {
f74172ab 170 wxChar chNext = m_dir[i + 1];
4efd4259 171
9a83f860 172 if (chNext != wxT('\\') && chNext != wxT('/'))
4efd4259
DW
173 break;
174
175 //
176 // Ignore the next one, unless it is at the start of a UNC path
177 //
178 if (i > 0)
179 i++;
180 else
181 break;
182 }
183
184 //
185 // Fall through
186 //
187
188 default:
189 //
190 // Normal char
191 sDir += ch;
192 }
193 }
f74172ab 194 if ( wxStrlen(m_wildCard) == 0 )
0fba44b4 195 sTheFilter = wxEmptyString;
4efd4259 196 else
f74172ab 197 sTheFilter = m_wildCard;
4efd4259 198
6d8eb95b 199 wxStrtok(sTheFilter.wchar_str(), wxT("|"), &pzFilterBuffer);
b93f4bb9 200 while(pzFilterBuffer != NULL)
4efd4259 201 {
b93f4bb9
DW
202 if (nCount > 0 && !(nCount % 2))
203 sDir += wxT(";");
204 if (nCount % 2)
4efd4259 205 {
b93f4bb9 206 sDir += pzFilterBuffer;
4efd4259 207 }
0fba44b4 208 wxStrtok(NULL, wxT("|"), &pzFilterBuffer);
b93f4bb9 209 nCount++;
4efd4259 210 }
b93f4bb9 211 if (nCount == 0)
f74172ab 212 sDir += m_fileName;
6670f564 213 if (sDir.empty())
0fba44b4
DW
214 sDir = wxT("*.*");
215 wxStrcpy((wxChar*)vFileDlg.szFullFile, sDir);
25fc812c 216 sFilterBuffer = sDir;
4efd4259 217
b93f4bb9 218 hWnd = ::WinFileDlg( HWND_DESKTOP
f74172ab 219 ,GetHwndOf(m_parent)
4efd4259
DW
220 ,&vFileDlg
221 );
222 if (hWnd && vFileDlg.lReturn == DID_OK)
223 {
f74172ab 224 m_fileNames.Empty();
e031f1df 225 if ((m_windowStyle & wxFD_MULTIPLE ) && vFileDlg.ulFQFCount > 1)
4efd4259 226 {
9923c37d 227 for (int i = 0; i < (int)vFileDlg.ulFQFCount; i++)
4efd4259
DW
228 {
229 if (i == 0)
230 {
0fba44b4
DW
231 m_dir = wxPathOnly(wxString((const wxChar*)*vFileDlg.papszFQFilename[0]));
232 m_path = (const wxChar*)*vFileDlg.papszFQFilename[0];
4efd4259 233 }
0fba44b4 234 m_fileName = wxFileNameFromPath(wxString((const wxChar*)*vFileDlg.papszFQFilename[i]));
f74172ab 235 m_fileNames.Add(m_fileName);
4efd4259 236 }
b93f4bb9 237 ::WinFreeFileDlgList(vFileDlg.papszFQFilename);
4efd4259 238 }
e031f1df 239 else if (!(m_windowStyle & wxFD_SAVE))
4efd4259 240 {
0fba44b4
DW
241 m_path = (wxChar*)vFileDlg.szFullFile;
242 m_fileName = wxFileNameFromPath(wxString((const wxChar*)vFileDlg.szFullFile));
243 m_dir = wxPathOnly((const wxChar*)vFileDlg.szFullFile);
4efd4259
DW
244 }
245 else // save file
246 {
247 const wxChar* pzExtension = NULL;
248
0fba44b4 249 wxStrcpy(zFileNameBuffer, (const wxChar*)vFileDlg.szFullFile);
4efd4259
DW
250
251 int nIdx = wxStrlen(zFileNameBuffer) - 1;
25fc812c 252 wxString sExt;
4efd4259 253
bd365871
FM
254 wxFileName::SplitPath( zFileNameBuffer
255 ,&m_path
256 ,&m_fileName
257 ,&sExt
258 );
6670f564 259 if (zFileNameBuffer[nIdx] == wxT('.') || sExt.empty())
4efd4259
DW
260 {
261 zFileNameBuffer[nIdx] = wxT('\0');
262
263 //
264 // User has typed a filename without an extension:
265 //
266 // A filename can end in a "." here ("abc."), this means it
267 // does not have an extension. Because later on a "." with
268 // the default extension is appended we remove the "." if
269 // filename ends with one (We don't want files called
270 // "abc..ext")
271 //
272 pzExtension = sFilterBuffer.c_str();
273
9923c37d 274 for( int i = 0; i < (int)sFilterBuffer.length(); i++ )
4efd4259
DW
275 {
276 //
277 // Get extension
278 //
279 pzExtension = wxStrrchr(pzExtension, wxT('.'));
280 if ( pzExtension &&
281 !wxStrrchr(pzExtension, wxT('*')) &&
282 !wxStrrchr(pzExtension, wxT('?')) &&
283 pzExtension[1] &&
284 pzExtension[1] != wxT(' ')
285 ) // != "blabla. "
286 {
287 //
288 // Now concat extension to the fileName:
289 //
f74172ab 290 m_path = wxString(zFileNameBuffer) + pzExtension;
4efd4259
DW
291 }
292 }
293 }
294 else
295 {
0fba44b4 296 m_path = (wxChar*)vFileDlg.szFullFile;
4efd4259 297 }
0fba44b4
DW
298 m_fileName = wxFileNameFromPath((const wxChar*)vFileDlg.szFullFile);
299 m_dir = wxPathOnly((const wxChar*)vFileDlg.szFullFile);
4efd4259
DW
300
301 //
e031f1df 302 // === Simulating the wxFD_OVERWRITE_PROMPT >>============================
4efd4259 303 //
e031f1df
WS
304 if ((m_windowStyle & wxFD_OVERWRITE_PROMPT) &&
305 (m_windowStyle & wxFD_SAVE) &&
f74172ab 306 (wxFileExists(m_path.c_str())))
4efd4259
DW
307 {
308 wxString sMessageText;
309
310 sMessageText.Printf( _("File '%s' already exists.\nDo you want to replace it?")
f74172ab 311 ,m_path.c_str()
4efd4259
DW
312 );
313 if (wxMessageBox( sMessageText
314 ,wxT("Save File As")
315 ,wxYES_NO | wxICON_EXCLAMATION
316 ) != wxYES)
317 {
318 return wxID_CANCEL;
319 }
320 }
321 }
322 return wxID_OK;
323 }
0e320a79 324 return wxID_CANCEL;
4efd4259 325} // end of wxFileDialog::ShowModal
0e320a79 326
6670f564 327#endif // wxUSE_FILEDLG