filepicker.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: filepicker.h
  3. // Purpose: interface of wxFilePickerCtrl
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. #define wxFLP_OPEN 0x0400
  8. #define wxFLP_SAVE 0x0800
  9. #define wxFLP_OVERWRITE_PROMPT 0x1000
  10. #define wxFLP_FILE_MUST_EXIST 0x2000
  11. #define wxFLP_CHANGE_DIR 0x4000
  12. #define wxFLP_SMALL wxPB_SMALL
  13. #define wxFLP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
  14. #define wxFLP_DEFAULT_STYLE (wxFLP_OPEN|wxFLP_FILE_MUST_EXIST)
  15. #define wxDIRP_DIR_MUST_EXIST 0x0008
  16. #define wxDIRP_CHANGE_DIR 0x0010
  17. #define wxDIRP_SMALL wxPB_SMALL
  18. #define wxDIRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
  19. #define wxDIRP_DEFAULT_STYLE (wxDIRP_DIR_MUST_EXIST)
  20. wxEventType wxEVT_FILEPICKER_CHANGED;
  21. wxEventType wxEVT_DIRPICKER_CHANGED;
  22. /**
  23. @class wxFilePickerCtrl
  24. This control allows the user to select a file. The generic implementation is
  25. a button which brings up a wxFileDialog when clicked. Native implementation
  26. may differ but this is usually a (small) widget which give access to the
  27. file-chooser dialog.
  28. It is only available if @c wxUSE_FILEPICKERCTRL is set to 1 (the default).
  29. @beginStyleTable
  30. @style{wxFLP_DEFAULT_STYLE}
  31. The default style: includes wxFLP_OPEN | wxFLP_FILE_MUST_EXIST and,
  32. under wxMSW only, wxFLP_USE_TEXTCTRL.
  33. @style{wxFLP_USE_TEXTCTRL}
  34. Creates a text control to the left of the picker button which is
  35. completely managed by the wxFilePickerCtrl and which can be used by
  36. the user to specify a path (see SetPath). The text control is
  37. automatically synchronized with button's value. Use functions
  38. defined in wxPickerBase to modify the text control.
  39. @style{wxFLP_OPEN}
  40. Creates a picker which allows the user to select a file to open.
  41. @style{wxFLP_SAVE}
  42. Creates a picker which allows the user to select a file to save.
  43. @style{wxFLP_OVERWRITE_PROMPT}
  44. Can be combined with wxFLP_SAVE only: ask confirmation to the user
  45. before selecting a file.
  46. @style{wxFLP_FILE_MUST_EXIST}
  47. Can be combined with wxFLP_OPEN only: the selected file must be an
  48. existing file.
  49. @style{wxFLP_CHANGE_DIR}
  50. Change current working directory on each user file selection change.
  51. @style{wxFLP_SMALL}
  52. Use smaller version of the control with a small "..." button instead
  53. of the normal "Browse" one. This flag is new since wxWidgets 2.9.3.
  54. @endStyleTable
  55. @beginEventEmissionTable{wxFileDirPickerEvent}
  56. @event{EVT_FILEPICKER_CHANGED(id, func)}
  57. The user changed the file selected in the control either using the
  58. button or using text control (see wxFLP_USE_TEXTCTRL; note that in
  59. this case the event is fired only if the user's input is valid,
  60. e.g. an existing file path if wxFLP_FILE_MUST_EXIST was given).
  61. @endEventTable
  62. @library{wxcore}
  63. @category{pickers}
  64. @appearance{filepickerctrl}
  65. @see wxFileDialog, wxFileDirPickerEvent
  66. */
  67. class wxFilePickerCtrl : public wxPickerBase
  68. {
  69. public:
  70. wxFilePickerCtrl();
  71. /**
  72. Initializes the object and calls Create() with
  73. all the parameters.
  74. */
  75. wxFilePickerCtrl(wxWindow* parent, wxWindowID id,
  76. const wxString& path = wxEmptyString,
  77. const wxString& message = wxFileSelectorPromptStr,
  78. const wxString& wildcard = wxFileSelectorDefaultWildcardStr,
  79. const wxPoint& pos = wxDefaultPosition,
  80. const wxSize& size = wxDefaultSize,
  81. long style = wxFLP_DEFAULT_STYLE,
  82. const wxValidator& validator = wxDefaultValidator,
  83. const wxString& name = wxFilePickerCtrlNameStr);
  84. /**
  85. Creates this widget with the given parameters.
  86. @param parent
  87. Parent window, must not be non-@NULL.
  88. @param id
  89. The identifier for the control.
  90. @param path
  91. The initial file shown in the control. Must be a valid path to a file or
  92. the empty string.
  93. @param message
  94. The message shown to the user in the wxFileDialog shown by the control.
  95. @param wildcard
  96. A wildcard which defines user-selectable files (use the same syntax as for
  97. wxFileDialog's wildcards).
  98. @param pos
  99. Initial position.
  100. @param size
  101. Initial size.
  102. @param style
  103. The window style, see wxFLP_* flags.
  104. @param validator
  105. Validator which can be used for additional data checks.
  106. @param name
  107. Control name.
  108. @return @true if the control was successfully created or @false if
  109. creation failed.
  110. */
  111. bool Create(wxWindow* parent, wxWindowID id,
  112. const wxString& path = wxEmptyString,
  113. const wxString& message = wxFileSelectorPromptStr,
  114. const wxString& wildcard = wxFileSelectorDefaultWildcardStr,
  115. const wxPoint& pos = wxDefaultPosition,
  116. const wxSize& size = wxDefaultSize,
  117. long style = wxFLP_DEFAULT_STYLE,
  118. const wxValidator& validator = wxDefaultValidator,
  119. const wxString& name = wxFilePickerCtrlNameStr);
  120. /**
  121. Similar to GetPath() but returns the path of the currently selected
  122. file as a wxFileName object.
  123. */
  124. wxFileName GetFileName() const;
  125. /**
  126. Returns the absolute path of the currently selected file.
  127. */
  128. wxString GetPath() const;
  129. /**
  130. This method does the same thing as SetPath() but takes a wxFileName
  131. object instead of a string.
  132. */
  133. void SetFileName(const wxFileName& filename);
  134. /**
  135. Set the directory to show when starting to browse for files.
  136. This function is mostly useful for the file picker controls which have
  137. no selection initially to configure the directory that should be shown
  138. if the user starts browsing for files as otherwise the directory of
  139. initially selected file is used, which is usually the desired
  140. behaviour and so the directory specified by this function is ignored in
  141. this case.
  142. @since 2.9.4
  143. */
  144. void SetInitialDirectory(const wxString& dir);
  145. /**
  146. Sets the absolute path of the currently selected file.
  147. This must be a valid file if the @c wxFLP_FILE_MUST_EXIST style was given.
  148. */
  149. void SetPath(const wxString& filename);
  150. };
  151. /**
  152. @class wxDirPickerCtrl
  153. This control allows the user to select a directory. The generic implementation
  154. is a button which brings up a wxDirDialog when clicked. Native implementation
  155. may differ but this is usually a (small) widget which give access to the
  156. dir-chooser dialog.
  157. It is only available if @c wxUSE_DIRPICKERCTRL is set to 1 (the default).
  158. @beginStyleTable
  159. @style{wxDIRP_DEFAULT_STYLE}
  160. The default style: includes wxDIRP_DIR_MUST_EXIST and, under wxMSW
  161. only, wxDIRP_USE_TEXTCTRL.
  162. @style{wxDIRP_USE_TEXTCTRL}
  163. Creates a text control to the left of the picker button which is
  164. completely managed by the wxDirPickerCtrl and which can be used by
  165. the user to specify a path (see SetPath). The text control is
  166. automatically synchronized with button's value. Use functions
  167. defined in wxPickerBase to modify the text control.
  168. @style{wxDIRP_DIR_MUST_EXIST}
  169. Creates a picker which allows to select only existing directories.
  170. wxGTK control always adds this flag internally as it does not
  171. support its absence.
  172. @style{wxDIRP_CHANGE_DIR}
  173. Change current working directory on each user directory selection change.
  174. @style{wxDIRP_SMALL}
  175. Use smaller version of the control with a small "..." button instead
  176. of the normal "Browse" one. This flag is new since wxWidgets 2.9.3.
  177. @endStyleTable
  178. @beginEventEmissionTable{wxFileDirPickerEvent}
  179. @event{EVT_DIRPICKER_CHANGED(id, func)}
  180. The user changed the directory selected in the control either using the
  181. button or using text control (see wxDIRP_USE_TEXTCTRL; note that in this
  182. case the event is fired only if the user's input is valid, e.g. an
  183. existing directory path).
  184. @endEventTable
  185. @library{wxcore}
  186. @category{pickers}
  187. @appearance{dirpickerctrl}
  188. @see wxDirDialog, wxFileDirPickerEvent
  189. */
  190. class wxDirPickerCtrl : public wxPickerBase
  191. {
  192. public:
  193. wxDirPickerCtrl();
  194. /**
  195. Initializes the object and calls Create() with
  196. all the parameters.
  197. */
  198. wxDirPickerCtrl(wxWindow* parent, wxWindowID id,
  199. const wxString& path = wxEmptyString,
  200. const wxString& message = wxDirSelectorPromptStr,
  201. const wxPoint& pos = wxDefaultPosition,
  202. const wxSize& size = wxDefaultSize,
  203. long style = wxDIRP_DEFAULT_STYLE,
  204. const wxValidator& validator = wxDefaultValidator,
  205. const wxString& name = wxDirPickerCtrlNameStr);
  206. /**
  207. Creates the widgets with the given parameters.
  208. @param parent
  209. Parent window, must not be non-@NULL.
  210. @param id
  211. The identifier for the control.
  212. @param path
  213. The initial directory shown in the control. Must be a valid path to a
  214. directory or the empty string.
  215. @param message
  216. The message shown to the user in the wxDirDialog shown by the control.
  217. @param pos
  218. Initial position.
  219. @param size
  220. Initial size.
  221. @param style
  222. The window style, see wxDIRP_* flags.
  223. @param validator
  224. Validator which can be used for additional date checks.
  225. @param name
  226. Control name.
  227. @return @true if the control was successfully created or @false if
  228. creation failed.
  229. */
  230. bool Create(wxWindow* parent, wxWindowID id,
  231. const wxString& path = wxEmptyString,
  232. const wxString& message = wxDirSelectorPromptStr,
  233. const wxPoint& pos = wxDefaultPosition,
  234. const wxSize& size = wxDefaultSize,
  235. long style = wxDIRP_DEFAULT_STYLE,
  236. const wxValidator& validator = wxDefaultValidator,
  237. const wxString& name = wxDirPickerCtrlNameStr);
  238. /**
  239. Returns the absolute path of the currently selected directory as a
  240. wxFileName object.
  241. This function is equivalent to GetPath().
  242. */
  243. wxFileName GetDirName() const;
  244. /**
  245. Returns the absolute path of the currently selected directory.
  246. */
  247. wxString GetPath() const;
  248. /**
  249. Just like SetPath() but this function takes a wxFileName object.
  250. */
  251. void SetDirName(const wxFileName& dirname);
  252. /**
  253. Set the directory to show when starting to browse for directories.
  254. This function is mostly useful for the directory picker controls which
  255. have no selection initially to configure the directory that should be
  256. shown if the user starts browsing for directories as otherwise the
  257. initially selected directory is used, which is usually the desired
  258. behaviour and so the directory specified by this function is ignored in
  259. this case.
  260. @since 2.9.4
  261. */
  262. void SetInitialDirectory(const wxString& dir);
  263. /**
  264. Sets the absolute path of the currently selected directory (the default converter uses current locale's
  265. charset).
  266. This must be a valid directory if @c wxDIRP_DIR_MUST_EXIST style was given.
  267. */
  268. void SetPath(const wxString& dirname);
  269. };
  270. /**
  271. @class wxFileDirPickerEvent
  272. This event class is used for the events generated by
  273. wxFilePickerCtrl and by wxDirPickerCtrl.
  274. @beginEventTable{wxFileDirPickerEvent}
  275. @event{EVT_FILEPICKER_CHANGED(id, func)}
  276. Generated whenever the selected file changes.
  277. @event{EVT_DIRPICKER_CHANGED(id, func)}
  278. Generated whenever the selected directory changes.
  279. @endEventTable
  280. @library{wxcore}
  281. @category{events}
  282. @see wxFilePickerCtrl, wxDirPickerCtrl
  283. */
  284. class wxFileDirPickerEvent : public wxCommandEvent
  285. {
  286. public:
  287. wxFileDirPickerEvent();
  288. /**
  289. The constructor is not normally used by the user code.
  290. */
  291. wxFileDirPickerEvent(wxEventType type, wxObject* generator,
  292. int id,
  293. const wxString& path);
  294. /**
  295. Retrieve the absolute path of the file/directory the user has just selected.
  296. */
  297. wxString GetPath() const;
  298. /**
  299. Set the absolute path of the file/directory associated with the event.
  300. */
  301. void SetPath(const wxString& path);
  302. };