static VALUE ifact_create_item(int argc, VALUE *argv, VALUE self) { VALUE path, type, accel, extdata, data, func; GtkItemFactoryEntry *entry; rb_scan_args(argc, argv, "14", &path, &type, &accel, &extdata, &data); entry = ALLOC(GtkItemFactoryEntry); func = rb_rescue((VALUE(*)())rb_block_proc, 0, NULL, 0); create_factory_entry(entry, self, path, type, accel, extdata, func, data); gtk_item_factory_create_item(_SELF(self), entry, (gpointer)self, 1); g_free(entry); return self; }
/****************************************************************************** * gtk_ItemFactoryCreateItems( itemFactory, array_entry ) --> NIL ******************************************************************************/ int clip_GTK_ITEMFACTORYCREATEITEMS(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); ClipArrVar *cventry = (ClipArrVar *)_clip_vptr(_clip_par(cm, 2)); gint i, n ; CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, ARRAY_t); n = cventry->count; for (i=0; i<n; i++) { ClipArrVar *it = (ClipArrVar *)_clip_vptr(cventry->items[i].a.items); ClipVar *cfunc ; C_var *c ; GtkItemFactoryEntry entry; entry.path = (it->items[0].t.type==UNDEF_t)?NULL:it->items[0].s.str.buf; entry.accelerator = (it->items[1].t.type==UNDEF_t)?NULL:it->items[1].s.str.buf; cfunc = (it->items[2].t.type==UNDEF_t)?NULL:&it->items[2]; c = NEW(C_var); c->cm = cm; c->co = citem; _clip_mclone(cm, &c->cfunc, cfunc); entry.callback = (cfunc==NULL)?0:(GtkItemFactoryCallback1)_item_factory_callback1; entry.callback_action = 1; entry.item_type = (it->items[4].t.type==UNDEF_t)?0:it->items[4].s.str.buf; //citem->destroy = __itemfactory_destroy_data; //citem->data = c; gtk_item_factory_create_item(GTK_ITEM_FACTORY(citem->object), &entry, c, 1); } return 0; err: return 1; }
PRIVATE GtkItemFactory *get_new_ifact( void ) { GtkItemFactory *ifact = gtk_item_factory_new(GTK_TYPE_MENU, "<new>", NULL); GList *lst = menuentries; while (lst != NULL) { MenuEntry *m = lst->data; GtkItemFactoryEntry ent = { m->menupath, NULL, newmenu_callback, 0, NULL }; gtk_item_factory_create_item(ifact, &ent, m, 1); lst = g_list_next(lst); } menuentries_dirty = FALSE; return ifact; }
/****************************************************************************** * gtk_ItemFactoryCreateItem( itemFactory, entry, ncallback_type ) --> NIL * entry is array with elements: * - path, string (f.e. "_File") * - accelerator, string or NIL (f.e. "<control>N" ) * - callback function, code block or 0 (f.e code block or 0) * - callback action, numeric (f.e. 1) * - item type, string or NIL (f.e. "<RadioItem>") * possible values: * NIL -> "<Item>" * "" -> "<Item>" * "<Title>" -> create a title item * "<Item>" -> create a simple item * "<ImageItem>" -> create an item holding an image * "<StockItem>" -> create an item holding a stock image * "<CheckItem>" -> create a check item * "<ToggleItem>" -> create a toggle item * "<RadioItem>" -> create a radio item * <path> -> path of a radio item to link against * "<Separator>" -> create a separator * "<Tearoff>" -> create a tearoff separator * "<Branch>" -> create an item to hold sub items * "<LastBranch>" -> create a right justified item to hold sub items *****************************************************************************/ int clip_GTK_ITEMFACTORYCREATEITEM(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); ClipArrVar *cventry = (ClipArrVar *)_clip_vptr(_clip_par(cm, 2)); gint type = INT_OPTION(cm, 3, 1); GtkItemFactoryEntry entry ; ClipVar *cfunc ; C_var *data ; CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, ARRAY_t); CHECKARG(3, NUMERIC_t); entry.path = (cventry->items[0].t.type==UNDEF_t)?NULL:cventry->items[0].s.str.buf; entry.accelerator = (cventry->items[1].t.type==UNDEF_t)?NULL:cventry->items[1].s.str.buf; cfunc = &cventry->items[2]; data = NEW(C_var); data->cm = cm; data->co = citem; _clip_mclone(cm, &data->cfunc, cfunc); if (type == 1) entry.callback = (cfunc==NULL)?0:(GtkItemFactoryCallback1)_item_factory_callback1; else entry.callback = (cfunc==NULL)?0:(GtkItemFactoryCallback2)_item_factory_callback2; entry.callback_action = (cventry->items[3].t.type==UNDEF_t)?0:(guint)cventry->items[3].n.d; entry.item_type = (cventry->items[4].t.type==UNDEF_t)?NULL:cventry->items[4].s.str.buf; gtk_item_factory_create_item(GTK_ITEM_FACTORY(citem->object), &entry, data, type); return 0; err: return 1; }
static void layers_panel_init ( VikLayersPanel *vlp ) { GtkWidget *hbox; GtkWidget *addbutton, *addimage; GtkWidget *removebutton, *removeimage; GtkWidget *upbutton, *upimage; GtkWidget *downbutton, *downimage; GtkWidget *cutbutton, *cutimage; GtkWidget *copybutton, *copyimage; GtkWidget *pastebutton, *pasteimage; GtkWidget *scrolledwindow; GtkItemFactoryEntry entry; guint i, tmp; vlp->vvp = NULL; hbox = gtk_hbox_new ( TRUE, 2 ); vlp->vt = vik_treeview_new ( ); vlp->toplayer = vik_aggregate_layer_new (); vik_layer_rename ( VIK_LAYER(vlp->toplayer), _("Top Layer")); g_signal_connect_swapped ( G_OBJECT(vlp->toplayer), "update", G_CALLBACK(vik_layers_panel_emit_update), vlp ); vik_treeview_add_layer ( vlp->vt, NULL, &(vlp->toplayer_iter), VIK_LAYER(vlp->toplayer)->name, NULL, vlp->toplayer, VIK_LAYER_AGGREGATE, VIK_LAYER_AGGREGATE ); vik_layer_realize ( VIK_LAYER(vlp->toplayer), vlp->vt, &(vlp->toplayer_iter) ); g_signal_connect_swapped ( vlp->vt, "popup_menu", G_CALLBACK(menu_popup_cb), vlp); g_signal_connect_swapped ( vlp->vt, "button_press_event", G_CALLBACK(layers_button_press_cb), vlp); g_signal_connect_swapped ( vlp->vt, "item_toggled", G_CALLBACK(layers_item_toggled), vlp); g_signal_connect_swapped ( vlp->vt, "item_edited", G_CALLBACK(layers_item_edited), vlp); g_signal_connect_swapped ( vlp->vt, "key_press_event", G_CALLBACK(layers_key_press_cb), vlp); /* Add button */ addimage = gtk_image_new_from_stock ( GTK_STOCK_ADD, GTK_ICON_SIZE_SMALL_TOOLBAR ); addbutton = gtk_button_new ( ); gtk_container_add ( GTK_CONTAINER(addbutton), addimage ); gtk_widget_set_tooltip_text ( GTK_WIDGET(addbutton), _("Add new layer")); gtk_box_pack_start ( GTK_BOX(hbox), addbutton, TRUE, TRUE, 0 ); g_signal_connect_swapped ( G_OBJECT(addbutton), "clicked", G_CALLBACK(layers_popup_cb), vlp ); /* Remove button */ removeimage = gtk_image_new_from_stock ( GTK_STOCK_REMOVE, GTK_ICON_SIZE_SMALL_TOOLBAR ); removebutton = gtk_button_new ( ); gtk_container_add ( GTK_CONTAINER(removebutton), removeimage ); gtk_widget_set_tooltip_text ( GTK_WIDGET(removebutton), _("Remove selected layer")); gtk_box_pack_start ( GTK_BOX(hbox), removebutton, TRUE, TRUE, 0 ); g_signal_connect_swapped ( G_OBJECT(removebutton), "clicked", G_CALLBACK(vik_layers_panel_delete_selected), vlp ); /* Up button */ upimage = gtk_image_new_from_stock ( GTK_STOCK_GO_UP, GTK_ICON_SIZE_SMALL_TOOLBAR ); upbutton = gtk_button_new ( ); gtk_container_add ( GTK_CONTAINER(upbutton), upimage ); gtk_widget_set_tooltip_text ( GTK_WIDGET(upbutton), _("Move selected layer up")); gtk_box_pack_start ( GTK_BOX(hbox), upbutton, TRUE, TRUE, 0 ); g_signal_connect_swapped ( G_OBJECT(upbutton), "clicked", G_CALLBACK(layers_move_item_up), vlp ); /* Down button */ downimage = gtk_image_new_from_stock ( GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_SMALL_TOOLBAR ); downbutton = gtk_button_new ( ); gtk_container_add ( GTK_CONTAINER(downbutton), downimage ); gtk_widget_set_tooltip_text ( GTK_WIDGET(downbutton), _("Move selected layer down")); gtk_box_pack_start ( GTK_BOX(hbox), downbutton, TRUE, TRUE, 0 ); g_signal_connect_swapped ( G_OBJECT(downbutton), "clicked", G_CALLBACK(layers_move_item_down), vlp ); /* Cut button */ cutimage = gtk_image_new_from_stock ( GTK_STOCK_CUT, GTK_ICON_SIZE_SMALL_TOOLBAR ); cutbutton = gtk_button_new ( ); gtk_container_add ( GTK_CONTAINER(cutbutton), cutimage ); gtk_widget_set_tooltip_text ( GTK_WIDGET(cutbutton), _("Cut selected layer")); gtk_box_pack_start ( GTK_BOX(hbox), cutbutton, TRUE, TRUE, 0 ); g_signal_connect_swapped ( G_OBJECT(cutbutton), "clicked", G_CALLBACK(vik_layers_panel_cut_selected), vlp ); /* Copy button */ copyimage = gtk_image_new_from_stock ( GTK_STOCK_COPY, GTK_ICON_SIZE_SMALL_TOOLBAR ); copybutton = gtk_button_new ( ); gtk_container_add ( GTK_CONTAINER(copybutton), copyimage ); gtk_widget_set_tooltip_text ( GTK_WIDGET(copybutton), _("Copy selected layer")); gtk_box_pack_start ( GTK_BOX(hbox), copybutton, TRUE, TRUE, 0 ); g_signal_connect_swapped ( G_OBJECT(copybutton), "clicked", G_CALLBACK(vik_layers_panel_copy_selected), vlp ); /* Paste button */ pasteimage = gtk_image_new_from_stock ( GTK_STOCK_PASTE, GTK_ICON_SIZE_SMALL_TOOLBAR ); pastebutton = gtk_button_new ( ); gtk_container_add ( GTK_CONTAINER(pastebutton),pasteimage ); gtk_widget_set_tooltip_text ( GTK_WIDGET(pastebutton), _("Paste layer below selected layer")); gtk_box_pack_start ( GTK_BOX(hbox), pastebutton, TRUE, TRUE, 0 ); g_signal_connect_swapped ( G_OBJECT(pastebutton), "clicked", G_CALLBACK(vik_layers_panel_paste_selected), vlp ); scrolledwindow = gtk_scrolled_window_new ( NULL, NULL ); gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC ); gtk_container_add ( GTK_CONTAINER(scrolledwindow), GTK_WIDGET(vlp->vt) ); gtk_box_pack_start ( GTK_BOX(vlp), scrolledwindow, TRUE, TRUE, 0 ); gtk_box_pack_start ( GTK_BOX(vlp), hbox, FALSE, FALSE, 0 ); vlp->popup_factory = gtk_item_factory_new ( GTK_TYPE_MENU, "<main>", NULL ); gtk_item_factory_create_items ( vlp->popup_factory, NUM_BASE_ENTRIES, base_entries, vlp ); for ( i = 0; i < VIK_LAYER_NUM_TYPES; i++ ) { /* TODO: FIXME: if name has a '/' in it it will get all messed up. why not have an itemfactory field with name, icon, shortcut, etc.? */ /* Note: we use a temporary label in order to share translation with other codde */ gchar *label = g_strdup_printf(_("New %s Layer"), vik_layer_get_interface(i)->name ); entry.path = g_strdup_printf("%s/%s", base_entries[NUM_BASE_ENTRIES-1].path, label ); g_free ( label ); entry.accelerator = NULL; entry.callback = (GtkItemFactoryCallback) vik_layers_panel_new_layer; entry.callback_action = i; if ( vik_layer_get_interface(i)->icon ) { entry.item_type = "<ImageItem>"; entry.extra_data = gdk_pixdata_serialize ( vik_layer_get_interface(i)->icon, &tmp ); } else entry.item_type = "<Item>"; gtk_item_factory_create_item ( vlp->popup_factory, &entry, vlp, 1 ); g_free ( (gpointer) entry.extra_data ); g_free ( entry.path ); } }
void gui_init () { GtkWidget *hbox = NULL, *vbox = NULL, *vbox1 = NULL, *frame = NULL; GtkWidget *separator; GtkAccelGroup *ag; GtkItemFactoryEntry game_items [num_games+1]; GtkItemFactoryEntry items[] = { #if GTK_MAJOR_VERSION == 1 /* { "/_File", NULL, NULL, 0, "<Branch>" }, { "/File/_Load game", "<control>L", menu_load_file_dialog, 0, "" }, { "/File/_Save game", NULL, NULL, 0, "" }, { "/File/_Quit", "<control>Q", (GtkSignalFunc) ui_cleanup, 0, "" }, */ { "/_Game", NULL, NULL, 0, "<Branch>" }, { "/Game/Select _Game", NULL, NULL, 0, "<LastBranch>" }, { "/Game/_Levels", NULL, NULL, 0, "<Branch>"}, { "/Game/Sep1", NULL, NULL, 0, "<Separator>" }, { "/Game/_New", "<control>N", menu_start_stop_game, MENU_RESET_GAME, "" }, { "/Game/_Start", "<control>G", menu_start_stop_game, MENU_START_GAME, "" }, { "/Game/_Pause", "<control>P", menu_start_stop_game, MENU_STOP_GAME, "" }, { "/Game/Sep2", NULL, NULL, 0, "<Separator>" }, { "/Game/_Highscores", NULL, prefs_show_scores, 0, ""}, { "/Game/_Zap Highscores", NULL, prefs_zap_highscores, 0, ""}, { "/Game/Sep3", NULL, NULL, 0, "<Separator>" }, { "/Game/_Quit", "<control>Q", (GtkSignalFunc) ui_cleanup, 0, "" }, { "/_Move", NULL, NULL, 0, "<Branch>" }, { "/Move/_Back", "<control>B", menu_back_forw, MENU_BACK, "" }, { "/Move/_Forward", "<control>F", menu_back_forw, MENU_FORW, "" }, { "/Move/Sep1", NULL, NULL, 0, "<Separator>" }, { "/Move/_Move Now", "<control>M", (GtkItemFactoryCallback) ui_move_now_cb, 0, "" }, #else /* { "/_File", NULL, NULL, 0, "<Branch>" }, { "/File/_Load game", "<control>L", menu_load_file_dialog, 0, "<StockItem>", GTK_STOCK_OPEN }, { "/File/_Save game", NULL, menu_save_file_dialog, 0, "<StockItem>", GTK_STOCK_SAVE }, { "/File/_Quit", "<control>Q", (GtkSignalFunc) ui_cleanup, 0, "<StockItem>", GTK_STOCK_QUIT }, */ { "/_Game", NULL, NULL, 0, "<Branch>" }, { "/Game/Select _Game", NULL, NULL, 0, "<LastBranch>" }, { "/Game/Levels", NULL, NULL, 0, "<Branch>"}, { "/Game/Sep1", NULL, NULL, 0, "<Separator>" }, { "/Game/_New", "<control>N", menu_start_stop_game, MENU_RESET_GAME, "<StockItem>", GTK_STOCK_NEW }, { "/Game/_Start", "<control>G", menu_start_stop_game, MENU_START_GAME, "<StockItem>", GTK_STOCK_YES }, { "/Game/_Pause", "<control>P", menu_start_stop_game, MENU_STOP_GAME, "<StockItem>", GTK_STOCK_STOP }, { "/Game/Sep2", NULL, NULL, 0, "<Separator>" }, //FIXME: there's a scores stock item but I can't seem to find it { "/Game/_Highscores", NULL, prefs_show_scores, 0, ""}, { "/Game/_Zap Highscores", NULL, prefs_zap_highscores, 0, ""}, { "/Game/Sep3", NULL, NULL, 0, "<Separator>" }, { "/Game/_Quit", "<control>Q", (GtkSignalFunc) ui_cleanup, 0, "<StockItem>", GTK_STOCK_QUIT }, { "/_Move", NULL, NULL, 0, "<Branch>" }, { "/Move/_Back", "<control>B", menu_back_forw, 1, "<StockItem>", GTK_STOCK_GO_BACK }, { "/Move/_Forward", "<control>F", menu_back_forw, 2, "<StockItem>", GTK_STOCK_GO_FORWARD }, { "/Move/Sep1", NULL, NULL, 0, "<Separator>" }, { "/Move/_Move Now", "<control>M", (GtkItemFactoryCallback) ui_move_now_cb, 0, "" }, #endif { "/_Settings", NULL, NULL, 0, "<Branch>" }, { "/Settings/_Player", NULL, NULL, 0, "<Branch>" }, { "/Settings/Player/File", NULL, NULL, 0, "<RadioItem>" }, { "/Settings/Player/Human-Human", NULL, menu_set_player, 1, "/Settings/Player/File" }, { "/Settings/Player/Human-Machine", NULL, menu_set_player, 2, "/Settings/Player/File" }, { "/Settings/Player/Machine-Human", NULL, menu_set_player, 3, "/Settings/Player/File" }, { "/Settings/Player/Machine-Machine", NULL, menu_set_player, 4, "/Settings/Player/File" }, // { "/Settings/_Eval function", NULL, NULL, 0, "<Branch>" }, // { "/Settings/_Eval function/_White", NULL, NULL, 0, "<Branch>" }, // { "/Settings/_Eval function/_Black", NULL, NULL, 0, "<Branch>" }, { "/Settings/_Flip Board", "<control>T", menu_board_flip_cb, 0, "" }, { "/Settings/_Enable Sound", NULL, menu_enable_sound_cb, 1, ""}, { "/Settings/_Disable Sound", NULL, menu_enable_sound_cb, 0, ""}, { "/Settings/_Time per move", NULL, NULL, 0, "<Branch>" }, { "/Settings/_Time per move/Default", NULL, menu_set_delay_cb, DEF_TIME_PER_MOVE, "<RadioItem>" }, { "/Settings/_Time per move/100 milliseconds", NULL, menu_set_delay_cb, 100, "/Settings/Time per move/Default" }, { "/Settings/Time per move/200 milliseconds", NULL, menu_set_delay_cb, 200, "/Settings/Time per move/Default" }, { "/Settings/Time per move/500 milliseconds", NULL, menu_set_delay_cb, 500, "/Settings/Time per move/Default" }, { "/Settings/Time per move/1 second", NULL, menu_set_delay_cb, 1000, "/Settings/Time per move/Default" }, { "/Settings/Time per move/2 seconds", NULL, menu_set_delay_cb, 2000, "/Settings/Time per move/Default" }, { "/Settings/Time per move/5 seconds", NULL, menu_set_delay_cb, 5000, "/Settings/Time per move/Default" }, { "/Settings/Time per move/10 seconds", NULL, menu_set_delay_cb, 10000, "/Settings/Time per move/Default" }, { "/Settings/Time per move/30 seconds", NULL, menu_set_delay_cb, 30000, "/Settings/Time per move/Default" }, { "/Settings/Time per move/1 minute", NULL, menu_set_delay_cb, 600000, "/Settings/Time per move/Default" }, { "/_Help", NULL, NULL, 0, "<Branch>" }, { "/Help/_About", NULL, menu_show_about_dialog, 0, ""}, #ifdef HAVE_GNOME { "/Help/_Home Page", NULL, menu_help_home_page, 0, "<StockItem>", GTK_STOCK_HOME}, #endif // TODO: implement context help // { "/Help/_Context help", NULL, ui_set_context_help, 0, ""}, }; int i; gdk_rgb_init (); main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_policy (GTK_WINDOW (main_window), FALSE, FALSE, TRUE); gtk_signal_connect (GTK_OBJECT (main_window), "delete_event", GTK_SIGNAL_FUNC(ui_cleanup), NULL); gtk_window_set_title (GTK_WINDOW (main_window), "Gtkboard"); ag = gtk_accel_group_new(); menu_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", ag); gtk_window_add_accel_group (GTK_WINDOW (main_window), ag); gtk_item_factory_create_items (menu_factory, sizeof (items) / sizeof (items[0]), items, NULL); for (i=0; i<=num_games; i++) { if (i==0) game_items[i].path = "/Game/Select Game/none"; else { if (games[i-1]->group) { GtkItemFactoryEntry group_item = {NULL, NULL, NULL, 0, "<Branch>"}; group_item.path = g_strdup_printf ("/Game/Select Game/%s", games[i-1]->group); // FIXME: this is O(N^2) where N is the number of games if (gtk_item_factory_get_widget (menu_factory, group_item.path) == NULL) gtk_item_factory_create_item (menu_factory, &group_item, NULL, 1); game_items[i].path = g_strdup_printf ("/Game/Select Game/%s/%s", games[i-1]->group ? games[i-1]->group : "", games[i-1]->name); } else game_items[i].path = g_strdup_printf ("/Game/Select Game/%s", games[i-1]->name); } game_items[i].accelerator = NULL; game_items[i].callback = menu_set_game; game_items[i].callback_action = i-1; game_items[i].item_type = (i == 0 ? "<RadioItem>": "/Game/Select Game/none"); } gtk_item_factory_create_items (menu_factory, num_games+1, game_items, NULL); // ugly hack to create a group of radio button with no button selected by default gtk_item_factory_delete_item (menu_factory, "/Game/Select Game/none"); menu_main = gtk_item_factory_get_widget (menu_factory, "<main>"); gtk_widget_set_state (gtk_item_factory_get_widget (menu_factory, "/Settings/Player/File"), GTK_STATE_INSENSITIVE); for (i=1; i<=NUM_RECENT_GAMES; i++) { gchar *tmp; gchar *gamename; gamename = prefs_get_config_val (tmp = g_strdup_printf ("recent_game_%d", i)); g_free (tmp); if (gamename && gamename[0] != '\0') menu_insert_game_item (gamename, i); } menu_set_eval_function (); vbox = gtk_vbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX(vbox), menu_main, FALSE, FALSE, 0); frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); { GtkWidget *innerframe; board_colbox = gtk_vbox_new (FALSE, 0); board_area = gtk_drawing_area_new (); hbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), board_colbox, FALSE, FALSE, 0); vbox1 = gtk_vbox_new (FALSE, 0); board_rowbox = gtk_hbox_new (FALSE, 0); innerframe = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (innerframe), GTK_SHADOW_IN); gtk_container_add (GTK_CONTAINER (vbox1), innerframe); gtk_container_add (GTK_CONTAINER (innerframe), board_area); gtk_container_add (GTK_CONTAINER (vbox1), board_rowbox); gtk_box_pack_start (GTK_BOX (hbox), vbox1, TRUE, FALSE, 0); gtk_container_add (GTK_CONTAINER (frame), hbox); gtk_signal_connect (GTK_OBJECT (board_area), "expose_event", GTK_SIGNAL_FUNC (board_redraw), NULL); gtk_widget_set_events(board_area, gtk_widget_get_events (board_area) | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK ); gtk_signal_connect (GTK_OBJECT (board_area), "leave_notify_event", GTK_SIGNAL_FUNC (board_signal_handler), NULL); gtk_signal_connect (GTK_OBJECT (board_area), "motion_notify_event", GTK_SIGNAL_FUNC (board_signal_handler), NULL); gtk_signal_connect (GTK_OBJECT (board_area), "button_release_event", GTK_SIGNAL_FUNC (board_signal_handler), NULL); gtk_signal_connect (GTK_OBJECT (board_area), "button_press_event", GTK_SIGNAL_FUNC (board_signal_handler), NULL); gtk_signal_connect (GTK_OBJECT (main_window), "key_press_event", GTK_SIGNAL_FUNC (board_signal_handler), NULL); gtk_signal_connect (GTK_OBJECT (main_window), "key_release_event", GTK_SIGNAL_FUNC (board_signal_handler), NULL); menu_info_bar = hbox = gtk_hbox_new (FALSE, 0); sb_game_label = gtk_label_new (opt_game ? opt_game->name : NULL); gtk_box_pack_start (GTK_BOX (hbox), sb_game_label, FALSE, FALSE, 3); sb_game_separator = gtk_vseparator_new (); gtk_box_pack_start (GTK_BOX (hbox), sb_game_separator, FALSE, FALSE, 0); sb_player_label = gtk_label_new (NULL); gtk_box_pack_start (GTK_BOX (hbox), sb_player_label, FALSE, FALSE, 3); sb_player_separator = gtk_vseparator_new (); gtk_box_pack_start (GTK_BOX (hbox), sb_player_separator, FALSE, FALSE, 0); sb_who_label = gtk_label_new (NULL); gtk_box_pack_start (GTK_BOX (hbox), sb_who_label, FALSE, FALSE, 3); sb_who_separator = gtk_vseparator_new (); gtk_box_pack_start (GTK_BOX (hbox), sb_who_separator, FALSE, FALSE, 0); sb_score_label = gtk_label_new (NULL); gtk_box_pack_start (GTK_BOX (hbox), sb_score_label, FALSE, FALSE, 3); sb_score_separator = gtk_vseparator_new (); gtk_box_pack_start (GTK_BOX (hbox), sb_score_separator, FALSE, FALSE, 0); #if GTK_MAJOR_VERSION == 2 sb_turn_image = gtk_image_new_from_stock (GTK_STOCK_YES, GTK_ICON_SIZE_MENU); gtk_box_pack_end (GTK_BOX (hbox), sb_turn_image, FALSE, FALSE, 0); sb_turn_separator = gtk_vseparator_new (); gtk_box_pack_end (GTK_BOX (hbox), sb_turn_separator, FALSE, FALSE, 0); #endif sb_time_label = gtk_label_new (NULL); gtk_box_pack_end (GTK_BOX (hbox), sb_time_label, FALSE, FALSE, 0); sb_time_separator = gtk_vseparator_new (); gtk_box_pack_end (GTK_BOX (hbox), sb_time_separator, FALSE, FALSE, 0); } menu_info_separator = separator = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); separator = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0); menu_warning_bar = gtk_label_new ("Warning: this game has not yet been completely implemented."); gtk_box_pack_start (GTK_BOX (vbox), menu_warning_bar, FALSE, FALSE, 0); sb_warning_separator = separator = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); separator = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0); sb_message_label = gtk_label_new (NULL); gtk_misc_set_alignment (GTK_MISC (sb_message_label), 0, 0.5); hbox = gtk_hbox_new (TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), sb_message_label, TRUE, TRUE, 3); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (main_window), vbox); // FIXME: board_init() needs show() to be called to get a gc, but // leads to the whole window not popping up at once gtk_widget_show_all (main_window); if (!opt_game) board_init (); gtk_timeout_add (100, sb_update_periodic, NULL); // this should be called before setting state_gui_active = TRUE if (opt_game) menu_put_game (); state_gui_active = TRUE; if (opt_game) menu_start_game (); menu_put_player (TRUE); // if (!opt_game) sb_message ("Select a game from the Game menu", FALSE); sb_update (); }
/** * gwy_graph_func_build_menu: * @item_factory: A #GtkItemFactory to add items to. * @prefix: Where to add the menu items to the factory. * @item_callback: A #GtkItemFactoryCallback1 called when an item from the * menu is selected. * * Creates #GtkItemFactory for a graph menu with all registered graph * functions. * * Returns: The menu item factory as a #GtkObject. **/ GtkObject* gwy_graph_func_build_menu(GtkObject *item_factory, const gchar *prefix, GCallback item_callback) { GtkItemFactoryEntry branch = { NULL, NULL, NULL, 0, "<Branch>", NULL }; GtkItemFactoryEntry tearoff = { NULL, NULL, NULL, 0, "<Tearoff>", NULL }; GtkItemFactoryEntry item = { NULL, NULL, item_callback, 0, "<Item>", NULL }; GtkItemFactory *factory; GString *current, *prev; const gchar *mpath; GSList *l, *entries = NULL; gint i, dp_len; g_return_val_if_fail(GTK_IS_ITEM_FACTORY(item_factory), NULL); factory = GTK_ITEM_FACTORY(item_factory); if (!graph_funcs) { g_warning("No graph function present to build menu of"); entries = NULL; } else g_hash_table_foreach(graph_funcs, gwy_hash_table_to_slist_cb, &entries); entries = g_slist_sort(entries, (GCompareFunc)graph_menu_entry_compare); dp_len = strlen(prefix); /* the root branch */ current = g_string_new(prefix); /* the root tearoff */ prev = g_string_new(prefix); g_string_append(prev, "/---"); tearoff.path = prev->str; gtk_item_factory_create_item(factory, &tearoff, NULL, 1); /* create missing branches * XXX: Gtk+ essentially can do this itself * but this way we can e. g. put a tearoff at the top of each branch... */ for (l = entries; l; l = g_slist_next(l)) { GraphFuncInfo *func_info = (GraphFuncInfo*)l->data; mpath = func_info->menu_path_translated; if (!mpath || !*mpath) continue; if (mpath[0] != '/') { g_warning("Menu path `%s' doesn't start with a slash", mpath); continue; } g_string_truncate(current, dp_len); g_string_append(current, mpath); /* find where the paths differ */ i = gwy_strdiffpos(current->str + dp_len, prev->str + dp_len); if (!current->str[i] && !prev->str[i]) g_warning("Duplicate menu entry `%s'", mpath); else { /* find where the next / is */ do { i++; } while (current->str[i] && current->str[i] != '/'); } while (current->str[i]) { /* create a branch with a tearoff */ current->str[i] = '\0'; branch.path = current->str; gtk_item_factory_create_item(factory, &branch, NULL, 1); g_string_assign(prev, current->str); g_string_append(prev, "/---"); tearoff.path = prev->str; gtk_item_factory_create_item(factory, &tearoff, NULL, 1); current->str[i] = '/'; /* find where the next / is */ do { i++; } while (current->str[i] && current->str[i] != '/'); } /* XXX: passing directly func_info->name may be a little dangerous, * OTOH who would eventually free a newly allocated string? */ item.path = current->str; gtk_item_factory_create_item(factory, &item, (gpointer)func_info->info.name, 1); GWY_SWAP(GString*, current, prev); } g_string_free(prev, TRUE); g_string_free(current, TRUE); g_slist_free(entries); return item_factory; }
GtkWidget *create_menubar(GtkWidget *window) { GtkItemFactory *item_factory; GtkAccelGroup *accel_group; struct dirent **namelist; int n; const char *script_path=config_get_string(CONFIG_PATH_SCRIPT); GtkItemFactoryEntry fentry; struct menu_script* menu_item; char *dot; /* Make an accelerator group (shortcut keys) */ accel_group = gtk_accel_group_new (); /* Make an ItemFactory (that makes a menubar) */ item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group); /* This function generates the menu items. Pass the item factory, the number of items in the array, the array itself, and any callback data for the the menu items. */ gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL); if (script_path) { n = scandir(script_path, &namelist, select_lua, alphasort); if (n > 0) { while(n--) { log_printf(LOG_INFO,"Adding %s script to menu", namelist[n]->d_name); menu_item=(struct menu_script *)malloc(sizeof(struct menu_script)); menu_item->script_name = (char* )malloc(strlen(namelist[n]->d_name)+11); strcpy(menu_item->script_name,"/Analyser/"); strcat(menu_item->script_name,namelist[n]->d_name); dot = rindex(menu_item->script_name,'.'); if (dot) *dot=0; menu_item->script_file = strdup(namelist[n]->d_name); menu_item->prev=SCRIPTS; SCRIPTS = menu_item; fentry.path=menu_item->script_name; fentry.callback=G_CALLBACK(gui_run_script_cb); fentry.callback_action=0; fentry.item_type="<StockItem>"; fentry.extra_data=GTK_STOCK_PROPERTIES; gtk_item_factory_create_item(item_factory,&fentry,menu_item,2); } free(namelist); } else log_printf(LOG_WARNING,"No scripts found in %s",script_path); } /* FIXME: namelist must be deallocated but it holds pointer data for the callback */ /* Attach the new accelerator group to the window. */ gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); /* Finally, return the actual menu bar created by the item factory. */ return gtk_item_factory_get_widget (item_factory, "<main>"); }