X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e2762ff06a5e84c82242d0883d24d21042e5a97e..1c405bb51093fc7812fb66e7d47faac5707e02b5:/src/gtk/window.cpp diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 2d74acd135..a6f5fa3652 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -785,8 +785,14 @@ static int gtk_window_expose_callback( GtkWidget *widget, if (!parent) parent = win; - gtk_paint_flat_box (parent->m_widget->style, pizza->bin_window, GTK_STATE_NORMAL, - GTK_SHADOW_NONE, &gdk_event->area, parent->m_widget, "base", 0, 0, -1, -1); + gtk_paint_flat_box (parent->m_widget->style, + pizza->bin_window, + GTK_STATE_NORMAL, + GTK_SHADOW_NONE, + &gdk_event->area, + parent->m_widget, + (char *)"base", + 0, 0, -1, -1); } win->GetUpdateRegion().Union( gdk_event->area.x, @@ -928,8 +934,14 @@ static void gtk_window_draw_callback( GtkWidget *widget, if (!parent) parent = win; - gtk_paint_flat_box (parent->m_widget->style, pizza->bin_window, GTK_STATE_NORMAL, - GTK_SHADOW_NONE, rect, parent->m_widget, "base", 0, 0, -1, -1); + gtk_paint_flat_box (parent->m_widget->style, + pizza->bin_window, + GTK_STATE_NORMAL, + GTK_SHADOW_NONE, + rect, + parent->m_widget, + (char *)"base", + 0, 0, -1, -1); } @@ -1208,6 +1220,27 @@ static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk return FALSE; } +// ============================================================================ +// the mouse events +// ============================================================================ + +// init wxMouseEvent with the info from gdk_event +#define InitMouseEvent(win, event, gdk_event) \ + { \ + event.SetTimestamp( gdk_event->time ); \ + event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); \ + event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); \ + event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); \ + event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); \ + event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK); \ + event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK); \ + event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK); \ +\ + wxPoint pt = win->GetClientAreaOrigin(); \ + event.m_x = (wxCoord)gdk_event->x - pt.x; \ + event.m_y = (wxCoord)gdk_event->y - pt.y; \ + } + // ---------------------------------------------------------------------------- // mouse event processing helper // ---------------------------------------------------------------------------- @@ -1320,22 +1353,12 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton } wxMouseEvent event( event_type ); - event.SetTimestamp( gdk_event->time ); - event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); - event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); - event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); - event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); - event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK); - event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK); - event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK); - - event.m_x = (wxCoord)gdk_event->x; - event.m_y = (wxCoord)gdk_event->y; + InitMouseEvent( win, event, gdk_event ); AdjustEventButtonState(event); - + // wxListBox actually get mouse events from the item - + if (win->m_isListBox) { event.m_x += widget->allocation.x; @@ -1461,21 +1484,12 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto } wxMouseEvent event( event_type ); - event.SetTimestamp( gdk_event->time ); - event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); - event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); - event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); - event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); - event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK); - event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK); - event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK); - event.m_x = (wxCoord)gdk_event->x; - event.m_y = (wxCoord)gdk_event->y; + InitMouseEvent( win, event, gdk_event ); AdjustEventButtonState(event); // wxListBox actually get mouse events from the item - + if (win->m_isListBox) { event.m_x += widget->allocation.x; @@ -1557,24 +1571,6 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto return FALSE; } -// ============================================================================ -// the mouse events -// ============================================================================ - -// init wxMouseEvent with the info from gdk_event -#define InitMouseEvent(event, gdk_event) \ - event.SetTimestamp( gdk_event->time ); \ - event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); \ - event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); \ - event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); \ - event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); \ - event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK); \ - event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK); \ - event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK); \ -\ - event.m_x = (wxCoord)gdk_event->x; \ - event.m_y = (wxCoord)gdk_event->y \ - //----------------------------------------------------------------------------- // "motion_notify_event" //----------------------------------------------------------------------------- @@ -1612,7 +1608,7 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, */ wxMouseEvent event( wxEVT_MOTION ); - InitMouseEvent(event, gdk_event); + InitMouseEvent(win, event, gdk_event); if ( g_captureWindow ) { @@ -1626,7 +1622,7 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, wxMouseEvent event(g_captureWindowHasMouse ? wxEVT_ENTER_WINDOW : wxEVT_LEAVE_WINDOW); - InitMouseEvent(event, gdk_event); + InitMouseEvent(win, event, gdk_event); event.SetEventObject(win); win->GetEventHandler()->ProcessEvent(event); } @@ -1828,7 +1824,14 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED if ( !g_activeFrameLostFocus && g_activeFrame ) { - wxASSERT_MSG( wxGetTopLevelParent(win) == g_activeFrame, wxT("unfocusing window that haven't gained focus properly") ) + // VZ: commenting this out because it does happen (although not easy + // to reproduce, I only see it when using wxMiniFrame and not + // always) and makes using Mahogany quite annoying +#if 0 + wxASSERT_MSG( wxGetTopLevelParent(win) == g_activeFrame, + wxT("unfocusing window that hasn't gained focus properly") ) +#endif // 0 + g_activeFrameLostFocus = TRUE; } @@ -1902,10 +1905,10 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_ gdk_window_get_pointer( widget->window, &x, &y, &state ); - InitMouseEvent(event, gdk_event); - - event.m_x = x; - event.m_y = y; + InitMouseEvent(win, event, gdk_event); + wxPoint pt = win->GetClientAreaOrigin(); + event.m_x = x + pt.x; + event.m_y = y + pt.y; if (win->GetEventHandler()->ProcessEvent( event )) { @@ -1950,8 +1953,9 @@ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_ event.m_middleDown = (state & GDK_BUTTON2_MASK); event.m_rightDown = (state & GDK_BUTTON3_MASK); - event.m_x = x; - event.m_y = y; + wxPoint pt = win->GetClientAreaOrigin(); + event.m_x = x + pt.x; + event.m_y = y + pt.y; if (win->GetEventHandler()->ProcessEvent( event )) { @@ -2366,7 +2370,7 @@ void wxWindowGTK::Init() m_noExpose = FALSE; m_nativeSizeEvent = FALSE; - + m_hasScrolling = FALSE; m_isScrolling = FALSE; @@ -2541,7 +2545,7 @@ bool wxWindowGTK::Create( wxWindow *parent, if (m_parent) m_parent->DoAddChild( this ); - + m_focusWidget = m_wxwindow; PostCreation(); @@ -2635,7 +2639,7 @@ bool wxWindowGTK::PreCreation( wxWindowGTK *parent, const wxPoint &pos, const w void wxWindowGTK::PostCreation() { wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") ); - + if (m_wxwindow) { if (!m_noExpose) @@ -3083,7 +3087,7 @@ void wxWindowGTK::DoGetPosition( int *x, int *y ) const dx = pizza->xoffset; dy = pizza->yoffset; } - + if (x) (*x) = m_x - dx; if (y) (*y) = m_y - dy; } @@ -3245,6 +3249,13 @@ void wxWindowGTK::SetFocus() { wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); +#if 0 + wxPrintf( "SetFocus from " ); + if (GetClassInfo() && GetClassInfo()->GetClassName()) + wxPrintf( GetClassInfo()->GetClassName() ); + wxPrintf( ".\n" ); +#endif + if (m_wxwindow) { if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow)) @@ -3269,6 +3280,14 @@ void wxWindowGTK::SetFocus() // ? } } + +#if 0 + wxPrintf( "SetFocus finished in " ); + if (GetClassInfo() && GetClassInfo()->GetClassName()) + wxPrintf( GetClassInfo()->GetClassName() ); + wxPrintf( ".\n" ); +#endif + } bool wxWindowGTK::AcceptsFocus() const @@ -3529,7 +3548,7 @@ bool wxWindowGTK::SetBackgroundColour( const wxColour &colour ) if ((m_wxwindow) && (m_wxwindow->window) && - (m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE))) + (m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE))) { /* wxMSW doesn't clear the window here. I don't do that either to provide compatibility. call Clear() to do the job. */ @@ -3625,7 +3644,7 @@ void wxWindowGTK::SetWidgetStyle() GtkStyle *style = GetWidgetStyle(); - if (m_font != wxSystemSettings::GetSystemFont( 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 ) ); @@ -3634,7 +3653,7 @@ void wxWindowGTK::SetWidgetStyle() if (m_foregroundColour.Ok()) { m_foregroundColour.CalcPixel( gtk_widget_get_colormap( m_widget ) ); - if (m_foregroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNTEXT)) + if (m_foregroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)) { style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor(); style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor(); @@ -3660,7 +3679,7 @@ void wxWindowGTK::SetWidgetStyle() if (m_backgroundColour.Ok()) { m_backgroundColour.CalcPixel( gtk_widget_get_colormap( m_widget ) ); - if (m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE)) + if (m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) { style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); @@ -3706,7 +3725,8 @@ void wxWindowGTK::ApplyWidgetStyle() #if wxUSE_MENUS_NATIVE -static void gtk_pop_hide_callback( GtkWidget *WXUNUSED(widget), bool* is_waiting ) +extern "C" +void gtk_pop_hide_callback( GtkWidget *WXUNUSED(widget), bool* is_waiting ) { *is_waiting = FALSE; } @@ -3727,16 +3747,29 @@ static void SetInvokingWindow( wxMenu *menu, wxWindowGTK *win ) } } +// used to pass the coordinates from wxWindowGTK::DoPopupMenu() to +// wxPopupMenuPositionCallback() +// +// should be safe even in the MT case as the user can hardly popup 2 menus +// simultaneously, can he? static gint gs_pop_x = 0; static gint gs_pop_y = 0; -static void pop_pos_callback( GtkMenu * WXUNUSED(menu), - gint *x, gint *y, - wxWindowGTK *win ) +extern "C" void wxPopupMenuPositionCallback( GtkMenu *menu, + gint *x, gint *y, + gpointer WXUNUSED(user_data) ) { - win->ClientToScreen( &gs_pop_x, &gs_pop_y ); - *x = gs_pop_x; - *y = gs_pop_y; + // ensure that the menu appears entirely on screen + GtkRequisition req; + gtk_widget_get_child_requisition(GTK_WIDGET(menu), &req); + + wxSize sizeScreen = wxGetDisplaySize(); + + gint xmax = sizeScreen.x - req.width, + ymax = sizeScreen.y - req.height; + + *x = gs_pop_x < xmax ? gs_pop_x : xmax; + *y = gs_pop_y < ymax ? gs_pop_y : ymax; } bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y ) @@ -3751,20 +3784,23 @@ bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y ) gs_pop_x = x; gs_pop_y = y; + ClientToScreen( &gs_pop_x, &gs_pop_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_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 + (GtkWidget *) NULL, // parent menu shell + (GtkWidget *) NULL, // parent menu item + wxPopupMenuPositionCallback, // function to position it + NULL, // client data + 0, // button used to activate it + gs_timeLastClick // the time of activation ); while (is_waiting) @@ -3821,7 +3857,7 @@ bool wxWindowGTK::SetFont( const wxFont &font ) return FALSE; } - wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ); + wxColour sysbg = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ); if ( sysbg == m_backgroundColour ) { m_backgroundColour = wxNullColour; @@ -3836,7 +3872,7 @@ bool wxWindowGTK::SetFont( const wxFont &font ) return TRUE; } -void wxWindowGTK::CaptureMouse() +void wxWindowGTK::DoCaptureMouse() { wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); @@ -3865,12 +3901,14 @@ void wxWindowGTK::CaptureMouse() g_captureWindowHasMouse = TRUE; } -void wxWindowGTK::ReleaseMouse() +void wxWindowGTK::DoReleaseMouse() { wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); wxCHECK_RET( g_captureWindow, wxT("can't release mouse - not captured") ); + g_captureWindow = (wxWindowGTK*) NULL; + GdkWindow *window = (GdkWindow*) NULL; if (m_wxwindow) window = GTK_PIZZA(m_wxwindow)->bin_window; @@ -3881,7 +3919,6 @@ void wxWindowGTK::ReleaseMouse() return; gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME ); - g_captureWindow = (wxWindowGTK*) NULL; } /* static */