]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/filectrl.h | |
3 | // Purpose: Header for wxFileCtrlBase and other common functions used by | |
4 | // platform-specific wxFileCtrl's | |
5 | // Author: Diaa M. Sami | |
6 | // Modified by: | |
7 | // Created: Jul-07-2007 | |
8 | // Copyright: (c) Diaa M. Sami | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_FILECTRL_H_BASE_ | |
13 | #define _WX_FILECTRL_H_BASE_ | |
14 | ||
15 | #include "wx/defs.h" | |
16 | ||
17 | #if wxUSE_FILECTRL | |
18 | ||
19 | #include "wx/string.h" | |
20 | #include "wx/event.h" | |
21 | ||
22 | enum | |
23 | { | |
24 | wxFC_OPEN = 0x0001, | |
25 | wxFC_SAVE = 0x0002, | |
26 | wxFC_MULTIPLE = 0x0004, | |
27 | wxFC_NOSHOWHIDDEN = 0x0008 | |
28 | }; | |
29 | ||
30 | #define wxFC_DEFAULT_STYLE wxFC_OPEN | |
31 | extern WXDLLIMPEXP_DATA_CORE(const char) wxFileCtrlNameStr[]; // in filectrlcmn.cpp | |
32 | ||
33 | class WXDLLIMPEXP_CORE wxFileCtrlBase | |
34 | { | |
35 | public: | |
36 | virtual ~wxFileCtrlBase() {} | |
37 | ||
38 | virtual void SetWildcard( const wxString& wildCard ) = 0; | |
39 | virtual void SetFilterIndex( int filterindex ) = 0; | |
40 | virtual bool SetDirectory( const wxString& dir ) = 0; | |
41 | ||
42 | // Selects a certain file. | |
43 | // In case the filename specified isn't found/couldn't be shown with | |
44 | // currently selected filter, false is returned and nothing happens | |
45 | virtual bool SetFilename( const wxString& name ) = 0; | |
46 | ||
47 | // chdirs to a certain directory and selects a certain file. | |
48 | // In case the filename specified isn't found/couldn't be shown with | |
49 | // currently selected filter, false is returned and if directory exists | |
50 | // it's chdir'ed to | |
51 | virtual bool SetPath( const wxString& path ) = 0; | |
52 | ||
53 | virtual wxString GetFilename() const = 0; | |
54 | virtual wxString GetDirectory() const = 0; | |
55 | virtual wxString GetWildcard() const = 0; | |
56 | virtual wxString GetPath() const = 0; | |
57 | virtual void GetPaths( wxArrayString& paths ) const = 0; | |
58 | virtual void GetFilenames( wxArrayString& files ) const = 0; | |
59 | virtual int GetFilterIndex() const = 0; | |
60 | ||
61 | virtual bool HasMultipleFileSelection() const = 0; | |
62 | virtual void ShowHidden(bool show) = 0; | |
63 | }; | |
64 | ||
65 | void GenerateFilterChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd ); | |
66 | void GenerateFolderChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd ); | |
67 | void GenerateSelectionChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd ); | |
68 | void GenerateFileActivatedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd, const wxString filename = wxEmptyString ); | |
69 | ||
70 | #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__) | |
71 | #define wxFileCtrl wxGtkFileCtrl | |
72 | #include "wx/gtk/filectrl.h" | |
73 | #else | |
74 | #define wxFileCtrl wxGenericFileCtrl | |
75 | #include "wx/generic/filectrlg.h" | |
76 | #endif | |
77 | ||
78 | // Some documentation | |
79 | // On wxEVT_FILECTRL_FILTERCHANGED, only the value returned by GetFilterIndex is | |
80 | // valid and it represents the (new) current filter index for the wxFileCtrl. | |
81 | // On wxEVT_FILECTRL_FOLDERCHANGED, only the value returned by GetDirectory is | |
82 | // valid and it represents the (new) current directory for the wxFileCtrl. | |
83 | // On wxEVT_FILECTRL_FILEACTIVATED, GetDirectory returns the current directory | |
84 | // for the wxFileCtrl and GetFiles returns the names of the file(s) activated. | |
85 | // On wxEVT_FILECTRL_SELECTIONCHANGED, GetDirectory returns the current directory | |
86 | // for the wxFileCtrl and GetFiles returns the names of the currently selected | |
87 | // file(s). | |
88 | // In wxGTK, after each wxEVT_FILECTRL_FOLDERCHANGED, wxEVT_FILECTRL_SELECTIONCHANGED | |
89 | // is fired automatically once or more with 0 files. | |
90 | class WXDLLIMPEXP_CORE wxFileCtrlEvent : public wxCommandEvent | |
91 | { | |
92 | public: | |
93 | wxFileCtrlEvent() {} | |
94 | wxFileCtrlEvent( wxEventType type, wxObject *evtObject, int id ) | |
95 | : wxCommandEvent( type, id ) | |
96 | { | |
97 | SetEventObject( evtObject ); | |
98 | } | |
99 | ||
100 | // no need for the copy constructor as the default one will be fine. | |
101 | virtual wxEvent *Clone() const { return new wxFileCtrlEvent( *this ); } | |
102 | ||
103 | void SetFiles( const wxArrayString &files ) { m_files = files; } | |
104 | void SetDirectory( const wxString &directory ) { m_directory = directory; } | |
105 | void SetFilterIndex( int filterIndex ) { m_filterIndex = filterIndex; } | |
106 | ||
107 | wxArrayString GetFiles() const { return m_files; } | |
108 | wxString GetDirectory() const { return m_directory; } | |
109 | int GetFilterIndex() const { return m_filterIndex; } | |
110 | ||
111 | wxString GetFile() const; | |
112 | ||
113 | protected: | |
114 | int m_filterIndex; | |
115 | wxString m_directory; | |
116 | wxArrayString m_files; | |
117 | ||
118 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN( wxFileCtrlEvent ) | |
119 | }; | |
120 | ||
121 | typedef void ( wxEvtHandler::*wxFileCtrlEventFunction )( wxFileCtrlEvent& ); | |
122 | ||
123 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILECTRL_SELECTIONCHANGED, wxFileCtrlEvent ); | |
124 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILECTRL_FILEACTIVATED, wxFileCtrlEvent ); | |
125 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILECTRL_FOLDERCHANGED, wxFileCtrlEvent ); | |
126 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILECTRL_FILTERCHANGED, wxFileCtrlEvent ); | |
127 | ||
128 | #define wxFileCtrlEventHandler(func) \ | |
129 | wxEVENT_HANDLER_CAST( wxFileCtrlEventFunction, func ) | |
130 | ||
131 | #define EVT_FILECTRL_FILEACTIVATED(id, fn) \ | |
132 | wx__DECLARE_EVT1(wxEVT_FILECTRL_FILEACTIVATED, id, wxFileCtrlEventHandler(fn)) | |
133 | ||
134 | #define EVT_FILECTRL_SELECTIONCHANGED(id, fn) \ | |
135 | wx__DECLARE_EVT1(wxEVT_FILECTRL_SELECTIONCHANGED, id, wxFileCtrlEventHandler(fn)) | |
136 | ||
137 | #define EVT_FILECTRL_FOLDERCHANGED(id, fn) \ | |
138 | wx__DECLARE_EVT1(wxEVT_FILECTRL_FOLDERCHANGED, id, wxFileCtrlEventHandler(fn)) | |
139 | ||
140 | #define EVT_FILECTRL_FILTERCHANGED(id, fn) \ | |
141 | wx__DECLARE_EVT1(wxEVT_FILECTRL_FILTERCHANGED, id, wxFileCtrlEventHandler(fn)) | |
142 | ||
143 | #endif // wxUSE_FILECTRL | |
144 | ||
145 | #endif // _WX_FILECTRL_H_BASE_ |