filectrlg.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/filectrlg.h
  3. // Purpose: wxGenericFileCtrl Header
  4. // Author: Diaa M. Sami
  5. // Modified by:
  6. // Created: Jul-07-2007
  7. // Copyright: (c) Diaa M. Sami
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_GENERIC_FILECTRL_H_
  11. #define _WX_GENERIC_FILECTRL_H_
  12. #if wxUSE_FILECTRL
  13. #include "wx/containr.h"
  14. #include "wx/listctrl.h"
  15. #include "wx/filectrl.h"
  16. #include "wx/filename.h"
  17. class WXDLLIMPEXP_FWD_CORE wxCheckBox;
  18. class WXDLLIMPEXP_FWD_CORE wxChoice;
  19. class WXDLLIMPEXP_FWD_CORE wxStaticText;
  20. class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
  21. extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorDefaultWildcardStr[];
  22. //-----------------------------------------------------------------------------
  23. // wxFileData - a class to hold the file info for the wxFileListCtrl
  24. //-----------------------------------------------------------------------------
  25. class WXDLLIMPEXP_CORE wxFileData
  26. {
  27. public:
  28. enum fileType
  29. {
  30. is_file = 0x0000,
  31. is_dir = 0x0001,
  32. is_link = 0x0002,
  33. is_exe = 0x0004,
  34. is_drive = 0x0008
  35. };
  36. wxFileData() { Init(); }
  37. // Full copy constructor
  38. wxFileData( const wxFileData& fileData ) { Copy(fileData); }
  39. // Create a filedata from this information
  40. wxFileData( const wxString &filePath, const wxString &fileName,
  41. fileType type, int image_id );
  42. // make a full copy of the other wxFileData
  43. void Copy( const wxFileData &other );
  44. // (re)read the extra data about the file from the system
  45. void ReadData();
  46. // get the name of the file, dir, drive
  47. wxString GetFileName() const { return m_fileName; }
  48. // get the full path + name of the file, dir, path
  49. wxString GetFilePath() const { return m_filePath; }
  50. // Set the path + name and name of the item
  51. void SetNewName( const wxString &filePath, const wxString &fileName );
  52. // Get the size of the file in bytes
  53. wxFileOffset GetSize() const { return m_size; }
  54. // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE>
  55. wxString GetFileType() const;
  56. // get the last modification time
  57. wxDateTime GetDateTime() const { return m_dateTime; }
  58. // Get the time as a formatted string
  59. wxString GetModificationTime() const;
  60. // in UNIX get rwx for file, in MSW get attributes ARHS
  61. wxString GetPermissions() const { return m_permissions; }
  62. // Get the id of the image used in a wxImageList
  63. int GetImageId() const { return m_image; }
  64. bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); }
  65. bool IsDir() const { return (m_type & is_dir ) != 0; }
  66. bool IsLink() const { return (m_type & is_link ) != 0; }
  67. bool IsExe() const { return (m_type & is_exe ) != 0; }
  68. bool IsDrive() const { return (m_type & is_drive) != 0; }
  69. // Get/Set the type of file, file/dir/drive/link
  70. int GetType() const { return m_type; }
  71. // the wxFileListCtrl fields in report view
  72. enum fileListFieldType
  73. {
  74. FileList_Name,
  75. FileList_Size,
  76. FileList_Type,
  77. FileList_Time,
  78. #if defined(__UNIX__) || defined(__WIN32__)
  79. FileList_Perm,
  80. #endif // defined(__UNIX__) || defined(__WIN32__)
  81. FileList_Max
  82. };
  83. // Get the entry for report view of wxFileListCtrl
  84. wxString GetEntry( fileListFieldType num ) const;
  85. // Get a string representation of the file info
  86. wxString GetHint() const;
  87. // initialize a wxListItem attributes
  88. void MakeItem( wxListItem &item );
  89. // operators
  90. wxFileData& operator = (const wxFileData& fd) { Copy(fd); return *this; }
  91. protected:
  92. wxString m_fileName;
  93. wxString m_filePath;
  94. wxFileOffset m_size;
  95. wxDateTime m_dateTime;
  96. wxString m_permissions;
  97. int m_type;
  98. int m_image;
  99. private:
  100. void Init();
  101. };
  102. //-----------------------------------------------------------------------------
  103. // wxFileListCtrl
  104. //-----------------------------------------------------------------------------
  105. class WXDLLIMPEXP_CORE wxFileListCtrl : public wxListCtrl
  106. {
  107. public:
  108. wxFileListCtrl();
  109. wxFileListCtrl( wxWindow *win,
  110. wxWindowID id,
  111. const wxString &wild,
  112. bool showHidden,
  113. const wxPoint &pos = wxDefaultPosition,
  114. const wxSize &size = wxDefaultSize,
  115. long style = wxLC_LIST,
  116. const wxValidator &validator = wxDefaultValidator,
  117. const wxString &name = wxT("filelist") );
  118. virtual ~wxFileListCtrl();
  119. virtual void ChangeToListMode();
  120. virtual void ChangeToReportMode();
  121. virtual void ChangeToSmallIconMode();
  122. virtual void ShowHidden( bool show = true );
  123. bool GetShowHidden() const { return m_showHidden; }
  124. virtual long Add( wxFileData *fd, wxListItem &item );
  125. virtual void UpdateItem(const wxListItem &item);
  126. virtual void UpdateFiles();
  127. virtual void MakeDir();
  128. virtual void GoToParentDir();
  129. virtual void GoToHomeDir();
  130. virtual void GoToDir( const wxString &dir );
  131. virtual void SetWild( const wxString &wild );
  132. wxString GetWild() const { return m_wild; }
  133. wxString GetDir() const { return m_dirName; }
  134. void OnListDeleteItem( wxListEvent &event );
  135. void OnListDeleteAllItems( wxListEvent &event );
  136. void OnListEndLabelEdit( wxListEvent &event );
  137. void OnListColClick( wxListEvent &event );
  138. virtual void SortItems(wxFileData::fileListFieldType field, bool forward);
  139. bool GetSortDirection() const { return m_sort_forward; }
  140. wxFileData::fileListFieldType GetSortField() const { return m_sort_field; }
  141. protected:
  142. void FreeItemData(wxListItem& item);
  143. void FreeAllItemsData();
  144. wxString m_dirName;
  145. bool m_showHidden;
  146. wxString m_wild;
  147. bool m_sort_forward;
  148. wxFileData::fileListFieldType m_sort_field;
  149. private:
  150. DECLARE_DYNAMIC_CLASS(wxFileListCtrl)
  151. DECLARE_EVENT_TABLE()
  152. };
  153. class WXDLLIMPEXP_CORE wxGenericFileCtrl : public wxNavigationEnabled<wxControl>,
  154. public wxFileCtrlBase
  155. {
  156. public:
  157. wxGenericFileCtrl()
  158. {
  159. m_ignoreChanges = false;
  160. }
  161. wxGenericFileCtrl ( wxWindow *parent,
  162. wxWindowID id,
  163. const wxString& defaultDirectory = wxEmptyString,
  164. const wxString& defaultFilename = wxEmptyString,
  165. const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
  166. long style = wxFC_DEFAULT_STYLE,
  167. const wxPoint& pos = wxDefaultPosition,
  168. const wxSize& size = wxDefaultSize,
  169. const wxString& name = wxFileCtrlNameStr )
  170. {
  171. m_ignoreChanges = false;
  172. Create(parent, id, defaultDirectory, defaultFilename, wildCard,
  173. style, pos, size, name );
  174. }
  175. virtual ~wxGenericFileCtrl() {}
  176. bool Create( wxWindow *parent,
  177. wxWindowID id,
  178. const wxString& defaultDirectory = wxEmptyString,
  179. const wxString& defaultFileName = wxEmptyString,
  180. const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
  181. long style = wxFC_DEFAULT_STYLE,
  182. const wxPoint& pos = wxDefaultPosition,
  183. const wxSize& size = wxDefaultSize,
  184. const wxString& name = wxFileCtrlNameStr );
  185. virtual void SetWildcard( const wxString& wildCard );
  186. virtual void SetFilterIndex( int filterindex );
  187. virtual bool SetDirectory( const wxString& dir );
  188. // Selects a certain file.
  189. // In case the filename specified isn't found/couldn't be shown with
  190. // currently selected filter, false is returned and nothing happens
  191. virtual bool SetFilename( const wxString& name );
  192. // Changes to a certain directory and selects a certain file.
  193. // In case the filename specified isn't found/couldn't be shown with
  194. // currently selected filter, false is returned and if directory exists
  195. // it's chdir'ed to
  196. virtual bool SetPath( const wxString& path );
  197. virtual wxString GetFilename() const;
  198. virtual wxString GetDirectory() const;
  199. virtual wxString GetWildcard() const { return this->m_wildCard; }
  200. virtual wxString GetPath() const;
  201. virtual void GetPaths( wxArrayString& paths ) const;
  202. virtual void GetFilenames( wxArrayString& files ) const;
  203. virtual int GetFilterIndex() const { return m_filterIndex; }
  204. virtual bool HasMultipleFileSelection() const
  205. { return HasFlag(wxFC_MULTIPLE); }
  206. virtual void ShowHidden(bool show) { m_list->ShowHidden( show ); }
  207. void GoToParentDir();
  208. void GoToHomeDir();
  209. // get the directory currently shown in the control: this can be different
  210. // from GetDirectory() if the user entered a full path (with a path other
  211. // than the one currently shown in the control) in the text control
  212. // manually
  213. wxString GetShownDirectory() const { return m_list->GetDir(); }
  214. wxFileListCtrl *GetFileList() { return m_list; }
  215. void ChangeToReportMode() { m_list->ChangeToReportMode(); }
  216. void ChangeToListMode() { m_list->ChangeToListMode(); }
  217. private:
  218. void OnChoiceFilter( wxCommandEvent &event );
  219. void OnCheck( wxCommandEvent &event );
  220. void OnActivated( wxListEvent &event );
  221. void OnTextEnter( wxCommandEvent &WXUNUSED( event ) );
  222. void OnTextChange( wxCommandEvent &WXUNUSED( event ) );
  223. void OnSelected( wxListEvent &event );
  224. void HandleAction( const wxString &fn );
  225. void DoSetFilterIndex( int filterindex );
  226. void UpdateControls();
  227. // the first of these methods can only be used for the controls with single
  228. // selection (i.e. without wxFC_MULTIPLE style), the second one in any case
  229. wxFileName DoGetFileName() const;
  230. void DoGetFilenames( wxArrayString& filenames, bool fullPath ) const;
  231. int m_style;
  232. wxString m_filterExtension;
  233. wxChoice *m_choice;
  234. wxTextCtrl *m_text;
  235. wxFileListCtrl *m_list;
  236. wxCheckBox *m_check;
  237. wxStaticText *m_static;
  238. wxString m_dir;
  239. wxString m_fileName;
  240. wxString m_wildCard; // wild card in one string as we got it
  241. int m_filterIndex;
  242. bool m_inSelected;
  243. bool m_ignoreChanges;
  244. bool m_noSelChgEvent; // suppress selection changed events.
  245. DECLARE_DYNAMIC_CLASS( wxGenericFileCtrl )
  246. DECLARE_EVENT_TABLE()
  247. };
  248. #endif // wxUSE_FILECTRL
  249. #endif // _WX_GENERIC_FILECTRL_H_