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