]>
Commit | Line | Data |
---|---|---|
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 | #if !USE_SHARED_LIBRARY | |
23 | IMPLEMENT_CLASS(wxFileDialog, wxDialog) | |
24 | #endif | |
25 | ||
26 | char *wxFileSelector(const char *title, | |
27 | const char *defaultDir, const char *defaultFileName, | |
28 | const char *defaultExtension, const char *filter, int flags, | |
29 | wxWindow *parent, int x, int y) | |
30 | { | |
31 | // If there's a default extension specified but no filter, we create a suitable | |
32 | // filter. | |
33 | ||
34 | wxString filter2(""); | |
35 | if ( defaultExtension && !filter ) | |
36 | filter2 = wxString("*.") + wxString(defaultExtension) ; | |
37 | else if ( filter ) | |
38 | filter2 = filter; | |
39 | ||
40 | wxString defaultDirString; | |
41 | if (defaultDir) | |
42 | defaultDirString = defaultDir; | |
43 | else | |
44 | defaultDirString = ""; | |
45 | ||
46 | wxString defaultFilenameString; | |
47 | if (defaultFileName) | |
48 | defaultFilenameString = defaultFileName; | |
49 | else | |
50 | defaultFilenameString = ""; | |
51 | ||
52 | wxFileDialog fileDialog(parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y)); | |
53 | ||
54 | if ( fileDialog.ShowModal() == wxID_OK ) | |
55 | { | |
56 | strcpy(wxBuffer, (const char *)fileDialog.GetPath()); | |
57 | return wxBuffer; | |
58 | } | |
59 | else | |
60 | return NULL; | |
61 | } | |
62 | ||
63 | char *wxFileSelectorEx(const char *title, | |
64 | const char *defaultDir, | |
65 | const char *defaultFileName, | |
66 | int* defaultFilterIndex, | |
67 | const char *filter, | |
68 | int flags, | |
69 | wxWindow* parent, | |
70 | int x, | |
71 | int y) | |
72 | ||
73 | { | |
74 | wxFileDialog fileDialog(parent, title ? title : "", defaultDir ? defaultDir : "", | |
75 | defaultFileName ? defaultFileName : "", filter ? filter : "", flags, wxPoint(x, y)); | |
76 | ||
77 | if ( fileDialog.ShowModal() == wxID_OK ) | |
78 | { | |
79 | *defaultFilterIndex = fileDialog.GetFilterIndex(); | |
80 | strcpy(wxBuffer, (const char *)fileDialog.GetPath()); | |
81 | return wxBuffer; | |
82 | } | |
83 | else | |
84 | return NULL; | |
85 | } | |
86 | ||
87 | wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, | |
88 | const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, | |
89 | long style, const wxPoint& pos) | |
90 | { | |
91 | m_message = message; | |
92 | m_dialogStyle = style; | |
93 | m_parent = parent; | |
94 | m_path = ""; | |
95 | m_fileName = defaultFileName; | |
96 | m_dir = defaultDir; | |
97 | m_wildCard = wildCard; | |
98 | m_filterIndex = 1; | |
99 | } | |
100 | ||
101 | int wxFileDialog::ShowModal() | |
102 | { | |
103 | // TODO | |
104 | return wxID_CANCEL; | |
105 | } | |
106 | ||
107 | // Generic file load/save dialog | |
108 | static char * | |
109 | wxDefaultFileSelector(bool load, const char *what, const char *extension, const char *default_name, wxWindow *parent) | |
110 | { | |
111 | char *ext = (char *)extension; | |
112 | ||
113 | char prompt[50]; | |
114 | wxString str; | |
115 | if (load) | |
116 | str = "Load %s file"; | |
117 | else | |
118 | str = "Save %s file"; | |
119 | sprintf(prompt, wxGetTranslation(str), what); | |
120 | ||
121 | if (*ext == '.') ext++; | |
122 | char wild[60]; | |
123 | sprintf(wild, "*.%s", ext); | |
124 | ||
125 | return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent); | |
126 | } | |
127 | ||
128 | // Generic file load dialog | |
129 | char * | |
130 | wxLoadFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent) | |
131 | { | |
132 | return wxDefaultFileSelector(TRUE, what, extension, default_name, parent); | |
133 | } | |
134 | ||
135 | ||
136 | // Generic file save dialog | |
137 | char * | |
138 | wxSaveFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent) | |
139 | { | |
140 | return wxDefaultFileSelector(FALSE, what, extension, default_name, parent); | |
141 | } | |
142 | ||
143 |