]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/window.cpp
fixed compilation problem with old gcc releases
[wxWidgets.git] / src / gtk1 / window.cpp
index e2c690114e78b90b1c2aaae7e805a74f6c2de8ea..dbbd4369195bd629de5da7552f6fc499bce3b9f8 100644 (file)
@@ -54,8 +54,7 @@
 
 #include <math.h>
 
 
 #include <math.h>
 
-#include <gdk/gdk.h>
-#include <gtk/gtk.h>
+#include "wx/gtk/private.h"
 #include <gdk/gdkprivate.h>
 #include <gdk/gdkkeysyms.h>
 #include <gdk/gdkx.h>
 #include <gdk/gdkprivate.h>
 #include <gdk/gdkkeysyms.h>
 #include <gdk/gdkx.h>
 
 #include "wx/gtk/win_gtk.h"
 
 
 #include "wx/gtk/win_gtk.h"
 
+#ifdef __WXGTK20__
+    #define SET_CONTAINER_FOCUS(w, d) gtk_widget_child_focus((w), (d))
+#else
+    #define SET_CONTAINER_FOCUS(w, d) gtk_container_focus(GTK_CONTAINER(w), (d))
+#endif
+
 //-----------------------------------------------------------------------------
 // documentation on internals
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // documentation on internals
 //-----------------------------------------------------------------------------
@@ -1212,20 +1217,15 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton
 
     if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
 
 
     if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
 
-    if (win->m_wxwindow)
+    if (win->m_wxwindow && (g_focusWindow != win) && win->AcceptsFocus())
     {
     {
-        if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow) && !GTK_WIDGET_HAS_FOCUS (win->m_wxwindow) )
-        {
-            gtk_widget_grab_focus (win->m_wxwindow);
-
+        gtk_widget_grab_focus( win->m_wxwindow );
 /*
 /*
-            wxPrintf( wxT("GrabFocus from ") );
-            if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-                wxPrintf( win->GetClassInfo()->GetClassName() );
-            wxPrintf( wxT(".\n") );
+        wxPrintf( wxT("GrabFocus from ") );
+        if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+            wxPrintf( win->GetClassInfo()->GetClassName() );
+        wxPrintf( wxT(".\n") );
 */
 */
-
-        }
     }
 
     wxEventType event_type = wxEVT_NULL;
     }
 
     wxEventType event_type = wxEVT_NULL;
@@ -1648,10 +1648,7 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
     g_focusWindow = win;
 
 #if 0
     g_focusWindow = win;
 
 #if 0
-    wxPrintf( "OnSetFocus from " );
-    if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        wxPrintf( win->GetClassInfo()->GetClassName() );
-    wxPrintf( ".\n" );
+    wxLogDebug( wxT("OnSetFocus from %s\n"), win->GetName().c_str() );
 #endif
 
     // notify the parent keeping track of focus for the kbd navigation
 #endif
 
     // notify the parent keeping track of focus for the kbd navigation
@@ -1710,9 +1707,7 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
 // "focus_out_event"
 //-----------------------------------------------------------------------------
 
 // "focus_out_event"
 //-----------------------------------------------------------------------------
 
