+bool wxWindow::SetForegroundColour( const wxColour &colour )
+{
+ wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid window") );
+
+ if (!wxWindowBase::SetForegroundColour(colour))
+ {
+ // don't leave if the GTK widget has just
+ // been realized
+ if (!m_delayedForegroundColour) return FALSE;
+ }
+
+ GdkWindow *window = (GdkWindow*) NULL;
+ if (m_wxwindow)
+ window = GTK_PIZZA(m_wxwindow)->bin_window;
+ else
+ window = GetConnectWidget()->window;
+
+ if (!window)
+ {
+ // indicate that a new style has been set
+ // but it couldn't get applied as the
+ // widget hasn't been realized yet.
+ m_delayedForegroundColour = TRUE;
+ }
+
+ ApplyWidgetStyle();
+
+ return TRUE;
+}
+
+GtkStyle *wxWindow::GetWidgetStyle()
+{
+ 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
+ remake->klass = m_widgetStyle->klass;
+#endif
+
+ gtk_style_unref( m_widgetStyle );
+ m_widgetStyle = remake;
+ }
+ else
+ {
+ GtkStyle *def = gtk_rc_get_style( m_widget );
+
+ if (!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
+ m_widgetStyle->klass = def->klass;
+#endif
+ }
+
+ return m_widgetStyle;
+}
+
+void wxWindow::SetWidgetStyle()
+{
+#if DISABLE_STYLE_IF_BROKEN_THEM
+ if (m_widget->style->engine_data)
+ {
+ static bool s_warningPrinted = FALSE;
+ if (!s_warningPrinted)
+ {
+ printf( "wxWindows warning: Widget styles disabled due to buggy GTK theme.\n" );
+ s_warningPrinted = TRUE;
+ }
+ m_widgetStyle = m_widget->style;
+ return;
+ }
+#endif
+
+ GtkStyle *style = GetWidgetStyle();
+
+ if (m_font != wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT ))
+ {
+ gdk_font_unref( style->font );
+ style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
+ }
+
+ if (m_foregroundColour.Ok())
+ {
+ m_foregroundColour.CalcPixel( gtk_widget_get_colormap( m_widget ) );
+ if (m_foregroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNTEXT))
+ {
+ style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor();
+ style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor();
+ style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor();
+ }
+ else
+ {
+ // Try to restore the gtk default style. This is still a little
+ // oversimplified for what is probably really needed here for controls
+ // other than buttons, but is better than not being able to (re)set a
+ // control's foreground colour to *wxBLACK -- RL
+ GtkStyle *def = gtk_rc_get_style( m_widget );
+
+ if (!def)
+ def = gtk_widget_get_default_style();
+
+ style->fg[GTK_STATE_NORMAL] = def->fg[GTK_STATE_NORMAL];
+ style->fg[GTK_STATE_PRELIGHT] = def->fg[GTK_STATE_PRELIGHT];
+ style->fg[GTK_STATE_ACTIVE] = def->fg[GTK_STATE_ACTIVE];
+ }
+ }
+
+ if (m_backgroundColour.Ok())
+ {
+ m_backgroundColour.CalcPixel( gtk_widget_get_colormap( m_widget ) );
+ if (m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE))
+ {
+ style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
+ style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
+ style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
+ style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
+ }
+ else
+ {
+ // Try to restore the gtk default style. This is still a little
+ // oversimplified for what is probably really needed here for controls
+ // other than buttons, but is better than not being able to (re)set a
+ // control's background colour to default grey and means resetting a
+ // button to wxSYS_COLOUR_BTNFACE will restore its usual highlighting
+ // behavior -- RL
+ GtkStyle *def = gtk_rc_get_style( m_widget );
+
+ if (!def)
+ def = gtk_widget_get_default_style();
+
+ style->bg[GTK_STATE_NORMAL] = def->bg[GTK_STATE_NORMAL];
+ style->base[GTK_STATE_NORMAL] = def->base[GTK_STATE_NORMAL];
+ style->bg[GTK_STATE_PRELIGHT] = def->bg[GTK_STATE_PRELIGHT];
+ style->base[GTK_STATE_PRELIGHT] = def->base[GTK_STATE_PRELIGHT];
+ style->bg[GTK_STATE_ACTIVE] = def->bg[GTK_STATE_ACTIVE];
+ style->base[GTK_STATE_ACTIVE] = def->base[GTK_STATE_ACTIVE];
+ style->bg[GTK_STATE_INSENSITIVE] = def->bg[GTK_STATE_INSENSITIVE];
+ style->base[GTK_STATE_INSENSITIVE] = def->base[GTK_STATE_INSENSITIVE];
+ }
+ }
+}
+
+void wxWindow::ApplyWidgetStyle()
+{
+}
+
+//-----------------------------------------------------------------------------
+// Pop-up menu stuff
+//-----------------------------------------------------------------------------
+
+static void gtk_pop_hide_callback( GtkWidget *WXUNUSED(widget), bool* is_waiting )
+{
+ *is_waiting = FALSE;
+}
+
+static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
+{
+ menu->SetInvokingWindow( win );
+ wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
+ while (node)
+ {
+ wxMenuItem *menuitem = node->GetData();
+ if (menuitem->IsSubMenu())
+ {
+ SetInvokingWindow( menuitem->GetSubMenu(), win );
+ }
+
+ node = node->GetNext();
+ }
+}
+
+static gint gs_pop_x = 0;
+static gint gs_pop_y = 0;
+
+static void pop_pos_callback( GtkMenu * WXUNUSED(menu),
+ gint *x, gint *y,
+ wxWindow *win )
+{
+ win->ClientToScreen( &gs_pop_x, &gs_pop_y );
+ *x = gs_pop_x;
+ *y = gs_pop_y;
+}
+
+bool wxWindow::DoPopupMenu( wxMenu *menu, int x, int y )
+{
+ wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid window") );
+
+ wxCHECK_MSG( menu != NULL, FALSE, wxT("invalid popup-menu") );
+
+ SetInvokingWindow( menu, this );
+
+ menu->UpdateUI();
+
+ gs_pop_x = x;
+ gs_pop_y = y;
+
+ bool is_waiting = TRUE;
+
+ gtk_signal_connect( GTK_OBJECT(menu->m_menu), "hide",
+ GTK_SIGNAL_FUNC(gtk_pop_hide_callback), (gpointer)&is_waiting );
+
+ gtk_menu_popup(
+ GTK_MENU(menu->m_menu),
+ (GtkWidget *) NULL, // parent menu shell
+ (GtkWidget *) NULL, // parent menu item
+ (GtkMenuPositionFunc) pop_pos_callback,
+ (gpointer) this, // client data
+ 0, // button used to activate it
+ gs_timeLastClick // the time of activation
+ );
+
+ while (is_waiting)
+ {
+ while (gtk_events_pending())
+ gtk_main_iteration();
+ }
+
+ return TRUE;
+}
+
+#if wxUSE_DRAG_AND_DROP
+
+void wxWindow::SetDropTarget( wxDropTarget *dropTarget )
+{
+ wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
+
+ GtkWidget *dnd_widget = GetConnectWidget();
+
+ if (m_dropTarget) m_dropTarget->UnregisterWidget( dnd_widget );
+
+ if (m_dropTarget) delete m_dropTarget;
+ m_dropTarget = dropTarget;
+
+ if (m_dropTarget) m_dropTarget->RegisterWidget( dnd_widget );
+}
+
+#endif // wxUSE_DRAG_AND_DROP
+
+GtkWidget* wxWindow::GetConnectWidget()
+{
+ GtkWidget *connect_widget = m_widget;
+ if (m_wxwindow) connect_widget = m_wxwindow;
+
+ return connect_widget;
+}
+
+bool wxWindow::IsOwnGtkWindow( GdkWindow *window )
+{
+ if (m_wxwindow)
+ return (window == GTK_PIZZA(m_wxwindow)->bin_window);
+
+ return (window == m_widget->window);
+}
+
+bool wxWindow::SetFont( const wxFont &font )
+{
+ wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid window") );
+
+ if (!wxWindowBase::SetFont(font))
+ {
+ return FALSE;
+ }
+
+ wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
+ if ( sysbg == m_backgroundColour )
+ {
+ m_backgroundColour = wxNullColour;
+ ApplyWidgetStyle();
+ m_backgroundColour = sysbg;
+ }
+ else
+ {
+ ApplyWidgetStyle();
+ }
+
+ return TRUE;
+}
+
+void wxWindow::CaptureMouse()
+{
+ wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
+
+ wxCHECK_RET( g_captureWindow == NULL, wxT("CaptureMouse called twice") );
+
+ GdkWindow *window = (GdkWindow*) NULL;
+ if (m_wxwindow)
+ window = GTK_PIZZA(m_wxwindow)->bin_window;
+ else
+ window = GetConnectWidget()->window;
+
+ if (!window) return;
+
+ wxCursor* cursor = & m_cursor;
+ if (!cursor->Ok())
+ cursor = wxSTANDARD_CURSOR;
+
+ gdk_pointer_grab( window, FALSE,
+ (GdkEventMask)
+ (GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_POINTER_MOTION_HINT_MASK |
+ GDK_POINTER_MOTION_MASK),
+ (GdkWindow *) NULL,
+ cursor->GetCursor(),
+ (guint32)GDK_CURRENT_TIME );
+ g_captureWindow = this;
+}
+
+void wxWindow::ReleaseMouse()
+{
+ wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
+
+ wxCHECK_RET( g_captureWindow, wxT("ReleaseMouse called twice") );
+
+ GdkWindow *window = (GdkWindow*) NULL;
+ if (m_wxwindow)
+ window = GTK_PIZZA(m_wxwindow)->bin_window;
+ else
+ window = GetConnectWidget()->window;
+
+ if (!window)
+ return;
+
+ gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME );
+ g_captureWindow = (wxWindow*) NULL;
+}
+
+bool wxWindow::IsRetained() const