Added wxDirDialog to generic directories
[wxWidgets.git] / include / wx / generic / dirdlgg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dirdlgg.h
3 // Purpose: wxDirDialog
4 // Author: Harm van der Heijden and Robert Roebling
5 // Modified by:
6 // Created: 12/12/98
7 // Copyright: (c) Harm van der Heijden and Robert Roebling
8 // Licence: wxWindows licence
9 //
10 // Notes: wxDirDialog class written by Harm van der Heijden,
11 // uses wxDirCtrl class written by Robert Roebling for the
12 // wxFile application, modified by Harm van der Heijden
13 //
14 // Description: This generic dirdialog implementation defines three classes:
15 // 1) wxDirItemData(public wxTreeItemData) stores pathname and
16 // displayed name for each item in the directory tree
17 // 2) wxDirCtrl(public wxTreeCtrl) is a tree widget that
18 // displays a directory tree. It is possible to define sections
19 // for fast access to parts of the file system (such as the
20 // user's homedir, /usr/local, /tmp ...etc), similar to
21 // Win95 Explorer's shortcuts to 'My Computer', 'Desktop', etc.
22 // 3) wxDirDialog is the dialog box itself. The user can choose
23 // a directory by navigating the tree, or by typing a dir
24 // in an inputbox. The inputbox displays paths selected in the
25 // tree. It is possible to create new directories. The user
26 // will automatically be prompted for dir creation if he
27 // enters a non-existing dir.
28 //
29 // TODO/BUGS: - standard sections only have reasonable defaults for Unix
30 // (but others are easily added in wxDirCtrl::SetupSections)
31 // - No direct support for "show hidden" toggle. Partly due
32 // to laziness on my part and partly because
33 // wxFindFirst/NextFile never seems to find hidden dirs
34 // anyway.
35 // - No automatic update of the tree (branch) after directory
36 // creation.
37 // - I call wxBeginBusyCursor while expanding items (creating
38 // a new branch might take a few seconds, especially if a
39 // CDROM drive or something is involved) but that doesn't
40 // seem to do anything. Need to look into that.
41 // - Am still looking for an efficient way to delete wxTreeCtrl
42 // branches. DeleteChildren has disappeared and
43 // CollapseAndReset( parent ) deletes the parent as well.
44 // - The dialog window layout is done using wxConstraints. It
45 // works, but it's not as simple as I'd like it to be (see
46 // comments in wxDirDialog::doSize)
47 //
48 /////////////////////////////////////////////////////////////////////////////
49
50 #ifndef _WX_DIRDLGG_H_
51 #define _WX_DIRDLGG_H_
52
53 #ifdef __GNUG__
54 #pragma interface "dirdlgg.h"
55 #endif
56
57 #include "wx/dialog.h"
58 //#include "wx/checkbox.h"
59 #include "wx/treectrl.h"
60
61 WXDLLEXPORT_DATA(extern const char*) wxFileSelectorPromptStr;
62
63 //-----------------------------------------------------------------------------
64 // wxDirItemData
65 //-----------------------------------------------------------------------------
66
67 class wxDirItemData : public wxTreeItemData
68 {
69 public:
70 wxDirItemData(wxString& path, wxString& name);
71 ~wxDirItemData();
72 bool HasSubDirs();
73 wxString *m_path, *m_name;
74 bool m_isHidden;
75 bool m_hasSubDirs;
76 };
77
78 //-----------------------------------------------------------------------------
79 // wxDirCtrl
80 //-----------------------------------------------------------------------------
81
82 class wxDirCtrl: public wxTreeCtrl
83 {
84 DECLARE_DYNAMIC_CLASS(wxDirCtrl)
85
86 public:
87 bool m_showHidden;
88 wxTreeItemId m_rootId;
89
90 wxDirCtrl(void);
91 wxDirCtrl(wxWindow *parent, const wxWindowID id = -1,
92 const wxString &dir = "/",
93 const wxPoint& pos = wxDefaultPosition,
94 const wxSize& size = wxDefaultSize,
95 const long style = wxTR_HAS_BUTTONS,
96 const wxString& name = "wxTreeCtrl" );
97 void OnExpandItem( const wxTreeEvent &event );
98 void OnCollapseItem( const wxTreeEvent &event );
99 void ShowHidden( const bool yesno );
100 DECLARE_EVENT_TABLE()
101 protected:
102 void CreateItems(const wxTreeItemId &parent);
103 void SetupSections(void);
104 wxArrayString m_paths, m_names;
105 };
106
107 //-----------------------------------------------------------------------------
108 // wxDirDialog
109 //-----------------------------------------------------------------------------
110
111 class WXDLLEXPORT wxDirDialog: public wxDialog
112 {
113 DECLARE_DYNAMIC_CLASS(wxDirDialog)
114 public:
115 wxDirDialog(wxWindow *parent,
116 const wxString& message = wxFileSelectorPromptStr,
117 const wxString& defaultPath = "",
118 long style = 0, const wxPoint& pos = wxDefaultPosition);
119 inline void SetMessage(const wxString& message) { m_message = message; }
120 inline void SetPath(const wxString& path) { m_path = path; }
121 inline void SetStyle(long style) { m_dialogStyle = style; }
122
123 inline wxString GetMessage() const { return m_message; }
124 inline wxString GetPath() const { return m_path; }
125 inline long GetStyle() const { return m_dialogStyle; }
126
127 int ShowModal();
128
129 void OnTreeSelected( wxTreeEvent &event );
130 void OnTreeKeyDown( wxKeyEvent &event );
131 void OnSize(wxSizeEvent& event);
132 void OnOK(wxCommandEvent& event);
133 void OnCancel(wxCommandEvent& event);
134 void OnNew(wxCommandEvent& event);
135 // void OnCheck(wxCommandEvent& event);
136 DECLARE_EVENT_TABLE()
137
138 protected:
139 // implementation
140 wxString m_message;
141 long m_dialogStyle;
142 wxWindow * m_parent;
143 wxString m_path;
144 wxDirCtrl *m_dir;
145 wxTextCtrl *m_input;
146 // wxCheckBox *m_check;
147 wxButton *m_ok, *m_cancel, *m_new;
148 void doSize();
149 };
150
151 #endif
152 // _WX_DIRDLGG_H_
153