-static GtkWidget *gs_widgetLastFocus = NULL;
-
-static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindowGTK *win )
+static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEventFocus *gdk_event, wxWindowGTK *win )
 {
     DEBUG_MAIN_THREAD
 
 {
     DEBUG_MAIN_THREAD
 
@@ -1722,17 +1717,9 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
     if (!win->m_hasVMT) return FALSE;
     if (g_blockEventsOnDrag) return FALSE;
 
     if (!win->m_hasVMT) return FALSE;
     if (g_blockEventsOnDrag) return FALSE;
 
-    // VZ: this is really weird but GTK+ seems to call us from inside
-    //     gtk_widget_grab_focus(), i.e. it first sends "focus_out" signal to
-    //     this widget and then "focus_in". This is totally unexpected and
-    //     completely breaks wxUniv code so ignore this dummy event (we can't
-    //     be losing focus if we're about to acquire it!)
-    if ( widget == gs_widgetLastFocus )
-    {
-        gs_widgetLastFocus = NULL;
-
-        return FALSE;
-    }
+#if 0
+    wxLogDebug( wxT("OnKillFocus from %s"), win->GetName().c_str() );
+#endif
 
     if ( !g_activeFrameLostFocus && g_activeFrame )
     {
 
     if ( !g_activeFrameLostFocus && g_activeFrame )
     {
@@ -1758,13 +1745,6 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
 
     g_focusWindow = (wxWindowGTK *)NULL;
 
 
     g_focusWindow = (wxWindowGTK *)NULL;
 
-#if 0
-    wxPrintf( "OnKillFocus from " );
-    if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        wxPrintf( win->GetClassInfo()->GetClassName() );
-    wxPrintf( ".\n" );
-#endif
-
 #ifdef HAVE_XIM
     if (win->m_ic)
         gdk_im_end();
 #ifdef HAVE_XIM
     if (win->m_ic)
         gdk_im_end();
@@ -1882,7 +1862,9 @@ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_
 // "value_changed" from m_vAdjust
 //-----------------------------------------------------------------------------
 
 // "value_changed" from m_vAdjust
 //-----------------------------------------------------------------------------
 
-static void gtk_window_vscroll_callback( GtkAdjustment *adjust, wxWindowGTK *win )
+static void gtk_window_vscroll_callback( GtkAdjustment *adjust,
+                                         SCROLLBAR_CBACK_ARG
+                                         wxWindowGTK *win )
 {
     DEBUG_MAIN_THREAD
 
 {
     DEBUG_MAIN_THREAD
 
@@ -1898,14 +1880,7 @@ static void gtk_window_vscroll_callback( GtkAdjustment *adjust, wxWindowGTK *win
 
     win->m_oldVerticalPos = adjust->value;
 
 
     win->m_oldVerticalPos = adjust->value;
 
-    GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(win->m_widget);
-    GtkRange *range = GTK_RANGE( scrolledWindow->vscrollbar );
-
-    wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK;
-    if      (range->scroll_type == GTK_SCROLL_STEP_BACKWARD) command = wxEVT_SCROLLWIN_LINEUP;
-    else if (range->scroll_type == GTK_SCROLL_STEP_FORWARD)  command = wxEVT_SCROLLWIN_LINEDOWN;
-    else if (range->scroll_type == GTK_SCROLL_PAGE_BACKWARD) command = wxEVT_SCROLLWIN_PAGEUP;
-    else if (range->scroll_type == GTK_SCROLL_PAGE_FORWARD)  command = wxEVT_SCROLLWIN_PAGEDOWN;
+    wxEventType command = GtkScrollWinTypeToWx(GET_SCROLL_TYPE(win->m_widget));
 
     int value = (int)(adjust->value+0.5);
 
 
     int value = (int)(adjust->value+0.5);
 
@@ -1918,7 +1893,9 @@ static void gtk_window_vscroll_callback( GtkAdjustment *adjust, wxWindowGTK *win
 // "value_changed" from m_hAdjust
 //-----------------------------------------------------------------------------
 
 // "value_changed" from m_hAdjust
 //-----------------------------------------------------------------------------
 
-static void gtk_window_hscroll_callback( GtkAdjustment *adjust, wxWindowGTK *win )
+static void gtk_window_hscroll_callback( GtkAdjustment *adjust,
+                                         SCROLLBAR_CBACK_ARG
+                                         wxWindowGTK *win )
 {
     DEBUG_MAIN_THREAD
 
 {
     DEBUG_MAIN_THREAD
 
@@ -1931,16 +1908,9 @@ static void gtk_window_hscroll_callback( GtkAdjustment *adjust, wxWindowGTK *win
     float diff = adjust->value - win->m_oldHorizontalPos;
     if (fabs(diff) < 0.2) return;
 
     float diff = adjust->value - win->m_oldHorizontalPos;
     if (fabs(diff) < 0.2) return;
 
-    win->m_oldHorizontalPos = adjust->value;
-
-    GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(win->m_widget);
-    GtkRange *range = GTK_RANGE( scrolledWindow->hscrollbar );
+    wxEventType command = GtkScrollWinTypeToWx(GET_SCROLL_TYPE(win->m_widget));
 
 
-    wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK;
-    if      (range->scroll_type == GTK_SCROLL_STEP_BACKWARD) command = wxEVT_SCROLLWIN_LINEUP;
-    else if (range->scroll_type == GTK_SCROLL_STEP_FORWARD)  command = wxEVT_SCROLLWIN_LINEDOWN;
-    else if (range->scroll_type == GTK_SCROLL_PAGE_BACKWARD) command = wxEVT_SCROLLWIN_PAGEUP;
-    else if (range->scroll_type == GTK_SCROLL_PAGE_FORWARD)  command = wxEVT_SCROLLWIN_PAGEDOWN;
+    win->m_oldHorizontalPos = adjust->value;
 
     int value = (int)(adjust->value+0.5);
 
 
     int value = (int)(adjust->value+0.5);
 
@@ -1964,7 +1934,11 @@ static gint gtk_scrollbar_button_press_callback( GtkRange *widget,
 
 
     g_blockEventsOnScroll = TRUE;
 
 
     g_blockEventsOnScroll = TRUE;
+
+    // FIXME: there is no 'slider' field in GTK+ 2.0 any more
+#ifndef __WXGTK20__
     win->m_isScrolling = (gdk_event->window == widget->slider);
     win->m_isScrolling = (gdk_event->window == widget->slider);
+#endif
 
     return FALSE;
 }
 
     return FALSE;
 }
@@ -2366,7 +2340,8 @@ bool wxWindowGTK::Create( wxWindow *parent,
     gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
 
 #ifndef __WXUNIVERSAL__
     gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
 
 #ifndef __WXUNIVERSAL__
-#if (GTK_MINOR_VERSION > 0)
+
+#if GTK_CHECK_VERSION(1, 2, 0)
     GtkPizza *pizza = GTK_PIZZA(m_wxwindow);
 
     if (HasFlag(wxRAISED_BORDER))
     GtkPizza *pizza = GTK_PIZZA(m_wxwindow);
 
     if (HasFlag(wxRAISED_BORDER))
@@ -2385,7 +2360,7 @@ bool wxWindowGTK::Create( wxWindow *parent,
     {
         gtk_pizza_set_shadow_type( pizza, GTK_MYSHADOW_NONE );
     }
     {
         gtk_pizza_set_shadow_type( pizza, GTK_MYSHADOW_NONE );
     }
-#else // GTK_MINOR_VERSION == 0
+#else // GTK+ 1.0
     GtkViewport *viewport = GTK_VIEWPORT(scrolledWindow->viewport);
 
     if (HasFlag(wxRAISED_BORDER))
     GtkViewport *viewport = GTK_VIEWPORT(scrolledWindow->viewport);
 
     if (HasFlag(wxRAISED_BORDER))
@@ -2400,17 +2375,18 @@ bool wxWindowGTK::Create( wxWindow *parent,
     {
         gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE );
     }
     {
         gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE );
     }
-#endif // GTK_MINOR_VERSION
+#endif // GTK+ > 1.0/<= 1.0
+
 #endif // __WXUNIVERSAL__
 
     GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
     m_acceptsFocus = TRUE;
 
 #endif // __WXUNIVERSAL__
 
     GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
     m_acceptsFocus = TRUE;
 
-#if (GTK_MINOR_VERSION == 0)
+#if !GTK_CHECK_VERSION(1, 2, 0)
     // shut the viewport up
     gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
     gtk_viewport_set_vadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
     // shut the viewport up
     gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
     gtk_viewport_set_vadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
-#endif // GTK_MINOR_VERSION == 0
+#endif // GTK+ 1.0
 
     // I _really_ don't want scrollbars in the beginning
     m_vAdjust->lower = 0.0;
 
     // I _really_ don't want scrollbars in the beginning
     m_vAdjust->lower = 0.0;
@@ -3181,8 +3157,6 @@ void wxWindowGTK::SetFocus()
     {
         if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow))
         {
     {
         if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow))
         {
-            // see comment in gtk_window_focus_out_callback()
-            gs_widgetLastFocus = m_wxwindow;
             gtk_widget_grab_focus (m_wxwindow);
         }
     }
             gtk_widget_grab_focus (m_wxwindow);
         }
     }
@@ -3194,21 +3168,13 @@ void wxWindowGTK::SetFocus()
         }
         else if (GTK_IS_CONTAINER(m_widget))
         {
         }
         else if (GTK_IS_CONTAINER(m_widget))
         {
-            gtk_container_focus( GTK_CONTAINER(m_widget), GTK_DIR_TAB_FORWARD );
+            SET_CONTAINER_FOCUS( m_widget, GTK_DIR_TAB_FORWARD );
         }
         else
         {
            // ?
         }
     }
         }
         else
         {
            // ?
         }
     }
-
-#if 0
-    wxPrintf( "SetFocus finished in " );
-    if (GetClassInfo() && GetClassInfo()->GetClassName())
-        wxPrintf( GetClassInfo()->GetClassName() );
-    wxPrintf( ".\n" );
-#endif
-
 }
 
 bool wxWindowGTK::AcceptsFocus() const
 }
 
 bool wxWindowGTK::AcceptsFocus() const
@@ -3576,10 +3542,9 @@ GtkStyle *wxWindowGTK::GetWidgetStyle()
     if (m_widgetStyle)
     {
         GtkStyle *remake = gtk_style_copy( m_widgetStyle );
     if (m_widgetStyle)
     {
         GtkStyle *remake = gtk_style_copy( m_widgetStyle );
-#ifdef __WXGTK20__
-        /* FIXME: is this necessary? */
-        _G_TYPE_IGC(remake, GtkObjectClass) = _G_TYPE_IGC(m_widgetStyle, GtkObjectClass);
-#else
+
+        // FIXME: no more klass in 2.0
+#ifndef __WXGTK20__
         remake->klass = m_widgetStyle->klass;
 #endif
 
         remake->klass = m_widgetStyle->klass;
 #endif
 
@@ -3594,10 +3559,9 @@ GtkStyle *wxWindowGTK::GetWidgetStyle()
             def = gtk_widget_get_default_style();
 
         m_widgetStyle = gtk_style_copy( def );
             def = gtk_widget_get_default_style();
 
         m_widgetStyle = gtk_style_copy( def );
-#ifdef __WXGTK20__
-        /* FIXME: is this necessary? */
-        _G_TYPE_IGC(m_widgetStyle, GtkObjectClass) = _G_TYPE_IGC(def, GtkObjectClass);
-#else
+
+        // FIXME: no more klass in 2.0
+#ifndef __WXGTK20__
         m_widgetStyle->klass = def->klass;
 #endif
     }
         m_widgetStyle->klass = def->klass;
 #endif
     }
@@ -3625,8 +3589,7 @@ void wxWindowGTK::SetWidgetStyle()
 
     if (m_font != wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ))
     {
 
     if (m_font != wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ))
     {
-        gdk_font_unref( style->font );
-        style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
+        SET_STYLE_FONT(style, m_font.GetInternalFont( 1.0 ));
     }
 
     if (m_foregroundColour.Ok())
     }
 
     if (m_foregroundColour.Ok())
@@ -3736,6 +3699,9 @@ static gint gs_pop_y = 0;
 
 extern "C" void wxPopupMenuPositionCallback( GtkMenu *menu,
                                              gint *x, gint *y,
 
 extern "C" void wxPopupMenuPositionCallback( GtkMenu *menu,
                                              gint *x, gint *y,
+#ifdef __WXGTK20__
+                                             gboolean * WXUNUSED(whatever),
+#endif
                                              gpointer WXUNUSED(user_data) )
 {
     // ensure that the menu appears entirely on screen
                                              gpointer WXUNUSED(user_data) )
 {
     // ensure that the menu appears entirely on screen