From 7a30ee8f2c5e90a26415132033a98b82ac9af5b4 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 18 May 1999 14:49:18 +0000 Subject: [PATCH] Correxted myfixed widget to prevent warnings from GTK Changed listbox dclick emission git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2495 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/listbox.cpp | 65 ++++++++++++++++++++++++++++++++------------ src/gtk/win_gtk.c | 2 +- src/gtk1/listbox.cpp | 65 ++++++++++++++++++++++++++++++++------------ src/gtk1/win_gtk.c | 2 +- 4 files changed, 98 insertions(+), 36 deletions(-) diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 10c1097045..dc0d32c66b 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -64,12 +64,20 @@ extern bool g_isIdle; extern bool g_blockEventsOnDrag; extern bool g_blockEventsOnScroll; +static bool g_hasDoubleClicked = FALSE; + //----------------------------------------------------------------------------- -// "button_press_event" +// "button_release_event" //----------------------------------------------------------------------------- +/* we would normally emit a wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event once + a GDK_2BUTTON_PRESS occurs, but this has the particular problem of the + listbox keeping the focus until it receives a GDK_BUTTON_RELEASE event. + this can lead to race conditions so that we emit the dclick event + after the GDK_BUTTON_RELEASE event after the GDK_2BUTTON_PRESS event */ + static gint -gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxListBox *listbox ) +gtk_listbox_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxListBox *listbox ) { if (g_isIdle) wxapp_install_idle_handler(); @@ -78,22 +86,8 @@ gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, if (!listbox->m_hasVMT) return FALSE; - int sel = listbox->GetIndex( widget ); + if (!g_hasDoubleClicked) return FALSE; - if ((listbox->m_hasCheckBoxes) && (gdk_event->x < 15) && (gdk_event->type != GDK_2BUTTON_PRESS)) - { - wxCheckListBox *clb = (wxCheckListBox *)listbox; - - clb->Check( sel, !clb->IsChecked(sel) ); - - wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() ); - event.SetEventObject( listbox ); - event.SetInt( sel ); - listbox->GetEventHandler()->ProcessEvent( event ); - } - - if (gdk_event->type == GDK_2BUTTON_PRESS) - { wxCommandEvent event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, listbox->GetId() ); event.SetEventObject( listbox ); @@ -114,7 +108,39 @@ gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, listbox->GetEventHandler()->ProcessEvent( event ); + return FALSE; +} + +//----------------------------------------------------------------------------- +// "button_press_event" +//----------------------------------------------------------------------------- + +static gint +gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxListBox *listbox ) +{ + if (g_isIdle) wxapp_install_idle_handler(); + + if (g_blockEventsOnDrag) return FALSE; + if (g_blockEventsOnScroll) return FALSE; + + if (!listbox->m_hasVMT) return FALSE; + + int sel = listbox->GetIndex( widget ); + + if ((listbox->m_hasCheckBoxes) && (gdk_event->x < 15) && (gdk_event->type != GDK_2BUTTON_PRESS)) + { + wxCheckListBox *clb = (wxCheckListBox *)listbox; + + clb->Check( sel, !clb->IsChecked(sel) ); + + wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() ); + event.SetEventObject( listbox ); + event.SetInt( sel ); + listbox->GetEventHandler()->ProcessEvent( event ); } + + /* emit wxEVT_COMMAND_LISTBOX_DOUBLECLICKED later */ + g_hasDoubleClicked = (gdk_event->type == GDK_2BUTTON_PRESS); return FALSE; } @@ -269,6 +295,11 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, (GtkSignalFunc)gtk_listbox_button_press_callback, (gpointer) this ); + gtk_signal_connect_after( GTK_OBJECT(list_item), + "button_release_event", + (GtkSignalFunc)gtk_listbox_button_release_callback, + (gpointer) this ); + if (m_hasCheckBoxes) { gtk_signal_connect( GTK_OBJECT(list_item), diff --git a/src/gtk/win_gtk.c b/src/gtk/win_gtk.c index d7f721c56b..43f275e840 100644 --- a/src/gtk/win_gtk.c +++ b/src/gtk/win_gtk.c @@ -228,7 +228,7 @@ gtk_myfixed_put (GtkMyFixed *myfixed, if (GTK_WIDGET_REALIZED (myfixed) && !GTK_WIDGET_REALIZED (widget)) gtk_widget_realize (widget); - if (GTK_WIDGET_MAPPED (myfixed) && !GTK_WIDGET_MAPPED (widget)) + if (GTK_WIDGET_MAPPED (myfixed) && !GTK_WIDGET_MAPPED (widget) && GTK_WIDGET_VISIBLE (widget)) gtk_widget_map (widget); if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (myfixed)) diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index 10c1097045..dc0d32c66b 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -64,12 +64,20 @@ extern bool g_isIdle; extern bool g_blockEventsOnDrag; extern bool g_blockEventsOnScroll; +static bool g_hasDoubleClicked = FALSE; + //----------------------------------------------------------------------------- -// "button_press_event" +// "button_release_event" //----------------------------------------------------------------------------- +/* we would normally emit a wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event once + a GDK_2BUTTON_PRESS occurs, but this has the particular problem of the + listbox keeping the focus until it receives a GDK_BUTTON_RELEASE event. + this can lead to race conditions so that we emit the dclick event + after the GDK_BUTTON_RELEASE event after the GDK_2BUTTON_PRESS event */ + static gint -gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxListBox *listbox ) +gtk_listbox_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxListBox *listbox ) { if (g_isIdle) wxapp_install_idle_handler(); @@ -78,22 +86,8 @@ gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, if (!listbox->m_hasVMT) return FALSE; - int sel = listbox->GetIndex( widget ); + if (!g_hasDoubleClicked) return FALSE; - if ((listbox->m_hasCheckBoxes) && (gdk_event->x < 15) && (gdk_event->type != GDK_2BUTTON_PRESS)) - { - wxCheckListBox *clb = (wxCheckListBox *)listbox; - - clb->Check( sel, !clb->IsChecked(sel) ); - - wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() ); - event.SetEventObject( listbox ); - event.SetInt( sel ); - listbox->GetEventHandler()->ProcessEvent( event ); - } - - if (gdk_event->type == GDK_2BUTTON_PRESS) - { wxCommandEvent event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, listbox->GetId() ); event.SetEventObject( listbox ); @@ -114,7 +108,39 @@ gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, listbox->GetEventHandler()->ProcessEvent( event ); + return FALSE; +} + +//----------------------------------------------------------------------------- +// "button_press_event" +//----------------------------------------------------------------------------- + +static gint +gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxListBox *listbox ) +{ + if (g_isIdle) wxapp_install_idle_handler(); + + if (g_blockEventsOnDrag) return FALSE; + if (g_blockEventsOnScroll) return FALSE; + + if (!listbox->m_hasVMT) return FALSE; + + int sel = listbox->GetIndex( widget ); + + if ((listbox->m_hasCheckBoxes) && (gdk_event->x < 15) && (gdk_event->type != GDK_2BUTTON_PRESS)) + { + wxCheckListBox *clb = (wxCheckListBox *)listbox; + + clb->Check( sel, !clb->IsChecked(sel) ); + + wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() ); + event.SetEventObject( listbox ); + event.SetInt( sel ); + listbox->GetEventHandler()->ProcessEvent( event ); } + + /* emit wxEVT_COMMAND_LISTBOX_DOUBLECLICKED later */ + g_hasDoubleClicked = (gdk_event->type == GDK_2BUTTON_PRESS); return FALSE; } @@ -269,6 +295,11 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, (GtkSignalFunc)gtk_listbox_button_press_callback, (gpointer) this ); + gtk_signal_connect_after( GTK_OBJECT(list_item), + "button_release_event", + (GtkSignalFunc)gtk_listbox_button_release_callback, + (gpointer) this ); + if (m_hasCheckBoxes) { gtk_signal_connect( GTK_OBJECT(list_item), diff --git a/src/gtk1/win_gtk.c b/src/gtk1/win_gtk.c index d7f721c56b..43f275e840 100644 --- a/src/gtk1/win_gtk.c +++ b/src/gtk1/win_gtk.c @@ -228,7 +228,7 @@ gtk_myfixed_put (GtkMyFixed *myfixed, if (GTK_WIDGET_REALIZED (myfixed) && !GTK_WIDGET_REALIZED (widget)) gtk_widget_realize (widget); - if (GTK_WIDGET_MAPPED (myfixed) && !GTK_WIDGET_MAPPED (widget)) + if (GTK_WIDGET_MAPPED (myfixed) && !GTK_WIDGET_MAPPED (widget) && GTK_WIDGET_VISIBLE (widget)) gtk_widget_map (widget); if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (myfixed)) -- 2.45.2