X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c38373bd542fe5b38d24503f87392c9d998ae15e..bb996f289574defb0ae4339ae8e46ff3cf6fa54c:/src/gtk/window.cpp?ds=sidebyside diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 36344c4139..978f556ca7 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -43,6 +43,7 @@ #include "wx/gtk/private/gtk2-compat.h" #include "wx/gtk/private/event.h" #include "wx/gtk/private/win_gtk.h" +#include "wx/private/textmeasure.h" using namespace wxGTKImpl; #ifdef GDK_WINDOWING_X11 @@ -226,6 +227,17 @@ int g_lastButtonNumber = 0; // the trace mask used for the focus debugging messages #define TRACE_FOCUS wxT("focus") +// A handy function to run from under gdb to show information about the given +// GtkWidget. Right now it only shows its type, we could enhance it to show +// more information later but this is already pretty useful. +const char* wxDumpGtkWidget(GtkWidget* w) +{ + static wxString s; + s.Printf("GtkWidget %p, type \"%s\"", w, G_OBJECT_TYPE_NAME(w)); + + return s.c_str(); +} + //----------------------------------------------------------------------------- // "expose_event"/"draw" from m_wxwindow //----------------------------------------------------------------------------- @@ -314,21 +326,25 @@ draw_border(GtkWidget* widget, GdkEventExpose* gdk_event, wxWindow* win) if (win->HasFlag(wxBORDER_RAISED)) shadow = GTK_SHADOW_OUT; - // Style detail to use + GtkStyle* style; const char* detail; - if (win->m_widget == win->m_wxwindow) - // for non-scrollable wxWindows - detail = "entry"; - else - // for scrollable ones + if (win->HasFlag(wxHSCROLL | wxVSCROLL)) + { + style = gtk_widget_get_style(wxGTKPrivate::GetTreeWidget()); detail = "viewport"; + } + else + { + style = gtk_widget_get_style(wxGTKPrivate::GetEntryWidget()); + detail = "entry"; + } // clip rect is required to avoid painting background // over upper left (w,h) of parent window GdkRectangle clipRect = { x, y, w, h }; gtk_paint_shadow( - gtk_widget_get_style(win->m_wxwindow), gdk_event->window, GTK_STATE_NORMAL, - shadow, &clipRect, wxGTKPrivate::GetEntryWidget(), detail, x, y, w, h); + style, gdk_event->window, GTK_STATE_NORMAL, + shadow, &clipRect, widget, detail, x, y, w, h); #endif // !__WXGTK3__ } return false; @@ -662,6 +678,16 @@ static void wxFillOtherKeyEventFields(wxKeyEvent& event, event.m_altDown = (gdk_event->state & GDK_MOD1_MASK) != 0; event.m_metaDown = (gdk_event->state & GDK_META_MASK) != 0; + // At least with current Linux systems, MOD5 corresponds to AltGr key and + // we represent it, for consistency with Windows, which really allows to + // use Ctrl+Alt as a replacement for AltGr if this key is not present, as a + // combination of these two modifiers. + if ( gdk_event->state & GDK_MOD5_MASK ) + { + event.m_controlDown = + event.m_altDown = true; + } + // Normally we take the state of modifiers directly from the low level GDK // event but unfortunately GDK uses a different convention from MSW for the // key events corresponding to the modifier keys themselves: in it, when @@ -707,8 +733,6 @@ static void wxFillOtherKeyEventFields(wxKeyEvent& event, event.m_rawCode = (wxUint32) gdk_event->keyval; event.m_rawFlags = gdk_event->hardware_keycode; - wxGetMousePosition(&event.m_x, &event.m_y); - win->ScreenToClient(&event.m_x, &event.m_y); event.SetEventObject( win ); } @@ -927,8 +951,6 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget), GdkEventKey *gdk_event, wxWindow *win ) { - if (!win->m_hasVMT) - return FALSE; if (g_blockEventsOnDrag) return FALSE; @@ -947,8 +969,37 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget), return TRUE; } - // Emit KEY_DOWN event - ret = win->HandleWindowEvent( event ); + // Next check for accelerators. +#if wxUSE_ACCEL + wxWindowGTK *ancestor = win; + while (ancestor) + { + int command = ancestor->GetAcceleratorTable()->GetCommand( event ); + if (command != -1) + { + wxCommandEvent menu_event( wxEVT_COMMAND_MENU_SELECTED, command ); + ret = ancestor->HandleWindowEvent( menu_event ); + + if ( !ret ) + { + // if the accelerator wasn't handled as menu event, try + // it as button click (for compatibility with other + // platforms): + wxCommandEvent button_event( wxEVT_COMMAND_BUTTON_CLICKED, command ); + ret = ancestor->HandleWindowEvent( button_event ); + } + + break; + } + if (ancestor->IsTopLevel()) + break; + ancestor = ancestor->GetParent(); + } +#endif // wxUSE_ACCEL + + // If not an accelerator, then emit KEY_DOWN event + if ( !ret ) + ret = win->HandleWindowEvent( event ); } else { @@ -977,44 +1028,13 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget), if (return_after_IM) return FALSE; -#if wxUSE_ACCEL - if (!ret) - { - wxWindowGTK *ancestor = win; - while (ancestor) - { - int command = ancestor->GetAcceleratorTable()->GetCommand( event ); - if (command != -1) - { - wxCommandEvent menu_event( wxEVT_COMMAND_MENU_SELECTED, command ); - ret = ancestor->HandleWindowEvent( menu_event ); - - if ( !ret ) - { - // if the accelerator wasn't handled as menu event, try - // it as button click (for compatibility with other - // platforms): - wxCommandEvent button_event( wxEVT_COMMAND_BUTTON_CLICKED, command ); - ret = ancestor->HandleWindowEvent( button_event ); - } - - break; - } - if (ancestor->IsTopLevel()) - break; - ancestor = ancestor->GetParent(); - } - } -#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. if (!ret) { - long key_code; KeySym keysym = gdk_event->keyval; // Find key code for EVT_CHAR and EVT_CHAR_HOOK events - key_code = wxTranslateKeySymToWXKey(keysym, true /* isChar */); + long key_code = wxTranslateKeySymToWXKey(keysym, true /* isChar */); if ( !key_code ) { if ( wxIsAsciiKeysym(keysym) ) @@ -1036,6 +1056,9 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget), wxLogTrace(TRACE_KEYS, wxT("Char event: %ld"), key_code); eventChar.m_keyCode = key_code; +#if wxUSE_UNICODE + eventChar.m_uniChar = gdk_keyval_to_unicode(key_code); +#endif // wxUSE_UNICODE AdjustCharEventKeyCodes(eventChar); @@ -1100,9 +1123,6 @@ gtk_window_key_release_callback( GtkWidget * WXUNUSED(widget), GdkEventKey *gdk_event, wxWindowGTK *win ) { - if (!win->m_hasVMT) - return FALSE; - if (g_blockEventsOnDrag) return FALSE; @@ -1252,13 +1272,11 @@ bool wxWindowGTK::GTKProcessEvent(wxEvent& event) const bool wxWindowGTK::GTKShouldIgnoreEvent() const { - return !m_hasVMT || g_blockEventsOnDrag; + return g_blockEventsOnDrag; } int wxWindowGTK::GTKCallbackCommonPrologue(GdkEventAny *event) const { - if (!m_hasVMT) - return FALSE; if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnScroll) @@ -1309,142 +1327,79 @@ gtk_window_button_press_callback( GtkWidget* WXUNUSED_IN_GTK3(widget), g_lastButtonNumber = gdk_event->button; - // GDK sends surplus button down events - // before a double click event. We - // need to filter these out. - if ((gdk_event->type == GDK_BUTTON_PRESS) && (win->m_wxwindow)) + wxEventType event_type; + wxEventType down; + wxEventType dclick; + switch (gdk_event->button) { - GdkEvent *peek_event = gdk_event_peek(); - if (peek_event) - { - if ((peek_event->type == GDK_2BUTTON_PRESS) || - (peek_event->type == GDK_3BUTTON_PRESS)) + case 1: + down = wxEVT_LEFT_DOWN; + dclick = wxEVT_LEFT_DCLICK; + break; + case 2: + down = wxEVT_MIDDLE_DOWN; + dclick = wxEVT_MIDDLE_DCLICK; + break; + case 3: + down = wxEVT_RIGHT_DOWN; + dclick = wxEVT_RIGHT_DCLICK; + break; + case 8: + down = wxEVT_AUX1_DOWN; + dclick = wxEVT_AUX1_DCLICK; + break; + case 9: + down = wxEVT_AUX2_DOWN; + dclick = wxEVT_AUX2_DCLICK; + break; + default: + return false; + } + switch (gdk_event->type) + { + case GDK_BUTTON_PRESS: + event_type = down; + // GDK sends surplus button down events + // before a double click event. We + // need to filter these out. + if (win->m_wxwindow) { - gdk_event_free( peek_event ); - return TRUE; + GdkEvent* peek_event = gdk_event_peek(); + if (peek_event) + { + const GdkEventType peek_event_type = peek_event->type; + gdk_event_free(peek_event); + if (peek_event_type == GDK_2BUTTON_PRESS || + peek_event_type == GDK_3BUTTON_PRESS) + { + return true; + } + } } - else + break; + case GDK_2BUTTON_PRESS: + event_type = dclick; +#ifndef __WXGTK3__ + if (gdk_event->button >= 1 && gdk_event->button <= 3) { - gdk_event_free( peek_event ); + // Reset GDK internal timestamp variables in order to disable GDK + // triple click events. GDK will then next time believe no button has + // been clicked just before, and send a normal button click event. + GdkDisplay* display = gtk_widget_get_display(widget); + display->button_click_time[1] = 0; + display->button_click_time[0] = 0; } - } - } - - wxEventType event_type = wxEVT_NULL; - -#ifndef __WXGTK3__ - if ( gdk_event->type == GDK_2BUTTON_PRESS && - gdk_event->button >= 1 && gdk_event->button <= 3 ) - { - // Reset GDK internal timestamp variables in order to disable GDK - // triple click events. GDK will then next time believe no button has - // been clicked just before, and send a normal button click event. - GdkDisplay* display = gtk_widget_get_display (widget); - display->button_click_time[1] = 0; - display->button_click_time[0] = 0; - } #endif // !__WXGTK3__ - - if (gdk_event->button == 1) - { - // note that GDK generates triple click events which are not supported - // by wxWidgets but still have to be passed to the app as otherwise - // clicks would simply go missing - switch (gdk_event->type) - { - // we shouldn't get triple clicks at all for GTK2 because we - // suppress them artificially using the code above but we still - // should map them to something for GTK1 and not just ignore them - // as this would lose clicks - case GDK_3BUTTON_PRESS: // we could also map this to DCLICK... - case GDK_BUTTON_PRESS: - event_type = wxEVT_LEFT_DOWN; - break; - - case GDK_2BUTTON_PRESS: - event_type = wxEVT_LEFT_DCLICK; - break; - - default: - // just to silence gcc warnings - ; - } - } - else if (gdk_event->button == 2) - { - switch (gdk_event->type) - { - case GDK_3BUTTON_PRESS: - case GDK_BUTTON_PRESS: - event_type = wxEVT_MIDDLE_DOWN; - break; - - case GDK_2BUTTON_PRESS: - event_type = wxEVT_MIDDLE_DCLICK; - break; - - default: - ; - } - } - else if (gdk_event->button == 3) - { - switch (gdk_event->type) - { - case GDK_3BUTTON_PRESS: - case GDK_BUTTON_PRESS: - event_type = wxEVT_RIGHT_DOWN; - break; - - case GDK_2BUTTON_PRESS: - event_type = wxEVT_RIGHT_DCLICK; - break; - - default: - ; - } - } - - else if (gdk_event->button == 8) - { - switch (gdk_event->type) - { - case GDK_3BUTTON_PRESS: - case GDK_BUTTON_PRESS: - event_type = wxEVT_AUX1_DOWN; - break; - - case GDK_2BUTTON_PRESS: - event_type = wxEVT_AUX1_DCLICK; - break; - - default: - ; - } - } - - else if (gdk_event->button == 9) - { - switch (gdk_event->type) - { - case GDK_3BUTTON_PRESS: - case GDK_BUTTON_PRESS: - event_type = wxEVT_AUX2_DOWN; - break; - - case GDK_2BUTTON_PRESS: - event_type = wxEVT_AUX2_DCLICK; - break; - - default: - ; - } - } - - if ( event_type == wxEVT_NULL ) - { - // unknown mouse button or click type - return FALSE; + break; + // we shouldn't get triple clicks at all for GTK2 because we + // suppress them artificially using the code above but we still + // should map them to something for GTK3 and not just ignore them + // as this would lose clicks + case GDK_3BUTTON_PRESS: + event_type = down; + break; + default: + return false; } g_lastMouseEvent = (GdkEvent*) gdk_event; @@ -2020,22 +1975,21 @@ static void style_updated(GtkWidget*, GtkStyle*, wxWindow* win) } //----------------------------------------------------------------------------- -// "unrealize" from m_wxwindow +// "unrealize" //----------------------------------------------------------------------------- static void unrealize(GtkWidget*, wxWindow* win) { - if (win->m_imData) - gtk_im_context_set_client_window(win->m_imData->context, NULL); - - g_signal_handlers_disconnect_by_func( - win->m_wxwindow, (void*)style_updated, win); + win->GTKHandleUnrealize(); } } // extern "C" void wxWindowGTK::GTKHandleRealized() { + if (IsFrozen()) + DoFreeze(); + if (m_imData) { gtk_im_context_set_client_window @@ -2098,6 +2052,23 @@ void wxWindowGTK::GTKHandleRealized() } } +void wxWindowGTK::GTKHandleUnrealize() +{ + // unrealizing a frozen window seems to have some lingering effect + // preventing updates to the affected area + if (IsFrozen()) + DoThaw(); + + if (m_wxwindow) + { + if (m_imData) + gtk_im_context_set_client_window(m_imData->context, NULL); + + g_signal_handlers_disconnect_by_func( + m_wxwindow, (void*)style_updated, this); + } +} + // ---------------------------------------------------------------------------- // this wxWindowBase function is implemented here (in platform-specific file) // because it is static and so couldn't be made virtual @@ -2143,7 +2114,7 @@ wxWindow *wxGetActiveWindow() // Under Unix this is implemented using X11 functions in utilsx11.cpp but we // need to have this function under Windows too, so provide at least a stub. -#ifdef __WINDOWS__ +#ifndef GDK_WINDOWING_X11 bool wxGetKeyState(wxKeyCode WXUNUSED(key)) { wxFAIL_MSG(wxS("Not implemented under Windows")); @@ -2214,8 +2185,6 @@ void wxWindowGTK::Init() m_width = 0; m_height = 0; - m_hasVMT = false; - m_showOnIdle = false; m_noExpose = false; @@ -2264,6 +2233,71 @@ wxWindowGTK::wxWindowGTK( wxWindow *parent, Create( parent, id, pos, size, style, name ); } +void wxWindowGTK::GTKCreateScrolledWindowWith(GtkWidget* view) +{ + wxASSERT_MSG( HasFlag(wxHSCROLL) || HasFlag(wxVSCROLL), + wxS("Must not be called if scrolling is not needed.") ); + + m_widget = gtk_scrolled_window_new( NULL, NULL ); + + GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); + + // There is a conflict with default bindings at GTK+ + // level between scrolled windows and notebooks both of which want to use + // Ctrl-PageUp/Down: scrolled windows for scrolling in the horizontal + // direction and notebooks for changing pages -- we decide that if we don't + // have wxHSCROLL style we can safely sacrifice horizontal scrolling if it + // means we can get working keyboard navigation in notebooks + if ( !HasFlag(wxHSCROLL) ) + { + GtkBindingSet * + bindings = gtk_binding_set_by_class(G_OBJECT_GET_CLASS(m_widget)); + if ( bindings ) + { + gtk_binding_entry_remove(bindings, GDK_Page_Up, GDK_CONTROL_MASK); + gtk_binding_entry_remove(bindings, GDK_Page_Down, GDK_CONTROL_MASK); + } + } + + if (HasFlag(wxALWAYS_SHOW_SB)) + { + gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS ); + } + else + { + gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); + } + + m_scrollBar[ScrollDir_Horz] = GTK_RANGE(gtk_scrolled_window_get_hscrollbar(scrolledWindow)); + m_scrollBar[ScrollDir_Vert] = GTK_RANGE(gtk_scrolled_window_get_vscrollbar(scrolledWindow)); + if (GetLayoutDirection() == wxLayout_RightToLeft) + gtk_range_set_inverted( m_scrollBar[ScrollDir_Horz], TRUE ); + + gtk_container_add( GTK_CONTAINER(m_widget), view ); + + // connect various scroll-related events + for ( int dir = 0; dir < ScrollDir_Max; dir++ ) + { + // these handlers block mouse events to any window during scrolling + // such as motion events and prevent GTK and wxWidgets from fighting + // over where the slider should be + g_signal_connect(m_scrollBar[dir], "button_press_event", + G_CALLBACK(gtk_scrollbar_button_press_event), this); + g_signal_connect(m_scrollBar[dir], "button_release_event", + G_CALLBACK(gtk_scrollbar_button_release_event), this); + + gulong handler_id = g_signal_connect(m_scrollBar[dir], "event_after", + G_CALLBACK(gtk_scrollbar_event_after), this); + g_signal_handler_block(m_scrollBar[dir], handler_id); + + // these handlers get notified when scrollbar slider moves + g_signal_connect_after(m_scrollBar[dir], "value_changed", + G_CALLBACK(gtk_scrollbar_value_changed), this); + } + + gtk_widget_show( view ); +} + bool wxWindowGTK::Create( wxWindow *parent, wxWindowID id, const wxPoint &pos, @@ -2302,66 +2336,7 @@ bool wxWindowGTK::Create( wxWindow *parent, if (!HasFlag(wxHSCROLL) && !HasFlag(wxVSCROLL)) m_widget = m_wxwindow; else - { - m_widget = gtk_scrolled_window_new( NULL, NULL ); - - GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); - - // There is a conflict with default bindings at GTK+ - // level between scrolled windows and notebooks both of which want to use - // Ctrl-PageUp/Down: scrolled windows for scrolling in the horizontal - // direction and notebooks for changing pages -- we decide that if we don't - // have wxHSCROLL style we can safely sacrifice horizontal scrolling if it - // means we can get working keyboard navigation in notebooks - if ( !HasFlag(wxHSCROLL) ) - { - GtkBindingSet * - bindings = gtk_binding_set_by_class(G_OBJECT_GET_CLASS(m_widget)); - if ( bindings ) - { - gtk_binding_entry_remove(bindings, GDK_Page_Up, GDK_CONTROL_MASK); - gtk_binding_entry_remove(bindings, GDK_Page_Down, GDK_CONTROL_MASK); - } - } - - if (HasFlag(wxALWAYS_SHOW_SB)) - { - gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS ); - } - else - { - gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); - } - - m_scrollBar[ScrollDir_Horz] = GTK_RANGE(gtk_scrolled_window_get_hscrollbar(scrolledWindow)); - m_scrollBar[ScrollDir_Vert] = GTK_RANGE(gtk_scrolled_window_get_vscrollbar(scrolledWindow)); - if (GetLayoutDirection() == wxLayout_RightToLeft) - gtk_range_set_inverted( m_scrollBar[ScrollDir_Horz], TRUE ); - - gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); - - // connect various scroll-related events - for ( int dir = 0; dir < ScrollDir_Max; dir++ ) - { - // these handlers block mouse events to any window during scrolling - // such as motion events and prevent GTK and wxWidgets from fighting - // over where the slider should be - g_signal_connect(m_scrollBar[dir], "button_press_event", - G_CALLBACK(gtk_scrollbar_button_press_event), this); - g_signal_connect(m_scrollBar[dir], "button_release_event", - G_CALLBACK(gtk_scrollbar_button_release_event), this); - - gulong handler_id = g_signal_connect(m_scrollBar[dir], "event_after", - G_CALLBACK(gtk_scrollbar_event_after), this); - g_signal_handler_block(m_scrollBar[dir], handler_id); - - // these handlers get notified when scrollbar slider moves - g_signal_connect_after(m_scrollBar[dir], "value_changed", - G_CALLBACK(gtk_scrollbar_value_changed), this); - } - - gtk_widget_show( m_wxwindow ); - } + GTKCreateScrolledWindowWith(m_wxwindow); g_object_ref(m_widget); if (m_parent) @@ -2376,6 +2351,12 @@ bool wxWindowGTK::Create( wxWindow *parent, return true; } +void wxWindowGTK::GTKDisconnect(void* instance) +{ + g_signal_handlers_disconnect_matched(instance, + GSignalMatchType(G_SIGNAL_MATCH_DATA), 0, 0, NULL, NULL, this); +} + wxWindowGTK::~wxWindowGTK() { SendDestroyEvent(); @@ -2388,23 +2369,14 @@ wxWindowGTK::~wxWindowGTK() if ( gs_deferredFocusOut == this ) gs_deferredFocusOut = NULL; - m_hasVMT = false; + if (m_widget) + GTKDisconnect(m_widget); + if (m_wxwindow && m_wxwindow != m_widget) + GTKDisconnect(m_wxwindow); // destroy children before destroying this window itself DestroyChildren(); - // unhook focus handlers to prevent stray events being - // propagated to this (soon to be) dead object - if (m_focusWidget != NULL) - { - g_signal_handlers_disconnect_by_func (m_focusWidget, - (gpointer) gtk_window_focus_in_callback, - this); - g_signal_handlers_disconnect_by_func (m_focusWidget, - (gpointer) gtk_window_focus_out_callback, - this); - } - if (m_widget) Show( false ); @@ -2415,8 +2387,8 @@ wxWindowGTK::~wxWindowGTK() // avoid problem with GTK+ 2.18 where a frozen window causes the whole // TLW to be frozen, and if the window is then destroyed, nothing ever // gets painted again - if (IsFrozen()) - DoThaw(); + while (IsFrozen()) + Thaw(); if (m_widget) { @@ -2497,7 +2469,6 @@ void wxWindowGTK::PostCreation() g_signal_connect (m_imData->context, "commit", G_CALLBACK (gtk_wxwindow_commit_cb), this); - g_signal_connect(m_wxwindow, "unrealize", G_CALLBACK(unrealize), this); } // focus handling @@ -2542,13 +2513,14 @@ void wxWindowGTK::PostCreation() // was in fact realized already. if ( gtk_widget_get_realized(connect_widget) ) { - gtk_window_realized_callback(connect_widget, this); + GTKHandleRealized(); } else { g_signal_connect (connect_widget, "realize", G_CALLBACK (gtk_window_realized_callback), this); } + g_signal_connect(connect_widget, "unrealize", G_CALLBACK(unrealize), this); if (!IsTopLevel()) { @@ -2581,8 +2553,6 @@ void wxWindowGTK::PostCreation() InheritAttributes(); - m_hasVMT = true; - SetLayoutDirection(wxLayout_Default); // unless the window was created initially hidden (i.e. Hide() had been @@ -2627,13 +2597,6 @@ void wxWindowGTK::ConnectWidget( GtkWidget *widget ) G_CALLBACK (gtk_window_leave_callback), this); } -bool wxWindowGTK::Destroy() -{ - m_hasVMT = false; - - return wxWindowBase::Destroy(); -} - static GSList* gs_queueResizeList; extern "C" { @@ -3118,52 +3081,18 @@ void wxWindowGTK::DoGetTextExtent( const wxString& string, int *externalLeading, const wxFont *theFont ) const { - wxFont fontToUse = theFont ? *theFont : GetFont(); + // ensure we work with a valid font + wxFont fontToUse; + if ( !theFont || !theFont->IsOk() ) + fontToUse = GetFont(); + else + fontToUse = *theFont; wxCHECK_RET( fontToUse.IsOk(), wxT("invalid font") ); - if (string.empty()) - { - if (x) (*x) = 0; - if (y) (*y) = 0; - return; - } - - PangoContext *context = NULL; - if (m_widget) - context = 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 = wxGTK_CONV( string ); - if ( data ) - pango_layout_set_text(layout, data, strlen(data)); - } - - PangoRectangle rect; - pango_layout_get_extents(layout, NULL, &rect); - - if (x) (*x) = (wxCoord) PANGO_PIXELS(rect.width); - if (y) (*y) = (wxCoord) PANGO_PIXELS(rect.height); - if (descent) - { - PangoLayoutIter *iter = pango_layout_get_iter(layout); - int baseline = pango_layout_iter_get_baseline(iter); - pango_layout_iter_free(iter); - *descent = *y - PANGO_PIXELS(baseline); - } - if (externalLeading) (*externalLeading) = 0; // ?? - - g_object_unref (layout); + const wxWindow* win = static_cast(this); + wxTextMeasure txm(win, &fontToUse); + txm.GetTextExtent(string, x, y, descent, externalLeading); } void wxWindowGTK::GTKDisableFocusOutEvent() @@ -4588,7 +4517,7 @@ wxEventType wxWindowGTK::GTKGetScrollEventType(GtkRange* range) // update current position m_scrollPos[barIndex] = value; // If event should be ignored, or integral position has not changed - if (!m_hasVMT || g_blockEventsOnDrag || wxRound(value) == wxRound(oldPos)) + if (g_blockEventsOnDrag || wxRound(value) == wxRound(oldPos)) { return wxEVT_NULL; } @@ -4712,91 +4641,38 @@ GdkWindow* wxWindowGTK::GTKGetDrawingWindow() const // freeze/thaw // ---------------------------------------------------------------------------- -extern "C" +void wxWindowGTK::GTKFreezeWidget(GtkWidget* widget) { - -// this is called if we attempted to freeze unrealized widget when it finally -// is realized (and so can be frozen): -static void wx_frozen_widget_realize(GtkWidget* w, wxWindowGTK* win) -{ - wxASSERT( w && gtk_widget_get_has_window(w) ); - wxASSERT( gtk_widget_get_realized(w) ); - - g_signal_handlers_disconnect_by_func - ( - w, - (void*)wx_frozen_widget_realize, - win - ); - - GdkWindow* window; - if (w == win->m_wxwindow) - window = win->GTKGetDrawingWindow(); - else - window = gtk_widget_get_window(w); - gdk_window_freeze_updates(window); -} - -} // extern "C" - -void wxWindowGTK::GTKFreezeWidget(GtkWidget *w) -{ - if ( !w || !gtk_widget_get_has_window(w) ) - return; // window-less widget, cannot be frozen - - GdkWindow* window = gtk_widget_get_window(w); - if (window == NULL) + if (widget && gtk_widget_get_has_window(widget)) { - // we can't thaw unrealized widgets because they don't have GdkWindow, - // so set it up to be done immediately after realization: - g_signal_connect_after - ( - w, - "realize", - G_CALLBACK(wx_frozen_widget_realize), - this - ); - return; + GdkWindow* window = gtk_widget_get_window(widget); + if (window) + gdk_window_freeze_updates(window); } - - if (w == m_wxwindow) - window = GTKGetDrawingWindow(); - gdk_window_freeze_updates(window); } -void wxWindowGTK::GTKThawWidget(GtkWidget *w) +void wxWindowGTK::GTKThawWidget(GtkWidget* widget) { - if ( !w || !gtk_widget_get_has_window(w) ) - return; // window-less widget, cannot be frozen - - GdkWindow* window = gtk_widget_get_window(w); - if (window == NULL) + if (widget && gtk_widget_get_has_window(widget)) { - // the widget wasn't realized yet, no need to thaw - g_signal_handlers_disconnect_by_func - ( - w, - (void*)wx_frozen_widget_realize, - this - ); - return; + GdkWindow* window = gtk_widget_get_window(widget); + if (window) + gdk_window_thaw_updates(window); } - - if (w == m_wxwindow) - window = GTKGetDrawingWindow(); - gdk_window_thaw_updates(window); } void wxWindowGTK::DoFreeze() { - GTKFreezeWidget(m_widget); - if ( m_wxwindow && m_widget != m_wxwindow ) - GTKFreezeWidget(m_wxwindow); + GtkWidget* widget = m_wxwindow; + if (widget == NULL) + widget = m_widget; + GTKFreezeWidget(widget); } void wxWindowGTK::DoThaw() { - GTKThawWidget(m_widget); - if ( m_wxwindow && m_widget != m_wxwindow ) - GTKThawWidget(m_wxwindow); + GtkWidget* widget = m_wxwindow; + if (widget == NULL) + widget = m_widget; + GTKThawWidget(widget); }