filectrl.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: filectrl.h
  3. // Purpose: interface of wxFileCtrl
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. enum
  8. {
  9. wxFC_OPEN = 0x0001,
  10. wxFC_SAVE = 0x0002,
  11. wxFC_MULTIPLE = 0x0004,
  12. wxFC_NOSHOWHIDDEN = 0x0008
  13. };
  14. #define wxFC_DEFAULT_STYLE wxFC_OPEN
  15. /**
  16. @class wxFileCtrl
  17. This control allows the user to select a file.
  18. Two implementations of this class exist, one for Gtk and another generic
  19. one for all the other ports.
  20. This class is only available if @c wxUSE_FILECTRL is set to 1.
  21. @beginStyleTable
  22. @style{wxFC_DEFAULT_STYLE}
  23. The default style: wxFC_OPEN
  24. @style{wxFC_OPEN}
  25. Creates an file control suitable for opening files. Cannot be
  26. combined with wxFC_SAVE.
  27. @style{wxFC_SAVE}
  28. Creates an file control suitable for saving files. Cannot be
  29. combined with wxFC_OPEN.
  30. @style{wxFC_MULTIPLE}
  31. For open control only, Allows selecting multiple files. Cannot be
  32. combined with wxFC_SAVE
  33. @style{wxFC_NOSHOWHIDDEN}
  34. Hides the "Show Hidden Files" checkbox (Generic only)
  35. @endStyleTable
  36. @beginEventEmissionTable{wxFileCtrlEvent}
  37. @event{EVT_FILECTRL_FILEACTIVATED(id, func)}
  38. The user activated a file(by double-clicking or pressing Enter)
  39. @event{EVT_FILECTRL_SELECTIONCHANGED(id, func)}
  40. The user changed the current selection(by selecting or deselecting a file)
  41. @event{EVT_FILECTRL_FOLDERCHANGED(id, func)}
  42. The current folder of the file control has been changed
  43. @event{EVT_FILECTRL_FILTERCHANGED(id, func)}
  44. The current file filter of the file control has been changed.
  45. @since 2.9.1.
  46. @endEventTable
  47. @library{wxcore}
  48. @category{ctrl}
  49. @appearance{filectrl}
  50. @nativeimpl{wxgtk}
  51. @see wxGenericDirCtrl
  52. */
  53. class wxFileCtrl : public wxControl
  54. {
  55. public:
  56. wxFileCtrl();
  57. /**
  58. Constructs the window.
  59. @param parent
  60. Parent window, must not be non-@NULL.
  61. @param id
  62. The identifier for the control.
  63. @param defaultDirectory
  64. The initial directory shown in the control.
  65. Must be a valid path to a directory or the empty string.
  66. In case it is the empty string, the current working directory is used.
  67. @param defaultFilename
  68. The default filename, or the empty string.
  69. @param wildCard
  70. A wildcard specifying which files can be selected,
  71. such as "*.*" or "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".
  72. @param style
  73. The window style, see wxFC_* flags.
  74. @param pos
  75. Initial position.
  76. @param size
  77. Initial size.
  78. @param name
  79. Control name.
  80. @return @true if the control was successfully created or @false if
  81. creation failed.
  82. */
  83. wxFileCtrl(wxWindow* parent, wxWindowID id,
  84. const wxString& defaultDirectory = wxEmptyString,
  85. const wxString& defaultFilename = wxEmptyString,
  86. const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
  87. long style = wxFC_DEFAULT_STYLE,
  88. const wxPoint& pos = wxDefaultPosition,
  89. const wxSize& size = wxDefaultSize,
  90. const wxString& name = wxFileCtrlNameStr);
  91. /**
  92. Create function for two-step construction. See wxFileCtrl() for details.
  93. */
  94. bool Create(wxWindow* parent, wxWindowID id,
  95. const wxString& defaultDirectory = wxEmptyString,
  96. const wxString& defaultFilename = wxEmptyString,
  97. const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
  98. long style = wxFC_DEFAULT_STYLE, const wxPoint& pos = wxDefaultPosition,
  99. const wxSize& size = wxDefaultSize,
  100. const wxString& name = wxFileCtrlNameStr);
  101. /**
  102. Returns the current directory of the file control (i.e.\ the directory shown by it).
  103. */
  104. virtual wxString GetDirectory() const;
  105. /**
  106. Returns the currently selected filename.
  107. For the controls having the @c wxFC_MULTIPLE style, use GetFilenames() instead.
  108. */
  109. virtual wxString GetFilename() const;
  110. /**
  111. Fills the array @a filenames with the filenames only of selected items.
  112. This function should only be used with the controls having the @c wxFC_MULTIPLE
  113. style, use GetFilename() for the others.
  114. @remarks filenames is emptied first.
  115. */
  116. virtual void GetFilenames(wxArrayString& filenames) const;
  117. /**
  118. Returns the zero-based index of the currently selected filter.
  119. */
  120. virtual int GetFilterIndex() const;
  121. /**
  122. Returns the full path (directory and filename) of the currently selected file.
  123. For the controls having the @c wxFC_MULTIPLE style, use GetPaths() instead.
  124. */
  125. virtual wxString GetPath() const;
  126. /**
  127. Fills the array @a paths with the full paths of the files chosen.
  128. This function should be used with the controls having the @c wxFC_MULTIPLE style,
  129. use GetPath() otherwise.
  130. @remarks paths is emptied first.
  131. */
  132. virtual void GetPaths(wxArrayString& paths) const;
  133. /**
  134. Returns the current wildcard.
  135. */
  136. virtual wxString GetWildcard() const;
  137. /**
  138. Sets(changes) the current directory displayed in the control.
  139. @return Returns @true on success, @false otherwise.
  140. */
  141. virtual bool SetDirectory(const wxString& directory);
  142. /**
  143. Selects a certain file.
  144. @return Returns @true on success, @false otherwise
  145. */
  146. virtual bool SetFilename(const wxString& filename);
  147. /**
  148. Changes to a certain directory and selects a certain file.
  149. In case the filename specified isn't found/couldn't be shown with
  150. currently selected filter, false is returned.
  151. @return Returns @true on success, @false otherwise
  152. */
  153. virtual bool SetPath(const wxString& path);
  154. /**
  155. Sets the current filter index, starting from zero.
  156. */
  157. virtual void SetFilterIndex(int filterIndex);
  158. /**
  159. Sets the wildcard, which can contain multiple file types, for example:
  160. "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif"
  161. */
  162. virtual void SetWildcard(const wxString& wildCard);
  163. /**
  164. Sets whether hidden files and folders are shown or not.
  165. */
  166. virtual void ShowHidden(bool show);
  167. };
  168. wxEventType wxEVT_FILECTRL_SELECTIONCHANGED;
  169. wxEventType wxEVT_FILECTRL_FILEACTIVATED;
  170. wxEventType wxEVT_FILECTRL_FOLDERCHANGED;
  171. wxEventType wxEVT_FILECTRL_FILTERCHANGED;
  172. /**
  173. @class wxFileCtrlEvent
  174. A file control event holds information about events associated with
  175. wxFileCtrl objects.
  176. @beginEventTable{wxFileCtrlEvent}
  177. @event{EVT_FILECTRL_FILEACTIVATED(id, func)}
  178. The user activated a file(by double-clicking or pressing Enter)
  179. @event{EVT_FILECTRL_SELECTIONCHANGED(id, func)}
  180. The user changed the current selection(by selecting or deselecting a file)
  181. @event{EVT_FILECTRL_FOLDERCHANGED(id, func)}
  182. The current folder of the file control has been changed
  183. @event{EVT_FILECTRL_FILTERCHANGED(id, func)}
  184. The current file filter of the file control has been changed
  185. @endEventTable
  186. @library{wxcore}
  187. @category{events}
  188. */
  189. class wxFileCtrlEvent : public wxCommandEvent
  190. {
  191. public:
  192. /**
  193. Constructor.
  194. */
  195. wxFileCtrlEvent(wxEventType type, wxObject *evtObject, int id);
  196. /**
  197. Returns the current directory.
  198. In case of a @b EVT_FILECTRL_FOLDERCHANGED, this method returns the new
  199. directory.
  200. */
  201. wxString GetDirectory() const;
  202. /**
  203. Returns the file selected (assuming it is only one file).
  204. */
  205. wxString GetFile() const;
  206. /**
  207. Returns the files selected.
  208. In case of a @b EVT_FILECTRL_SELECTIONCHANGED, this method returns the
  209. files selected after the event.
  210. */
  211. wxArrayString GetFiles() const;
  212. /**
  213. Returns the current file filter index.
  214. For a @b EVT_FILECTRL_FILTERCHANGED event, this method returns the new
  215. file filter index.
  216. @since 2.9.1
  217. */
  218. int GetFilterIndex() const;
  219. /**
  220. Sets the files changed by this event.
  221. */
  222. void SetFiles(const wxArrayString& files);
  223. /**
  224. Sets the directory of this event.
  225. */
  226. void SetDirectory( const wxString &directory );
  227. /**
  228. Sets the filter index changed by this event.
  229. @since 2.9.1
  230. */
  231. void SetFilterIndex(int index);
  232. };