]> git.saurik.com Git - wxWidgets.git/commitdiff
Invoke default action if dclick event after <ENTER> not handled in wxListBox, added...
authorRobert Roebling <robert@roebling.de>
Sat, 12 Jan 2008 14:59:17 +0000 (14:59 +0000)
committerRobert Roebling <robert@roebling.de>
Sat, 12 Jan 2008 14:59:17 +0000 (14:59 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51176 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/dialogs/dialogs.cpp
samples/dialogs/dialogs.h
src/gtk/listbox.cpp

index ffd6d9d424d1e81de60ada688c9e264bfaa15f92..19858fb8193dc6eca2bee84eae4d656b24809f69 100644 (file)
@@ -223,6 +223,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
 #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
@@ -439,6 +440,7 @@ bool MyApp::OnInit()
     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"));
@@ -1222,6 +1224,66 @@ void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent& WXUNUSED(event))
     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);
index 659e9c4e79bee6a942fa7e6cafd9fff896e6b4c2..b59b323ce2fd0417c4cfdea66fb6c2e2b4a478d3 100644 (file)
@@ -169,6 +169,22 @@ private:
     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
@@ -314,6 +330,9 @@ public:
 #endif // wxUSE_NOTIFICATION_MESSAGE
 
     void OnStandardButtonsSizerDialog(wxCommandEvent& event);
+    
+    void OnTestDefaultActionDialog(wxCommandEvent& event);
+    
     void OnExit(wxCommandEvent& event);
 
 private:
@@ -402,7 +421,8 @@ enum
     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
index 73edbd78f8a0652659c679730ce31a2ece601762..f1e5f96b1ebd071bcb212f15853b40014b6d6705 100644 (file)
@@ -33,6 +33,7 @@
 #endif
 
 #include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
 
 //-----------------------------------------------------------------------------
 // data
@@ -185,6 +186,67 @@ gtk_listitem_changed_callback(GtkTreeSelection * WXUNUSED(selection),
 }
 }
 
+//-----------------------------------------------------------------------------
+// "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)
 //-----------------------------------------------------------------------------
@@ -424,6 +486,10 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
     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);