]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/filedlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFileDialog
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/msgdlg.h"
22 #include "wx/dialog.h"
23 #include "wx/filedlg.h"
32 #include "wx/os2/private.h"
38 #include "wx/tokenzr.h"
40 #define wxMAXPATH 1024
41 #define wxMAXFILE 1024
59 IMPLEMENT_CLASS(wxFileDialog
, wxDialog
)
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 wxFileDialog::wxFileDialog (
67 , const wxString
& rsMessage
68 , const wxString
& rsDefaultDir
69 , const wxString
& rsDefaultFileName
70 , const wxString
& rsWildCard
75 m_sMessage
= rsMessage
;
76 m_lDialogStyle
= lStyle
;
77 if ((m_lDialogStyle
& wxMULTIPLE
) && (m_lDialogStyle
& wxSAVE
))
78 m_lDialogStyle
&= ~wxMULTIPLE
;
81 m_sFileName
= rsDefaultFileName
;
82 m_sDir
= rsDefaultDir
;
83 m_sWildCard
= rsWildCard
;
86 } // end of wxFileDialog::wxFileDialog
88 void wxFileDialog::GetPaths (
89 wxArrayString
& rasPaths
92 wxString
sDir(m_sDir
);
93 size_t nCount
= m_asFileNames
.GetCount();
96 if (m_sDir
.Last() != _T('\\'))
99 for ( size_t n
= 0; n
< nCount
; n
++ )
101 rasPaths
.Add(sDir
+ m_asFileNames
[n
]);
103 } // end of wxFileDialog::GetPaths
105 int wxFileDialog::ShowModal()
108 wxString sFilterBuffer
;
109 wxChar
* pzFilterBuffer
;
110 static wxChar zFileNameBuffer
[wxMAXPATH
]; // the file-name
112 wxChar zTitleBuffer
[wxMAXFILE
+ 1 + wxMAXEXT
]; // the file-name, without path
115 size_t nLen
= m_sDir
.length();
120 memset(&vFileDlg
, '\0', sizeof(FILEDLG
));
122 hWnd
= (HWND
) m_pParent
->GetHWND();
123 if (!hWnd
&& wxTheApp
->GetTopWindow())
124 hWnd
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
127 *zFileNameBuffer
= wxT('\0');
128 *zTitleBuffer
= wxT('\0');
130 if (m_lDialogStyle
& wxSAVE
)
131 lFlags
= FDS_SAVEAS_DIALOG
;
133 lFlags
= FDS_OPEN_DIALOG
;
135 if ((m_lDialogStyle
& wxHIDE_READONLY
) || (m_lDialogStyle
& wxSAVE
))
136 lFlags
|= FDS_SAVEAS_DIALOG
;
137 if (m_lDialogStyle
& wxMULTIPLE
)
138 lFlags
|= FDS_OPEN_DIALOG
| FDS_MULTIPLESEL
;
140 vFileDlg
.cbSize
= sizeof(FILEDLG
);
141 vFileDlg
.fl
= lFlags
;
142 vFileDlg
.pszTitle
= zTitleBuffer
;
145 // Convert forward slashes to backslashes (file selector doesn't like
146 // forward slashes) and also squeeze multiple consecutive slashes into one
147 // as it doesn't like two backslashes in a row neither
150 for ( i
= 0; i
< nLen
; i
++ )
152 wxChar ch
= m_sDir
[i
];
158 // Convert to backslash
168 wxChar chNext
= m_sDir
[i
+ 1];
170 if (chNext
!= _T('\\') && chNext
!= _T('/'))
174 // Ignore the next one, unless it is at the start of a UNC path
192 if ( wxStrlen(m_sWildCard
) == 0 )
195 sTheFilter
= m_sWildCard
;
197 pzFilterBuffer
= strtok((char*)sTheFilter
.c_str(), "|");
198 while(pzFilterBuffer
!= NULL
)
200 if (nCount
> 0 && !(nCount
% 2))
204 sDir
+= pzFilterBuffer
;
206 pzFilterBuffer
= strtok(NULL
, "|");
213 wxStrcpy(vFileDlg
.szFullFile
, sDir
.c_str());
214 sFilterBuffer
= sDir
;
216 hWnd
= ::WinFileDlg( HWND_DESKTOP
217 ,GetHwndOf(m_pParent
)
220 if (hWnd
&& vFileDlg
.lReturn
== DID_OK
)
222 m_asFileNames
.Empty();
223 if ((m_lDialogStyle
& wxMULTIPLE
) && vFileDlg
.ulFQFCount
> 1)
225 for (int i
= 0; i
< vFileDlg
.ulFQFCount
; i
++)
229 m_sDir
= wxPathOnly(wxString((const char*)*vFileDlg
.papszFQFilename
[0]));
230 m_sPath
= (const char*)*vFileDlg
.papszFQFilename
[0];
232 m_sFileName
= wxFileNameFromPath(wxString((const char*)*vFileDlg
.papszFQFilename
[i
]));
233 m_asFileNames
.Add(m_sFileName
);
235 ::WinFreeFileDlgList(vFileDlg
.papszFQFilename
);
237 else if (!(m_lDialogStyle
& wxSAVE
))
239 m_sPath
= vFileDlg
.szFullFile
;
240 m_sFileName
= wxFileNameFromPath(vFileDlg
.szFullFile
);
241 m_sDir
= wxPathOnly(vFileDlg
.szFullFile
);
245 const wxChar
* pzExtension
= NULL
;
247 wxStrcpy(zFileNameBuffer
, vFileDlg
.szFullFile
);
249 int nIdx
= wxStrlen(zFileNameBuffer
) - 1;
252 wxSplitPath( zFileNameBuffer
257 if (zFileNameBuffer
[nIdx
] == wxT('.') || sExt
.IsEmpty())
259 zFileNameBuffer
[nIdx
] = wxT('\0');
262 // User has typed a filename without an extension:
264 // A filename can end in a "." here ("abc."), this means it
265 // does not have an extension. Because later on a "." with
266 // the default extension is appended we remove the "." if
267 // filename ends with one (We don't want files called
270 pzExtension
= sFilterBuffer
.c_str();
272 for( int i
= 0; i
< sFilterBuffer
.length(); i
++ )
277 pzExtension
= wxStrrchr(pzExtension
, wxT('.'));
279 !wxStrrchr(pzExtension
, wxT('*')) &&
280 !wxStrrchr(pzExtension
, wxT('?')) &&
282 pzExtension
[1] != wxT(' ')
286 // Now concat extension to the fileName:
288 m_sPath
= wxString(zFileNameBuffer
) + pzExtension
;
294 m_sPath
= vFileDlg
.szFullFile
;
296 m_sFileName
= wxFileNameFromPath(vFileDlg
.szFullFile
);
297 m_sDir
= wxPathOnly(vFileDlg
.szFullFile
);
300 // === Simulating the wxOVERWRITE_PROMPT >>============================
302 if ((m_lDialogStyle
& wxOVERWRITE_PROMPT
) &&
303 (m_lDialogStyle
& wxSAVE
) &&
304 (wxFileExists(m_sPath
.c_str())))
306 wxString sMessageText
;
308 sMessageText
.Printf( _("File '%s' already exists.\nDo you want to replace it?")
311 if (wxMessageBox( sMessageText
313 ,wxYES_NO
| wxICON_EXCLAMATION
323 } // end of wxFileDialog::ShowModal