Invoke default action if dclick event after <ENTER> not handled in wxListBox, added test to dialogs sample
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51176 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -223,6 +223,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
#endif // USE_SETTINGS_DIALOG
|
#endif // USE_SETTINGS_DIALOG
|
||||||
|
|
||||||
EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, MyFrame::OnStandardButtonsSizerDialog)
|
EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, MyFrame::OnStandardButtonsSizerDialog)
|
||||||
|
EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION, MyFrame::OnTestDefaultActionDialog)
|
||||||
|
|
||||||
EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention)
|
EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention)
|
||||||
#if wxUSE_NOTIFICATION_MESSAGE
|
#if wxUSE_NOTIFICATION_MESSAGE
|
||||||
@@ -439,6 +440,7 @@ bool MyApp::OnInit()
|
|||||||
menuDlg->AppendSubMenu(menuNotif, "&User notifications");
|
menuDlg->AppendSubMenu(menuNotif, "&User notifications");
|
||||||
|
|
||||||
menuDlg->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, _T("&Standard Buttons Sizer Dialog"));
|
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->AppendSeparator();
|
||||||
menuDlg->Append(wxID_EXIT, _T("E&xit\tAlt-X"));
|
menuDlg->Append(wxID_EXIT, _T("E&xit\tAlt-X"));
|
||||||
@@ -1222,6 +1224,66 @@ void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent& WXUNUSED(event))
|
|||||||
dialog.ShowModal();
|
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) )
|
void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
Close(true);
|
Close(true);
|
||||||
|
@@ -169,6 +169,22 @@ private:
|
|||||||
DECLARE_EVENT_TABLE()
|
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
|
#if USE_SETTINGS_DIALOG
|
||||||
// Property sheet dialog
|
// Property sheet dialog
|
||||||
class SettingsDialog: public wxPropertySheetDialog
|
class SettingsDialog: public wxPropertySheetDialog
|
||||||
@@ -314,6 +330,9 @@ public:
|
|||||||
#endif // wxUSE_NOTIFICATION_MESSAGE
|
#endif // wxUSE_NOTIFICATION_MESSAGE
|
||||||
|
|
||||||
void OnStandardButtonsSizerDialog(wxCommandEvent& event);
|
void OnStandardButtonsSizerDialog(wxCommandEvent& event);
|
||||||
|
|
||||||
|
void OnTestDefaultActionDialog(wxCommandEvent& event);
|
||||||
|
|
||||||
void OnExit(wxCommandEvent& event);
|
void OnExit(wxCommandEvent& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -402,7 +421,8 @@ enum
|
|||||||
DIALOGS_PROPERTY_SHEET,
|
DIALOGS_PROPERTY_SHEET,
|
||||||
DIALOGS_PROPERTY_SHEET_TOOLBOOK,
|
DIALOGS_PROPERTY_SHEET_TOOLBOOK,
|
||||||
DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK,
|
DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK,
|
||||||
DIALOGS_STANDARD_BUTTON_SIZER_DIALOG
|
DIALOGS_STANDARD_BUTTON_SIZER_DIALOG,
|
||||||
|
DIALOGS_TEST_DEFAULT_ACTION
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
#include <gdk/gdkkeysyms.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// data
|
// 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)
|
// 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_signal_connect_after(m_treeview, "row-activated",
|
||||||
G_CALLBACK(gtk_listbox_row_activated_callback), this);
|
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 );
|
m_parent->DoAddChild( this );
|
||||||
|
|
||||||
PostCreation(size);
|
PostCreation(size);
|
||||||
|
Reference in New Issue
Block a user