]> git.saurik.com Git - wxWidgets.git/blame - src/os2/filedlg.cpp
corrected path splitting for mac relative paths
[wxWidgets.git] / src / os2 / filedlg.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: filedlg.cpp
3// Purpose: wxFileDialog
f0a56ab0 4// Author: David Webster
0e320a79 5// Modified by:
f0a56ab0 6// Created: 10/05/99
0e320a79 7// RCS-ID: $Id$
f0a56ab0 8// Copyright: (c) David Webster
0e320a79
DW
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
fb46a9a6
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20 #include <stdio.h>
21 #include "wx/defs.h"
22 #include "wx/utils.h"
23 #include "wx/msgdlg.h"
24 #include "wx/dialog.h"
25 #include "wx/filedlg.h"
26 #include "wx/intl.h"
27 #include "wx/log.h"
28#endif
29
30#define INCL_PM
31#include <os2.h>
32
33#include "wx/os2/private.h"
34
35#include <math.h>
36#include <stdlib.h>
37#include <string.h>
0e320a79 38
0e320a79 39IMPLEMENT_CLASS(wxFileDialog, wxDialog)
0e320a79 40
f0a56ab0
DW
41wxString wxFileSelector( const char* title
42 ,const char* defaultDir
43 ,const char* defaultFileName
44 ,const char* defaultExtension
45 ,const char* filter
46 ,int flags
47 ,wxWindow* parent
48 ,int x
49 ,int y
50 )
0e320a79
DW
51{
52 // If there's a default extension specified but no filter, we create a suitable
53 // filter.
54
55 wxString filter2("");
56 if ( defaultExtension && !filter )
57 filter2 = wxString("*.") + wxString(defaultExtension) ;
58 else if ( filter )
59 filter2 = filter;
60
61 wxString defaultDirString;
62 if (defaultDir)
63 defaultDirString = defaultDir;
64 else
65 defaultDirString = "";
66
67 wxString defaultFilenameString;
68 if (defaultFileName)
69 defaultFilenameString = defaultFileName;
70 else
71 defaultFilenameString = "";
72
73 wxFileDialog fileDialog(parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y));
74
75 if ( fileDialog.ShowModal() == wxID_OK )
76 {
77 return fileDialog.GetPath();
78 }
79 else
80 return wxEmptyString;
81}
82
fb46a9a6
DW
83# ifndef MAXPATH
84# define MAXPATH 400
85# endif
86
87# ifndef MAXDRIVE
88# define MAXDRIVE 3
89# endif
90
91# ifndef MAXFILE
92# define MAXFILE 9
93# endif
94
95# ifndef MAXEXT
96# define MAXEXT 5
97# endif
98
f0a56ab0
DW
99wxString wxFileSelectorEx( const char* title
100 ,const char* defaultDir
101 ,const char* defaultFileName
102 ,int* defaultFilterIndex
103 ,const char* filter
104 ,int flags
105 ,wxWindow* parent
106 ,int x
107 ,int y
108 )
0e320a79
DW
109{
110 wxFileDialog fileDialog(parent, title ? title : "", defaultDir ? defaultDir : "",
111 defaultFileName ? defaultFileName : "", filter ? filter : "", flags, wxPoint(x, y));
112
113 if ( fileDialog.ShowModal() == wxID_OK )
114 {
115 *defaultFilterIndex = fileDialog.GetFilterIndex();
116 return fileDialog.GetPath();
117 }
118 else
119 return wxEmptyString;
120}
121
f0a56ab0
DW
122wxFileDialog::wxFileDialog( wxWindow* parent
123 ,const wxString& message
124 ,const wxString& defaultDir
125 ,const wxString& defaultFileName
126 ,const wxString& wildCard
127 ,long style
128 ,const wxPoint& pos
129 )
0e320a79
DW
130{
131 m_message = message;
132 m_dialogStyle = style;
133 m_parent = parent;
134 m_path = "";
135 m_fileName = defaultFileName;
136 m_dir = defaultDir;
137 m_wildCard = wildCard;
138 m_filterIndex = 1;
139}
140
141int wxFileDialog::ShowModal()
142{
143 // TODO
144 return wxID_CANCEL;
145}
146
147// Generic file load/save dialog
f0a56ab0
DW
148static wxString wxDefaultFileSelector( bool load
149 ,const char* what
150 ,const char* extension
151 ,const char* default_name
152 ,wxWindow* parent
153 )
0e320a79
DW
154{
155 char *ext = (char *)extension;
f0a56ab0 156
0e320a79
DW
157 char prompt[50];
158 wxString str;
159 if (load)
160 str = "Load %s file";
161 else
162 str = "Save %s file";
163 sprintf(prompt, wxGetTranslation(str), what);
164
165 if (*ext == '.') ext++;
166 char wild[60];
167 sprintf(wild, "*.%s", ext);
168
169 return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent);
170}
171
172// Generic file load dialog
f0a56ab0
DW
173wxString wxLoadFileSelector( const char* what
174 ,const char* extension
175 ,const char* default_name
176 ,wxWindow* parent
177 )
0e320a79
DW
178{
179 return wxDefaultFileSelector(TRUE, what, extension, default_name, parent);
180}
181
182
183// Generic file save dialog
f0a56ab0
DW
184wxString wxSaveFileSelector( const char* what
185 ,const char* extension
186 ,const char* default_name
187 ,wxWindow* parent
188 )
0e320a79
DW
189{
190 return wxDefaultFileSelector(FALSE, what, extension, default_name, parent);
191}
192
193