fixup default toolbar button creation for depricated GTK 3 operations

This commit is contained in:
Vincent Sanders 2015-04-10 00:06:48 +01:00
parent 23ae8ccf11
commit 50f68b11a4
3 changed files with 38 additions and 13 deletions

View File

@ -483,3 +483,13 @@ GtkWidget *nsgtk_button_new_from_stock(const gchar *stock_id)
return nsgtk_button_new_from_stock(stock_id);
#endif
}
/* exported interface documented in gtk/compat.h */
gboolean nsgtk_stock_lookup(const gchar *stock_id, GtkStockItem *item)
{
#if GTK_CHECK_VERSION(3,10,0)
return false;
#else
return gtk_stock_lookup(stock_id, item);
#endif
}

View File

@ -148,6 +148,17 @@ GtkWidget *nsgtk_image_new_from_stock(const gchar *stock_id, GtkIconSize size);
*/
GtkWidget *nsgtk_button_new_from_stock(const gchar *stock_id);
/**
* Fills item with the registered values for stock_id.
*
* Compatability interface for original deprecated in GTK 3.10
*
* \param stock_id the name of the stock item
* \return TRUE if stock_id was known.
*/
gboolean nsgtk_stock_lookup(const gchar *stock_id, GtkStockItem *item);
GtkWidget *nsgtk_entry_new(void);
void nsgtk_entry_set_icon_from_pixbuf(GtkWidget *entry, GtkEntryIconPosition icon_pos, GdkPixbuf *pixbuf);

View File

@ -684,19 +684,23 @@ GtkWidget *nsgtk_toolbar_make_widget(struct nsgtk_scaffolding *g,
switch(i) {
/* gtk_tool_button_new() accepts NULL args */
#define MAKE_STOCKBUTTON(p, q) case p##_BUTTON: {\
GtkStockItem item;\
char *label = NULL;\
gtk_stock_lookup(q, &item);\
if (item.label != NULL)\
label = remove_underscores(item.label, false);\
GtkWidget *w = GTK_WIDGET(gtk_tool_button_new(GTK_WIDGET(\
theme->image[p##_BUTTON]), label));\
if (label != NULL) {\
free(label);\
label = NULL;\
}\
return w;\
#define MAKE_STOCKBUTTON(p, q) \
case p##_BUTTON: { \
GtkStockItem item; \
GtkWidget *w; \
if (nsgtk_stock_lookup(q, &item) && \
(item.label != NULL)) { \
char *label = NULL; \
w = GTK_WIDGET(gtk_tool_button_new(GTK_WIDGET( \
theme->image[p##_BUTTON]), label)); \
label = remove_underscores(item.label, false); \
free(label); \
label = NULL; \
} else { \
w = GTK_WIDGET(gtk_tool_button_new(GTK_WIDGET( \
theme->image[p##_BUTTON]), q)); \
} \
return w; \
}
MAKE_STOCKBUTTON(HOME, NSGTK_STOCK_HOME)