1
/////////////////////////////////////////////////////////////////////////////
3
// Purpose: A file browser widget with tree and/or list control views
4
// Author: John Labenski
6
// Copyright: John Labenski, 2002
8
/////////////////////////////////////////////////////////////////////////////
10
#ifndef __WX_FILEBROWSER_H__
11
#define __WX_FILEBROWSER_H__
13
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
14
#pragma interface "filebrws.h"
17
#include "wx/listctrl.h"
18
#include "wx/dirctrl.h"
19
#include "wx/filedlg.h"
20
#include "wx/textdlg.h"
21
#include "wx/generic/filedlgg.h"
22
#include "wx/things/thingdef.h"
24
class WXDLLEXPORT wxCheckBox;
25
class WXDLLEXPORT wxComboBox;
26
class WXDLLEXPORT wxTreeEvent;
27
class WXDLLEXPORT wxSplitterWindow;
28
class WXDLLEXPORT wxGenericDirCtrl;
29
class WXDLLEXPORT wxListCtrl;
30
class WXDLLEXPORT wxListEvent;
31
class WXDLLEXPORT wxToolBar;
32
class WXDLLEXPORT wxBitmapButton;
33
class WXDLLEXPORT wxConfigBase;
34
class WXDLLEXPORT wxFileCtrl;
35
class WXDLLEXPORT wxFileName;
37
class WXDLLIMPEXP_THINGS wxFileBrowser;
39
#include "wx/dynarray.h"
40
WX_DECLARE_OBJARRAY_WITH_DECL(wxFileData, wxArrayFileData, class WXDLLIMPEXP_THINGS);
42
//----------------------------------------------------------------------------
43
// MultilineTextDialog : wxTextEntryDialog for multiple lines
44
//----------------------------------------------------------------------------
46
class WXDLLIMPEXP_THINGS MultilineTextDialog : public wxTextEntryDialog
49
MultilineTextDialog(wxWindow *parent,
50
const wxString& message,
51
const wxString& caption = wxGetTextFromUserPromptStr,
52
const wxString& value = wxEmptyString,
54
const wxPoint& pos = wxDefaultPosition);
57
//----------------------------------------------------------------------------
58
// wxFileBrowserEvent : events for the wxFileBrowser
59
//----------------------------------------------------------------------------
60
// wxEVT_FILEBROWSER_FILE_SELECTED - a file has been selected (single click)
61
// wxEVT_FILEBROWSER_FILE_ACTIVATED - a file has been double clicked or enter pressed
62
// wxEVT_FILEBROWSER_DIR_SELECTED - a dir has been selected (single click)
63
// wxEVT_FILEBROWSER_DIR_ACTIVATED - a dir has been double clicked or enter pressed
65
BEGIN_DECLARE_EVENT_TYPES()
66
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_THINGS, wxEVT_FILEBROWSER_FILE_SELECTED, wxEVT_USER_FIRST + 1000)
67
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_THINGS, wxEVT_FILEBROWSER_FILE_ACTIVATED, wxEVT_USER_FIRST + 1001)
68
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_THINGS, wxEVT_FILEBROWSER_DIR_SELECTED, wxEVT_USER_FIRST + 1002)
69
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_THINGS, wxEVT_FILEBROWSER_DIR_ACTIVATED, wxEVT_USER_FIRST + 1003)
70
END_DECLARE_EVENT_TYPES()
72
class WXDLLIMPEXP_THINGS wxFileBrowserEvent : public wxCommandEvent
75
wxFileBrowserEvent( wxEventType commandType = wxEVT_NULL,
76
wxFileBrowser *fileBrowser = NULL,
77
wxWindowID id = wxID_ANY );
79
wxFileBrowserEvent( const wxFileBrowserEvent &event ) : wxCommandEvent(event) {}
81
// Get the full path + filename
82
wxString GetFilePath() const { return GetString(); }
83
void SetFilePath(const wxString &filepath) { SetString(filepath); }
85
virtual wxEvent *Clone() const { return new wxFileBrowserEvent(*this); }
88
DECLARE_ABSTRACT_CLASS(wxFileBrowserEvent)
91
typedef void (wxEvtHandler::*wxFileBrowserEventFunction)(wxFileBrowserEvent&);
93
#define wxFileBrowserEventHandler(func) \
94
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFileBrowserEventFunction, &func)
96
#define wx__DECLARE_FILEBROWSEREVT(evt, id, fn) wx__DECLARE_EVT1( evt, id, wxFileBrowserEventHandler(fn))
98
#define EVT_FILEBROWSER_FILE_SELECTED(id, fn) wx__DECLARE_FILEBROWSEREVT( wxEVT_FILEBROWSER_FILE_SELECTED, id, fn )
99
#define EVT_FILEBROWSER_FILE_ACTIVATED(id, fn) wx__DECLARE_FILEBROWSEREVT( wxEVT_FILEBROWSER_FILE_ACTIVATED, id, fn )
100
#define EVT_FILEBROWSER_DIR_SELECTED(id, fn) wx__DECLARE_FILEBROWSEREVT( wxEVT_FILEBROWSER_DIR_SELECTED, id, fn )
101
#define EVT_FILEBROWSER_DIR_ACTIVATED(id, fn) wx__DECLARE_FILEBROWSEREVT( wxEVT_FILEBROWSER_DIR_ACTIVATED, id, fn )
103
//----------------------------------------------------------------------------
105
//----------------------------------------------------------------------------
107
enum wxFileBrowserStyles_Type
109
// note: these are wxListCtrl styles to allow normal wxWindow styles to work
111
wxFILEBROWSER_TREE = wxLC_SORT_DESCENDING, // treectrl view
112
wxFILEBROWSER_LIST = wxLC_LIST, // listctrl view
113
wxFILEBROWSER_DETAILS = wxLC_REPORT, // listctrl details view
114
wxFILEBROWSER_SMALL_ICON = wxLC_SMALL_ICON, // listctrl icon view
115
wxFILEBROWSER_LARGE_ICON = wxLC_ICON, // NOT IMPL listctrl large icon
116
wxFILEBROWSER_PREVIEW = wxLC_SORT_ASCENDING, // NOT implemented
118
wxFILEBROWSER_SPLIT_VERTICAL = wxLC_NO_HEADER, // tree and listctrl are
119
// split vertically else horizontal
121
wxFILEBROWSER_SHOW_FOLDERS = wxLC_NO_SORT_HEADER, // when showing listview also show
122
// the folders in the treectrl
124
wxFILEBROWSER_VIEW_MASK = wxFILEBROWSER_TREE|wxFILEBROWSER_LIST|wxFILEBROWSER_DETAILS|wxFILEBROWSER_SMALL_ICON|wxFILEBROWSER_LARGE_ICON|wxFILEBROWSER_PREVIEW,
125
wxFILEBROWSER_STYLE_MASK = wxFILEBROWSER_VIEW_MASK|wxFILEBROWSER_SPLIT_VERTICAL|wxFILEBROWSER_SHOW_FOLDERS
128
class WXDLLIMPEXP_THINGS wxFileBrowser : public wxControl
131
wxFileBrowser() : wxControl() { Init(); }
133
wxFileBrowser( wxWindow* parent, const wxWindowID id,
134
const wxString& dir = wxDirDialogDefaultFolderStr,
135
const wxPoint& pos = wxDefaultPosition,
136
const wxSize& size = wxDefaultSize,
137
long style = wxFILEBROWSER_DETAILS,
138
const wxString& filter = wxFileSelectorDefaultWildcardStr,
139
int defaultFilter = 0,
140
const wxString& name = wxT("wxFileBrowser")) : wxControl()
143
Create(parent, id, dir, pos, size, style, filter, defaultFilter, name);
146
virtual ~wxFileBrowser();
148
bool Create( wxWindow* parent, const wxWindowID id,
149
const wxString& dir = wxDirDialogDefaultFolderStr,
150
const wxPoint& pos = wxDefaultPosition,
151
const wxSize& size = wxDefaultSize,
152
long style = wxFILEBROWSER_DETAILS,
153
const wxString& filter = wxFileSelectorDefaultWildcardStr,
154
int defaultFilter = 0,
155
const wxString& name = wxT("wxFileBrowser") );
157
// Get the current dir (not file), optionally add a trailing platform dependent '/' or '\'
158
wxString GetPath(bool add_wxFILE_SEP_PATH = false) const;
159
// Go to a directory, returns sucess
160
bool SetPath(const wxString &dirName);
162
// go to a dir or send an EVT_FILEBROWSER_FILE_ACTIVATED if a filename
163
bool OpenFilePath(const wxString &filePath);
165
// Go to a higher directory, returns sucess
166
bool CanGoUpDir() const;
169
// Go to your "Home" folder "~/" in unix, "My Documents" in MSW
172
// Go forwards and backwards through the recent dir history
173
bool CanGoPathHistoryForward();
174
bool CanGoPathHistoryBackward();
175
bool GoPathHistoryForward();
176
bool GoPathHistoryBackward();
177
// Add a new path to the history paths at the current index
178
void AddPathHistory(const wxString& path);
180
// Set the file filter to one of the filter combobox items
181
bool SetFilter(int comboItem);
182
// Set all the file filters, deleting previous and select one
183
bool SetFilters(const wxString &filters, int select = 0);
184
// Add or set the file filter, "All Files (*)|*", it must have a "|" in it
185
bool AddFilter(const wxString &filter);
186
// Get the current file filter
187
wxString GetFilter() const { return m_filter; }
188
// Get the wild card used for the filter
189
wxString GetWild() const { return m_filter.AfterLast(wxT('|')); }
191
// Set how the files are displayed - see enum wxFileBrowserStyles_Type
192
void SetBrowserStyle(long style);
193
long GetBrowserStyle() const { return m_browser_style; }
194
bool HasBrowserStyle(int style_mask) const { return (m_browser_style & style_mask) != 0; }
196
// Show or hide hidden files
197
void ShowHidden(bool show_hidden);
198
bool GetShowHidden() const { return m_show_hidden; }
200
// When showing the files in a listctrl also show the folders in the treectrl
201
// also don't let them unsplit it
202
void ShowFolders(bool show_folders);
203
bool GetShowFolders() const { return HasBrowserStyle(wxFILEBROWSER_SHOW_FOLDERS); }
205
// When splitting, split vertically or horizontally
206
void SplitVertical(bool split_vertically);
207
bool GetSplitVertical() const { return HasBrowserStyle(wxFILEBROWSER_SPLIT_VERTICAL); }
209
// -----------------------------------------------------------------------
212
// utility function, returns the dir part of the filepath w/ trailing wxFILE_SEP_PATH
213
bool GetPathFromFilePath(const wxString &filepath, wxString &path) const;
215
// Delete all selected items in the wxFileCtrl
216
bool DeleteSelectedListItems(bool ask_ok = true);
217
// Store a list of selected items that you'll copy/cut when you paste them
218
bool CopyCutSelectedListItems(bool copy_them);
219
// Paste the stored CopyCutSelectedListItems - based on CopyCutSelectedListItems list
220
bool PasteCopyCutSelectedListItems();
222
// Get a list of all the selected items in the list control
223
wxArrayInt GetSelectedListItems() const;
224
// Get the wxFileData items that are selected in the list control
225
wxArrayFileData GetSelectedListFileData() const;
226
// Get the currently focused list item or NULL if none selected
227
wxFileData *GetFocusedListItem() const;
229
// Create a wxFileData from a wxFileName
230
wxFileData CreateFileData(const wxFileName& fileName) const;
232
// Get the last or currently focused path + filename
233
wxString GetLastFocusedFilePath();
235
// Show a simple dialog that contains the properties of the file/dir
236
void ShowPropertiesDialog(const wxFileData &fileData) const;
238
// returns a string with the name of a program to run the file
239
wxString GetOpenWithFileCmd(wxFileData* fd) const;
241
// Get a pointer to the path history combo, can change its contents
242
wxComboBox *GetPathCombo() const { return m_pathCombo; }
243
// Get a pointer to the filter combo
244
// don't delete selections less than the # of filters passed in
245
// ie. check for items with GetClientData() !NULL
246
wxComboBox *GetFilterCombo() const { return m_filterCombo; }
248
// Can this file be read/opened?
249
bool CanRead(const wxString& filePath) const;
250
// Can this file be written to, deleted, moved, cut...
251
bool CanWrite(const wxString& filePath) const;
253
// Update the menu/toolbar items
254
void UpdateMenu(wxMenu *menu);
255
void UpdateToolBar(wxToolBar *toolBar);
256
// Update the state of the toolbar and menu items
260
// Load the recent paths/filters, max = 20
261
void LoadConfig(wxConfigBase& config,
262
bool paths=true, bool filters=true,
263
const wxString &configPath = wxT("/wxFileBrowser"));
264
// Save the recent paths, filters, if n_xxx < 0 then don't save it
265
void SaveConfig(wxConfigBase& config,
266
int n_paths=10, int n_filters=10,
267
const wxString &configPath = wxT("/wxFileBrowser"));
268
#endif // wxUSE_CONFIG
271
void OnSize( wxSizeEvent& event );
274
virtual wxSize DoGetBestSize() const;
276
// toolbar tools events
277
void OnViewButtons(wxCommandEvent &event);
278
void OnPathCombo(wxCommandEvent &event);
279
void OnPathComboEnter(wxCommandEvent &event);
280
void OnFilterCombo(wxCommandEvent &event);
281
void OnFilterComboEnter(wxCommandEvent &event);
283
// wxDirCtrl events - a wxTreeCtrl
284
void OnTreeItemSelection(wxTreeEvent &event);
285
void OnTreeItemActivation(wxTreeEvent &event);
286
void OnTreeRightClick(wxTreeEvent& event);
288
// wxFileCtrl events - a wxListCtrl
289
void OnListColClick(wxListEvent &event);
290
void OnListItemActivated(wxListEvent &event);
291
void OnListItemSelected(wxListEvent &event);
292
void OnListRightClick(wxListEvent &event);
294
void OnTreeMenu(wxCommandEvent &event);
295
void OnListMenu(wxCommandEvent &event);
297
void OnIdle( wxIdleEvent &event );
299
//for delayed set path from combo
300
void OnSetPath( wxCommandEvent &event );
301
void OnSetFilter( wxCommandEvent &event );
303
// (re)inserts the item at pos, deleting it if it existed after pos
304
// keeps recent items at top
305
bool InsertComboItem(wxComboBox *combo, const wxString &item, int pos = 0) const;
307
// Send an event, returns false if event.Veto() called
308
bool DoSendEvent(wxFileBrowserEvent &event) const;
310
int FBStyleToLCStyle(int fb_style) const; // wxFileBrowserStyles_Type to wxLC_XXX
311
int FBStyleToMenuID(int fb_style) const; // wxFileBrowserStyles_Type menu id
312
int MenuIDToFBStyle(int menuID) const; // menu id to wxFileBrowserStyles_Type
315
wxToolBar *m_viewToolBar;
316
wxToolBar *m_pathToolBar;
318
wxBitmapButton *m_viewButton;
319
wxComboBox *m_filterCombo;
321
wxComboBox *m_pathCombo;
323
wxSplitterWindow *m_splitterWin;
324
wxGenericDirCtrl *m_dirCtrl;
325
wxFileCtrl *m_fileCtrl;
327
wxMenu *m_listMenu; // popup menu in listctrl
328
wxMenu *m_treeMenu; // popup menu in treectrl
329
wxMenu *m_viewMenu; // popup menu in for changing view
332
wxString m_filter; // current filter
333
wxString m_path; // current path
334
wxString m_lastFocusedFilePath; // path + filename of last focused item
336
wxArrayString m_pathHistory; // recently used paths
337
int m_path_history_index; // current index in recently used paths
339
wxArrayFileData m_copycutFiles; // list of names when copying or cutting
340
bool m_last_copy; // last CopyCutSelectedListItems was a copy, else cut
342
int m_init_filters; // # of filters initially passed in
344
bool m_ignore_tree_event; // temporarily ignore m_dirCtrl events
345
long m_browser_style;
347
int m_filterComboSelection; // last selection of the filter/path combo
348
int m_pathComboSelection;
350
bool m_show_hidden; // show hidden files
354
DECLARE_EVENT_TABLE()
355
DECLARE_DYNAMIC_CLASS(wxFileBrowser)
358
#endif // __WX_FILEBROWSER_H__