]>
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"
26 #include "wx/filename.h"
36 #include "wx/os2/private.h"
41 #include "wx/tokenzr.h"
42 #include "wx/modalhook.h"
44 #define wxMAXPATH 1024
45 #define wxMAXFILE 1024
64 IMPLEMENT_CLASS(wxFileDialog
, wxFileDialogBase
)
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 wxFileDialog::wxFileDialog (
72 , const wxString
& rsMessage
73 , const wxString
& rsDefaultDir
74 , const wxString
& rsDefaultFileName
75 , const wxString
& rsWildCard
77 , const wxPoint
& rPos
,
81 :wxFileDialogBase(pParent
, rsMessage
, rsDefaultDir
, rsDefaultFileName
, rsWildCard
, lStyle
, rPos
, sz
, name
)
84 // NB: all style checks are done by wxFileDialogBase::Create
87 } // end of wxFileDialog::wxFileDialog
89 void wxFileDialog::GetPaths (
90 wxArrayString
& rasPaths
94 size_t nCount
= m_fileNames
.GetCount();
97 if (m_dir
.Last() != wxT('\\'))
100 for ( size_t n
= 0; n
< nCount
; n
++ )
102 rasPaths
.Add(sDir
+ m_fileNames
[n
]);
104 } // end of wxFileDialog::GetPaths
106 int wxFileDialog::ShowModal()
108 WX_HOOK_MODAL_DIALOG();
111 wxString sFilterBuffer
;
112 wxChar
* pzFilterBuffer
;
113 static wxChar zFileNameBuffer
[wxMAXPATH
]; // the file-name
115 wxChar zTitleBuffer
[wxMAXFILE
+ 1 + wxMAXEXT
]; // the file-name, without path
118 size_t nLen
= m_dir
.length();
123 memset(&vFileDlg
, '\0', sizeof(FILEDLG
));
125 hWnd
= (HWND
) m_parent
->GetHWND();
126 if (!hWnd
&& wxTheApp
->GetTopWindow())
127 hWnd
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
130 *zFileNameBuffer
= wxT('\0');
131 *zTitleBuffer
= wxT('\0');
133 if (m_windowStyle
& wxFD_SAVE
)
134 lFlags
= FDS_SAVEAS_DIALOG
;
136 lFlags
= FDS_OPEN_DIALOG
;
138 if (m_windowStyle
& wxFD_SAVE
)
139 lFlags
|= FDS_SAVEAS_DIALOG
;
140 if (m_windowStyle
& wxFD_MULTIPLE
)
141 lFlags
|= FDS_OPEN_DIALOG
| FDS_MULTIPLESEL
;
143 vFileDlg
.cbSize
= sizeof(FILEDLG
);
144 vFileDlg
.fl
= lFlags
;
145 vFileDlg
.pszTitle
= (PSZ
)zTitleBuffer
;
148 // Convert forward slashes to backslashes (file selector doesn't like
149 // forward slashes) and also squeeze multiple consecutive slashes into one
150 // as it doesn't like two backslashes in a row neither
153 for ( i
= 0; i
< nLen
; i
++ )
155 wxChar ch
= m_dir
[i
];
161 // Convert to backslash
171 wxChar chNext
= m_dir
[i
+ 1];
173 if (chNext
!= wxT('\\') && chNext
!= wxT('/'))
177 // Ignore the next one, unless it is at the start of a UNC path
195 if ( wxStrlen(m_wildCard
) == 0 )
196 sTheFilter
= wxEmptyString
;
198 sTheFilter
= m_wildCard
;
200 wxStrtok(sTheFilter
.wchar_str(), wxT("|"), &pzFilterBuffer
);
201 while(pzFilterBuffer
!= NULL
)
203 if (nCount
> 0 && !(nCount
% 2))
207 sDir
+= pzFilterBuffer
;
209 wxStrtok(NULL
, wxT("|"), &pzFilterBuffer
);
216 wxStrcpy((wxChar
*)vFileDlg
.szFullFile
, sDir
);
217 sFilterBuffer
= sDir
;
219 hWnd
= ::WinFileDlg( HWND_DESKTOP
223 if (hWnd
&& vFileDlg
.lReturn
== DID_OK
)
226 if ((m_windowStyle
& wxFD_MULTIPLE
) && vFileDlg
.ulFQFCount
> 1)
228 for (int i
= 0; i
< (int)vFileDlg
.ulFQFCount
; i
++)
232 m_dir
= wxPathOnly(wxString((const wxChar
*)*vFileDlg
.papszFQFilename
[0]));
233 m_path
= (const wxChar
*)*vFileDlg
.papszFQFilename
[0];
235 m_fileName
= wxFileNameFromPath(wxString((const wxChar
*)*vFileDlg
.papszFQFilename
[i
]));
236 m_fileNames
.Add(m_fileName
);
238 ::WinFreeFileDlgList(vFileDlg
.papszFQFilename
);
240 else if (!(m_windowStyle
& wxFD_SAVE
))
242 m_path
= (wxChar
*)vFileDlg
.szFullFile
;
243 m_fileName
= wxFileNameFromPath(wxString((const wxChar
*)vFileDlg
.szFullFile
));
244 m_dir
= wxPathOnly((const wxChar
*)vFileDlg
.szFullFile
);
248 const wxChar
* pzExtension
= NULL
;
250 wxStrcpy(zFileNameBuffer
, (const wxChar
*)vFileDlg
.szFullFile
);
252 int nIdx
= wxStrlen(zFileNameBuffer
) - 1;
255 wxFileName::SplitPath( zFileNameBuffer
260 if (zFileNameBuffer
[nIdx
] == wxT('.') || sExt
.empty())
262 zFileNameBuffer
[nIdx
] = wxT('\0');
265 // User has typed a filename without an extension:
267 // A filename can end in a "." here ("abc."), this means it
268 // does not have an extension. Because later on a "." with
269 // the default extension is appended we remove the "." if
270 // filename ends with one (We don't want files called
273 pzExtension
= sFilterBuffer
.c_str();
275 for( int i
= 0; i
< (int)sFilterBuffer
.length(); i
++ )
280 pzExtension
= wxStrrchr(pzExtension
, wxT('.'));
282 !wxStrrchr(pzExtension
, wxT('*')) &&
283 !wxStrrchr(pzExtension
, wxT('?')) &&
285 pzExtension
[1] != wxT(' ')
289 // Now concat extension to the fileName:
291 m_path
= wxString(zFileNameBuffer
) + pzExtension
;
297 m_path
= (wxChar
*)vFileDlg
.szFullFile
;
299 m_fileName
= wxFileNameFromPath((const wxChar
*)vFileDlg
.szFullFile
);
300 m_dir
= wxPathOnly((const wxChar
*)vFileDlg
.szFullFile
);
303 // === Simulating the wxFD_OVERWRITE_PROMPT >>============================
305 if ((m_windowStyle
& wxFD_OVERWRITE_PROMPT
) &&
306 (m_windowStyle
& wxFD_SAVE
) &&
307 (wxFileExists(m_path
.c_str())))
309 wxString sMessageText
;
311 sMessageText
.Printf( _("File '%s' already exists.\nDo you want to replace it?")
314 if (wxMessageBox( sMessageText
316 ,wxYES_NO
| wxICON_EXCLAMATION
326 } // end of wxFileDialog::ShowModal
328 #endif // wxUSE_FILEDLG