]>
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/filedlg.h"
31 #include "wx/os2/private.h"
37 #include "wx/tokenzr.h"
39 #define wxMAXPATH 1024
40 #define wxMAXFILE 1024
58 IMPLEMENT_CLASS(wxFileDialog
, wxFileDialogBase
)
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 wxFileDialog::wxFileDialog (
66 , const wxString
& rsMessage
67 , const wxString
& rsDefaultDir
68 , const wxString
& rsDefaultFileName
69 , const wxString
& rsWildCard
73 :wxFileDialogBase(pParent
, rsMessage
, rsDefaultDir
, rsDefaultFileName
, rsWildCard
, lStyle
, rPos
)
76 if ((m_dialogStyle
& wxMULTIPLE
) && (m_dialogStyle
& wxSAVE
))
77 m_dialogStyle
&= ~wxMULTIPLE
;
80 } // end of wxFileDialog::wxFileDialog
82 void wxFileDialog::GetPaths (
83 wxArrayString
& rasPaths
87 size_t nCount
= m_fileNames
.GetCount();
90 if (m_dir
.Last() != _T('\\'))
93 for ( size_t n
= 0; n
< nCount
; n
++ )
95 rasPaths
.Add(sDir
+ m_fileNames
[n
]);
97 } // end of wxFileDialog::GetPaths
99 int wxFileDialog::ShowModal()
102 wxString sFilterBuffer
;
103 wxChar
* pzFilterBuffer
;
104 static wxChar zFileNameBuffer
[wxMAXPATH
]; // the file-name
106 wxChar zTitleBuffer
[wxMAXFILE
+ 1 + wxMAXEXT
]; // the file-name, without path
109 size_t nLen
= m_dir
.length();
114 memset(&vFileDlg
, '\0', sizeof(FILEDLG
));
116 hWnd
= (HWND
) m_parent
->GetHWND();
117 if (!hWnd
&& wxTheApp
->GetTopWindow())
118 hWnd
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
121 *zFileNameBuffer
= wxT('\0');
122 *zTitleBuffer
= wxT('\0');
124 if (m_dialogStyle
& wxSAVE
)
125 lFlags
= FDS_SAVEAS_DIALOG
;
127 lFlags
= FDS_OPEN_DIALOG
;
129 #if WXWIN_COMPATIBILITY_2_4
130 if (m_dialogStyle
& wxHIDE_READONLY
)
131 lFlags
|= FDS_SAVEAS_DIALOG
;
134 if (m_dialogStyle
& wxSAVE
)
135 lFlags
|= FDS_SAVEAS_DIALOG
;
136 if (m_dialogStyle
& wxMULTIPLE
)
137 lFlags
|= FDS_OPEN_DIALOG
| FDS_MULTIPLESEL
;
139 vFileDlg
.cbSize
= sizeof(FILEDLG
);
140 vFileDlg
.fl
= lFlags
;
141 vFileDlg
.pszTitle
= 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 )
194 sTheFilter
= m_wildCard
;
196 pzFilterBuffer
= strtok((char*)sTheFilter
.c_str(), "|");
197 while(pzFilterBuffer
!= NULL
)
199 if (nCount
> 0 && !(nCount
% 2))
203 sDir
+= pzFilterBuffer
;
205 pzFilterBuffer
= strtok(NULL
, "|");
212 wxStrcpy(vFileDlg
.szFullFile
, sDir
.c_str());
213 sFilterBuffer
= sDir
;
215 hWnd
= ::WinFileDlg( HWND_DESKTOP
219 if (hWnd
&& vFileDlg
.lReturn
== DID_OK
)
222 if ((m_dialogStyle
& wxMULTIPLE
) && vFileDlg
.ulFQFCount
> 1)
224 for (int i
= 0; i
< (int)vFileDlg
.ulFQFCount
; i
++)
228 m_dir
= wxPathOnly(wxString((const char*)*vFileDlg
.papszFQFilename
[0]));
229 m_path
= (const char*)*vFileDlg
.papszFQFilename
[0];
231 m_fileName
= wxFileNameFromPath(wxString((const char*)*vFileDlg
.papszFQFilename
[i
]));
232 m_fileNames
.Add(m_fileName
);
234 ::WinFreeFileDlgList(vFileDlg
.papszFQFilename
);
236 else if (!(m_dialogStyle
& wxSAVE
))
238 m_path
= vFileDlg
.szFullFile
;
239 m_fileName
= wxFileNameFromPath(vFileDlg
.szFullFile
);
240 m_dir
= wxPathOnly(vFileDlg
.szFullFile
);
244 const wxChar
* pzExtension
= NULL
;
246 wxStrcpy(zFileNameBuffer
, vFileDlg
.szFullFile
);
248 int nIdx
= wxStrlen(zFileNameBuffer
) - 1;
251 wxSplitPath( zFileNameBuffer
256 if (zFileNameBuffer
[nIdx
] == wxT('.') || sExt
.IsEmpty())
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
= vFileDlg
.szFullFile
;
295 m_fileName
= wxFileNameFromPath(vFileDlg
.szFullFile
);
296 m_dir
= wxPathOnly(vFileDlg
.szFullFile
);
299 // === Simulating the wxOVERWRITE_PROMPT >>============================
301 if ((m_dialogStyle
& wxOVERWRITE_PROMPT
) &&
302 (m_dialogStyle
& wxSAVE
) &&
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