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