]> git.saurik.com Git - wxWidgets.git/blob - include/wx/filedlg.h
extracted common code into a single wxfileDialogBase class (patch 758901)
[wxWidgets.git] / include / wx / filedlg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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:
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_FILEDLG_H_BASE_
13 #define _WX_FILEDLG_H_BASE_
14
15 #if wxUSE_FILEDLG
16
17 #if defined(__GNUG__) && !defined(__APPLE__)
18 #pragma interface "filedlg.h"
19 #endif
20
21 #include "wx/dialog.h"
22
23 //----------------------------------------------------------------------------
24 // wxFileDialog data
25 //----------------------------------------------------------------------------
26
27 enum
28 {
29 wxOPEN = 0x0001,
30 wxSAVE = 0x0002,
31 wxOVERWRITE_PROMPT = 0x0004,
32 wxHIDE_READONLY = 0x0008,
33 wxFILE_MUST_EXIST = 0x0010,
34 wxMULTIPLE = 0x0020,
35 wxCHANGE_DIR = 0x0040
36 };
37
38 WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorPromptStr;
39 WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorDefaultWildcardStr;
40
41 //----------------------------------------------------------------------------
42 // wxFileDialogBase
43 //----------------------------------------------------------------------------
44
45 class WXDLLEXPORT wxFileDialogBase: public wxDialog
46 {
47 public:
48 wxFileDialogBase () {}
49
50 wxFileDialogBase(wxWindow *parent,
51 const wxString& message = wxFileSelectorPromptStr,
52 const wxString& defaultDir = wxEmptyString,
53 const wxString& defaultFile = wxEmptyString,
54 const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
55 long style = 0,
56 const wxPoint& pos = wxDefaultPosition);
57
58 virtual void SetMessage(const wxString& message) { m_message = message; }
59 virtual void SetPath(const wxString& path) { m_path = path; }
60 virtual void SetDirectory(const wxString& dir) { m_dir = dir; }
61 virtual void SetFilename(const wxString& name) { m_fileName = name; }
62 virtual void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
63 virtual void SetStyle(long style) { m_dialogStyle = style; }
64 virtual void SetFilterIndex(int filterIndex) { m_filterIndex = filterIndex; }
65
66 virtual wxString GetMessage() const { return m_message; }
67 virtual wxString GetPath() const { return m_path; }
68 virtual void GetPaths(wxArrayString& paths) const { paths.Empty(); paths.Add(m_path); }
69 virtual wxString GetDirectory() const { return m_dir; }
70 virtual wxString GetFilename() const { return m_fileName; }
71 virtual void GetFilenames(wxArrayString& files) const { files.Empty(); files.Add(m_fileName); }
72 virtual wxString GetWildcard() const { return m_wildCard; }
73 virtual long GetStyle() const { return m_dialogStyle; }
74 virtual int GetFilterIndex() const { return m_filterIndex; }
75
76 // Utility functions
77
78 // Parses the wildCard, returning the number of filters.
79 // Returns 0 if none or if there's a problem,
80 // The arrays will contain an equal number of items found before the error.
81 // wildCard is in the form:
82 // "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
83 static int ParseWildcard(const wxString& wildCard,
84 wxArrayString& descriptions,
85 wxArrayString& filters);
86
87 // Append first extension to filePath from a ';' separated extensionList
88 // if filePath = "path/foo.bar" just return it as is
89 // if filePath = "foo[.]" and extensionList = "*.jpg;*.png" return "foo.jpg"
90 // if the extension is "*.j?g" (has wildcards) or "jpg" then return filePath
91 static wxString AppendExtension(const wxString &filePath,
92 const wxString &extensionList);
93
94 protected:
95 wxString m_message;
96 long m_dialogStyle;
97 wxWindow *m_parent;
98 wxString m_dir;
99 wxString m_path; // Full path
100 wxString m_fileName;
101 wxString m_wildCard;
102 int m_filterIndex;
103
104 private:
105 DECLARE_DYNAMIC_CLASS(wxFileDialogBase)
106 DECLARE_NO_COPY_CLASS(wxFileDialogBase)
107 };
108
109 //----------------------------------------------------------------------------
110 // wxFileDialog convenience functions
111 //----------------------------------------------------------------------------
112
113 // File selector - backward compatibility
114 WXDLLEXPORT wxString
115 wxFileSelector(const wxChar *message = wxFileSelectorPromptStr,
116 const wxChar *default_path = NULL,
117 const wxChar *default_filename = NULL,
118 const wxChar *default_extension = NULL,
119 const wxChar *wildcard = wxFileSelectorDefaultWildcardStr,
120 int flags = 0,
121 wxWindow *parent = NULL,
122 int x = -1, int y = -1);
123
124 // An extended version of wxFileSelector
125 WXDLLEXPORT wxString
126 wxFileSelectorEx(const wxChar *message = wxFileSelectorPromptStr,
127 const wxChar *default_path = NULL,
128 const wxChar *default_filename = NULL,
129 int *indexDefaultExtension = NULL,
130 const wxChar *wildcard = wxFileSelectorDefaultWildcardStr,
131 int flags = 0,
132 wxWindow *parent = NULL,
133 int x = -1, int y = -1);
134
135 // Ask for filename to load
136 WXDLLEXPORT wxString
137 wxLoadFileSelector(const wxChar *what,
138 const wxChar *extension,
139 const wxChar *default_name = (const wxChar *)NULL,
140 wxWindow *parent = (wxWindow *) NULL);
141
142 // Ask for filename to save
143 WXDLLEXPORT wxString
144 wxSaveFileSelector(const wxChar *what,
145 const wxChar *extension,
146 const wxChar *default_name = (const wxChar *) NULL,
147 wxWindow *parent = (wxWindow *) NULL);
148
149
150 #if defined (__WXUNIVERSAL__)
151 #include "wx/generic/filedlgg.h"
152 #elif defined(__WXMSW__)
153 #include "wx/msw/filedlg.h"
154 #elif defined(__WXMOTIF__)
155 #include "wx/motif/filedlg.h"
156 #elif defined(__WXGTK__)
157 #include "wx/generic/filedlgg.h"
158 #elif defined(__WXX11__)
159 #include "wx/generic/filedlgg.h"
160 #elif defined(__WXMGL__)
161 #include "wx/generic/filedlgg.h"
162 #elif defined(__WXMAC__)
163 #include "wx/mac/filedlg.h"
164 #elif defined(__WXCOCOA__)
165 #include "wx/generic/filedlgg.h"
166 #elif defined(__WXPM__)
167 #include "wx/os2/filedlg.h"
168 #endif
169
170 #endif // wxUSE_FILEDLG
171
172 #endif // _WX_FILEDLG_H_BASE_