X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/61721d057edd248006baa0c02592f4d7f5d45980..8b0975a38e83e3a5a3874c4526bc0cee279305be:/src/gtk1/window.cpp diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 07ff8e6952..5b78c8b40e 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -73,11 +73,6 @@ #include #endif -#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 #ifdef __WXGTK20__ #ifdef HAVE_XIM @@ -632,7 +627,7 @@ static void gtk_window_draw_callback( GtkWidget *widget, #ifndef __WXUNIVERSAL__ GtkPizza *pizza = GTK_PIZZA (widget); - if (win->GetThemeEnabled()) + if (win->GetThemeEnabled() && win->GetBackgroundStyle() == wxBG_STYLE_SYSTEM) { wxWindow *parent = win->GetParent(); while (parent && !parent->IsTopLevel()) @@ -1337,24 +1332,13 @@ static void gtk_wxwindow_commit_cb (GtkIMContext *context, } #if wxUSE_UNICODE - event.m_uniChar = g_utf8_get_char( str ); - - // Backward compatible for ISO-8859 - if (event.m_uniChar < 256) - event.m_keyCode = event.m_uniChar; - wxLogTrace(TRACE_KEYS, _T("IM sent character '%c'"), event.m_uniChar); + const wxWCharBuffer data = wxConvUTF8.cMB2WC( (char*)str ); #else - wchar_t unistr[2]; - unistr[0] = g_utf8_get_char(str); - unistr[1] = 0; - wxCharBuffer ansistr(wxConvLocal.cWC2MB(unistr)); - // We cannot handle characters that cannot be represented in - // current locale's charset in non-Unicode mode: - if (ansistr.data() == NULL) - return; - event.m_keyCode = ansistr[0u]; - wxLogTrace(TRACE_KEYS, _T("IM sent character '%c'"), (wxChar)event.m_keyCode); + const wxWCharBuffer wdata = wxConvUTF8.cMB2WC( (char*)str ); + const wxCharBuffer data = wxConvLocal.cWC2MB( wdata ); #endif // wxUSE_UNICODE + if( !(const wxChar*)data ) + return; bool ret = false; @@ -1362,16 +1346,28 @@ static void gtk_wxwindow_commit_cb (GtkIMContext *context, wxWindow *parent = window; while (parent && !parent->IsTopLevel()) parent = parent->GetParent(); - if (parent) - { - event.SetEventType( wxEVT_CHAR_HOOK ); - ret = parent->GetEventHandler()->ProcessEvent( event ); - } - if (!ret) + for( const wxChar* pstr = data; *pstr; pstr++ ) { - event.SetEventType(wxEVT_CHAR); - ret = window->GetEventHandler()->ProcessEvent( event ); +#if wxUSE_UNICODE + event.m_uniChar = *pstr; + // Backward compatible for ISO-8859 + event.m_keyCode = *pstr < 256 ? event.m_uniChar : 0; + wxLogTrace(TRACE_KEYS, _T("IM sent character '%c'"), event.m_uniChar); +#else + event.m_keyCode = *pstr; +#endif // wxUSE_UNICODE + if (parent) + { + event.SetEventType( wxEVT_CHAR_HOOK ); + ret = parent->GetEventHandler()->ProcessEvent( event ); + } + + if (!ret) + { + event.SetEventType(wxEVT_CHAR); + ret = window->GetEventHandler()->ProcessEvent( event ); + } } } #endif @@ -2646,6 +2642,8 @@ void wxWindowGTK::Init() m_clipPaintRegion = FALSE; + m_needsStyleChange = false; + m_cursor = *wxSTANDARD_CURSOR; #ifdef __WXGTK20__ @@ -3119,6 +3117,13 @@ void wxWindowGTK::OnInternalIdle() if ( m_dirtyTabOrder ) RealizeTabOrder(); #endif + // Update style if the window was not yet realized + // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called + if (m_needsStyleChange) + { + SetBackgroundStyle(GetBackgroundStyle()); + m_needsStyleChange = false; + } // Update invalidated regions. GtkUpdate(); @@ -3601,7 +3606,6 @@ void wxWindowGTK::GetTextExtent( const wxString& string, void wxWindowGTK::SetFocus() { wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); - if ( m_hasFocus ) { // don't do anything if we already have focus @@ -3617,8 +3621,16 @@ void wxWindowGTK::SetFocus() } else if (m_widget) { +#ifdef __WXGTK20__ + if (GTK_IS_CONTAINER(m_widget)) + { + gtk_widget_child_focus( m_widget, GTK_DIR_TAB_FORWARD ); + } + else +#endif if (GTK_WIDGET_CAN_FOCUS(m_widget) && !GTK_WIDGET_HAS_FOCUS (m_widget) ) { + if (!GTK_WIDGET_REALIZED(m_widget)) { // we can't set the focus to the widget now so we remember that @@ -3639,11 +3651,14 @@ void wxWindowGTK::SetFocus() gtk_widget_grab_focus (m_widget); } } - else if (GTK_IS_CONTAINER(m_widget)) + else +#ifndef __WXGTK20__ + if (GTK_IS_CONTAINER(m_widget)) { - SET_CONTAINER_FOCUS( m_widget, GTK_DIR_TAB_FORWARD ); + gtk_container_focus( GTK_CONTAINER(m_widget), GTK_DIR_TAB_FORWARD ); } else +#endif { wxLogTrace(TRACE_FOCUS, _T("Can't set focus to %s(%s)"), @@ -3935,7 +3950,7 @@ void wxWindowGTK::GtkSendPaintEvents() // widget to draw on GtkPizza *pizza = GTK_PIZZA (m_wxwindow); - if (GetThemeEnabled()) + if (GetThemeEnabled() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM) { // find ancestor from which to steal background wxWindow *parent = GetParent(); @@ -3989,7 +4004,7 @@ void wxWindowGTK::GtkSendPaintEvents() wxEraseEvent erase_event( GetId(), &dc ); erase_event.SetEventObject( this ); - if (!GetEventHandler()->ProcessEvent(erase_event)) + if (!GetEventHandler()->ProcessEvent(erase_event) && GetBackgroundStyle() != wxBG_STYLE_CUSTOM) { if (!g_eraseGC) { @@ -4114,8 +4129,9 @@ bool wxWindowGTK::SetBackgroundColour( const wxColour &colour ) } // apply style change (forceStyle=true so that new style is applied - // even if the bg colour changed from valid to wxNullColour): - ApplyWidgetStyle(true); + // even if the bg colour changed from valid to wxNullColour) + if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM) + ApplyWidgetStyle(true); return true; } @@ -4230,6 +4246,9 @@ void wxWindowGTK::ApplyWidgetStyle(bool forceStyle) DoApplyWidgetStyle(style); gtk_rc_style_unref(style); } + + // Style change may affect GTK+'s size calculation: + InvalidateBestSize(); } void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle *style) @@ -4239,6 +4258,43 @@ void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle *style) gtk_widget_modify_style(m_widget, style); } +bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style) +{ + wxWindowBase::SetBackgroundStyle(style); + + if (style == wxBG_STYLE_CUSTOM) + { + GdkWindow *window = (GdkWindow*) NULL; + if (m_wxwindow) + window = GTK_PIZZA(m_wxwindow)->bin_window; + else + window = GetConnectWidget()->window; + + if (window) + { + // Make sure GDK/X11 doesn't refresh the window + // automatically. + gdk_window_set_back_pixmap( window, None, False ); +#ifdef __X__ + Display* display = GDK_WINDOW_DISPLAY(window); + XFlush(display); +#endif + m_needsStyleChange = false; + } + else + // Do in OnIdle, because the window is not yet available + m_needsStyleChange = true; + + // Don't apply widget style, or we get a grey background + } + else + { + // apply style change (forceStyle=true so that new style is applied + // even if the bg colour changed from valid to wxNullColour): + ApplyWidgetStyle(true); + } + return true; +} //----------------------------------------------------------------------------- // Pop-up menu stuff @@ -4301,10 +4357,10 @@ bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y ) bool is_waiting = true; - gtk_signal_connect( GTK_OBJECT(menu->m_menu), - "hide", - GTK_SIGNAL_FUNC(gtk_pop_hide_callback), - (gpointer)&is_waiting ); + gulong handler = gtk_signal_connect( GTK_OBJECT(menu->m_menu), + "hide", + GTK_SIGNAL_FUNC(gtk_pop_hide_callback), + (gpointer)&is_waiting ); wxPoint pos; gpointer userdata; @@ -4341,6 +4397,8 @@ bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y ) gtk_main_iteration(); } + gtk_signal_disconnect(GTK_OBJECT(menu->m_menu), handler); + return true; }