]> git.saurik.com Git - wxWidgets.git/blob - src/stubs/filedlg.cpp
Mingw32 fixes
[wxWidgets.git] / src / stubs / filedlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: filedlg.cpp
3 // Purpose: wxFileDialog
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "filedlg.h"
14 #endif
15
16 #include "wx/defs.h"
17 #include "wx/utils.h"
18 #include "wx/dialog.h"
19 #include "wx/filedlg.h"
20 #include "wx/intl.h"
21
22 IMPLEMENT_CLASS(wxFileDialog, wxDialog)
23
24 wxString wxFileSelector(const char *title,
25 const char *defaultDir, const char *defaultFileName,
26 const char *defaultExtension, const char *filter, int flags,
27 wxWindow *parent, int x, int y)
28 {
29 // If there's a default extension specified but no filter, we create a suitable
30 // filter.
31
32 wxString filter2("");
33 if ( defaultExtension && !filter )
34 filter2 = wxString("*.") + wxString(defaultExtension) ;
35 else if ( filter )
36 filter2 = filter;
37
38 wxString defaultDirString;
39 if (defaultDir)
40 defaultDirString = defaultDir;
41 else
42 defaultDirString = "";
43
44 wxString defaultFilenameString;
45 if (defaultFileName)
46 defaultFilenameString = defaultFileName;
47 else
48 defaultFilenameString = "";
49
50 wxFileDialog fileDialog(parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y));
51
52 if ( fileDialog.ShowModal() == wxID_OK )
53 {
54 return fileDialog.GetPath();
55 }
56 else
57 return wxEmptyString;
58 }
59
60 wxString wxFileSelectorEx(const char *title,
61 const char *defaultDir,
62 const char *defaultFileName,
63 int* defaultFilterIndex,
64 const char *filter,
65 int flags,
66 wxWindow* parent,
67 int x,
68 int y)
69
70 {
71 wxFileDialog fileDialog(parent, title ? title : "", defaultDir ? defaultDir : "",
72 defaultFileName ? defaultFileName : "", filter ? filter : "", flags, wxPoint(x, y));
73
74 if ( fileDialog.ShowModal() == wxID_OK )
75 {
76 *defaultFilterIndex = fileDialog.GetFilterIndex();
77 return fileDialog.GetPath();
78 }
79 else
80 return wxEmptyString;
81 }
82
83 wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
84 const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
85 long style, const wxPoint& pos)
86 {
87 m_message = message;
88 m_dialogStyle = style;
89 m_parent = parent;
90 m_path = "";
91 m_fileName = defaultFileName;
92 m_dir = defaultDir;
93 m_wildCard = wildCard;
94 m_filterIndex = 1;
95 }
96
97 int wxFileDialog::ShowModal()
98 {
99 // TODO
100 return wxID_CANCEL;
101 }
102
103 // Generic file load/save dialog
104 static wxString wxDefaultFileSelector(bool load, const char *what, const char *extension, const char *default_name, wxWindow *parent)
105 {
106 char *ext = (char *)extension;
107
108 char prompt[50];
109 wxString str;
110 if (load)
111 str = "Load %s file";
112 else
113 str = "Save %s file";
114 sprintf(prompt, wxGetTranslation(str), what);
115
116 if (*ext == '.') ext++;
117 char wild[60];
118 sprintf(wild, "*.%s", ext);
119
120 return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent);
121 }
122
123 // Generic file load dialog
124 wxString wxLoadFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent)
125 {
126 return wxDefaultFileSelector(TRUE, what, extension, default_name, parent);
127 }
128
129
130 // Generic file save dialog
131 wxString wxSaveFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent)
132 {
133 return wxDefaultFileSelector(FALSE, what, extension, default_name, parent);
134 }
135
136