X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9dc44eff0235c5f30940f32ccc6d9d82a236e7d2..af4168e2cfbeffbe3b53380471aa31e9ab63a598:/src/gtk/control.cpp diff --git a/src/gtk/control.cpp b/src/gtk/control.cpp index 40c21e9e15..b63b370645 100644 --- a/src/gtk/control.cpp +++ b/src/gtk/control.cpp @@ -2,7 +2,6 @@ // Name: src/gtk/control.cpp // Purpose: wxControl implementation for wxGTK // Author: Robert Roebling -// Id: $Id$ // Copyright: (c) 1998 Robert Roebling, Julian Smart and Vadim Zeitlin // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -86,24 +85,9 @@ wxSize wxControl::DoGetBestSize() const } else { - GtkRequisition req; -#ifdef __WXGTK3__ - if (gtk_widget_get_request_mode(m_widget) != GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH) - { - gtk_widget_get_preferred_height(m_widget, NULL, &req.height); - gtk_widget_get_preferred_width_for_height(m_widget, req.height, NULL, &req.width); - } - else - { - gtk_widget_get_preferred_width(m_widget, NULL, &req.width); - gtk_widget_get_preferred_height_for_width(m_widget, req.width, NULL, &req.height); - } -#else - GTK_WIDGET_GET_CLASS(m_widget)->size_request(m_widget, &req); -#endif - best.Set(req.width, req.height); + best = GTKGetPreferredSize(m_widget); } - CacheBestSize(best); + return best; } @@ -120,7 +104,6 @@ void wxControl::PostCreation(const wxSize& size) gtk_widget_ensure_style(m_widget); #endif - GTKApplyWidgetStyle(); SetInitialSize(size); } @@ -139,9 +122,7 @@ void wxControl::GTKFixSensitivity(bool WXUNUSED_IN_GTK3(onlyIfUnderMouse)) #endif ) { - wxPoint pt = wxGetMousePosition(); - wxRect rect(ClientToScreen(wxPoint(0, 0)), GetSize()); - if (!onlyIfUnderMouse || rect.Contains(pt)) + if (!onlyIfUnderMouse || GetScreenRect().Contains(wxGetMousePosition())) { Hide(); Show(); @@ -251,6 +232,14 @@ wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget, int state) { wxVisualAttributes attr; + + GtkWidget* tlw = NULL; + if (gtk_widget_get_parent(widget) == NULL) + { + tlw = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_container_add(GTK_CONTAINER(tlw), widget); + } + #ifdef __WXGTK3__ GtkStateFlags stateFlag = GTK_STATE_FLAG_NORMAL; if (state) @@ -275,29 +264,30 @@ wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget, if (!style) style = gtk_widget_get_default_style(); - if (!style) + if (style) { - return wxWindow::GetClassDefaultAttributes(wxWINDOW_VARIANT_NORMAL); - } - - // get the style's colours - attr.colFg = wxColour(style->fg[state]); - if (useBase) - attr.colBg = wxColour(style->base[state]); - else - attr.colBg = wxColour(style->bg[state]); + // get the style's colours + attr.colFg = wxColour(style->fg[state]); + if (useBase) + attr.colBg = wxColour(style->base[state]); + else + attr.colBg = wxColour(style->bg[state]); - // get the style's font - if ( !style->font_desc ) - style = gtk_widget_get_default_style(); - if ( style && style->font_desc ) - { - wxNativeFontInfo info; - info.description = style->font_desc; - attr.font = wxFont(info); - info.description = NULL; + // get the style's font + if (!style->font_desc) + style = gtk_widget_get_default_style(); + if (style && style->font_desc) + { + wxNativeFontInfo info; + info.description = style->font_desc; + attr.font = wxFont(info); + info.description = NULL; + } } + else + attr = wxWindow::GetClassDefaultAttributes(wxWINDOW_VARIANT_NORMAL); #endif + if (!attr.font.IsOk()) { GtkSettings *settings = gtk_settings_get_default(); @@ -313,57 +303,55 @@ wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget, g_free (font_name); } - return attr; -} - + if (tlw) + gtk_widget_destroy(tlw); -//static -wxVisualAttributes -wxControl::GetDefaultAttributesFromGTKWidget(wxGtkWidgetNew_t widget_new, - bool useBase, - int state) -{ - wxVisualAttributes attr; - // NB: we need toplevel window so that GTK+ can find the right style - GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL); - GtkWidget* widget = widget_new(); - gtk_container_add(GTK_CONTAINER(wnd), widget); - attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state); - gtk_widget_destroy(wnd); return attr; } -//static -wxVisualAttributes -wxControl::GetDefaultAttributesFromGTKWidget(wxGtkWidgetNewFromStr_t widget_new, - bool useBase, - int state) +// This is not the same as GetBestSize() because that size may have +// been recalculated and cached by us. We want GTK+ information. +wxSize wxControl::GTKGetPreferredSize(GtkWidget* widget) const { - wxVisualAttributes attr; - // NB: we need toplevel window so that GTK+ can find the right style - GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL); - GtkWidget* widget = widget_new(""); - gtk_container_add(GTK_CONTAINER(wnd), widget); - attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state); - gtk_widget_destroy(wnd); - return attr; -} + GtkRequisition req; +#ifdef __WXGTK3__ + gtk_widget_get_preferred_size(widget, NULL, &req); +#else + GTK_WIDGET_GET_CLASS(widget)->size_request(widget, &req); +#endif + return wxSize(req.width, req.height); +} -//static -wxVisualAttributes -wxControl::GetDefaultAttributesFromGTKWidget(wxGtkWidgetNewFromAdj_t widget_new, - bool useBase, - int state) +wxPoint wxControl::GTKGetEntryMargins(GtkEntry* entry) const { - wxVisualAttributes attr; - // NB: we need toplevel window so that GTK+ can find the right style - GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL); - GtkWidget* widget = widget_new(NULL); - gtk_container_add(GTK_CONTAINER(wnd), widget); - attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state); - gtk_widget_destroy(wnd); - return attr; + wxPoint marg(0, 0); + +#ifndef __WXGTK3__ +#if GTK_CHECK_VERSION(2,10,0) + // The margins we have previously set + const GtkBorder* border = gtk_entry_get_inner_border(entry); + if ( border ) + { + marg.x = border->left + border->right; + marg.y = border->top + border->bottom; + } +#endif // GTK+ 2.10+ +#else // GTK+ 3 + // Gtk3 does not use inner border, but StyleContext and CSS + // TODO: implement it, starting with wxTextEntry::DoSetMargins() +#endif // GTK+ 2/3 + + int x, y; + gtk_entry_get_layout_offsets(entry, &x, &y); + // inner borders are included. Substract them so we can get other margins + x -= marg.x; + y -= marg.y; + marg.x += 2 * x + 2; + marg.y += 2 * y + 2; + + return marg; } + #endif // wxUSE_CONTROLS