⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testgtk.c

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 C
📖 第 1 页 / 共 5 页
字号:
  /* create scrolled window */  scrolled_win = gtk_scrolled_window_new (NULL, NULL);  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),				  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);  gtk_box_pack_start (GTK_BOX (box2), scrolled_win, TRUE, TRUE, 0);  gtk_widget_set_usize (scrolled_win, 200, 200);  gtk_widget_show (scrolled_win);    /* create root tree widget */  root_tree = gtk_tree_new();  gtk_signal_connect(GTK_OBJECT(root_tree), "selection_changed",		     (GtkSignalFunc)cb_tree_changed,		     (gpointer)NULL);  gtk_object_set_user_data(GTK_OBJECT(root_tree), tree_buttons);  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), root_tree);  gtk_tree_set_selection_mode(GTK_TREE(root_tree), selection_mode);  gtk_tree_set_view_lines(GTK_TREE(root_tree), draw_line);  gtk_tree_set_view_mode(GTK_TREE(root_tree), !view_line);  gtk_widget_show(root_tree);  if ( no_root_item )    {      /* set root tree to subtree function with root item variable */      root_item = GTK_WIDGET(root_tree);    }  else    {      /* create root tree item widget */      root_item = gtk_tree_item_new_with_label("root item");      gtk_tree_append(GTK_TREE(root_tree), root_item);      gtk_widget_show(root_item);     }  create_subtree(root_item, -no_root_item, nb_item_max, recursion_level_max);  box2 = gtk_vbox_new(FALSE, 0);  gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0);  gtk_container_set_border_width(GTK_CONTAINER(box2), 5);  gtk_widget_show(box2);  button = gtk_button_new_with_label("Add Item");  gtk_widget_set_sensitive(button, FALSE);  gtk_signal_connect(GTK_OBJECT (button), "clicked",		     (GtkSignalFunc) cb_add_new_item, 		     (gpointer)root_tree);  gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);  gtk_widget_show(button);  tree_buttons->add_button = button;  button = gtk_button_new_with_label("Remove Item(s)");  gtk_widget_set_sensitive(button, FALSE);  gtk_signal_connect(GTK_OBJECT (button), "clicked",		     (GtkSignalFunc) cb_remove_item, 		     (gpointer)root_tree);  gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);  gtk_widget_show(button);  tree_buttons->remove_button = button;  button = gtk_button_new_with_label("Remove Subtree");  gtk_widget_set_sensitive(button, FALSE);  gtk_signal_connect(GTK_OBJECT (button), "clicked",		     (GtkSignalFunc) cb_remove_subtree, 		     (gpointer)root_tree);  gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);  gtk_widget_show(button);  tree_buttons->subtree_button = button;  /* create separator */  separator = gtk_hseparator_new();  gtk_box_pack_start(GTK_BOX(box1), separator, FALSE, FALSE, 0);  gtk_widget_show(separator);  /* create button box */  box2 = gtk_vbox_new(FALSE, 0);  gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0);  gtk_container_set_border_width(GTK_CONTAINER(box2), 5);  gtk_widget_show(box2);  button = gtk_button_new_with_label("Close");  gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);  gtk_signal_connect_object(GTK_OBJECT (button), "clicked",			    (GtkSignalFunc) gtk_widget_destroy, 			    GTK_OBJECT(window));  gtk_widget_show(button);  gtk_widget_show(window);}static voidcb_create_tree(GtkWidget* w){  guint selection_mode = GTK_SELECTION_SINGLE;  guint view_line;  guint draw_line;  guint no_root_item;  guint nb_item;  guint recursion_level;  /* get selection mode choice */  if(GTK_TOGGLE_BUTTON(sTreeSampleSelection.single_button)->active)    selection_mode = GTK_SELECTION_SINGLE;  else    if(GTK_TOGGLE_BUTTON(sTreeSampleSelection.browse_button)->active)      selection_mode = GTK_SELECTION_BROWSE;    else      selection_mode = GTK_SELECTION_MULTIPLE;  /* get options choice */  draw_line = GTK_TOGGLE_BUTTON(sTreeSampleSelection.draw_line_button)->active;  view_line = GTK_TOGGLE_BUTTON(sTreeSampleSelection.view_line_button)->active;  no_root_item = GTK_TOGGLE_BUTTON(sTreeSampleSelection.no_root_item_button)->active;      /* get levels */  nb_item = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(sTreeSampleSelection.nb_item_spinner));  recursion_level = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(sTreeSampleSelection.recursion_spinner));  if (pow (nb_item, recursion_level) > 10000)    {      g_print ("%g total items? That will take a very long time. Try less\n",	       pow (nb_item, recursion_level));      return;    }  create_tree_sample(selection_mode, draw_line, view_line, no_root_item, nb_item, recursion_level);}void create_tree_mode_window(void){  static GtkWidget* window;  GtkWidget* box1;  GtkWidget* box2;  GtkWidget* box3;  GtkWidget* box4;  GtkWidget* box5;  GtkWidget* button;  GtkWidget* frame;  GtkWidget* separator;  GtkWidget* label;  GtkWidget* spinner;  GtkAdjustment *adj;  if (!window)    {      /* create toplevel window  */      window = gtk_window_new(GTK_WINDOW_TOPLEVEL);      gtk_window_set_title(GTK_WINDOW(window), "Set Tree Parameters");      gtk_signal_connect (GTK_OBJECT (window), "destroy",			  GTK_SIGNAL_FUNC(gtk_widget_destroyed),			  &window);      box1 = gtk_vbox_new(FALSE, 0);      gtk_container_add(GTK_CONTAINER(window), box1);      /* create upper box - selection box */      box2 = gtk_vbox_new(FALSE, 5);      gtk_box_pack_start(GTK_BOX(box1), box2, TRUE, TRUE, 0);      gtk_container_set_border_width(GTK_CONTAINER(box2), 5);      box3 = gtk_hbox_new(FALSE, 5);      gtk_box_pack_start(GTK_BOX(box2), box3, TRUE, TRUE, 0);      /* create selection mode frame */      frame = gtk_frame_new("Selection Mode");      gtk_box_pack_start(GTK_BOX(box3), frame, TRUE, TRUE, 0);      box4 = gtk_vbox_new(FALSE, 0);      gtk_container_add(GTK_CONTAINER(frame), box4);      gtk_container_set_border_width(GTK_CONTAINER(box4), 5);      /* create radio button */        button = gtk_radio_button_new_with_label(NULL, "SINGLE");      gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);      sTreeSampleSelection.single_button = button;      button = gtk_radio_button_new_with_label(gtk_radio_button_group (GTK_RADIO_BUTTON (button)),					       "BROWSE");      gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);      sTreeSampleSelection.browse_button = button;      button = gtk_radio_button_new_with_label(gtk_radio_button_group (GTK_RADIO_BUTTON (button)),					       "MULTIPLE");      gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);      sTreeSampleSelection.multiple_button = button;      sTreeSampleSelection.selection_mode_group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));      /* create option mode frame */      frame = gtk_frame_new("Options");      gtk_box_pack_start(GTK_BOX(box3), frame, TRUE, TRUE, 0);      box4 = gtk_vbox_new(FALSE, 0);      gtk_container_add(GTK_CONTAINER(frame), box4);      gtk_container_set_border_width(GTK_CONTAINER(box4), 5);      /* create check button */      button = gtk_check_button_new_with_label("Draw line");      gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);      sTreeSampleSelection.draw_line_button = button;        button = gtk_check_button_new_with_label("View Line mode");      gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);      sTreeSampleSelection.view_line_button = button;        button = gtk_check_button_new_with_label("Without Root item");      gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0);      sTreeSampleSelection.no_root_item_button = button;      /* create recursion parameter */      frame = gtk_frame_new("Size Parameters");      gtk_box_pack_start(GTK_BOX(box2), frame, TRUE, TRUE, 0);      box4 = gtk_hbox_new(FALSE, 5);      gtk_container_add(GTK_CONTAINER(frame), box4);      gtk_container_set_border_width(GTK_CONTAINER(box4), 5);      /* create number of item spin button */      box5 = gtk_hbox_new(FALSE, 5);      gtk_box_pack_start(GTK_BOX(box4), box5, FALSE, FALSE, 0);      label = gtk_label_new("Number of items : ");      gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);      gtk_box_pack_start (GTK_BOX (box5), label, FALSE, TRUE, 0);      adj = (GtkAdjustment *) gtk_adjustment_new ((gfloat)DEFAULT_NUMBER_OF_ITEM, 1.0, 255.0, 1.0,						  5.0, 0.0);      spinner = gtk_spin_button_new (adj, 0, 0);      gtk_box_pack_start (GTK_BOX (box5), spinner, FALSE, TRUE, 0);      sTreeSampleSelection.nb_item_spinner = spinner;        /* create recursion level spin button */      box5 = gtk_hbox_new(FALSE, 5);      gtk_box_pack_start(GTK_BOX(box4), box5, FALSE, FALSE, 0);      label = gtk_label_new("Depth : ");      gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);      gtk_box_pack_start (GTK_BOX (box5), label, FALSE, TRUE, 0);      adj = (GtkAdjustment *) gtk_adjustment_new ((gfloat)DEFAULT_RECURSION_LEVEL, 0.0, 255.0, 1.0,						  5.0, 0.0);      spinner = gtk_spin_button_new (adj, 0, 0);      gtk_box_pack_start (GTK_BOX (box5), spinner, FALSE, TRUE, 0);      sTreeSampleSelection.recursion_spinner = spinner;        /* create horizontal separator */      separator = gtk_hseparator_new();      gtk_box_pack_start(GTK_BOX(box1), separator, FALSE, FALSE, 0);      /* create bottom button box */      box2 = gtk_hbox_new(TRUE, 10);      gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0);      gtk_container_set_border_width(GTK_CONTAINER(box2), 5);      button = gtk_button_new_with_label("Create Tree");      gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);      gtk_signal_connect(GTK_OBJECT (button), "clicked",			 (GtkSignalFunc) cb_create_tree, NULL);      button = gtk_button_new_with_label("Close");      gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0);      gtk_signal_connect_object (GTK_OBJECT (button), "clicked",                                 GTK_SIGNAL_FUNC(gtk_widget_destroy),                                 GTK_OBJECT (window));    }  if (!GTK_WIDGET_VISIBLE (window))    gtk_widget_show_all (window);  else    gtk_widget_destroy (window);}/* * GtkHandleBox */static voidhandle_box_child_signal (GtkHandleBox *hb,			 GtkWidget    *child,			 const gchar  *action){  printf ("%s: child <%s> %sed\n",	  gtk_type_name (GTK_OBJECT_TYPE (hb)),	  gtk_type_name (GTK_OBJECT_TYPE (child)),	  action);}static voidcreate_handle_box (void){  static GtkWidget* window = NULL;  GtkWidget *handle_box;  GtkWidget *handle_box2;  GtkWidget *vbox;  GtkWidget *hbox;  GtkWidget *toolbar;  GtkWidget *label;  GtkWidget *separator;	  if (!window)  {    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);    gtk_window_set_title (GTK_WINDOW (window),			  "Handle Box Test");    gtk_window_set_policy (GTK_WINDOW (window),			   TRUE,			   TRUE,			   TRUE);        gtk_signal_connect (GTK_OBJECT (window), "destroy",			GTK_SIGNAL_FUNC(gtk_widget_destroyed),			&window);        gtk_container_set_border_width (GTK_CONTAINER (window), 20);    vbox = gtk_vbox_new (FALSE, 0);    gtk_container_add (GTK_CONTAINER (window), vbox);    gtk_widget_show (vbox);    label = gtk_label_new ("Above");    gtk_container_add (GTK_CONTAINER (vbox), label);    gtk_widget_show (label);    separator = gtk_hseparator_new ();    gtk_container_add (GTK_CONTAINER (vbox), separator);    gtk_widget_show (separator);        hbox = gtk_hbox_new (FALSE, 10);    gtk_container_add (GTK_CONTAINER (vbox), hbox);    gtk_widget_show (hbox);    separator = gtk_hseparator_new ();    gtk_container_add (GTK_CONTAINER (vbox), separator);    gtk_widget_show (separator);    label = gtk_label_new ("Below");    gtk_container_add (GTK_CONTAINER (vbox), label);    gtk_widget_show (label);    handle_box = gtk_handle_box_new ();    gtk_box_pack_start (GTK_BOX (hbox), handle_box, FALSE, FALSE, 0);    gtk_signal_connect (GTK_OBJECT (handle_box),			"child_attached",			GTK_SIGNAL_FUNC (handle_box_child_signal),			"attached");    gtk_signal_connect (GTK_OBJECT (handle_box),			"child_detached",			GTK_SIGNAL_FUNC (handle_box_child_signal),			"detached");    gtk_widget_show (handle_box);    toolbar = make_toolbar (window);    gtk_toolbar_set_button_relief (GTK_TOOLBAR (toolbar), GTK_RELIEF_NORMAL);    gtk_container_add (GTK_CONTAINER (handle_box), toolbar);    gtk_widget_show (toolbar);    handle_box = gtk_handle_box_new ();    gtk_box_pack_start (GTK_BOX (hbox), handle_box, FALSE, FALSE, 0);    gtk_signal_connect (GTK_OBJECT (handle_box),			"child_attached",			GTK_SIGNAL_FUNC (handle_box_child_signal),			"attached");    gtk_signal_connect (GTK_OBJECT (handle_box),			"child_detached",			GTK_SIGNAL_FUNC (handle_box_child_signal),			"detached");    gtk_widget_show (handle_box);    handle_box2 = gtk_handle_box_new ();    gtk_container_add (GTK_CONTAINER (handle_box), handle_box2);    gtk_signal_connect (GTK_OBJECT (handle_box2),			"child_attached",			GTK_SIGNAL_FUNC (handle_box_child_signal),			"attached");    gtk_signal_connect (GTK_OBJECT (handle_box2),			"child_detached",			GTK_SIGNAL_FUNC (handle_box_child_signal),			"detached");    gtk_widget_show (handle_box2);    label = gtk_label_new ("Fooo!");    gtk_container_add (GTK_CONTAINER (handle_box2), label);    gtk_widget_show (label);  }  if (!GTK_WIDGET_VISIBLE (window))    gtk_widget_show (window);  else    gtk_widget_destroy (window);}/*  * Label Demo */void create_labels (void){  static GtkWidget *window = NULL;  GtkWidget *hbox;  GtkWidget *vbox;  GtkWidget *frame;  GtkWidget *label;  if (!window)    {      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);      gtk_signal_connect (GTK_OBJECT (window), "destroy",			  GTK_SIGNAL_FUNC(gtk_widget_destroyed),			  &window);      gtk_window_set_title (GTK_WINDOW (window), "Label");      vbox = gtk_vbox_new (FALSE, 5);      hbox = gtk_hbox_new (FALSE, 5);      gtk_container_add (GTK_CONTAINER (window), hbox);      gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);      gtk_container_set_border_width (GTK_CONTAINER (window), 5);      frame = gtk_frame_new ("Normal Label");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -