X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/259858fc6a55dd1f611dbec323264fdbad8b44fb..5b008dd712dc781933629f19039587076094ed8a:/src/gtk/window.cpp diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 43673380dc..d98386fe20 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -56,6 +56,12 @@ #include "wx/math.h" #include +// FIXME: Due to a hack we use GtkCombo in here, which is deprecated since gtk2.3.0 +#include +#if defined(GTK_DISABLE_DEPRECATED) && GTK_CHECK_VERSION(2,3,0) +#undef GTK_DISABLE_DEPRECATED +#endif + #include "wx/gtk/private.h" #include #include @@ -1835,9 +1841,9 @@ static bool DoSendFocusEvents(wxWindow *win) } extern "C" { -static gint gtk_window_focus_in_callback( GtkWidget *widget, - GdkEvent *WXUNUSED(event), - wxWindow *win ) +static gboolean gtk_window_focus_in_callback( GtkWidget *widget, + GdkEvent *WXUNUSED(event), + wxWindow *win ) { DEBUG_MAIN_THREAD @@ -1867,20 +1873,25 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, } #endif // wxUSE_CARET + gboolean ret = FALSE; + // does the window itself think that it has the focus? if ( !win->m_hasFocus ) { // not yet, notify it win->m_hasFocus = true; - if ( DoSendFocusEvents(win) ) - { - g_signal_stop_emission_by_name (widget, "focus_in_event"); - return TRUE; - } + (void)DoSendFocusEvents(win); + + ret = true; } - return FALSE; + // Disable default focus handling for custom windows + // since the default GTK+ handler issues a repaint + if (win->m_wxwindow) + return ret; + + return false; } } @@ -1889,7 +1900,9 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, //----------------------------------------------------------------------------- extern "C" { -static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEventFocus *gdk_event, wxWindowGTK *win ) +static gboolean gtk_window_focus_out_callback( GtkWidget *widget, + GdkEventFocus *gdk_event, + wxWindowGTK *win ) { DEBUG_MAIN_THREAD @@ -1923,6 +1936,8 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEventFocus *gdk } #endif // wxUSE_CARET + gboolean ret = FALSE; + // don't send the window a kill focus event if it thinks that it doesn't // have focus already if ( win->m_hasFocus ) @@ -1932,14 +1947,17 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEventFocus *gdk wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() ); event.SetEventObject( win ); - // even if we did process the event in wx code, still let GTK itself - // process it too as otherwise bad things happen, especially in GTK2 - // where the text control simply aborts the program if it doesn't get - // the matching focus out event (void)win->GetEventHandler()->ProcessEvent( event ); + + ret = true; } - - return FALSE; + + // Disable default focus handling for custom windows + // since the default GTK+ handler issues a repaint + if (win->m_wxwindow) + return ret; + + return false; } } @@ -1948,10 +1966,10 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEventFocus *gdk //----------------------------------------------------------------------------- extern "C" { -static -gint gtk_window_enter_callback( GtkWidget *widget, - GdkEventCrossing *gdk_event, - wxWindowGTK *win ) +static gboolean +gtk_window_enter_callback( GtkWidget *widget, + GdkEventCrossing *gdk_event, + wxWindowGTK *win ) { DEBUG_MAIN_THREAD @@ -1993,7 +2011,10 @@ gint gtk_window_enter_callback( GtkWidget *widget, //----------------------------------------------------------------------------- extern "C" { -static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindowGTK *win ) +static gboolean +gtk_window_leave_callback( GtkWidget *widget, + GdkEventCrossing *gdk_event, + wxWindowGTK *win ) { DEBUG_MAIN_THREAD @@ -2709,7 +2730,7 @@ void wxWindowGTK::PostCreation() g_signal_connect (m_wxwindow, "expose_event", G_CALLBACK (gtk_window_expose_callback), this); - // gtk_widget_set_redraw_on_allocate( GTK_WIDGET(m_wxwindow), !HasFlag( wxFULL_REPAINT_ON_RESIZE ) ); + gtk_widget_set_redraw_on_allocate( GTK_WIDGET(m_wxwindow), HasFlag( wxFULL_REPAINT_ON_RESIZE ) ); } // Create input method handler @@ -2733,10 +2754,20 @@ void wxWindowGTK::PostCreation() if (m_focusWidget == NULL) m_focusWidget = m_widget; - g_signal_connect (m_focusWidget, "focus_in_event", + if (m_wxwindow) + { + g_signal_connect (m_focusWidget, "focus_in_event", + G_CALLBACK (gtk_window_focus_in_callback), this); + g_signal_connect (m_focusWidget, "focus_out_event", + G_CALLBACK (gtk_window_focus_out_callback), this); + } + else + { + g_signal_connect_after (m_focusWidget, "focus_in_event", G_CALLBACK (gtk_window_focus_in_callback), this); - g_signal_connect_after (m_focusWidget, "focus_out_event", + g_signal_connect_after (m_focusWidget, "focus_out_event", G_CALLBACK (gtk_window_focus_out_callback), this); + } } // connect to the various key and mouse handlers @@ -3652,6 +3683,39 @@ void wxWindowGTK::WarpPointer( int x, int y ) gdk_window_warp_pointer( window, x, y ); } +static bool wxScrollAdjust(GtkAdjustment* adj, double change) +{ + double value_start = adj->value; + double value = value_start + change; + double upper = adj->upper - adj->page_size; + if (value > upper) + { + value = upper; + } + // Lower bound will be checked by gtk_adjustment_set_value + gtk_adjustment_set_value(adj, value); + return adj->value != value_start; +} + +bool wxWindowGTK::ScrollLines(int lines) +{ + return + m_vAdjust != NULL && + wxScrollAdjust(m_vAdjust, lines * m_vAdjust->step_increment); +} + +bool wxWindowGTK::ScrollPages(int pages) +{ + return + m_vAdjust != NULL && + wxScrollAdjust(m_vAdjust, pages * m_vAdjust->page_increment); +} + +void wxWindowGTK::SetVScrollAdjustment(GtkAdjustment* adj) +{ + wxASSERT(m_vAdjust == NULL); + m_vAdjust = adj; +} void wxWindowGTK::Refresh( bool eraseBackground, const wxRect *rect ) {