Re: How to put a pixmap on a GtkMenuItem?
- From: Thierry Brichler <thierry brichler noos fr>
- To: gtk-list gnome org
- Subject: Re: How to put a pixmap on a GtkMenuItem?
- Date: Sat, 23 Mar 2002 16:14:13 +0100
Hello,
Simply create a GtkMenuItem, in which you placed an hbox, which
contains the pixmap and the associated label.
Here is an example :
/* CheckMenu.c */
#include <gtk/gtk.h>
static char *Icon[] = {
/* width height num_colors char_per_pixel */
" 10 9 2 1",
/* colors */
". c None",
"y c #ff1f00",
/* pixels */
"..........",
"........yy",
".......yy.",
"......yy..",
".yyy.yy...",
"..yyyy....",
"...yy.....",
"..........",
"..........",
};
int
main (int argc, char *argv[])
{
GtkWidget *Fenetre;
GtkWidget *MenuBar;
GtkWidget *Menu;
GtkWidget *MenuItem;
GtkWidget *Label;
GtkWidget *hbox;
/*==================================================*/
/*============== Pixmap declarations ====================*/
/*===================================================*/
GtkWidget *Pixmap;
GdkPixmap *PixmapIcon;
GdkBitmap *MaskIcon;
GdkColor transparent;
/*===================================================*/
/*============== End Pixmap declarations =================*/
/*===================================================*/
gtk_init (&argc, &argv);
Fenetre = gtk_window_new (GTK_WINDOW_TOPLEVEL);
/* Connexion des signaux "delete" et "destroy" */
gtk_signal_connect (GTK_OBJECT (Fenetre), "delete_event",
(GtkSignalFunc) gtk_exit, NULL);
gtk_signal_connect (GTK_OBJECT (Fenetre), "destroy",
(GtkSignalFunc) gtk_exit, NULL);
/*=================================================*/
/*============= Dealing with the pixmap =================*/
/*=================================================*/
gtk_widget_realize (Fenetre);
PixmapIcon = gdk_pixmap_create_from_xpm_d (Fenetre->window,
&MaskIcon, &transparent, Icon);
Pixmap = gtk_pixmap_new (PixmapIcon, MaskIcon);
gdk_pixmap_unref (PixmapIcon);
/*================================================*/
/*============= End Dealing with the pixmap ============*/
/*================================================*/
MenuBar = gtk_menu_bar_new ();
gtk_container_add (GTK_CONTAINER (Fenetre), MenuBar);
MenuItem = gtk_menu_item_new_with_label ("Cases");
gtk_menu_bar_append (GTK_MENU_BAR (MenuBar), MenuItem);
Menu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (MenuItem), Menu);
MenuItem = gtk_menu_item_new ();
/*=================================================*/
/*============= Including the pixmap in the Menu Item ======*/
/*=================================================*/
hbox = gtk_hbox_new (FALSE, 5);
gtk_box_pack_start_defaults (GTK_BOX (hbox), Pixmap);
Label = gtk_label_new ("Case 1");
gtk_box_pack_start_defaults (GTK_BOX (hbox), Label);
gtk_container_add (GTK_CONTAINER (MenuItem), hbox);
/*================================================*/
/*============= End Including the pixmap in the Menu Item ==*/
/*================================================*/
gtk_menu_append (GTK_MENU (Menu), MenuItem);
MenuItem = gtk_menu_item_new_with_label ("Case 2");
gtk_menu_append (GTK_MENU (Menu), MenuItem);
MenuItem = gtk_menu_item_new_with_label ("Quitter");
gtk_menu_bar_append (GTK_MENU_BAR (MenuBar), MenuItem);
gtk_signal_connect (GTK_OBJECT (MenuItem), "activate",
(GtkSignalFunc) gtk_exit, NULL);
gtk_menu_item_right_justify (GTK_MENU_ITEM (MenuItem));
gtk_widget_show_all (Fenetre);
/* La boucle principale */
gtk_main ();
}
Regards, Thierry Brichler
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]