📄 testgtk.c
字号:
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); button = gtk_button_new_with_label ("close"); gtk_signal_connect_object (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT (window)); gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); gtk_widget_grab_default (button); } if (!GTK_WIDGET_VISIBLE (window)) gtk_widget_show_all (window); else gtk_widget_destroy (window);}/* * GtkButtonBox */static GtkWidget *create_bbox (gint horizontal, char* title, gint spacing, gint child_w, gint child_h, gint layout){ GtkWidget *frame; GtkWidget *bbox; GtkWidget *button; frame = gtk_frame_new (title); if (horizontal) bbox = gtk_hbutton_box_new (); else bbox = gtk_vbutton_box_new (); gtk_container_border_width (GTK_CONTAINER (bbox), 5); gtk_container_add (GTK_CONTAINER (frame), bbox); gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout); gtk_button_box_set_spacing (GTK_BUTTON_BOX (bbox), spacing); gtk_button_box_set_child_size (GTK_BUTTON_BOX (bbox), child_w, child_h); button = gtk_button_new_with_label ("OK"); gtk_container_add (GTK_CONTAINER (bbox), button); button = gtk_button_new_with_label ("Cancel"); gtk_container_add (GTK_CONTAINER (bbox), button); button = gtk_button_new_with_label ("Help"); gtk_container_add (GTK_CONTAINER (bbox), button); return frame;}static voidcreate_button_box (void){ static GtkWidget* window = NULL; GtkWidget *main_vbox; GtkWidget *vbox; GtkWidget *hbox; GtkWidget *frame_horz; GtkWidget *frame_vert; if (!window) { window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "Button Boxes"); gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &window); gtk_container_border_width (GTK_CONTAINER (window), 10); main_vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (window), main_vbox); frame_horz = gtk_frame_new ("Horizontal Button Boxes"); gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz, TRUE, TRUE, 10); vbox = gtk_vbox_new (FALSE, 0); gtk_container_border_width (GTK_CONTAINER (vbox), 10); gtk_container_add (GTK_CONTAINER (frame_horz), vbox); gtk_box_pack_start (GTK_BOX (vbox), create_bbox (TRUE, "Spread", 40, 85, 20, GTK_BUTTONBOX_SPREAD), TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), create_bbox (TRUE, "Edge", 40, 85, 20, GTK_BUTTONBOX_EDGE), TRUE, TRUE, 5); gtk_box_pack_start (GTK_BOX (vbox), create_bbox (TRUE, "Start", 40, 85, 20, GTK_BUTTONBOX_START), TRUE, TRUE, 5); gtk_box_pack_start (GTK_BOX (vbox), create_bbox (TRUE, "End", 40, 85, 20, GTK_BUTTONBOX_END), TRUE, TRUE, 5); frame_vert = gtk_frame_new ("Vertical Button Boxes"); gtk_box_pack_start (GTK_BOX (main_vbox), frame_vert, TRUE, TRUE, 10); hbox = gtk_hbox_new (FALSE, 0); gtk_container_border_width (GTK_CONTAINER (hbox), 10); gtk_container_add (GTK_CONTAINER (frame_vert), hbox); gtk_box_pack_start (GTK_BOX (hbox), create_bbox (FALSE, "Spread", 30, 85, 20, GTK_BUTTONBOX_SPREAD), TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), create_bbox (FALSE, "Edge", 30, 85, 20, GTK_BUTTONBOX_EDGE), TRUE, TRUE, 5); gtk_box_pack_start (GTK_BOX (hbox), create_bbox (FALSE, "Start", 30, 85, 20, GTK_BUTTONBOX_START), TRUE, TRUE, 5); gtk_box_pack_start (GTK_BOX (hbox), create_bbox (FALSE, "End", 30, 85, 20, GTK_BUTTONBOX_END), TRUE, TRUE, 5); } if (!GTK_WIDGET_VISIBLE (window)) gtk_widget_show_all (window); else gtk_widget_destroy (window);}/* * GtkToolBar */static GtkWidget*new_pixmap (char *filename, GdkWindow *window, GdkColor *background){ GtkWidget *wpixmap; GdkPixmap *pixmap; GdkBitmap *mask; pixmap = gdk_pixmap_create_from_xpm (window, &mask, background, filename); wpixmap = gtk_pixmap_new (pixmap, mask); return wpixmap;}static voidset_toolbar_horizontal (GtkWidget *widget, gpointer data){ gtk_toolbar_set_orientation (GTK_TOOLBAR (data), GTK_ORIENTATION_HORIZONTAL);}static voidset_toolbar_vertical (GtkWidget *widget, gpointer data){ gtk_toolbar_set_orientation (GTK_TOOLBAR (data), GTK_ORIENTATION_VERTICAL);}static voidset_toolbar_icons (GtkWidget *widget, gpointer data){ gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_ICONS);}static voidset_toolbar_text (GtkWidget *widget, gpointer data){ gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_TEXT);}static voidset_toolbar_both (GtkWidget *widget, gpointer data){ gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_BOTH);}static voidset_toolbar_small_space (GtkWidget *widget, gpointer data){ gtk_toolbar_set_space_size (GTK_TOOLBAR (data), 5);}static voidset_toolbar_big_space (GtkWidget *widget, gpointer data){ gtk_toolbar_set_space_size (GTK_TOOLBAR (data), 10);}static voidset_toolbar_enable (GtkWidget *widget, gpointer data){ gtk_toolbar_set_tooltips (GTK_TOOLBAR (data), TRUE);}static voidset_toolbar_disable (GtkWidget *widget, gpointer data){ gtk_toolbar_set_tooltips (GTK_TOOLBAR (data), FALSE);}static voidset_toolbar_borders (GtkWidget *widget, gpointer data){ gtk_toolbar_set_button_relief (GTK_TOOLBAR (data), GTK_RELIEF_NORMAL);}static voidset_toolbar_borderless (GtkWidget *widget, gpointer data){ gtk_toolbar_set_button_relief (GTK_TOOLBAR (data), GTK_RELIEF_NONE);}static voidcreate_toolbar (void){ static GtkWidget *window = NULL; GtkWidget *toolbar; GtkWidget *entry; if (!window) { window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "Toolbar test"); gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, TRUE); gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (gtk_widget_destroyed), &window); gtk_container_border_width (GTK_CONTAINER (window), 0); gtk_widget_realize (window); toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH); gtk_toolbar_set_button_relief (GTK_TOOLBAR (toolbar), GTK_RELIEF_NONE); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Horizontal", "Horizontal toolbar layout", "Toolbar/Horizontal", new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_horizontal, toolbar); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Vertical", "Vertical toolbar layout", "Toolbar/Vertical", new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_vertical, toolbar); gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Icons", "Only show toolbar icons", "Toolbar/IconsOnly", new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_icons, toolbar); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Text", "Only show toolbar text", "Toolbar/TextOnly", new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_text, toolbar); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Both", "Show toolbar icons and text", "Toolbar/Both", new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_both, toolbar); gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); entry = gtk_entry_new (); gtk_toolbar_append_widget (GTK_TOOLBAR (toolbar), entry, "This is an unusable GtkEntry ;)", "Hey don't click me!!!"); gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Small", "Use small spaces", "Toolbar/Small", new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_small_space, toolbar); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Big", "Use big spaces", "Toolbar/Big", new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_big_space, toolbar); gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Enable", "Enable tooltips", NULL, new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_enable, toolbar); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Disable", "Disable tooltips", NULL, new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_disable, toolbar); gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Borders", "Show Borders", NULL, new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_borders, toolbar); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Borderless", "Hide Borders", NULL, new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_borderless, toolbar); gtk_container_add (GTK_CONTAINER (window), toolbar); } if (!GTK_WIDGET_VISIBLE (window)) gtk_widget_show_all (window); else gtk_widget_destroy (window);}static GtkWidget*make_toolbar (GtkWidget *window){ GtkWidget *toolbar; if (!GTK_WIDGET_REALIZED (window)) gtk_widget_realize (window); toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH); gtk_toolbar_set_button_relief (GTK_TOOLBAR (toolbar), GTK_RELIEF_NONE); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Horizontal", "Horizontal toolbar layout", NULL, new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_horizontal, toolbar); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Vertical", "Vertical toolbar layout", NULL, new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_vertical, toolbar); gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Icons", "Only show toolbar icons", NULL, new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_icons, toolbar); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Text", "Only show toolbar text", NULL, new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_text, toolbar); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Both", "Show toolbar icons and text", NULL, new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_both, toolbar); gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Small", "Use small spaces", NULL, new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_small_space, toolbar); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Big", "Use big spaces", "Toolbar/Big", new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_big_space, toolbar); gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Enable", "Enable tooltips", NULL, new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_enable, toolbar); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Disable", "Disable tooltips", NULL, new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_disable, toolbar); gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Borders", "Show Borders", NULL, new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_borders, toolbar); gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), "Borderless", "Hide Borders", NULL, new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), (GtkSignalFunc) set_toolbar_borderless, toolbar); return toolbar;}/* * GtkStatusBar */static guint statusbar_counter = 1;static voidstatusbar_push (GtkWidget *button, GtkStatusbar *statusbar){ gchar text[1024]; sprintf (text, "something %d", statusbar_counter++); gtk_statusbar_push (statusbar, 1, text);}static voidstatusbar_pop (GtkWidget *button, GtkStatusbar *statusbar){ gtk_statusbar_pop (statusbar, 1);}static void
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -