#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 "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
//-----------------------------------------------------------------------------
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;
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
// "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
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 )
{
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();
// "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
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);
// "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
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);
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);
+#endif
return FALSE;
}
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))
{
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))
{
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;
-#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) );
-#endif // GTK_MINOR_VERSION == 0
+#endif // GTK+ 1.0
// I _really_ don't want scrollbars in the beginning
m_vAdjust->lower = 0.0;
{
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);
}
}
}
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
{
// ?
}
}
-
-#if 0
- wxPrintf( "SetFocus finished in " );
- if (GetClassInfo() && GetClassInfo()->GetClassName())
- wxPrintf( GetClassInfo()->GetClassName() );
- wxPrintf( ".\n" );
-#endif
-
}
bool wxWindowGTK::AcceptsFocus() const
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
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
}
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())
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