menus.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include "xgdipc.h"
  2. #if (GTK_MINOR_VERSION < 1 && GTK_MAJOR_VERSION <= 1)
  3. static GtkMenuEntry menu[] = {
  4. {"<Main>/File/About", "<control>A", show_about, NULL},
  5. {"<Main>/File/<separator>", NULL, NULL, NULL},
  6. {"<Main>/File/Exit", "<control>X", gtk_main_quit, NULL}};
  7. void get_main_menu(GtkWidget *window, GtkWidget **menubar) {
  8. int nmenu_items = sizeof(menu) / sizeof(menu[0]);
  9. GtkMenuFactory *factory;
  10. GtkMenuFactory *subfactory;
  11. factory = gtk_menu_factory_new(GTK_MENU_FACTORY_MENU_BAR);
  12. subfactory = gtk_menu_factory_new(GTK_MENU_FACTORY_MENU_BAR);
  13. gtk_menu_factory_add_subfactory(factory, subfactory, "<Main>");
  14. gtk_menu_factory_add_entries(factory, menu, nmenu_items);
  15. gtk_window_add_accelerator_table(GTK_WINDOW(window), subfactory->table);
  16. if (menubar)
  17. *menubar = subfactory->widget;
  18. }
  19. #else
  20. void get_main_menu(GtkWidget *window, GtkWidget *vbox) {
  21. GtkWidget *menubar;
  22. GtkWidget *menubox;
  23. GtkAccelGroup *accel;
  24. GtkItemFactory *factory;
  25. GtkItemFactoryEntry menu[] = {{"/_File", "<alt>F", NULL, 0, "<Branch>"},
  26. {"/File/About", "<control>A", show_about, 0},
  27. {"/File/sep1", NULL, NULL, 0, "<Separator>"},
  28. {"/File/Exit", "<control>X", gtk_main_quit, 0}};
  29. int nmenu_items = sizeof(menu) / sizeof(menu[0]);
  30. accel = gtk_accel_group_new();
  31. factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<Main>", accel);
  32. gtk_item_factory_create_items(factory, nmenu_items, menu, NULL);
  33. menubar = gtk_item_factory_get_widget(factory, "<Main>");
  34. menubox = gtk_handle_box_new();
  35. gtk_accel_group_attach(accel, GTK_OBJECT(window));
  36. gtk_container_add(GTK_CONTAINER(menubox), menubar);
  37. gtk_box_pack_start(GTK_BOX(vbox), menubox, FALSE, TRUE, 0);
  38. gtk_widget_show(menubox);
  39. gtk_widget_show(menubar);
  40. }
  41. #endif
  42. void show_about(GtkWidget *widget, gpointer data) {
  43. GtkWidget *window;
  44. GtkWidget *table;
  45. GtkWidget *label1;
  46. GtkWidget *label2;
  47. GtkWidget *button;
  48. GtkWidget *box1;
  49. GtkWidget *pixmapwid;
  50. GdkBitmap *mask;
  51. GdkPixmap *pixmap;
  52. GtkStyle *style;
  53. window = gtk_window_new(GTK_WINDOW_DIALOG);
  54. gtk_signal_connect(GTK_OBJECT(window), "destroy",
  55. GTK_SIGNAL_FUNC(gtk_widget_destroy), window);
  56. gtk_window_set_title(GTK_WINDOW(window), "About: X-GnuDIP2");
  57. gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE);
  58. gtk_widget_realize(window);
  59. table = gtk_table_new(8, 4, TRUE);
  60. gtk_container_add(GTK_CONTAINER(window), table);
  61. style = gtk_widget_get_style(window);
  62. pixmap = gdk_pixmap_create_from_xpm(GTK_WIDGET(window)->window, &mask,
  63. &style->bg[GTK_STATE_NORMAL],
  64. #ifdef XPMPATH
  65. XPMPATH);
  66. #else
  67. "xgdip.xpm");
  68. #endif
  69. pixmapwid = gtk_pixmap_new(pixmap, mask);
  70. gtk_widget_show(pixmapwid);
  71. label1 = gtk_label_new("By: Mike Machado <mike@innercite.com>");
  72. label2 = gtk_label_new(" Ryan Wahle <wahle@innercite.com>");
  73. gtk_widget_show(label1);
  74. gtk_widget_show(label2);
  75. gtk_table_attach_defaults(GTK_TABLE(table), pixmapwid, 0, 4, 2, 4);
  76. gtk_table_attach_defaults(GTK_TABLE(table), label1, 0, 4, 5, 6);
  77. gtk_table_attach_defaults(GTK_TABLE(table), label2, 0, 4, 6, 7);
  78. button = gtk_button_new_with_label("Ok");
  79. gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
  80. GTK_SIGNAL_FUNC(gtk_widget_destroy),
  81. GTK_OBJECT(window));
  82. gtk_widget_show(button);
  83. gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 3, 7, 8);
  84. gtk_widget_show(table);
  85. gtk_widget_show(window);
  86. }