IconTextButton.h

Go to the documentation of this file.
00001 #ifndef ICONTEXTBUTTON_H_
00002 #define ICONTEXTBUTTON_H_
00003 
00004 #include <gtk/gtklabel.h>
00005 #include <gtk/gtkvbox.h>
00006 #include <gtk/gtkbutton.h>
00007 #include <gtk/gtktogglebutton.h>
00008 
00009 namespace gtkutil
00010 {
00011 
00015     class IconTextButton
00016     {
00017             // Icon pixbuf
00018             GdkPixbuf* _icon;
00019 
00020             // Label widget
00021             GtkWidget* _label;
00022 
00023             // Toggle button flag
00024             bool _isToggle;
00025 
00026         public:
00027 
00033             IconTextButton (const std::string& name, GdkPixbuf* icon, bool isToggle) :
00034                 _icon(icon), _label(NULL), _isToggle(isToggle)
00035             {
00036                 if (name != "") {
00037                     _label = gtk_label_new(name.c_str());
00038                 }
00039             }
00040 
00044             operator GtkWidget* ()
00045             {
00046                 // Create vbox containing image and label
00047                 GtkWidget* vbx = gtk_vbox_new(FALSE, 3);
00048                 gtk_box_pack_start(GTK_BOX(vbx), gtk_image_new_from_pixbuf(_icon), TRUE, FALSE, 0);
00049                 if (_label != NULL) {
00050                     gtk_box_pack_end(GTK_BOX(vbx), _label, TRUE, FALSE, 0);
00051                 }
00052 
00053                 // Create a button and add the vbox
00054                 GtkWidget* button;
00055                 if (_isToggle)
00056                     button = gtk_toggle_button_new();
00057                 else
00058                     button = gtk_button_new();
00059                 gtk_container_add(GTK_CONTAINER(button), vbx);
00060 
00061                 // Set the button to standard size
00062                 int w = 3 * gdk_pixbuf_get_width(_icon);
00063                 gtk_widget_set_size_request(button, w, -1);
00064 
00065                 // Return the button
00066                 return button;
00067             }
00068     };
00069 
00070 }
00071 
00072 #endif /*ICONTEXTBUTTON_H_*/

Generated by  doxygen 1.6.2