diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2016-05-04 08:16:27 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2016-05-04 08:16:27 +0000 |
| commit | 6712ab21f6dbc8bff3a8cf99b72a807f6821e4f7 (patch) | |
| tree | 7b6b237bb50ec3d3f251c6044dce063c30ed8f1e /src | |
| parent | Correct comment. (diff) | |
| parent | Fix rendering of tool bar icons. (diff) | |
| download | inkscape-6712ab21f6dbc8bff3a8cf99b72a807f6821e4f7.tar.gz inkscape-6712ab21f6dbc8bff3a8cf99b72a807f6821e4f7.zip | |
Fix rendering of tool bar icons in GTK3. Fix some GTK3 warnings.
(bzr r14870)
Diffstat (limited to 'src')
| -rw-r--r-- | src/widgets/button.cpp | 16 | ||||
| -rw-r--r-- | src/widgets/icon.cpp | 46 |
2 files changed, 38 insertions, 24 deletions
diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index 54f073c01..6ea8c1360 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -106,11 +106,13 @@ static void sp_button_get_preferred_width(GtkWidget *widget, gint *minimal_width GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkBorder padding; + GtkBorder border; - gtk_style_context_get_border(context, static_cast<GtkStateFlags>(0), &padding); + gtk_style_context_get_padding(context, GTK_STATE_FLAG_NORMAL, &padding); + gtk_style_context_get_border( context, GTK_STATE_FLAG_NORMAL, &border ); - *minimal_width += 2 + 2 * MAX(2, padding.left + padding.right); - *natural_width += 2 + 2 * MAX(2, padding.left + padding.right); + *minimal_width += MAX(2, padding.left + padding.right + border.left + border.right); + *natural_width += MAX(2, padding.left + padding.right + border.left + border.right); } static void sp_button_get_preferred_height(GtkWidget *widget, gint *minimal_height, gint *natural_height) @@ -126,11 +128,13 @@ static void sp_button_get_preferred_height(GtkWidget *widget, gint *minimal_heig GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkBorder padding; + GtkBorder border; - gtk_style_context_get_border(context, static_cast<GtkStateFlags>(0), &padding); + gtk_style_context_get_padding(context, GTK_STATE_FLAG_NORMAL, &padding); + gtk_style_context_get_border( context, GTK_STATE_FLAG_NORMAL, &border ); - *minimal_height += 2 + 2 * MAX(2, padding.top + padding.bottom); - *natural_height += 2 + 2 * MAX(2, padding.top + padding.bottom); + *minimal_height += MAX(2, padding.top + padding.bottom + border.top + border.bottom); + *natural_height += MAX(2, padding.top + padding.bottom + border.top + border.bottom); } #else static void sp_button_size_request(GtkWidget *widget, GtkRequisition *requisition) diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 010b3a6fb..f2031fe51 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -232,6 +232,7 @@ void IconImpl::sizeAllocate(GtkWidget *widget, GtkAllocation *allocation) } } +// GTK3 Only, Doesn't actually seem to be used. gboolean IconImpl::draw(GtkWidget *widget, cairo_t* cr) { SPIcon *icon = SP_ICON(widget); @@ -247,32 +248,34 @@ gboolean IconImpl::draw(GtkWidget *widget, cairo_t* cr) if (gtk_widget_get_state_flags (GTK_WIDGET(icon)) != GTK_STATE_FLAG_NORMAL && image) { #else if (gtk_widget_get_state (GTK_WIDGET(icon)) != GTK_STATE_NORMAL && image) { + std::cerr << "IconImpl::draw: Ooops! It is called in GTK2" << std::endl; #endif - GtkIconSource *source = gtk_icon_source_new(); - gtk_icon_source_set_pixbuf(source, icon->pb); - gtk_icon_source_set_size(source, GTK_ICON_SIZE_SMALL_TOOLBAR); // note: this is boilerplate and not used - gtk_icon_source_set_size_wildcarded(source, FALSE); + std::cerr << "IconImpl::draw: No image, creating fallback" << std::endl; #if GTK_CHECK_VERSION(3,0,0) - image = gtk_render_icon_pixbuf(gtk_widget_get_style_context(widget), - source, - (GtkIconSize)-1); + // image = gtk_render_icon_pixbuf(gtk_widget_get_style_context(widget), + // source, + // (GtkIconSize)-1); // gtk_render_icon_pixbuf deprecated, replaced by: - // GtkIconTheme *icon_theme = gtk_icon_theme_get_default(); - // image = gtk_icon_theme_load_icon (icon_theme, - // name, - // 32, - // 0, - // NULL); + GtkIconTheme *icon_theme = gtk_icon_theme_get_default(); + image = gtk_icon_theme_load_icon (icon_theme, + "gtk-image", + 32, + (GtkIconLookupFlags)0, + NULL); #else + GtkIconSource *source = gtk_icon_source_new(); + gtk_icon_source_set_pixbuf(source, icon->pb); + gtk_icon_source_set_size(source, GTK_ICON_SIZE_SMALL_TOOLBAR); // note: this is boilerplate and not used + gtk_icon_source_set_size_wildcarded(source, FALSE); image = gtk_style_render_icon(gtk_widget_get_style(widget), source, gtk_widget_get_direction(widget), (GtkStateType) gtk_widget_get_state(widget), (GtkIconSize)-1, widget, "gtk-image"); + gtk_icon_source_free(source); #endif - gtk_icon_source_free(source); unref_image = true; } @@ -801,6 +804,10 @@ GtkWidget *IconImpl::newFull( Inkscape::IconSize lsize, gchar const *name ) GtkWidget *widget = NULL; gint trySize = CLAMP( static_cast<gint>(lsize), 0, static_cast<gint>(G_N_ELEMENTS(iconSizeLookup) - 1) ); + if (trySize != lsize ) { + std::cerr << "GtkWidget *IconImple::newFull(): lsize != trySize: lsize: " << lsize + << " try Size: " << trySize << " " << (name?name:"NULL") << std::endl; + } if ( !sizeMapDone ) { injectCustomSize(); } @@ -828,6 +835,7 @@ GtkWidget *IconImpl::newFull( Inkscape::IconSize lsize, gchar const *name ) if ( Inkscape::Preferences::get()->getBool("/options/iconrender/named_nodelay") ) { int psize = getPhysSize(lsize); + // std::cout << " name: " << name << " size: " << psize << std::endl; prerenderIcon(name, mappedSize, psize); } else { addPreRender( mappedSize, name ); @@ -1000,8 +1008,6 @@ int IconImpl::getPhysSize(int size) "inkscape-decoration" }; - GtkWidget *icon = GTK_WIDGET(g_object_new(SP_TYPE_ICON, NULL)); - for (unsigned i = 0; i < G_N_ELEMENTS(gtkSizes); ++i) { guint const val_ix = (gtkSizes[i] <= GTK_ICON_SIZE_DIALOG) ? (guint)gtkSizes[i] : (guint)Inkscape::ICON_SIZE_DECORATION; @@ -1026,7 +1032,12 @@ int IconImpl::getPhysSize(int size) // gtk_icon_size_lookup(), because themes are free to render the pixbuf however // they like, including changing the usual size." gchar const *id = INKSCAPE_ICON("document-open"); - GdkPixbuf *pb = gtk_widget_render_icon( icon, id, gtkSizes[i], NULL); + GtkIconTheme *icon_theme = gtk_icon_theme_get_default(); + GdkPixbuf *pb = gtk_icon_theme_load_icon (icon_theme, + id, + vals[val_ix], + (GtkIconLookupFlags)0, + NULL); if (pb) { width = gdk_pixbuf_get_width(pb); height = gdk_pixbuf_get_height(pb); @@ -1042,7 +1053,6 @@ int IconImpl::getPhysSize(int size) g_object_unref(G_OBJECT(pb)); } } - //g_object_unref(icon); init = true; } |
