]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/filedlg.cpp
f4fc9da6f11269bc69734045a1ca7ed63b9fb494
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"
26 #include "wx/filename.h"
36 #include "wx/os2/private.h"
41 #include "wx/tokenzr.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()
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_dir
.length();
120 memset(&vFileDlg
, '\0', sizeof(FILEDLG
));
122 hWnd
= (HWND
) m_parent
->GetHWND();
123 if (!hWnd
&& wxTheApp
->GetTopWindow())
124 hWnd
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
127 *zFileNameBuffer
= wxT('\0');
128 *zTitleBuffer
= wxT('\0');
130 if (m_windowStyle
& wxFD_SAVE
)
131 lFlags
= FDS_SAVEAS_DIALOG
;
133 lFlags
= FDS_OPEN_DIALOG
;
135 if (m_windowStyle
& wxFD_SAVE
)
136 lFlags
|= FDS_SAVEAS_DIALOG
;
137 if (m_windowStyle
& wxFD_MULTIPLE
)
138 lFlags
|= FDS_OPEN_DIALOG
| FDS_MULTIPLESEL
;
140 vFileDlg
.cbSize
= sizeof(FILEDLG
);
141 vFileDlg
.fl
= lFlags
;
142 vFileDlg
.pszTitle
= (PSZ
)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_dir
[i
];
158 // Convert to backslash
168 wxChar chNext
= m_dir
[i
+ 1];
170 if (chNext
!= wxT('\\') && chNext
!= wxT('/'))
174 // Ignore the next one, unless it is at the start of a UNC path
192 if ( wxStrlen(m_wildCard
) == 0 )
193 sTheFilter
= wxEmptyString
;
195 sTheFilter
= m_wildCard
;
197 wxStrtok(sTheFilter
.wchar_str(), wxT("|"), &pzFilterBuffer
);
198 while(pzFilterBuffer
!= NULL
)
200 if (nCount
> 0 && !(nCount
% 2))
204 sDir
+= pzFilterBuffer
;
206 wxStrtok(NULL
, wxT("|"), &pzFilterBuffer
);
213 wxStrcpy((wxChar
*)vFileDlg
.szFullFile
, sDir
);
214 sFilterBuffer
= sDir
;
216 hWnd
= ::WinFileDlg( HWND_DESKTOP
220 if (hWnd
&& vFileDlg
.lReturn
== DID_OK
)
223 if ((m_windowStyle
& wxFD_MULTIPLE
) && vFileDlg
.ulFQFCount
> 1)
225 for (int i
= 0; i
< (int)vFileDlg
.ulFQFCount
; i
++)
229 m_dir
= wxPathOnly(wxString((const wxChar
*)*vFileDlg
.papszFQFilename
[0]));
230 m_path
= (const wxChar
*)*vFileDlg
.papszFQFilename
[0];
232 m_fileName
= wxFileNameFromPath(wxString((const wxChar
*)*vFileDlg
.papszFQFilename
[i
]));
233 m_fileNames
.Add(m_fileName
);
235 ::WinFreeFileDlgList(vFileDlg
.papszFQFilename
);
237 else if (!(m_windowStyle
& wxFD_SAVE
))
239 m_path
= (wxChar
*)vFileDlg
.szFullFile
;
240 m_fileName
= wxFileNameFromPath(wxString((const wxChar
*)vFileDlg
.szFullFile
));
241 m_dir
= wxPathOnly((const wxChar
*)vFileDlg
.szFullFile
);
245 const wxChar
* pzExtension
= NULL
;
247 wxStrcpy(zFileNameBuffer
, (const wxChar
*)vFileDlg
.szFullFile
);
249 int nIdx
= wxStrlen(zFileNameBuffer
) - 1;
252 wxFileName::SplitPath( zFileNameBuffer
257 if (zFileNameBuffer
[nIdx
] == wxT('.') || sExt
.empty())
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
< (int)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_path
= wxString(zFileNameBuffer
) + pzExtension
;
294 m_path
= (wxChar
*)vFileDlg
.szFullFile
;
296 m_fileName
= wxFileNameFromPath((const wxChar
*)vFileDlg
.szFullFile
);
297 m_dir
= wxPathOnly((const wxChar
*)vFileDlg
.szFullFile
);
300 // === Simulating the wxFD_OVERWRITE_PROMPT >>============================
302 if ((m_windowStyle
& wxFD_OVERWRITE_PROMPT
) &&
303 (m_windowStyle
& wxFD_SAVE
) &&
304 (wxFileExists(m_path
.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
325 #endif // wxUSE_FILEDLG