Utility function to create a button with a stock icon.

2003-04-14  Not Zed  <NotZed@Ximian.com>

        * e-gtk-utils.c (e_gtk_button_new_with_icon): Utility function to
        create a button with a stock icon.

svn path=/trunk/; revision=20843
This commit is contained in:
Not Zed
2003-04-15 01:08:52 +00:00
committed by Michael Zucci
parent fb04925566
commit 0cf177cc2d
3 changed files with 56 additions and 0 deletions

View File

@ -1,3 +1,8 @@
2003-04-14 Not Zed <NotZed@Ximian.com>
* e-gtk-utils.c (e_gtk_button_new_with_icon): Utility function to
create a button with a stock icon.
2003-04-09 Jeffrey Stedfast <fejj@ximian.com>
* e-host-utils.c (e_gethostbyaddr_r): Change the 'len' argument to

View File

@ -28,6 +28,12 @@
#include <gtk/gtklayout.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkwidget.h>
#include <gtk/gtkbutton.h>
#include <gtk/gtkstock.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkimage.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtkalignment.h>
#include <gdk/gdkx.h>
@ -167,3 +173,46 @@ e_make_widget_backing_stored (GtkWidget *widget)
{
g_signal_connect (widget, "realize", G_CALLBACK (widget_realize_callback_for_backing_store), NULL);
}
/**
* e_gtk_button_new_with_icon:
* @text: The mnemonic text for the label.
* @stock: The name of the stock item to get the icon from.
*
* Create a gtk button with a custom label and a stock icon.
*
*
* Return value: The widget.
**/
GtkWidget *
e_gtk_button_new_with_icon(const char *text, const char *stock)
{
GtkWidget *button, *label;
GtkStockItem item;
button = gtk_button_new();
label = gtk_label_new_with_mnemonic(text);
gtk_label_set_mnemonic_widget((GtkLabel *)label, button);
if (gtk_stock_lookup(stock, &item)) {
GtkWidget *image, *hbox, *align;
printf("new stock button '%s' label '%s'\n", stock, text);
image = gtk_image_new_from_stock(stock, GTK_ICON_SIZE_BUTTON);
hbox = gtk_hbox_new(FALSE, 2);
align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
gtk_box_pack_start((GtkBox *)hbox, image, FALSE, FALSE, 0);
gtk_box_pack_end((GtkBox *)hbox, label, FALSE, FALSE, 0);
gtk_container_add((GtkContainer *)align, hbox);
gtk_container_add((GtkContainer *)button, align);
gtk_widget_show_all(align);
} else {
gtk_misc_set_alignment((GtkMisc *)label, 0.5, 0.5);
gtk_container_add((GtkContainer *)button, label);
gtk_widget_show(label);
}
return button;
}

View File

@ -44,4 +44,6 @@ void e_signal_connect_full_while_alive (void *instance,
void e_make_widget_backing_stored (GtkWidget *widget);
GtkWidget *e_gtk_button_new_with_icon(const char *text, const char *stock);
#endif