]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/filedlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/filedlg.cpp
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/filedlg.h"
25 #include "wx/msgdlg.h"
35 #include "wx/os2/private.h"
40 #include "wx/tokenzr.h"
42 #define wxMAXPATH 1024
43 #define wxMAXFILE 1024
62 IMPLEMENT_CLASS(wxFileDialog
, wxFileDialogBase
)
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 wxFileDialog::wxFileDialog (
70 , const wxString
& rsMessage
71 , const wxString
& rsDefaultDir
72 , const wxString
& rsDefaultFileName
73 , const wxString
& rsWildCard
75 , const wxPoint
& rPos
,
79 :wxFileDialogBase(pParent
, rsMessage
, rsDefaultDir
, rsDefaultFileName
, rsWildCard
, lStyle
, rPos
, sz
, name
)
82 // NB: all style checks are done by wxFileDialogBase::Create
85 } // end of wxFileDialog::wxFileDialog
87 void wxFileDialog::GetPaths (
88 wxArrayString
& rasPaths
92 size_t nCount
= m_fileNames
.GetCount();
95 if (m_dir
.Last() != _T('\\'))
98 for ( size_t n
= 0; n
< nCount
; n
++ )
100 rasPaths
.Add(sDir
+ m_fileNames
[n
]);
102 } // end of wxFileDialog::GetPaths
104 int wxFileDialog::ShowModal()
107 wxString sFilterBuffer
;
108 wxChar
* pzFilterBuffer
;
109 static wxChar zFileNameBuffer
[wxMAXPATH
]; // the file-name
111 wxChar zTitleBuffer
[wxMAXFILE
+ 1 + wxMAXEXT
]; // the file-name, without path
114 size_t nLen
= m_dir
.length();
119 memset(&vFileDlg
, '\0', sizeof(FILEDLG
));
121 hWnd
= (HWND
) m_parent
->GetHWND();
122 if (!hWnd
&& wxTheApp
->GetTopWindow())
123 hWnd
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
126 *zFileNameBuffer
= wxT('\0');
127 *zTitleBuffer
= wxT('\0');
129 if (m_windowStyle
& wxFD_SAVE
)
130 lFlags
= FDS_SAVEAS_DIALOG
;
132 lFlags
= FDS_OPEN_DIALOG
;
134 if (m_windowStyle
& wxFD_SAVE
)
135 lFlags
|= FDS_SAVEAS_DIALOG
;
136 if (m_windowStyle
& wxFD_MULTIPLE
)
137 lFlags
|= FDS_OPEN_DIALOG
| FDS_MULTIPLESEL
;
139 vFileDlg
.cbSize
= sizeof(FILEDLG
);
140 vFileDlg
.fl
= lFlags
;
141 vFileDlg
.pszTitle
= (PSZ
)zTitleBuffer
;
144 // Convert forward slashes to backslashes (file selector doesn't like
145 // forward slashes) and also squeeze multiple consecutive slashes into one
146 // as it doesn't like two backslashes in a row neither
149 for ( i
= 0; i
< nLen
; i
++ )
151 wxChar ch
= m_dir
[i
];
157 // Convert to backslash
167 wxChar chNext
= m_dir
[i
+ 1];
169 if (chNext
!= _T('\\') && chNext
!= _T('/'))
173 // Ignore the next one, unless it is at the start of a UNC path
191 if ( wxStrlen(m_wildCard
) == 0 )
192 sTheFilter
= wxEmptyString
;
194 sTheFilter
= m_wildCard
;
196 wxStrtok(sTheFilter
.char_str(), wxT("|"), &pzFilterBuffer
);
197 while(pzFilterBuffer
!= NULL
)
199 if (nCount
> 0 && !(nCount
% 2))
203 sDir
+= pzFilterBuffer
;
205 wxStrtok(NULL
, wxT("|"), &pzFilterBuffer
);
212 wxStrcpy((wxChar
*)vFileDlg
.szFullFile
, sDir
);
213 sFilterBuffer
= sDir
;
215 hWnd
= ::WinFileDlg( HWND_DESKTOP
219 if (hWnd
&& vFileDlg
.lReturn
== DID_OK
)
222 if ((m_windowStyle
& wxFD_MULTIPLE
) && vFileDlg
.ulFQFCount
> 1)
224 for (int i
= 0; i
< (int)vFileDlg
.ulFQFCount
; i
++)
228 m_dir
= wxPathOnly(wxString((const wxChar
*)*vFileDlg
.papszFQFilename
[0]));
229 m_path
= (const wxChar
*)*vFileDlg
.papszFQFilename
[0];
231 m_fileName
= wxFileNameFromPath(wxString((const wxChar
*)*vFileDlg
.papszFQFilename
[i
]));
232 m_fileNames
.Add(m_fileName
);
234 ::WinFreeFileDlgList(vFileDlg
.papszFQFilename
);
236 else if (!(m_windowStyle
& wxFD_SAVE
))
238 m_path
= (wxChar
*)vFileDlg
.szFullFile
;
239 m_fileName
= wxFileNameFromPath(wxString((const wxChar
*)vFileDlg
.szFullFile
));
240 m_dir
= wxPathOnly((const wxChar
*)vFileDlg
.szFullFile
);
244 const wxChar
* pzExtension
= NULL
;
246 wxStrcpy(zFileNameBuffer
, (const wxChar
*)vFileDlg
.szFullFile
);
248 int nIdx
= wxStrlen(zFileNameBuffer
) - 1;
251 wxSplitPath( zFileNameBuffer
256 if (zFileNameBuffer
[nIdx
] == wxT('.') || sExt
.empty())
258 zFileNameBuffer
[nIdx
] = wxT('\0');
261 // User has typed a filename without an extension:
263 // A filename can end in a "." here ("abc."), this means it
264 // does not have an extension. Because later on a "." with
265 // the default extension is appended we remove the "." if
266 // filename ends with one (We don't want files called
269 pzExtension
= sFilterBuffer
.c_str();
271 for( int i
= 0; i
< (int)sFilterBuffer
.length(); i
++ )
276 pzExtension
= wxStrrchr(pzExtension
, wxT('.'));
278 !wxStrrchr(pzExtension
, wxT('*')) &&
279 !wxStrrchr(pzExtension
, wxT('?')) &&
281 pzExtension
[1] != wxT(' ')
285 // Now concat extension to the fileName:
287 m_path
= wxString(zFileNameBuffer
) + pzExtension
;
293 m_path
= (wxChar
*)vFileDlg
.szFullFile
;
295 m_fileName
= wxFileNameFromPath((const wxChar
*)vFileDlg
.szFullFile
);
296 m_dir
= wxPathOnly((const wxChar
*)vFileDlg
.szFullFile
);
299 // === Simulating the wxFD_OVERWRITE_PROMPT >>============================
301 if ((m_windowStyle
& wxFD_OVERWRITE_PROMPT
) &&
302 (m_windowStyle
& wxFD_SAVE
) &&
303 (wxFileExists(m_path
.c_str())))
305 wxString sMessageText
;
307 sMessageText
.Printf( _("File '%s' already exists.\nDo you want to replace it?")
310 if (wxMessageBox( sMessageText
312 ,wxYES_NO
| wxICON_EXCLAMATION
322 } // end of wxFileDialog::ShowModal
324 #endif // wxUSE_FILEDLG