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