]> git.saurik.com Git - wxWidgets.git/blob - include/wx/filedlg.h
Updated setup.
[wxWidgets.git] / include / wx / filedlg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/filedlg.h
3 // Purpose: wxFileDialog base header
4 // Author: Robert Roebling
5 // Modified by:
6 // Created: 8/17/99
7 // Copyright: (c) Robert Roebling
8 // RCS-ID: $Id$
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_FILEDLG_H_BASE_
13 #define _WX_FILEDLG_H_BASE_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_FILEDLG
18
19 #include "wx/dialog.h"
20 #include "wx/arrstr.h"
21
22 //----------------------------------------------------------------------------
23 // wxFileDialog data
24 //----------------------------------------------------------------------------
25
26 enum
27 {
28 wxFD_OPEN = 0x0001,
29 wxFD_SAVE = 0x0002,
30 wxFD_OVERWRITE_PROMPT = 0x0004,
31 wxFD_FILE_MUST_EXIST = 0x0010,
32 wxFD_MULTIPLE = 0x0020,
33 wxFD_CHANGE_DIR = 0x0040,
34 wxFD_PREVIEW = 0x0080
35 };
36
37 #if WXWIN_COMPATIBILITY_2_6
38 enum
39 {
40 wxOPEN = wxFD_OPEN,
41 wxSAVE = wxFD_SAVE,
42 wxOVERWRITE_PROMPT = wxFD_OVERWRITE_PROMPT,
43 #if WXWIN_COMPATIBILITY_2_4
44 wxHIDE_READONLY = 0x0008,
45 #endif
46 wxFILE_MUST_EXIST = wxFD_FILE_MUST_EXIST,
47 wxMULTIPLE = wxFD_MULTIPLE,
48 wxCHANGE_DIR = wxFD_CHANGE_DIR
49 };
50 #endif
51
52 #define wxFD_DEFAULT_STYLE wxFD_OPEN
53
54 extern WXDLLEXPORT_DATA(const wxChar) wxFileDialogNameStr[];
55 extern WXDLLEXPORT_DATA(const wxChar) wxFileSelectorPromptStr[];
56 extern WXDLLEXPORT_DATA(const wxChar) wxFileSelectorDefaultWildcardStr[];
57
58 //----------------------------------------------------------------------------
59 // wxFileDialogBase
60 //----------------------------------------------------------------------------
61
62 class WXDLLEXPORT wxFileDialogBase: public wxDialog
63 {
64 public:
65 wxFileDialogBase () { Init(); }
66
67 wxFileDialogBase(wxWindow *parent,
68 const wxString& message = wxFileSelectorPromptStr,
69 const wxString& defaultDir = wxEmptyString,
70 const wxString& defaultFile = wxEmptyString,
71 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
72 long style = wxFD_DEFAULT_STYLE,
73 const wxPoint& pos = wxDefaultPosition,
74 const wxSize& sz = wxDefaultSize,
75 const wxString& name = wxFileDialogNameStr)
76 {
77 Init();
78 Create(parent, message, defaultDir, defaultFile, wildCard, style, pos, sz, name);
79 }
80
81 bool Create(wxWindow *parent,
82 const wxString& message = wxFileSelectorPromptStr,
83 const wxString& defaultDir = wxEmptyString,
84 const wxString& defaultFile = wxEmptyString,
85 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
86 long style = wxFD_DEFAULT_STYLE,
87 const wxPoint& pos = wxDefaultPosition,
88 const wxSize& sz = wxDefaultSize,
89 const wxString& name = wxFileDialogNameStr);
90
91 bool HasFdFlag(int flag) const { return (m_fdStyle & flag) != 0; }
92
93 virtual void SetMessage(const wxString& message) { m_message = message; }
94 virtual void SetPath(const wxString& path) { m_path = path; }
95 virtual void SetDirectory(const wxString& dir) { m_dir = dir; }
96 virtual void SetFilename(const wxString& name) { m_fileName = name; }
97 virtual void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
98 virtual void SetFilterIndex(int filterIndex) { m_filterIndex = filterIndex; }
99
100 virtual wxString GetMessage() const { return m_message; }
101 virtual wxString GetPath() const { return m_path; }
102 virtual void GetPaths(wxArrayString& paths) const { paths.Empty(); paths.Add(m_path); }
103 virtual wxString GetDirectory() const { return m_dir; }
104 virtual wxString GetFilename() const { return m_fileName; }
105 virtual void GetFilenames(wxArrayString& files) const { files.Empty(); files.Add(m_fileName); }
106 virtual wxString GetWildcard() const { return m_wildCard; }
107 virtual int GetFilterIndex() const { return m_filterIndex; }
108
109 // Utility functions
110
111 #if WXWIN_COMPATIBILITY_2_4
112 // Parses the wildCard, returning the number of filters.
113 // Returns 0 if none or if there's a problem,
114 // The arrays will contain an equal number of items found before the error.
115 // wildCard is in the form:
116 // "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
117 wxDEPRECATED( static int ParseWildcard(const wxString& wildCard,
118 wxArrayString& descriptions,
119 wxArrayString& filters) );
120 #endif // WXWIN_COMPATIBILITY_2_4
121
122 // Append first extension to filePath from a ';' separated extensionList
123 // if filePath = "path/foo.bar" just return it as is
124 // if filePath = "foo[.]" and extensionList = "*.jpg;*.png" return "foo.jpg"
125 // if the extension is "*.j?g" (has wildcards) or "jpg" then return filePath
126 static wxString AppendExtension(const wxString &filePath,
127 const wxString &extensionList);
128
129 protected:
130 wxString m_message;
131 wxString m_dir;
132 wxString m_path; // Full path
133 wxString m_fileName;
134 wxString m_wildCard;
135 int m_filterIndex;
136 int m_fdStyle;
137
138 private:
139 void Init();
140 DECLARE_DYNAMIC_CLASS(wxFileDialogBase)
141 DECLARE_NO_COPY_CLASS(wxFileDialogBase)
142 };
143
144 //----------------------------------------------------------------------------
145 // wxFileDialog convenience functions
146 //----------------------------------------------------------------------------
147
148 // File selector - backward compatibility
149 WXDLLEXPORT wxString
150 wxFileSelector(const wxChar *message = wxFileSelectorPromptStr,
151 const wxChar *default_path = NULL,
152 const wxChar *default_filename = NULL,
153 const wxChar *default_extension = NULL,
154 const wxChar *wildcard = wxFileSelectorDefaultWildcardStr,
155 int flags = 0,
156 wxWindow *parent = NULL,
157 int x = wxDefaultCoord, int y = wxDefaultCoord);
158
159 // An extended version of wxFileSelector
160 WXDLLEXPORT wxString
161 wxFileSelectorEx(const wxChar *message = wxFileSelectorPromptStr,
162 const wxChar *default_path = NULL,
163 const wxChar *default_filename = NULL,
164 int *indexDefaultExtension = NULL,
165 const wxChar *wildcard = wxFileSelectorDefaultWildcardStr,
166 int flags = 0,
167 wxWindow *parent = NULL,
168 int x = wxDefaultCoord, int y = wxDefaultCoord);
169
170 // Ask for filename to load
171 WXDLLEXPORT wxString
172 wxLoadFileSelector(const wxChar *what,
173 const wxChar *extension,
174 const wxChar *default_name = (const wxChar *)NULL,
175 wxWindow *parent = (wxWindow *) NULL);
176
177 // Ask for filename to save
178 WXDLLEXPORT wxString
179 wxSaveFileSelector(const wxChar *what,
180 const wxChar *extension,
181 const wxChar *default_name = (const wxChar *) NULL,
182 wxWindow *parent = (wxWindow *) NULL);
183
184
185 #if defined (__WXUNIVERSAL__)
186 #define wxUSE_GENERIC_FILEDIALOG
187 #include "wx/generic/filedlgg.h"
188 #elif defined(__WXMSW__)
189 #include "wx/msw/filedlg.h"
190 #elif defined(__WXMOTIF__)
191 #include "wx/motif/filedlg.h"
192 #elif defined(__WXGTK24__)
193 #include "wx/gtk/filedlg.h" // GTK+ > 2.4 has native version
194 #elif defined(__WXGTK20__)
195 #define wxUSE_GENERIC_FILEDIALOG
196 #include "wx/generic/filedlgg.h"
197 #elif defined(__WXGTK__)
198 #include "wx/gtk1/filedlg.h"
199 #elif defined(__WXMAC__)
200 #include "wx/mac/filedlg.h"
201 #elif defined(__WXCOCOA__)
202 #include "wx/cocoa/filedlg.h"
203 #elif defined(__WXPM__)
204 #include "wx/os2/filedlg.h"
205 #endif
206
207 #endif // wxUSE_FILEDLG
208
209 #endif // _WX_FILEDLG_H_BASE_