📄 menu.c
字号:
/*menu.c - manage main menu actionsCopyright (C) 2006 Obada Denis (obadadenis@gmail.com)Project home page : http://tictactoegtk.sourceforge.netThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 2.1 of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/#ifndef menu_c#define menu_c//Data structuresstatic GtkItemFactoryEntry menu_items[] = { { "/_File", NULL, NULL, 0, "<Branch>" }, { "/File/_New Game","<control>N", callnewgame, 0, "<Item>" }, { "/File/filesep", NULL, NULL, 0, "<Separator>"}, { "/File/_Quit", "<control>Q", callexit, 0, "<Item>"}, { "/_Help", NULL, NULL, 0, "<LastBranch>" }, { "/_Help/_About", NULL, call_about, 0, "<Item>" },};static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);//CodeGtkWidget *get_menubar_menu( GtkWidget *window){ GtkItemFactory *item_factory; GtkAccelGroup *accel_group; accel_group = gtk_accel_group_new (); //Create menu bar item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group); //Create menu items gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL); gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); return gtk_item_factory_get_widget (item_factory, "<main>");}void callexit( GtkWidget *w,gpointer data ){//Call Exit confirm dialog and process result#if debugg_printf("callexit()\n");#endif if (confirm_exit_dialog()) gtk_main_quit();}void callnewgame(GtkWidget *w,gpointer data){//Call NewGame confirm dialog and process result#if debugg_printf("callnewgame()\n");#endifif (newgame_confirm()) { init_game(); login(); redraw(); }}gint newgame_confirm(){//Show NewGame confirm dialogGtkWidget *dialog;GtkWidget *label;gint result;#if debugg_printf("newgame_confirm()\n");#endif//Create dialogdialog=gtk_dialog_new_with_buttons(new_game_title,GTK_WINDOW(window),GTK_DIALOG_MODAL,GTK_STOCK_YES,GTK_RESPONSE_ACCEPT,GTK_STOCK_NO,GTK_RESPONSE_REJECT,NULL);gtk_window_set_policy(GTK_WINDOW(dialog),FALSE,FALSE,FALSE);//Create labellabel=gtk_label_new(new_game_str);gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),label);//Show dialoggtk_widget_show_all(dialog);if (gtk_dialog_run(GTK_DIALOG(dialog))==GTK_RESPONSE_ACCEPT) result=1; else result=0;gtk_widget_destroy(dialog);return result;}void call_about(GtkWidget *w,gpointer data){//About DialogGtkWidget *dialog;GtkWidget *label;gint result;#if debugg_printf("callnewgame()\n");#endif//Create dialogdialog=gtk_dialog_new_with_buttons(about_title,GTK_WINDOW(window),GTK_DIALOG_MODAL,GTK_STOCK_OK,GTK_RESPONSE_ACCEPT,NULL);gtk_window_set_policy(GTK_WINDOW(dialog),FALSE,FALSE,FALSE);gtk_widget_set_size_request(dialog,350,200);//Create labellabel=gtk_label_new(NULL);gtk_label_set_markup (GTK_LABEL (label),about_str);gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),label);//Show dialoggtk_widget_show_all(dialog);gtk_dialog_run(GTK_DIALOG(dialog));gtk_widget_destroy(dialog);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -