StockIconMenuItem.h

Go to the documentation of this file.
00001 #ifndef STOCKICONMENUITEM_H_
00002 #define STOCKICONMENUITEM_H_
00003 
00004 #include <gtk/gtklabel.h>
00005 #include <gtk/gtkmenuitem.h>
00006 #include <gtk/gtkhbox.h>
00007 #include <gtk/gtkimage.h>
00008 #include <string>
00009 
00010 namespace gtkutil
00011 {
00012 
00017     class StockIconMenuItem
00018     {
00019         private:
00020 
00021             GtkWidget* _icon;
00022             GtkWidget* _label;
00023 
00024         public:
00025 
00026             // Constructor takes the icon name and the label text.
00027             StockIconMenuItem (const gchar* stockName, const std::string& text) :
00028                 _icon(gtk_image_new_from_stock(stockName, GTK_ICON_SIZE_MENU)), _label(gtk_label_new(text.c_str()))
00029             {
00030             }
00031 
00032             // Operator cast to GtkWidget* packs the widgets into an hbox which
00033             // is then returned.
00034             operator GtkWidget* ()
00035             {
00036                 GtkWidget* hbx = gtk_hbox_new(FALSE, 4);
00037                 gtk_box_pack_start(GTK_BOX(hbx), _icon, FALSE, FALSE, 0);
00038                 gtk_box_pack_start(GTK_BOX(hbx), _label, FALSE, FALSE, 0);
00039 
00040                 GtkWidget* menuItem = gtk_menu_item_new();
00041                 gtk_container_add(GTK_CONTAINER(menuItem), hbx);
00042                 return menuItem;
00043             }
00044 
00045     };
00046 
00047 } // namespace gtkutil
00048 
00049 #endif /*STOCKICONMENUITEM_H_*/

Generated by  doxygen 1.6.2