- Added wxToolBar::GetToolByPos().
- Added wxProgressDialog::Was{Cancelled,Skipped}() (Julien Weinzorn).
- Added wxTreeCtrl::{Clear,Set}FocusedItem() (Nikolay Tiushkov).
+- Added "filter changed" event to wxFileCtrl (Bill Jones).
GTK:
virtual void ShowHidden(bool show) = 0;
};
+void GenerateFilterChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd );
void GenerateFolderChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd );
void GenerateSelectionChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd );
void GenerateFileActivatedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd, const wxString filename = wxEmptyString );
#endif
// Some documentation
+// On wxEVT_FILECTRL_FILTERCHANGED, only the value returned by GetFilterIndex is
+// valid and it represents the (new) current filter index for the wxFileCtrl.
// On wxEVT_FILECTRL_FOLDERCHANGED, only the value returned by GetDirectory is
// valid and it represents the (new) current directory for the wxFileCtrl.
// On wxEVT_FILECTRL_FILEACTIVATED, GetDirectory returns the current directory
void SetFiles( const wxArrayString &files ) { m_files = files; }
void SetDirectory( const wxString &directory ) { m_directory = directory; }
+ void SetFilterIndex( int filterIndex ) { m_filterIndex = filterIndex; }
wxArrayString GetFiles() const { return m_files; }
wxString GetDirectory() const { return m_directory; }
+ int GetFilterIndex() const { return m_filterIndex; }
wxString GetFile() const;
protected:
+ int m_filterIndex;
wxString m_directory;
wxArrayString m_files;
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILECTRL_SELECTIONCHANGED, wxFileCtrlEvent );
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILECTRL_FILEACTIVATED, wxFileCtrlEvent );
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILECTRL_FOLDERCHANGED, wxFileCtrlEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILECTRL_FILTERCHANGED, wxFileCtrlEvent );
#define wxFileCtrlEventHandler(func) \
wxEVENT_HANDLER_CAST( wxFileCtrlEventFunction, func )
#define EVT_FILECTRL_FOLDERCHANGED(id, fn) \
wx__DECLARE_EVT1(wxEVT_FILECTRL_FOLDERCHANGED, id, wxFileCtrlEventHandler(fn))
+#define EVT_FILECTRL_FILTERCHANGED(id, fn) \
+ wx__DECLARE_EVT1(wxEVT_FILECTRL_FILTERCHANGED, id, wxFileCtrlEventHandler(fn))
+
#endif // wxUSE_FILECTRL
#endif // _WX_FILECTRL_H_BASE_
class WXDLLIMPEXP_CORE wxGtkFileChooser
{
public:
- wxGtkFileChooser() {}
+ wxGtkFileChooser() { m_ignoreNextFilterEvent = false; }
void SetWidget(GtkFileChooser *w);
void SetWildcard( const wxString& wildCard );
void SetFilterIndex( int filterIndex );
+ bool HasFilterChoice() const;
+
+ bool ShouldIgnoreNextFilterEvent() const { return m_ignoreNextFilterEvent; }
+
wxString GetCurrentWildCard() const
{ return m_wildcards[GetFilterIndex()]; }
// First wildcard in filter, to be used when the user
// saves a file without giving an extension.
wxArrayString m_wildcards;
+
+ // If true, ignore the next event because it was generated by us and not
+ // the user.
+ bool m_ignoreNextFilterEvent;
};
#if wxUSE_FILECTRL
virtual bool HasMultipleFileSelection() const { return HasFlag( wxFC_MULTIPLE ); }
virtual void ShowHidden(bool show);
+ virtual bool HasFilterChoice() const
+ { return m_fc.HasFilterChoice(); }
+
+
+ // Implementation only from now on.
+ bool GTKShouldIgnoreNextFilterEvent() const
+ { return m_fc.ShouldIgnoreNextFilterEvent(); }
+
bool m_checkNextSelEvent;
bool m_ignoreNextFolderChangeEvent;
The user changed the current selection(by selecting or deselecting a file)
@event{EVT_FILECTRL_FOLDERCHANGED(id, func)}
The current folder of the file control has been changed
+ @event{EVT_FILECTRL_FILTERCHANGED(id, func)}
+ The current file filter of the file control has been changed.
+ @since 2.9.1
@endEventTable
@library{wxbase}
The user changed the current selection(by selecting or deselecting a file)
@event{EVT_FILECTRL_FOLDERCHANGED(id, func)}
The current folder of the file control has been changed
+ @event{EVT_FILECTRL_FILTERCHANGED(id, func)}
+ The current file filter of the file control has been changed
@endEventTable
@library{wxbase}
*/
wxArrayString GetFiles() const;
+ /**
+ Returns the current file filter index.
+
+ For a @b EVT_FILECTRL_FILTERCHANGED event, this method returns the new
+ file filter index.
+
+ @since 2.9.1
+ */
+ int GetFilterIndex() const;
+
/**
Sets the files changed by this event.
*/
Sets the directory of this event.
*/
void SetDirectory( const wxString &directory );
+
+ /**
+ Sets the filter index changed by this event.
+
+ @since 2.9.1
+ */
+ void SetFilterIndex(int index);
};
EVT_CHECKBOX( wxID_ANY, FileCtrlWidgetsPage::OnCheckBox )
EVT_RADIOBOX( wxID_ANY, FileCtrlWidgetsPage::OnRadioBox )
+ EVT_FILECTRL_FILTERCHANGED( wxID_ANY, FileCtrlWidgetsPage::OnFileCtrl )
EVT_FILECTRL_FOLDERCHANGED( wxID_ANY, FileCtrlWidgetsPage::OnFileCtrl )
EVT_FILECTRL_SELECTIONCHANGED( wxID_ANY, FileCtrlWidgetsPage::OnFileCtrl )
EVT_FILECTRL_FILEACTIVATED( wxID_ANY, FileCtrlWidgetsPage::OnFileCtrl )
{
wxLogMessage("Selection changed event: %s", wxJoin(event.GetFiles(), ' '));
}
+ else if ( event.GetEventType() == wxEVT_FILECTRL_FILTERCHANGED )
+ {
+ wxLogMessage("Filter changed event: filter %d selected",
+ event.GetFilterIndex() + 1);
+ }
}
#endif // wxUSE_FILECTRL
wxDEFINE_EVENT( wxEVT_FILECTRL_SELECTIONCHANGED, wxFileCtrlEvent );
wxDEFINE_EVENT( wxEVT_FILECTRL_FILEACTIVATED, wxFileCtrlEvent );
wxDEFINE_EVENT( wxEVT_FILECTRL_FOLDERCHANGED, wxFileCtrlEvent );
+wxDEFINE_EVENT( wxEVT_FILECTRL_FILTERCHANGED, wxFileCtrlEvent );
IMPLEMENT_DYNAMIC_CLASS( wxFileCtrlEvent, wxCommandEvent )
// some helper functions
+void GenerateFilterChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd )
+{
+ wxFileCtrlEvent event( wxEVT_FILECTRL_FILTERCHANGED, wnd, wnd->GetId() );
+
+ event.SetFilterIndex( fileCtrl->GetFilterIndex() );
+
+ wnd->GetEventHandler()->ProcessEvent( event );
+}
+
void GenerateFolderChangedEvent( wxFileCtrlBase *fileCtrl, wxWindow *wnd )
{
wxFileCtrlEvent event( wxEVT_FILECTRL_FOLDERCHANGED, wnd, wnd->GetId() );
{
m_filterExtension.clear();
}
+
+ GenerateFilterChangedEvent( this, this );
}
void wxGenericFileCtrl::SetWildcard( const wxString& wildCard )
#include "wx/gtk/private.h"
#include "wx/filedlg.h"
#include "wx/filename.h"
+#include "wx/scopeguard.h"
#include "wx/tokenzr.h"
//-----------------------------------------------------------------------------
GSList* ifilters = gtk_file_chooser_list_filters( chooser );
GSList* filters = ifilters;
+ m_ignoreNextFilterEvent = true;
+ wxON_BLOCK_EXIT_SET(m_ignoreNextFilterEvent, false);
+
while ( ifilters )
{
gtk_file_chooser_remove_filter( chooser, GTK_FILE_FILTER( ifilters->data ) );
return index;
}
+bool wxGtkFileChooser::HasFilterChoice() const
+{
+ return gtk_file_chooser_get_filter( m_widget ) != NULL;
+}
+
//-----------------------------------------------------------------------------
// end wxGtkFileChooser Implementation
//-----------------------------------------------------------------------------
}
}
+extern "C"
+{
+ static void
+ gtkfilechooserwidget_notify_callback( GObject *WXUNUSED( gobject ), GParamSpec *arg1, wxGtkFileCtrl *fileCtrl )
+ {
+ const char *name = g_param_spec_get_name (arg1);
+ if ( strcmp( name, "filter" ) == 0 &&
+ fileCtrl->HasFilterChoice() &&
+ !fileCtrl->GTKShouldIgnoreNextFilterEvent() )
+ {
+ GenerateFilterChangedEvent( fileCtrl, fileCtrl );
+ }
+ }
+}
+
// wxGtkFileCtrl implementation
IMPLEMENT_DYNAMIC_CLASS( wxGtkFileCtrl, wxControl )
G_CALLBACK ( gtkfilechooserwidget_selection_changed_callback ),
this );
+ g_signal_connect ( m_fcWidget, "notify",
+ G_CALLBACK ( gtkfilechooserwidget_notify_callback ),
+ this );
+
m_fc.SetWidget( m_fcWidget );
if ( style & wxFC_MULTIPLE )