1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
void setup_menu_item(MenuItem *menuitem, const char *label, const char *accel_label, const char *image, GtkAccelGroup *menu_files_accel_group, GdkModifierType accel_modifier, guint accel_key, bool is_menu_button) {
/** Generate one menu item according to the given settings **/
menuitem->menuitem = gtk_menu_item_new() ;
menuitem->label = gtk_label_new(label) ;
gtk_label_set_justify(GTK_LABEL(menuitem->label), GTK_JUSTIFY_LEFT);
if (accel_label) {
/** Menu item has an shortcut **/
menuitem->accel_label = gtk_label_new(accel_label) ;
gtk_label_set_justify(GTK_LABEL(menuitem->accel_label), GTK_JUSTIFY_RIGHT) ;
if (accel_key != 0) {
gtk_widget_add_accelerator(menuitem->menuitem,
"activate",
menu_files_accel_group,
accel_key,
accel_modifier,
GTK_ACCEL_VISIBLE);
}
}
if (image) {
/** Menu item has an associate image **/
char *filepath = malloc(PATH_MAX) ;
strcpy(filepath, PATH_TO_MENU_ICON) ;
strcat(filepath, image) ;
menuitem->image = gtk_image_new_from_file(filepath) ;
free(filepath) ;
}
/** Menu item container **/
menuitem->hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0) ;
if (image) {
gtk_box_pack_start(GTK_BOX(menuitem->hbox), menuitem->image, FALSE, FALSE, 0) ;
}
gtk_box_pack_start(GTK_BOX(menuitem->hbox), menuitem->label, FALSE, FALSE, 0) ;
GtkWidget *dummy_label=gtk_label_new("") ; /** For expand between Text and shortcut text **/
gtk_box_pack_start(GTK_BOX(menuitem->hbox), dummy_label, TRUE, TRUE, 0) ;
if (accel_label) {
gtk_box_pack_start(GTK_BOX(menuitem->hbox), menuitem->accel_label, FALSE, FALSE, 0) ;
}
gtk_container_add(GTK_CONTAINER(menuitem->menuitem),menuitem->hbox) ;
return ;
} |
Partager