]>
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 WXWIN_COMPATIBILITY_2_4
135 if (m_windowStyle
& wxHIDE_READONLY
)
136 lFlags
|= FDS_SAVEAS_DIALOG
;
139 if (m_windowStyle
& wxFD_SAVE
)
140 lFlags
|= FDS_SAVEAS_DIALOG
;
141 if (m_windowStyle
& wxFD_MULTIPLE
)
142 lFlags
|= FDS_OPEN_DIALOG
| FDS_MULTIPLESEL
;
144 vFileDlg
.cbSize
= sizeof(FILEDLG
);
145 vFileDlg
.fl
= lFlags
;
146 vFileDlg
.pszTitle
= (PSZ
)zTitleBuffer
;
149 // Convert forward slashes to backslashes (file selector doesn't like
150 // forward slashes) and also squeeze multiple consecutive slashes into one
151 // as it doesn't like two backslashes in a row neither
154 for ( i
= 0; i
< nLen
; i
++ )
156 wxChar ch
= m_dir
[i
];
162 // Convert to backslash
172 wxChar chNext
= m_dir
[i
+ 1];
174 if (chNext
!= _T('\\') && chNext
!= _T('/'))
178 // Ignore the next one, unless it is at the start of a UNC path
196 if ( wxStrlen(m_wildCard
) == 0 )
197 sTheFilter
= wxEmptyString
;
199 sTheFilter
= m_wildCard
;
201 wxStrtok((wxChar
*)sTheFilter
.c_str(), wxT("|"), &pzFilterBuffer
);
202 while(pzFilterBuffer
!= NULL
)
204 if (nCount
> 0 && !(nCount
% 2))
208 sDir
+= pzFilterBuffer
;
210 wxStrtok(NULL
, wxT("|"), &pzFilterBuffer
);
217 wxStrcpy((wxChar
*)vFileDlg
.szFullFile
, sDir
);
218 sFilterBuffer
= sDir
;
220 hWnd
= ::WinFileDlg( HWND_DESKTOP
224 if (hWnd
&& vFileDlg
.lReturn
== DID_OK
)
227 if ((m_windowStyle
& wxFD_MULTIPLE
) && vFileDlg
.ulFQFCount
> 1)
229 for (int i
= 0; i
< (int)vFileDlg
.ulFQFCount
; i
++)
233 m_dir
= wxPathOnly(wxString((const wxChar
*)*vFileDlg
.papszFQFilename
[0]));
234 m_path
= (const wxChar
*)*vFileDlg
.papszFQFilename
[0];
236 m_fileName
= wxFileNameFromPath(wxString((const wxChar
*)*vFileDlg
.papszFQFilename
[i
]));
237 m_fileNames
.Add(m_fileName
);
239 ::WinFreeFileDlgList(vFileDlg
.papszFQFilename
);
241 else if (!(m_windowStyle
& wxFD_SAVE
))
243 m_path
= (wxChar
*)vFileDlg
.szFullFile
;
244 m_fileName
= wxFileNameFromPath(wxString((const wxChar
*)vFileDlg
.szFullFile
));
245 m_dir
= wxPathOnly((const wxChar
*)vFileDlg
.szFullFile
);
249 const wxChar
* pzExtension
= NULL
;
251 wxStrcpy(zFileNameBuffer
, (const wxChar
*)vFileDlg
.szFullFile
);
253 int nIdx
= wxStrlen(zFileNameBuffer
) - 1;
256 wxSplitPath( zFileNameBuffer
261 if (zFileNameBuffer
[nIdx
] == wxT('.') || sExt
.empty())
263 zFileNameBuffer
[nIdx
] = wxT('\0');
266 // User has typed a filename without an extension:
268 // A filename can end in a "." here ("abc."), this means it
269 // does not have an extension. Because later on a "." with
270 // the default extension is appended we remove the "." if
271 // filename ends with one (We don't want files called
274 pzExtension
= sFilterBuffer
.c_str();
276 for( int i
= 0; i
< (int)sFilterBuffer
.length(); i
++ )
281 pzExtension
= wxStrrchr(pzExtension
, wxT('.'));
283 !wxStrrchr(pzExtension
, wxT('*')) &&
284 !wxStrrchr(pzExtension
, wxT('?')) &&
286 pzExtension
[1] != wxT(' ')
290 // Now concat extension to the fileName:
292 m_path
= wxString(zFileNameBuffer
) + pzExtension
;
298 m_path
= (wxChar
*)vFileDlg
.szFullFile
;
300 m_fileName
= wxFileNameFromPath((const wxChar
*)vFileDlg
.szFullFile
);
301 m_dir
= wxPathOnly((const wxChar
*)vFileDlg
.szFullFile
);
304 // === Simulating the wxFD_OVERWRITE_PROMPT >>============================
306 if ((m_windowStyle
& wxFD_OVERWRITE_PROMPT
) &&
307 (m_windowStyle
& wxFD_SAVE
) &&
308 (wxFileExists(m_path
.c_str())))
310 wxString sMessageText
;
312 sMessageText
.Printf( _("File '%s' already exists.\nDo you want to replace it?")
315 if (wxMessageBox( sMessageText
317 ,wxYES_NO
| wxICON_EXCLAMATION
327 } // end of wxFileDialog::ShowModal
329 #endif // wxUSE_FILEDLG