X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/af3653ddfa77e0937adfb8bc17fd77385d0ab8ab..5f1d3069010e74475d6b5887a59e242d452f4f2a:/src/gtk/window.cpp diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 61eef683dc..6691ffd0ce 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -48,12 +48,14 @@ #include "wx/intl.h" #include "wx/settings.h" #include "wx/log.h" +#include "wx/fontutil.h" #ifdef __WXDEBUG__ #include "wx/thread.h" #endif #include +#include #include "wx/gtk/private.h" #include @@ -508,6 +510,22 @@ static int gtk_window_expose_callback( GtkWidget *widget, } #endif +#ifdef __WXGTK20__ + // This callback gets called in drawing-idle time under + // GTK 2.0, so we don't need to defer anything to idle + // time anymore. + + win->GetUpdateRegion() = wxRegion( gdk_event->region ); + + win->GtkSendPaintEvents(); + + // Draw window less widgets + (* GTK_WIDGET_CLASS (pizza_parent_class)->expose_event) (widget, gdk_event); +#else + // This gets called immediately after an expose event + // under GTK 1.2 so we collect the calls and wait for + // the idle handler to pick things up. + win->GetUpdateRegion().Union( gdk_event->area.x, gdk_event->area.y, gdk_event->area.width, @@ -518,14 +536,10 @@ static int gtk_window_expose_callback( GtkWidget *widget, gdk_event->area.height ); // Actual redrawing takes place in idle time. - win->GtkUpdate(); - -#ifdef __WXGTK20__ - - (* GTK_WIDGET_CLASS (pizza_parent_class)->expose_event) (widget, gdk_event); - + // win->GtkUpdate(); #endif + return TRUE; } @@ -611,20 +625,12 @@ static void gtk_window_draw_callback( GtkWidget *widget, (char *)"base", 0, 0, -1, -1); } - - - if (!(GTK_WIDGET_APP_PAINTABLE (widget)) && - (pizza->clear_on_draw)) - { - gdk_window_clear_area( pizza->bin_window, - rect->x, rect->y, rect->width, rect->height); - } #endif + win->m_clearRegion.Union( rect->x, rect->y, rect->width, rect->height ); win->GetUpdateRegion().Union( rect->x, rect->y, rect->width, rect->height ); - // Actual redrawing takes place in idle time. - + // Update immediately, not in idle time. win->GtkUpdate(); #ifndef __WXUNIVERSAL__ @@ -953,7 +959,7 @@ wxTranslateGTKKeyEventToWx(wxKeyEvent& event, KeySym keysym = gdk_event->keyval; - wxLogTrace(TRACE_KEYS, _T("Key %s event: keysym = %d"), + wxLogTrace(TRACE_KEYS, _T("Key %s event: keysym = %ld"), event.GetEventType() == wxEVT_KEY_UP ? _T("release") : _T("press"), keysym); @@ -1023,7 +1029,7 @@ wxTranslateGTKKeyEventToWx(wxKeyEvent& event, } } - wxLogTrace(TRACE_KEYS, _T("\t-> wxKeyCode %d"), key_code); + wxLogTrace(TRACE_KEYS, _T("\t-> wxKeyCode %ld"), key_code); // sending unknown key events doesn't really make sense if ( !key_code ) @@ -1066,28 +1072,16 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, if (g_blockEventsOnDrag) return FALSE; - bool ret = FALSE; - - wxKeyEvent event( wxEVT_CHAR_HOOK ); + + wxKeyEvent event( wxEVT_KEY_DOWN ); if ( !wxTranslateGTKKeyEventToWx(event, win, gdk_event) ) { // unknown key pressed, ignore (the event would be useless anyhow) return FALSE; } - // Implement wxFrame::OnCharHook by checking ancestor. - wxWindow *parent = win; - while (parent && !parent->IsTopLevel()) - parent = parent->GetParent(); - - if (parent) - ret = parent->GetEventHandler()->ProcessEvent( event ); - - if (!ret) - { - event.SetEventType(wxEVT_KEY_DOWN); - ret = win->GetEventHandler()->ProcessEvent( event ); - } + // Emit KEY_DOWN event + bool ret = win->GetEventHandler()->ProcessEvent( event ); #if wxUSE_ACCEL if (!ret) @@ -1109,10 +1103,11 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, } #endif // wxUSE_ACCEL - /* Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x - will only be sent if it is not in an accelerator table. */ + // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x + // will only be sent if it is not in an accelerator table. if (!ret) { + // Find key code for EVT_CHAR and EVT_CHAR_HOOK events KeySym keysym = gdk_event->keyval; long key_code = wxTranslateKeySymToWXKey(keysym, TRUE /* isChar */); if ( !key_code ) @@ -1132,16 +1127,27 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, { wxLogTrace(TRACE_KEYS, _T("Char event: %ld"), key_code); - // reuse the same event object, just change its type and use the - // translated keycode instead of the raw one - event.SetEventType(wxEVT_CHAR); event.m_keyCode = key_code; + + // Implement OnCharHook by checking ancesteror top level windows + wxWindow *parent = win; + while (parent && !parent->IsTopLevel()) + parent = parent->GetParent(); + if (parent) + { + event.SetEventType( wxEVT_CHAR_HOOK ); + ret = parent->GetEventHandler()->ProcessEvent( event ); + } - ret = win->GetEventHandler()->ProcessEvent( event ); + if (!ret) + { + event.SetEventType(wxEVT_CHAR); + ret = win->GetEventHandler()->ProcessEvent( event ); + } } } - /* win is a control: tab can be propagated up */ + // win is a control: tab can be propagated up if ( !ret && ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab)) && // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may @@ -1154,15 +1160,15 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, { wxNavigationKeyEvent new_event; new_event.SetEventObject( win->GetParent() ); - /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */ + // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB new_event.SetDirection( (gdk_event->keyval == GDK_Tab) ); - /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ + // CTRL-TAB changes the (parent) window, i.e. switch notebook page new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) ); new_event.SetCurrentFocus( win ); ret = win->GetParent()->GetEventHandler()->ProcessEvent( new_event ); } - /* generate wxID_CANCEL if has been pressed (typically in dialogs) */ + // generate wxID_CANCEL if has been pressed (typically in dialogs) if ( !ret && (gdk_event->keyval == GDK_Escape) ) { @@ -1171,9 +1177,9 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, ret = win->GetEventHandler()->ProcessEvent( new_event ); } - /* Doesn't work. */ -#if 0 // (GTK_MINOR_VERSION > 0) - /* Pressing F10 will activate the menu bar of the top frame. */ + // Doesn't work. +#if 0 + // Pressing F10 will activate the menu bar of the top frame if ( (!ret) && (gdk_event->keyval == GDK_F10) ) { @@ -1206,7 +1212,7 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); return TRUE; } - + return FALSE; } @@ -1252,21 +1258,30 @@ static gint gtk_window_key_release_callback( GtkWidget *widget, // ---------------------------------------------------------------------------- // 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; \ - } +// +// NB: this has to be a macro as gdk_event type is different for different +// events we're used with +#define InitMouseEvent(/* wxWindowGTK * */ win, \ + /* wxMouseEvent& */ event, \ + /* GdkEventXXX * */ 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; \ + \ + event.SetEventObject( win ); \ + event.SetId( win->GetId() ); \ + event.SetTimestamp( gdk_event->time ); \ +} \ static void AdjustEventButtonState(wxMouseEvent& event) { @@ -1453,8 +1468,6 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, if ( !g_captureWindow ) win = FindWindowForMouseEvent(win, event.m_x, event.m_y); - event.SetEventObject( win ); - gs_timeLastClick = gdk_event->time; /* @@ -1518,8 +1531,6 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto if ( !g_captureWindow ) win = FindWindowForMouseEvent(win, event.m_x, event.m_y); - event.SetEventObject( win ); - if (win->GetEventHandler()->ProcessEvent( event )) { gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_release_event" ); @@ -1590,8 +1601,6 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, win = FindWindowForMouseEvent(win, event.m_x, event.m_y); } - event.SetEventObject( win ); - if (win->GetEventHandler()->ProcessEvent( event )) { gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "motion_notify_event" ); @@ -1730,7 +1739,7 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEventFocus *gdk // always) and makes using Mahogany quite annoying #if 0 wxASSERT_MSG( wxGetTopLevelParent(win) == g_activeFrame, - wxT("unfocusing window that hasn't gained focus properly") ) + wxT("unfocusing window that hasn't gained focus properly") ); #endif // 0 g_activeFrameLostFocus = TRUE; @@ -1784,7 +1793,10 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEventFocus *gdk // "enter_notify_event" //----------------------------------------------------------------------------- -static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindowGTK *win ) +static +gint gtk_window_enter_callback( GtkWidget *widget, + GdkEventCrossing *gdk_event, + wxWindowGTK *win ) { DEBUG_MAIN_THREAD @@ -1796,16 +1808,13 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_ if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; - wxMouseEvent event( wxEVT_ENTER_WINDOW ); - event.SetTimestamp( gdk_event->time ); - event.SetEventObject( win ); - int x = 0; int y = 0; GdkModifierType state = (GdkModifierType)0; gdk_window_get_pointer( widget->window, &x, &y, &state ); + wxMouseEvent event( wxEVT_ENTER_WINDOW ); InitMouseEvent(win, event, gdk_event); wxPoint pt = win->GetClientAreaOrigin(); event.m_x = x + pt.x; @@ -2014,12 +2023,18 @@ wxWindow *wxWindowBase::FindFocus() // "destroy" event //----------------------------------------------------------------------------- +// VZ: Robert commented the code using out so it generates warnings: should +// be either fixed or removed completely +#if 0 + static void gtk_window_destroy_callback( GtkWidget* widget, wxWindow *win ) { wxWindowDestroyEvent event(win); win->GetEventHandler()->ProcessEvent(event); } +#endif // 0 + //----------------------------------------------------------------------------- // "realize" from m_widget //----------------------------------------------------------------------------- @@ -2494,17 +2509,17 @@ bool wxWindowGTK::PreCreation( wxWindowGTK *parent, const wxPoint &pos, const w { wxCHECK_MSG( !m_needParent || parent, FALSE, wxT("Need complete parent.") ); - /* this turns -1 into 20 so that a minimal window is - visible even although -1,-1 has been given as the - size of the window. the same trick is used in other - ports and should make debugging easier */ - m_width = WidthDefault(size.x); + // This turns -1 into 30 so that a minimal window is + // visible even although -1,-1 has been given as the + // size of the window. the same trick is used in other + // ports and should make debugging easier. + m_width = WidthDefault(size.x) ; m_height = HeightDefault(size.y); m_x = (int)pos.x; m_y = (int)pos.y; - /* some reasonable defaults */ + // some reasonable defaults if (!parent) { if (m_x == -1) @@ -2635,8 +2650,10 @@ void wxWindowGTK::ConnectWidget( GtkWidget *widget ) gtk_signal_connect( GTK_OBJECT(widget), "leave_notify_event", GTK_SIGNAL_FUNC(gtk_window_leave_callback), (gpointer)this ); - gtk_signal_connect( GTK_OBJECT(widget), "destroy", - GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this ); + // This keeps crashing on me. RR. + // + // gtk_signal_connect( GTK_OBJECT(widget), "destroy", + // GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this ); } bool wxWindowGTK::Destroy() @@ -2688,16 +2705,14 @@ void wxWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags { if (x != -1) m_x = x + pizza->xoffset; if (y != -1) m_y = y + pizza->yoffset; - if (width != -1) m_width = width; - if (height != -1) m_height = height; } else { m_x = x + pizza->xoffset; m_y = y + pizza->yoffset; - m_width = width; - m_height = height; } + if (width != -1) m_width = width; + if (height != -1) m_height = height; if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) { @@ -3136,12 +3151,55 @@ void wxWindowGTK::GetTextExtent( const wxString& string, if (theFont) fontToUse = *theFont; wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") ); + + if (string.IsEmpty()) + { + if (x) (*x) = 0; + if (y) (*y) = 0; + return; + } +#ifdef __WXGTK20__ + PangoContext *context = NULL; + if (m_widget) + gtk_widget_get_pango_context( m_widget ); + + if (!context) + { + if (x) (*x) = 0; + if (y) (*y) = 0; + return; + } + + PangoFontDescription *desc = fontToUse.GetNativeFontInfo()->description; + PangoLayout *layout = pango_layout_new(context); + pango_layout_set_font_description(layout, desc); + { + const wxCharBuffer data = wxConvUTF8.cWC2MB( string ); + pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data )); + } + PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data; + + PangoRectangle rect; + pango_layout_line_get_extents(line, NULL, &rect); + + if (x) (*x) = (wxCoord) (rect.width / PANGO_SCALE); + if (y) (*y) = (wxCoord) (rect.height / PANGO_SCALE); + if (descent) + { + // Do something about metrics here + (*descent) = 0; + } + if (externalLeading) (*externalLeading) = 0; // ?? + + g_object_unref( G_OBJECT( layout ) ); +#else GdkFont *font = fontToUse.GetInternalFont( 1.0 ); - if (x) (*x) = gdk_string_width( font, string.mbc_str() ); + if (x) (*x) = gdk_string_width( font, wxGTK_CONV( string ) ); if (y) (*y) = font->ascent + font->descent; if (descent) (*descent) = font->descent; if (externalLeading) (*externalLeading) = 0; // ?? +#endif } void wxWindowGTK::SetFocus() @@ -3305,11 +3363,12 @@ void wxWindowGTK::WarpPointer( int x, int y ) gdk_window_warp_pointer( window, x, y ); } + void wxWindowGTK::Refresh( bool eraseBackground, const wxRect *rect ) { if (!m_widget) return; if (!m_widget->window) return; - + #ifndef __WXGTK20__ if (g_isIdle) wxapp_install_idle_handler(); @@ -3389,27 +3448,31 @@ void wxWindowGTK::GtkUpdate() #ifdef __WXGTK20__ if (m_wxwindow && GTK_PIZZA(m_wxwindow)->bin_window) gdk_window_process_updates( GTK_PIZZA(m_wxwindow)->bin_window, FALSE ); -#endif - +#else if (!m_updateRegion.IsEmpty()) GtkSendPaintEvents(); +#endif } void wxWindowGTK::GtkSendPaintEvents() { if (!m_wxwindow) { +#ifndef __WXGTK20__ m_clearRegion.Clear(); +#endif m_updateRegion.Clear(); return; } + // Clip to paint region in wxClientDC + m_clipPaintRegion = TRUE; + +#ifndef __WXGTK20__ // widget to draw on GtkPizza *pizza = GTK_PIZZA (m_wxwindow); - // Clip to paint region in wxClientDC - m_clipPaintRegion = TRUE; - + // later for GTK 2.0, too. if (GetThemeEnabled()) { // find ancestor from which to steal background @@ -3441,10 +3504,26 @@ void wxWindowGTK::GtkSendPaintEvents() } } else - // if (!m_clearRegion.IsEmpty()) // always send an erase event +#endif + +#ifdef __WXGTK20__ { wxWindowDC dc( (wxWindow*)this ); - dc.SetClippingRegion( m_clearRegion ); + dc.SetClippingRegion( m_updateRegion ); + + wxEraseEvent erase_event( GetId(), &dc ); + erase_event.SetEventObject( this ); + + GetEventHandler()->ProcessEvent(erase_event); + } +#else + // if (!m_clearRegion.IsEmpty()) // Always send an erase event under GTK 1.2 + { + wxWindowDC dc( (wxWindow*)this ); + if (m_clearRegion.IsEmpty()) + dc.SetClippingRegion( m_updateRegion ); + else + dc.SetClippingRegion( m_clearRegion ); wxEraseEvent erase_event( GetId(), &dc ); erase_event.SetEventObject( this ); @@ -3468,6 +3547,7 @@ void wxWindowGTK::GtkSendPaintEvents() } m_clearRegion.Clear(); } +#endif wxNcPaintEvent nc_paint_event( GetId() ); nc_paint_event.SetEventObject( this ); @@ -3530,6 +3610,7 @@ void wxWindowGTK::Clear() { wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); +#ifndef __WXGTK20__ if (m_wxwindow && m_wxwindow->window) { m_clearRegion.Clear(); @@ -3539,6 +3620,7 @@ void wxWindowGTK::Clear() // Better do this in idle? GtkUpdate(); } +#endif } #if wxUSE_TOOLTIPS