diff options
author | Not Zed <NotZed@Ximian.com> | 2003-04-15 09:08:52 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2003-04-15 09:08:52 +0800 |
commit | 0cf177cc2dc95096b9235adc242f3c698f1d9bee (patch) | |
tree | 3d9f7edd23e3d6f9bea68b4b067dd7984d7cd403 | |
parent | fb04925566a101e3d0995cf715ea2128e801548c (diff) | |
download | gsoc2013-evolution-0cf177cc2dc95096b9235adc242f3c698f1d9bee.tar.gz gsoc2013-evolution-0cf177cc2dc95096b9235adc242f3c698f1d9bee.tar.zst gsoc2013-evolution-0cf177cc2dc95096b9235adc242f3c698f1d9bee.zip |
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
-rw-r--r-- | e-util/ChangeLog | 5 | ||||
-rw-r--r-- | e-util/e-gtk-utils.c | 49 | ||||
-rw-r--r-- | e-util/e-gtk-utils.h | 2 |
3 files changed, 56 insertions, 0 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index c7c91c1a27..fd727c9505 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -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 diff --git a/e-util/e-gtk-utils.c b/e-util/e-gtk-utils.c index 9b9c7f99b7..345f092e8d 100644 --- a/e-util/e-gtk-utils.c +++ b/e-util/e-gtk-utils.c @@ -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; +} diff --git a/e-util/e-gtk-utils.h b/e-util/e-gtk-utils.h index 19d208ffec..cebb5b757d 100644 --- a/e-util/e-gtk-utils.h +++ b/e-util/e-gtk-utils.h @@ -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 |