filectrl.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/filectrl.h
  3. // Purpose: Header for wxFileCtrlBase and other common functions used by
  4. // platform-specific wxFileCtrl's
  5. // Author: Diaa M. Sami
  6. // Modified by:
  7. // Created: Jul-07-2007
  8. // Copyright: (c) Diaa M. Sami
  9. // Licence: wxWindows licence
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #ifndef _WX_FILECTRL_H_BASE_
  12. #define _WX_FILECTRL_H_BASE_
  13. #include "wx/defs.h"
  14. #if wxUSE_FILECTRL
  15. #include "wx/string.h"
  16. #include "wx/event.h"
  17. enum
  18. {
  19. wxFC_OPEN = 0x0001,
  20. wxFC_SAVE = 0x0002,
  21. wxFC_MULTIPLE = 0x0004,
  22. wxFC_NOSHOWHIDDEN = 0x0008
  23. };
  24. #define wxFC_DEFAULT_STYLE wxFC_OPEN
  25. extern WXDLLIMPEXP_DATA_CORE(const char) wxFileCtrlNameStr[]; // in filectrlcmn.cpp
  26. class WXDLLIMPEXP_CORE wxFileCtrlBase
  27. {
  28. public:
  29. virtual ~wxFileCtrlBase() {}
  30. virtual void SetWildcard( const wxString& wildCard ) = 0;
  31. virtual void SetFilterIndex( int filterindex ) = 0;
  32. virtual bool SetDirectory( const wxString& dir ) = 0;
  33. // Selects a certain file.
  34. // In case the filename specified isn't found/couldn't be shown with
  35. // currently selected filter, false is returned and nothing happens
  36. virtual bool SetFilename( const wxString& name ) = 0;
  37. // chdirs to a certain directory and selects a certain file.
  38. // In case the filename specified isn't found/couldn't be shown with
  39. // currently selected filter, false is returned and if directory exists
  40. // it's chdir'ed to
  41. virtual bool SetPath( const wxString& path ) = 0;
  42. virtual wxString GetFilename() const = 0;
  43. virtual wxString GetDirectory() const = 0;
  44. virtual wxString GetWildcard() const = 0;
  45. virtual wxString GetPath() const = 0;
  46. virtual void GetPaths( wxArrayString& paths ) const = 0;
  47. virtual void GetFilenames( wxArrayString& files ) const = 0;
  48. virtual int GetFilterIndex() const = 0;
  49. virtual bool HasMultipleFileSelection() const = 0;
  50. virtual void ShowHidden(bool show) = 0;
  51. };
  52. void GenerateFilterChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd );
  53. void GenerateFolderChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd );
  54. void GenerateSelectionChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd );
  55. void GenerateFileActivatedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd, const wxString filename = wxEmptyString );
  56. #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
  57. #define wxFileCtrl wxGtkFileCtrl
  58. #include "wx/gtk/filectrl.h"
  59. #else
  60. #define wxFileCtrl wxGenericFileCtrl
  61. #include "wx/generic/filectrlg.h"
  62. #endif
  63. // Some documentation
  64. // On wxEVT_FILECTRL_FILTERCHANGED, only the value returned by GetFilterIndex is
  65. // valid and it represents the (new) current filter index for the wxFileCtrl.
  66. // On wxEVT_FILECTRL_FOLDERCHANGED, only the value returned by GetDirectory is
  67. // valid and it represents the (new) current directory for the wxFileCtrl.
  68. // On wxEVT_FILECTRL_FILEACTIVATED, GetDirectory returns the current directory
  69. // for the wxFileCtrl and GetFiles returns the names of the file(s) activated.
  70. // On wxEVT_FILECTRL_SELECTIONCHANGED, GetDirectory returns the current directory
  71. // for the wxFileCtrl and GetFiles returns the names of the currently selected
  72. // file(s).
  73. // In wxGTK, after each wxEVT_FILECTRL_FOLDERCHANGED, wxEVT_FILECTRL_SELECTIONCHANGED
  74. // is fired automatically once or more with 0 files.
  75. class WXDLLIMPEXP_CORE wxFileCtrlEvent : public wxCommandEvent
  76. {
  77. public:
  78. wxFileCtrlEvent() {}
  79. wxFileCtrlEvent( wxEventType type, wxObject *evtObject, int id )
  80. : wxCommandEvent( type, id )
  81. {
  82. SetEventObject( evtObject );
  83. }
  84. // no need for the copy constructor as the default one will be fine.
  85. virtual wxEvent *Clone() const { return new wxFileCtrlEvent( *this ); }
  86. void SetFiles( const wxArrayString &files ) { m_files = files; }
  87. void SetDirectory( const wxString &directory ) { m_directory = directory; }
  88. void SetFilterIndex( int filterIndex ) { m_filterIndex = filterIndex; }
  89. wxArrayString GetFiles() const { return m_files; }
  90. wxString GetDirectory() const { return m_directory; }
  91. int GetFilterIndex() const { return m_filterIndex; }
  92. wxString GetFile() const;
  93. protected:
  94. int m_filterIndex;
  95. wxString m_directory;
  96. wxArrayString m_files;
  97. DECLARE_DYNAMIC_CLASS_NO_ASSIGN( wxFileCtrlEvent )
  98. };
  99. typedef void ( wxEvtHandler::*wxFileCtrlEventFunction )( wxFileCtrlEvent& );
  100. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILECTRL_SELECTIONCHANGED, wxFileCtrlEvent );
  101. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILECTRL_FILEACTIVATED, wxFileCtrlEvent );
  102. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILECTRL_FOLDERCHANGED, wxFileCtrlEvent );
  103. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILECTRL_FILTERCHANGED, wxFileCtrlEvent );
  104. #define wxFileCtrlEventHandler(func) \
  105. wxEVENT_HANDLER_CAST( wxFileCtrlEventFunction, func )
  106. #define EVT_FILECTRL_FILEACTIVATED(id, fn) \
  107. wx__DECLARE_EVT1(wxEVT_FILECTRL_FILEACTIVATED, id, wxFileCtrlEventHandler(fn))
  108. #define EVT_FILECTRL_SELECTIONCHANGED(id, fn) \
  109. wx__DECLARE_EVT1(wxEVT_FILECTRL_SELECTIONCHANGED, id, wxFileCtrlEventHandler(fn))
  110. #define EVT_FILECTRL_FOLDERCHANGED(id, fn) \
  111. wx__DECLARE_EVT1(wxEVT_FILECTRL_FOLDERCHANGED, id, wxFileCtrlEventHandler(fn))
  112. #define EVT_FILECTRL_FILTERCHANGED(id, fn) \
  113. wx__DECLARE_EVT1(wxEVT_FILECTRL_FILTERCHANGED, id, wxFileCtrlEventHandler(fn))
  114. #endif // wxUSE_FILECTRL
  115. #endif // _WX_FILECTRL_H_BASE_