?? appwindow.c
字號:
/* Application main window * * Demonstrates a typical application window with menubar, toolbar, statusbar. */#include <gtk/gtk.h>#include "config.h"#include "demo-common.h"static GtkWidget *window = NULL;static voidactivate_action (GtkAction *action){ const gchar *name = gtk_action_get_name (action); const gchar *typename = G_OBJECT_TYPE_NAME (action); GtkWidget *dialog; dialog = gtk_message_dialog_new (GTK_WINDOW (window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "You activated action: \"%s\" of type \"%s\"", name, typename); /* Close dialog on user response */ g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); gtk_widget_show (dialog);}static voidactivate_radio_action (GtkAction *action, GtkRadioAction *current){ const gchar *name = gtk_action_get_name (GTK_ACTION (current)); const gchar *typename = G_OBJECT_TYPE_NAME (GTK_ACTION (current)); gboolean active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current)); gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current)); if (active) { GtkWidget *dialog; dialog = gtk_message_dialog_new (GTK_WINDOW (window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "You activated radio action: \"%s\" of type \"%s\".\n" "Current value: %d", name, typename, value); /* Close dialog on user response */ g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); gtk_widget_show (dialog); }}static void activate_email (GtkAboutDialog *about, const gchar *link, gpointer data){ g_print ("send mail to %s\n", link);static void activate_url (GtkAboutDialog *about, const gchar *link, gpointer data){ g_print ("show url %s\n", link);}static voidabout_cb (GtkAction *action, GtkWidget *window){ GdkPixbuf *pixbuf, *transparent; gchar *filename; const gchar *authors[] = { "Peter Mattis", "Spencer Kimball", "Josh MacDonald", "and many more...", NULL }; const gchar *documentors[] = { "Owen Taylor", "Tony Gale", "Matthias Clasen <mclasen@redhat.com>", "and many more...", NULL }; const gchar *license = "This library is free software; you can redistribute it and/or\n" "modify it under the terms of the GNU Library General Public License as\n" "published by the Free Software Foundation; either version 2 of the\n" "License, or (at your option) any later version.\n" "\n" "This library is distributed in the hope that it will be useful,\n" "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" "Library General Public License for more details.\n" "\n" "You should have received a copy of the GNU Library General Public\n" "License along with the Gnome Library; see the file COPYING.LIB. If not,\n" "write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\n" "Boston, MA 02111-1307, USA.\n"; pixbuf = NULL; transparent = NULL; filename = demo_find_file ("gtk-logo-rgb.gif", NULL); if (filename) { pixbuf = gdk_pixbuf_new_from_file (filename, NULL); g_free (filename); transparent = gdk_pixbuf_add_alpha (pixbuf, TRUE, 0xff, 0xff, 0xff); g_object_unref (pixbuf); } gtk_about_dialog_set_email_hook (activate_email, NULL, NULL); gtk_about_dialog_set_url_hook (activate_url, NULL, NULL); gtk_show_about_dialog (GTK_WINDOW (window), "name", "GTK+ Code Demos", "version", PACKAGE_VERSION, "copyright", "(C) 1997-2005 The GTK+ Team", "license", license, "website", "http://www.gtk.org", "comments", "Program to demonstrate GTK+ functions.", "authors", authors, "documenters", documentors, "logo", transparent, "title", "About GTK+ Code Demos", NULL); g_object_unref (transparent);}typedef struct { GtkAction action;} ToolMenuAction;typedef struct { GtkActionClass parent_class;} ToolMenuActionClass;G_DEFINE_TYPE(ToolMenuAction, tool_menu_action, GTK_TYPE_ACTION)static voidtool_menu_action_class_init (ToolMenuActionClass *class){ GTK_ACTION_CLASS (class)->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;}static voidtool_menu_action_init (ToolMenuAction *action){}static GtkActionEntry entries[] = { { "FileMenu", NULL, "_File" }, /* name, stock id, label */ { "OpenMenu", NULL, "_Open" }, /* name, stock id, label */ { "PreferencesMenu", NULL, "_Preferences" }, /* name, stock id, label */ { "ColorMenu", NULL, "_Color" }, /* name, stock id, label */ { "ShapeMenu", NULL, "_Shape" }, /* name, stock id, label */ { "HelpMenu", NULL, "_Help" }, /* name, stock id, label */ { "New", GTK_STOCK_NEW, /* name, stock id */ "_New", "<control>N", /* label, accelerator */ "Create a new file", /* tooltip */ G_CALLBACK (activate_action) }, { "File1", NULL, /* name, stock id */ "File1", NULL, /* label, accelerator */ "Open first file", /* tooltip */ G_CALLBACK (activate_action) }, { "Save", GTK_STOCK_SAVE, /* name, stock id */ "_Save","<control>S", /* label, accelerator */ "Save current file", /* tooltip */ G_CALLBACK (activate_action) }, { "SaveAs", GTK_STOCK_SAVE, /* name, stock id */ "Save _As...", NULL, /* label, accelerator */ "Save to a file", /* tooltip */ G_CALLBACK (activate_action) }, { "Quit", GTK_STOCK_QUIT, /* name, stock id */ "_Quit", "<control>Q", /* label, accelerator */ "Quit", /* tooltip */ G_CALLBACK (activate_action) }, { "About", NULL, /* name, stock id */ "_About", "<control>A", /* label, accelerator */ "About", /* tooltip */ G_CALLBACK (about_cb) }, { "Logo", "demo-gtk-logo", /* name, stock id */ NULL, NULL, /* label, accelerator */ "GTK+", /* tooltip */ G_CALLBACK (activate_action) },};static guint n_entries = G_N_ELEMENTS (entries);static GtkToggleActionEntry toggle_entries[] = { { "Bold", GTK_STOCK_BOLD, /* name, stock id */ "_Bold", "<control>B", /* label, accelerator */ "Bold", /* tooltip */ G_CALLBACK (activate_action), TRUE }, /* is_active */};static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries);enum { COLOR_RED, COLOR_GREEN, COLOR_BLUE};static GtkRadioActionEntry color_entries[] = { { "Red", NULL, /* name, stock id */ "_Red", "<control>R", /* label, accelerator */ "Blood", COLOR_RED }, /* tooltip, value */ { "Green", NULL, /* name, stock id */ "_Green", "<control>G", /* label, accelerator */ "Grass", COLOR_GREEN }, /* tooltip, value */ { "Blue", NULL, /* name, stock id */ "_Blue", "<control>B", /* label, accelerator */ "Sky", COLOR_BLUE }, /* tooltip, value */};static guint n_color_entries = G_N_ELEMENTS (color_entries);enum { SHAPE_SQUARE, SHAPE_RECTANGLE, SHAPE_OVAL};static GtkRadioActionEntry shape_entries[] = { { "Square", NULL, /* name, stock id */ "_Square", "<control>S", /* label, accelerator */ "Square", SHAPE_SQUARE }, /* tooltip, value */ { "Rectangle", NULL, /* name, stock id */ "_Rectangle", "<control>R", /* label, accelerator */ "Rectangle", SHAPE_RECTANGLE }, /* tooltip, value */ { "Oval", NULL, /* name, stock id */ "_Oval", "<control>O", /* label, accelerator */ "Egg", SHAPE_OVAL }, /* tooltip, value */ };static guint n_shape_entries = G_N_ELEMENTS (shape_entries);static const gchar *ui_info = "<ui>"" <menubar name='MenuBar'>"" <menu action='FileMenu'>"" <menuitem action='New'/>"" <menuitem action='Open'/>"" <menuitem action='Save'/>"" <menuitem action='SaveAs'/>"" <separator/>"" <menuitem action='Quit'/>"" </menu>"" <menu action='PreferencesMenu'>"" <menu action='ColorMenu'>"" <menuitem action='Red'/>"" <menuitem action='Green'/>"" <menuitem action='Blue'/>"" </menu>"" <menu action='ShapeMenu'>"" <menuitem action='Square'/>"" <menuitem action='Rectangle'/>"" <menuitem action='Oval'/>"" </menu>"" <menuitem action='Bold'/>"" </menu>"" <menu action='HelpMenu'>"" <menuitem action='About'/>"" </menu>"" </menubar>"" <toolbar name='ToolBar'>"" <toolitem action='Open'>"" <menu action='OpenMenu'>"" <menuitem action='File1'/>"" </menu>" " </toolitem>"" <toolitem action='Quit'/>"" <separator action='Sep1'/>"" </toolbar>""</ui>";
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -