]> git.saurik.com Git - wxWidgets.git/blob - include/wx/filedlg.h
Added option to set style from style listbox when single
[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 virtual void SetMessage(const wxString& message) { m_message = message; }
92 virtual void SetPath(const wxString& path) { m_path = path; }
93 virtual void SetDirectory(const wxString& dir) { m_dir = dir; }
94 virtual void SetFilename(const wxString& name) { m_fileName = name; }
95 virtual void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
96 virtual void SetFilterIndex(int filterIndex) { m_filterIndex = filterIndex; }
97
98 virtual wxString GetMessage() const { return m_message; }
99 virtual wxString GetPath() const { return m_path; }
100 virtual void GetPaths(wxArrayString& paths) const { paths.Empty(); paths.Add(m_path); }
101 virtual wxString GetDirectory() const { return m_dir; }
102 virtual wxString GetFilename() const { return m_fileName; }
103 virtual void GetFilenames(wxArrayString& files) const { files.Empty(); files.Add(m_fileName); }
104 virtual wxString GetWildcard() const { return m_wildCard; }
105 virtual int GetFilterIndex() const { return m_filterIndex; }
106
107 // Utility functions
108
109 #if WXWIN_COMPATIBILITY_2_4
110 // Parses the wildCard, returning the number of filters.
111 // Returns 0 if none or if there's a problem,
112 // The arrays will contain an equal number of items found before the error.
113 // wildCard is in the form:
114 // "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
115 wxDEPRECATED( static int ParseWildcard(const wxString& wildCard,
116 wxArrayString& descriptions,
117 wxArrayString& filters) );
118 #endif // WXWIN_COMPATIBILITY_2_4
119
120 // Append first extension to filePath from a ';' separated extensionList
121 // if filePath = "path/foo.bar" just return it as is
122 // if filePath = "foo[.]" and extensionList = "*.jpg;*.png" return "foo.jpg"
123 // if the extension is "*.j?g" (has wildcards) or "jpg" then return filePath
124 static wxString AppendExtension(const wxString &filePath,
125 const wxString &extensionList);
126
127 protected:
128 wxString m_message;
129 wxString m_dir;
130 wxString m_path; // Full path
131 wxString m_fileName;
132 wxString m_wildCard;
133 int m_filterIndex;
134
135 private:
136 void Init();
137 DECLARE_DYNAMIC_CLASS(wxFileDialogBase)
138 DECLARE_NO_COPY_CLASS(wxFileDialogBase)
139 };
140
141 //----------------------------------------------------------------------------
142 // wxFileDialog convenience functions
143 //----------------------------------------------------------------------------
144
145 // File selector - backward compatibility
146 WXDLLEXPORT wxString
147 wxFileSelector(const wxChar *message = wxFileSelectorPromptStr,
148 const wxChar *default_path = NULL,
149 const wxChar *default_filename = NULL,
150 const wxChar *default_extension = NULL,
151 const wxChar *wildcard = wxFileSelectorDefaultWildcardStr,
152 int flags = 0,
153 wxWindow *parent = NULL,
154 int x = wxDefaultCoord, int y = wxDefaultCoord);
155
156 // An extended version of wxFileSelector
157 WXDLLEXPORT wxString
158 wxFileSelectorEx(const wxChar *message = wxFileSelectorPromptStr,
159 const wxChar *default_path = NULL,
160 const wxChar *default_filename = NULL,
161 int *indexDefaultExtension = NULL,
162 const wxChar *wildcard = wxFileSelectorDefaultWildcardStr,
163 int flags = 0,
164 wxWindow *parent = NULL,
165 int x = wxDefaultCoord, int y = wxDefaultCoord);
166
167 // Ask for filename to load
168 WXDLLEXPORT wxString
169 wxLoadFileSelector(const wxChar *what,
170 const wxChar *extension,
171 const wxChar *default_name = (const wxChar *)NULL,
172 wxWindow *parent = (wxWindow *) NULL);
173
174 // Ask for filename to save
175 WXDLLEXPORT wxString
176 wxSaveFileSelector(const wxChar *what,
177 const wxChar *extension,
178 const wxChar *default_name = (const wxChar *) NULL,
179 wxWindow *parent = (wxWindow *) NULL);
180
181
182 #if defined (__WXUNIVERSAL__)
183 #define wxUSE_GENERIC_FILEDIALOG
184 #include "wx/generic/filedlgg.h"
185 #elif defined(__WXMSW__)
186 #include "wx/msw/filedlg.h"
187 #elif defined(__WXMOTIF__)
188 #include "wx/motif/filedlg.h"
189 #elif defined(__WXGTK24__)
190 #include "wx/gtk/filedlg.h" // GTK+ > 2.4 has native version
191 #elif defined(__WXGTK20__)
192 #define wxUSE_GENERIC_FILEDIALOG
193 #include "wx/generic/filedlgg.h"
194 #elif defined(__WXGTK__)
195 #include "wx/gtk1/filedlg.h"
196 #elif defined(__WXMAC__)
197 #include "wx/mac/filedlg.h"
198 #elif defined(__WXCOCOA__)
199 #include "wx/cocoa/filedlg.h"
200 #elif defined(__WXPM__)
201 #include "wx/os2/filedlg.h"
202 #endif
203
204 #endif // wxUSE_FILEDLG
205
206 #endif // _WX_FILEDLG_H_BASE_