dirctrl.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: dirctrl.h
  3. // Purpose: interface of wxGenericDirCtrl
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. enum
  8. {
  9. // Only allow directory viewing/selection, no files
  10. wxDIRCTRL_DIR_ONLY = 0x0010,
  11. // When setting the default path, select the first file in the directory
  12. wxDIRCTRL_SELECT_FIRST = 0x0020,
  13. // Show the filter list
  14. wxDIRCTRL_SHOW_FILTERS = 0x0040,
  15. // Use 3D borders on internal controls
  16. wxDIRCTRL_3D_INTERNAL = 0x0080,
  17. // Editable labels
  18. wxDIRCTRL_EDIT_LABELS = 0x0100,
  19. // Allow multiple selection
  20. wxDIRCTRL_MULTIPLE = 0x0200
  21. };
  22. /**
  23. @class wxGenericDirCtrl
  24. This control can be used to place a directory listing (with optional
  25. files) on an arbitrary window.
  26. The control contains a wxTreeCtrl window representing the directory
  27. hierarchy, and optionally, a wxChoice window containing a list of filters.
  28. @beginStyleTable
  29. @style{wxDIRCTRL_DIR_ONLY}
  30. Only show directories, and not files.
  31. @style{wxDIRCTRL_3D_INTERNAL}
  32. Use 3D borders for internal controls.
  33. @style{wxDIRCTRL_SELECT_FIRST}
  34. When setting the default path, select the first file in the
  35. directory.
  36. @style{wxDIRCTRL_SHOW_FILTERS}
  37. Show the drop-down filter list.
  38. @style{wxDIRCTRL_EDIT_LABELS}
  39. Allow the folder and file labels to be editable.
  40. @style{wxDIRCTRL_MULTIPLE}
  41. Allows multiple files and folders to be selected.
  42. @endStyleTable
  43. @library{wxcore}
  44. @category{ctrl}
  45. @appearance{genericdirctrl}
  46. @beginEventEmissionTable
  47. @event{EVT_DIRCTRL_SELECTIONCHANGED(id, func)}
  48. Selected directory has changed.
  49. Processes a @c wxEVT_DIRCTRL_SELECTIONCHANGED event type.
  50. Notice that this event is generated even for the changes done by the
  51. program itself and not only those done by the user.
  52. Available since wxWidgets 2.9.5.
  53. @event{EVT_DIRCTRL_FILEACTIVATED(id, func)}
  54. The user activated a file by double-clicking or pressing Enter.
  55. Available since wxWidgets 2.9.5.
  56. @endEventTable
  57. */
  58. class wxGenericDirCtrl : public wxControl
  59. {
  60. public:
  61. /**
  62. Default constructor.
  63. */
  64. wxGenericDirCtrl();
  65. /**
  66. Main constructor.
  67. @param parent
  68. Parent window.
  69. @param id
  70. Window identifier.
  71. @param dir
  72. Initial folder.
  73. @param pos
  74. Position.
  75. @param size
  76. Size.
  77. @param style
  78. Window style. Please see wxGenericDirCtrl for a list of possible
  79. styles.
  80. @param filter
  81. A filter string, using the same syntax as that for wxFileDialog.
  82. This may be empty if filters are not being used. Example:
  83. @c "All files (*.*)|*.*|JPEG files (*.jpg)|*.jpg"
  84. @param defaultFilter
  85. The zero-indexed default filter setting.
  86. @param name
  87. The window name.
  88. */
  89. wxGenericDirCtrl(wxWindow* parent, const wxWindowID id = wxID_ANY,
  90. const wxString& dir = wxDirDialogDefaultFolderStr,
  91. const wxPoint& pos = wxDefaultPosition,
  92. const wxSize& size = wxDefaultSize,
  93. long style = wxDIRCTRL_3D_INTERNAL,
  94. const wxString& filter = wxEmptyString,
  95. int defaultFilter = 0,
  96. const wxString& name = wxTreeCtrlNameStr);
  97. /**
  98. Destructor.
  99. */
  100. virtual ~wxGenericDirCtrl();
  101. /**
  102. Collapse the given @a path.
  103. */
  104. virtual bool CollapsePath(const wxString& path);
  105. /**
  106. Collapses the entire tree.
  107. */
  108. virtual void CollapseTree();
  109. /**
  110. Create function for two-step construction. See wxGenericDirCtrl() for
  111. details.
  112. */
  113. bool Create(wxWindow* parent, const wxWindowID id = wxID_ANY,
  114. const wxString& dir = wxDirDialogDefaultFolderStr,
  115. const wxPoint& pos = wxDefaultPosition,
  116. const wxSize& size = wxDefaultSize,
  117. long style = wxDIRCTRL_3D_INTERNAL,
  118. const wxString& filter = wxEmptyString, int defaultFilter = 0,
  119. const wxString& name = wxTreeCtrlNameStr);
  120. /**
  121. Tries to expand as much of the given @a path as possible, so that the
  122. filename or directory is visible in the tree control.
  123. */
  124. virtual bool ExpandPath(const wxString& path);
  125. /**
  126. Gets the default path.
  127. */
  128. virtual wxString GetDefaultPath() const;
  129. /**
  130. Gets selected filename path only (else empty string).
  131. This function doesn't count a directory as a selection.
  132. */
  133. virtual wxString GetFilePath() const;
  134. /**
  135. Fills the array @a paths with the currently selected filepaths.
  136. This function doesn't count a directory as a selection.
  137. */
  138. virtual void GetFilePaths(wxArrayString& paths) const;
  139. /**
  140. Returns the filter string.
  141. */
  142. virtual wxString GetFilter() const;
  143. /**
  144. Returns the current filter index (zero-based).
  145. */
  146. virtual int GetFilterIndex() const;
  147. /**
  148. Returns a pointer to the filter list control (if present).
  149. */
  150. virtual wxDirFilterListCtrl* GetFilterListCtrl() const;
  151. /**
  152. Gets the currently-selected directory or filename.
  153. */
  154. virtual wxString GetPath() const;
  155. /**
  156. Gets the path corresponding to the given tree control item.
  157. @since 2.9.5
  158. */
  159. wxString GetPath(wxTreeItemId itemId) const;
  160. /**
  161. Fills the array @a paths with the selected directories and filenames.
  162. */
  163. virtual void GetPaths(wxArrayString& paths) const;
  164. /**
  165. Returns the root id for the tree control.
  166. */
  167. virtual wxTreeItemId GetRootId();
  168. /**
  169. Returns a pointer to the tree control.
  170. */
  171. virtual wxTreeCtrl* GetTreeCtrl() const;
  172. /**
  173. Initializes variables.
  174. */
  175. virtual void Init();
  176. /**
  177. Collapse and expand the tree, thus re-creating it from scratch. May be
  178. used to update the displayed directory content.
  179. */
  180. virtual void ReCreateTree();
  181. /**
  182. Sets the default path.
  183. */
  184. virtual void SetDefaultPath(const wxString& path);
  185. /**
  186. Sets the filter string.
  187. */
  188. virtual void SetFilter(const wxString& filter);
  189. /**
  190. Sets the current filter index (zero-based).
  191. */
  192. virtual void SetFilterIndex(int n);
  193. /**
  194. Sets the current path.
  195. */
  196. virtual void SetPath(const wxString& path);
  197. /**
  198. @param show
  199. If @true, hidden folders and files will be displayed by the
  200. control. If @false, they will not be displayed.
  201. */
  202. virtual void ShowHidden(bool show);
  203. /**
  204. Selects the given item.
  205. In multiple selection controls, can be also used to deselect a
  206. currently selected item if the value of @a select is false.
  207. Existing selections are not changed. Only visible items can be
  208. (de)selected, otherwise use ExpandPath().
  209. */
  210. virtual void SelectPath(const wxString& path, bool select = true);
  211. /**
  212. Selects only the specified paths, clearing any previous selection.
  213. Only supported when wxDIRCTRL_MULTIPLE is set.
  214. */
  215. virtual void SelectPaths(const wxArrayString& paths);
  216. /**
  217. Removes the selection from all currently selected items.
  218. */
  219. virtual void UnselectAll();
  220. };
  221. class wxDirFilterListCtrl: public wxChoice
  222. {
  223. public:
  224. wxDirFilterListCtrl();
  225. wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY,
  226. const wxPoint& pos = wxDefaultPosition,
  227. const wxSize& size = wxDefaultSize,
  228. long style = 0);
  229. bool Create(wxGenericDirCtrl* parent, const wxWindowID id = wxID_ANY,
  230. const wxPoint& pos = wxDefaultPosition,
  231. const wxSize& size = wxDefaultSize,
  232. long style = 0);
  233. virtual ~wxDirFilterListCtrl() {}
  234. void Init();
  235. //// Operations
  236. void FillFilterList(const wxString& filter, int defaultFilter);
  237. };
  238. wxEventType wxEVT_DIRCTRL_SELECTIONCHANGED;
  239. wxEventType wxEVT_DIRCTRL_FILEACTIVATED;