]>
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
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/filedlg.h"
24 #include "wx/msgdlg.h"
25 #include "wx/filename.h"
35 #include "wx/os2/private.h"
40 #include "wx/tokenzr.h"
41 #include "wx/modalhook.h"
43 #define wxMAXPATH 1024
44 #define wxMAXFILE 1024
63 IMPLEMENT_CLASS(wxFileDialog
, wxFileDialogBase
)
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 wxFileDialog::wxFileDialog (
71 , const wxString
& rsMessage
72 , const wxString
& rsDefaultDir
73 , const wxString
& rsDefaultFileName
74 , const wxString
& rsWildCard
76 , const wxPoint
& rPos
,
80 :wxFileDialogBase(pParent
, rsMessage
, rsDefaultDir
, rsDefaultFileName
, rsWildCard
, lStyle
, rPos
, sz
, name
)
83 // NB: all style checks are done by wxFileDialogBase::Create
86 } // end of wxFileDialog::wxFileDialog
88 void wxFileDialog::GetPaths (
89 wxArrayString
& rasPaths
93 size_t nCount
= m_fileNames
.GetCount();
96 if (m_dir
.Last() != wxT('\\'))
99 for ( size_t n
= 0; n
< nCount
; n
++ )
101 rasPaths
.Add(sDir
+ m_fileNames
[n
]);
103 } // end of wxFileDialog::GetPaths
105 int wxFileDialog::ShowModal()
107 WX_HOOK_MODAL_DIALOG();
110 wxString sFilterBuffer
;
111 wxChar
* pzFilterBuffer
;
112 static wxChar zFileNameBuffer
[wxMAXPATH
]; // the file-name
114 wxChar zTitleBuffer
[wxMAXFILE
+ 1 + wxMAXEXT
]; // the file-name, without path
117 size_t nLen
= m_dir
.length();
122 memset(&vFileDlg
, '\0', sizeof(FILEDLG
));
124 hWnd
= (HWND
) m_parent
->GetHWND();
125 if (!hWnd
&& wxTheApp
->GetTopWindow())
126 hWnd
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
129 *zFileNameBuffer
= wxT('\0');
130 *zTitleBuffer
= wxT('\0');
132 if (m_windowStyle
& wxFD_SAVE
)
133 lFlags
= FDS_SAVEAS_DIALOG
;
135 lFlags
= FDS_OPEN_DIALOG
;
137 if (m_windowStyle
& wxFD_SAVE
)
138 lFlags
|= FDS_SAVEAS_DIALOG
;
139 if (m_windowStyle
& wxFD_MULTIPLE
)
140 lFlags
|= FDS_OPEN_DIALOG
| FDS_MULTIPLESEL
;
142 vFileDlg
.cbSize
= sizeof(FILEDLG
);
143 vFileDlg
.fl
= lFlags
;
144 vFileDlg
.pszTitle
= (PSZ
)zTitleBuffer
;
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
152 for ( i
= 0; i
< nLen
; i
++ )
154 wxChar ch
= m_dir
[i
];
160 // Convert to backslash
170 wxChar chNext
= m_dir
[i
+ 1];
172 if (chNext
!= wxT('\\') && chNext
!= wxT('/'))
176 // Ignore the next one, unless it is at the start of a UNC path
194 if ( wxStrlen(m_wildCard
) == 0 )
195 sTheFilter
= wxEmptyString
;
197 sTheFilter
= m_wildCard
;
199 wxStrtok(sTheFilter
.wchar_str(), wxT("|"), &pzFilterBuffer
);
200 while(pzFilterBuffer
!= NULL
)
202 if (nCount
> 0 && !(nCount
% 2))
206 sDir
+= pzFilterBuffer
;
208 wxStrtok(NULL
, wxT("|"), &pzFilterBuffer
);
215 wxStrcpy((wxChar
*)vFileDlg
.szFullFile
, sDir
);
216 sFilterBuffer
= sDir
;
218 hWnd
= ::WinFileDlg( HWND_DESKTOP
222 if (hWnd
&& vFileDlg
.lReturn
== DID_OK
)
225 if ((m_windowStyle
& wxFD_MULTIPLE
) && vFileDlg
.ulFQFCount
> 1)
227 for (int i
= 0; i
< (int)vFileDlg
.ulFQFCount
; i
++)
231 m_dir
= wxPathOnly(wxString((const wxChar
*)*vFileDlg
.papszFQFilename
[0]));
232 m_path
= (const wxChar
*)*vFileDlg
.papszFQFilename
[0];
234 m_fileName
= wxFileNameFromPath(wxString((const wxChar
*)*vFileDlg
.papszFQFilename
[i
]));
235 m_fileNames
.Add(m_fileName
);
237 ::WinFreeFileDlgList(vFileDlg
.papszFQFilename
);
239 else if (!(m_windowStyle
& wxFD_SAVE
))
241 m_path
= (wxChar
*)vFileDlg
.szFullFile
;
242 m_fileName
= wxFileNameFromPath(wxString((const wxChar
*)vFileDlg
.szFullFile
));
243 m_dir
= wxPathOnly((const wxChar
*)vFileDlg
.szFullFile
);
247 const wxChar
* pzExtension
= NULL
;
249 wxStrcpy(zFileNameBuffer
, (const wxChar
*)vFileDlg
.szFullFile
);
251 int nIdx
= wxStrlen(zFileNameBuffer
) - 1;
254 wxFileName::SplitPath( zFileNameBuffer
259 if (zFileNameBuffer
[nIdx
] == wxT('.') || sExt
.empty())
261 zFileNameBuffer
[nIdx
] = wxT('\0');
264 // User has typed a filename without an extension:
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
272 pzExtension
= sFilterBuffer
.c_str();
274 for( int i
= 0; i
< (int)sFilterBuffer
.length(); i
++ )
279 pzExtension
= wxStrrchr(pzExtension
, wxT('.'));
281 !wxStrrchr(pzExtension
, wxT('*')) &&
282 !wxStrrchr(pzExtension
, wxT('?')) &&
284 pzExtension
[1] != wxT(' ')
288 // Now concat extension to the fileName:
290 m_path
= wxString(zFileNameBuffer
) + pzExtension
;
296 m_path
= (wxChar
*)vFileDlg
.szFullFile
;
298 m_fileName
= wxFileNameFromPath((const wxChar
*)vFileDlg
.szFullFile
);
299 m_dir
= wxPathOnly((const wxChar
*)vFileDlg
.szFullFile
);
302 // === Simulating the wxFD_OVERWRITE_PROMPT >>============================
304 if ((m_windowStyle
& wxFD_OVERWRITE_PROMPT
) &&
305 (m_windowStyle
& wxFD_SAVE
) &&
306 (wxFileExists(m_path
.c_str())))
308 wxString sMessageText
;
310 sMessageText
.Printf( _("File '%s' already exists.\nDo you want to replace it?")
313 if (wxMessageBox( sMessageText
315 ,wxYES_NO
| wxICON_EXCLAMATION
325 } // end of wxFileDialog::ShowModal
327 #endif // wxUSE_FILEDLG