#endif // USE_SETTINGS_DIALOG
EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, MyFrame::OnStandardButtonsSizerDialog)
+ EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION, MyFrame::OnTestDefaultActionDialog)
EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention)
#if wxUSE_NOTIFICATION_MESSAGE
menuDlg->AppendSubMenu(menuNotif, "&User notifications");
menuDlg->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, _T("&Standard Buttons Sizer Dialog"));
+ menuDlg->Append(DIALOGS_TEST_DEFAULT_ACTION, _T("&Test dialog default action"));
menuDlg->AppendSeparator();
menuDlg->Append(wxID_EXIT, _T("E&xit\tAlt-X"));
dialog.ShowModal();
}
+// TestDefaultAction
+
+#define ID_CATCH_LISTBOX_DCLICK 100
+#define ID_LISTBOX 101
+
+BEGIN_EVENT_TABLE(TestDefaultActionDialog, wxDialog)
+ EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK, TestDefaultActionDialog::OnCatchListBoxDClick)
+ EVT_LISTBOX_DCLICK(ID_LISTBOX, TestDefaultActionDialog::OnListBoxDClick)
+END_EVENT_TABLE()
+
+TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) :
+ wxDialog( parent, -1, "Test default action" )
+{
+ m_catchListBoxDClick = false;
+
+ wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
+
+ wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 5, 5 );
+
+ wxListBox *listbox = new wxListBox( this, ID_LISTBOX );
+ listbox->Append( "String 1" );
+ listbox->Append( "String 2" );
+ listbox->Append( "String 3" );
+ listbox->Append( "String 4" );
+ grid_sizer->Add( listbox );
+
+ grid_sizer->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL );
+
+ grid_sizer->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL );
+ grid_sizer->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL );
+
+ grid_sizer->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition, wxSize(80,-1), wxTE_PROCESS_ENTER ), 0, wxALIGN_CENTRE_VERTICAL );
+ grid_sizer->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL );
+
+ main_sizer->Add( grid_sizer, 0, wxALL, 10 );
+
+ wxSizer *button_sizer = CreateSeparatedButtonSizer( wxOK|wxCANCEL );
+ if (button_sizer)
+ main_sizer->Add( button_sizer, 0, wxALL|wxGROW, 5 );
+
+ SetSizer( main_sizer );
+ main_sizer->SetSizeHints( this );
+}
+
+void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent& event)
+{
+ event.Skip( !m_catchListBoxDClick );
+}
+
+void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent& WXUNUSED(event))
+{
+ m_catchListBoxDClick = !m_catchListBoxDClick;
+}
+
+void MyFrame::OnTestDefaultActionDialog(wxCommandEvent& WXUNUSED(event))
+{
+ TestDefaultActionDialog dialog( this );
+ dialog.ShowModal();
+}
+
void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
{
Close(true);
DECLARE_EVENT_TABLE()
};
+class TestDefaultActionDialog: public wxDialog
+{
+public:
+ TestDefaultActionDialog( wxWindow *parent );
+
+ void OnListBoxDClick(wxCommandEvent& event);
+ void OnCatchListBoxDClick(wxCommandEvent& event);
+
+private:
+ bool m_catchListBoxDClick;
+
+private:
+ DECLARE_EVENT_TABLE()
+};
+
+
#if USE_SETTINGS_DIALOG
// Property sheet dialog
class SettingsDialog: public wxPropertySheetDialog
#endif // wxUSE_NOTIFICATION_MESSAGE
void OnStandardButtonsSizerDialog(wxCommandEvent& event);
+
+ void OnTestDefaultActionDialog(wxCommandEvent& event);
+
void OnExit(wxCommandEvent& event);
private:
DIALOGS_PROPERTY_SHEET,
DIALOGS_PROPERTY_SHEET_TOOLBOOK,
DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK,
- DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
+ DIALOGS_STANDARD_BUTTON_SIZER_DIALOG,
+ DIALOGS_TEST_DEFAULT_ACTION
};
#endif
#endif
#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
//-----------------------------------------------------------------------------
// data
}
}
+//-----------------------------------------------------------------------------
+// "key_press_event"
+//-----------------------------------------------------------------------------
+
+extern "C" {
+static gint
+gtk_listbox_key_press_callback( GtkWidget *WXUNUSED(widget),
+ GdkEventKey *gdk_event,
+ wxListBox *listbox )
+{
+ if ((gdk_event->keyval == GDK_Return) ||
+ (gdk_event->keyval == GDK_ISO_Enter) ||
+ (gdk_event->keyval == GDK_KP_Enter))
+ {
+ int index = listbox->GetSelection();
+ if (index != wxNOT_FOUND)
+ {
+ wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, listbox->GetId() );
+ event.SetEventObject( listbox );
+
+ GtkTreeEntry* entry = listbox->GtkGetEntry( index );
+
+ // indicate that this is a selection
+ event.SetExtraLong( 1 );
+
+ event.SetInt( index );
+ event.SetString(wxConvUTF8.cMB2WX(gtk_tree_entry_get_label(entry)));
+
+ if ( listbox->HasClientObjectData() )
+ event.SetClientObject(
+ (wxClientData*) gtk_tree_entry_get_userdata(entry)
+ );
+ else if ( listbox->HasClientUntypedData() )
+ event.SetClientData( gtk_tree_entry_get_userdata(entry) );
+
+ bool ret = listbox->HandleWindowEvent( event );
+
+ g_object_unref (entry);
+
+ if (!ret)
+ {
+ // DClick not handled -> invoke default action
+ wxWindow *tlw = wxGetTopLevelParent( listbox );
+ if (tlw)
+ {
+ GtkWindow *gtk_window = GTK_WINDOW( tlw->GetHandle() );
+ if (gtk_window)
+ gtk_window_activate_default( gtk_window );
+ }
+ }
+
+ // Always intercept, otherwise we'd get another dclick
+ // event from row_activated
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+}
+
//-----------------------------------------------------------------------------
// GtkTreeEntry destruction (to destroy client data)
//-----------------------------------------------------------------------------
g_signal_connect_after(m_treeview, "row-activated",
G_CALLBACK(gtk_listbox_row_activated_callback), this);
+ // for intercepting dclick generation by <ENTER>
+ g_signal_connect (m_treeview, "key_press_event",
+ G_CALLBACK (gtk_listbox_key_press_callback),
+ this);
m_parent->DoAddChild( this );
PostCreation(size);