filectrl.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk/filectrl.h
  3. // Purpose: wxGtkFileCtrl Header
  4. // Author: Diaa M. Sami
  5. // Modified by:
  6. // Created: Aug-10-2007
  7. // Copyright: (c) Diaa M. Sami
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_GTK_FILECTRL_H_
  11. #define _WX_GTK_FILECTRL_H_
  12. #include "wx/control.h"
  13. #include "wx/filectrl.h"
  14. extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorDefaultWildcardStr[];
  15. typedef struct _GtkFileChooser GtkFileChooser;
  16. // [GTK] current problems:
  17. // All methods(e.g. SetFilename(), SetPath(), etc) which change the state of
  18. // the control result in events fired, such events should be suppressed.
  19. // ------
  20. // Sometimes a selection event(with 0 files) is fired before
  21. // wxEVT_FILECTRL_FOLDERCHANGED, unfortunately this can hardly be detected!
  22. // A wx wrapper for any Gtk object implementing the interface GtkFileChooser
  23. class WXDLLIMPEXP_CORE wxGtkFileChooser
  24. {
  25. public:
  26. wxGtkFileChooser() { m_ignoreNextFilterEvent = false; }
  27. void SetWidget(GtkFileChooser *w);
  28. wxString GetPath() const;
  29. void GetPaths( wxArrayString& paths ) const;
  30. wxString GetDirectory() const;
  31. wxString GetFilename() const;
  32. void GetFilenames( wxArrayString& files ) const;
  33. int GetFilterIndex() const;
  34. bool SetPath( const wxString& path );
  35. bool SetDirectory( const wxString& dir );
  36. void SetWildcard( const wxString& wildCard );
  37. void SetFilterIndex( int filterIndex );
  38. bool HasFilterChoice() const;
  39. bool ShouldIgnoreNextFilterEvent() const { return m_ignoreNextFilterEvent; }
  40. wxString GetCurrentWildCard() const
  41. { return m_wildcards[GetFilterIndex()]; }
  42. private:
  43. GtkFileChooser *m_widget;
  44. // First wildcard in filter, to be used when the user
  45. // saves a file without giving an extension.
  46. wxArrayString m_wildcards;
  47. // If true, ignore the next event because it was generated by us and not
  48. // the user.
  49. bool m_ignoreNextFilterEvent;
  50. };
  51. #if wxUSE_FILECTRL
  52. class WXDLLIMPEXP_CORE wxGtkFileCtrl: public wxControl,
  53. public wxFileCtrlBase
  54. {
  55. public:
  56. wxGtkFileCtrl () { Init(); }
  57. wxGtkFileCtrl ( wxWindow *parent,
  58. wxWindowID id,
  59. const wxString& defaultDirectory = wxEmptyString,
  60. const wxString& defaultFilename = wxEmptyString,
  61. const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
  62. long style = wxFC_DEFAULT_STYLE,
  63. const wxPoint& pos = wxDefaultPosition,
  64. const wxSize& size = wxDefaultSize,
  65. const wxString& name = wxFileCtrlNameStr )
  66. {
  67. Init();
  68. Create( parent, id, defaultDirectory, defaultFilename, wildCard, style, pos, size, name );
  69. }
  70. virtual ~wxGtkFileCtrl();
  71. bool Create( wxWindow *parent,
  72. wxWindowID id,
  73. const wxString& defaultDirectory = wxEmptyString,
  74. const wxString& defaultFileName = wxEmptyString,
  75. const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
  76. long style = wxFC_DEFAULT_STYLE,
  77. const wxPoint& pos = wxDefaultPosition,
  78. const wxSize& size = wxDefaultSize,
  79. const wxString& name = wxFileCtrlNameStr );
  80. virtual void SetWildcard( const wxString& wildCard );
  81. virtual void SetFilterIndex( int filterIndex );
  82. virtual bool SetDirectory( const wxString& dir );
  83. virtual bool SetFilename( const wxString& name );
  84. virtual bool SetPath( const wxString& path );
  85. virtual wxString GetFilename() const;
  86. virtual wxString GetDirectory() const;
  87. virtual wxString GetWildcard() const { return this->m_wildCard; }
  88. virtual wxString GetPath() const;
  89. virtual void GetPaths( wxArrayString& paths ) const;
  90. virtual void GetFilenames( wxArrayString& files ) const;
  91. virtual int GetFilterIndex() const { return m_fc.GetFilterIndex(); }
  92. virtual bool HasMultipleFileSelection() const { return HasFlag( wxFC_MULTIPLE ); }
  93. virtual void ShowHidden(bool show);
  94. virtual bool HasFilterChoice() const
  95. { return m_fc.HasFilterChoice(); }
  96. // Implementation only from now on.
  97. bool GTKShouldIgnoreNextFilterEvent() const
  98. { return m_fc.ShouldIgnoreNextFilterEvent(); }
  99. bool m_checkNextSelEvent;
  100. bool m_ignoreNextFolderChangeEvent;
  101. protected:
  102. GtkFileChooser *m_fcWidget;
  103. wxGtkFileChooser m_fc;
  104. wxString m_wildCard;
  105. private:
  106. void Init();
  107. DECLARE_DYNAMIC_CLASS( wxGtkFileCtrl )
  108. };
  109. #endif // wxUSE_FILECTRL
  110. #endif // _WX_GTK_FILECTRL_H_