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

📄 testgtk.c

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 C
📖 第 1 页 / 共 5 页
字号:
  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 voidstatusbar_steal (GtkWidget *button,	         GtkStatusbar *statusbar){  gtk_statusbar_remove (statusbar, 1, 4);}static voidstatusbar_popped (GtkStatusbar  *statusbar,		  guint          context_id,		  const gchar	*text){  if (!statusbar->messages)    statusbar_counter = 1;}static voidstatusbar_contexts (GtkStatusbar *statusbar){  gchar *string;  string = "any context";  g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n",	   string,	   gtk_statusbar_get_context_id (statusbar, string));    string = "idle messages";  g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n",	   string,	   gtk_statusbar_get_context_id (statusbar, string));    string = "some text";  g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n",	   string,	   gtk_statusbar_get_context_id (statusbar, string));  string = "hit the mouse";  g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n",	   string,	   gtk_statusbar_get_context_id (statusbar, string));  string = "hit the mouse2";  g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n",	   string,	   gtk_statusbar_get_context_id (statusbar, string));}static voidstatusbar_dump_stack (GtkStatusbar *statusbar){  GSList *list;  for (list = statusbar->messages; list; list = list->next)    {      GtkStatusbarMsg *msg;      msg = list->data;      g_print ("context_id: %d, message_id: %d, status_text: \"%s\"\n",               msg->context_id,               msg->message_id,               msg->text);    }}static voidcreate_statusbar (void){  static GtkWidget *window = NULL;  GtkWidget *box1;  GtkWidget *box2;  GtkWidget *button;  GtkWidget *separator;  GtkWidget *statusbar;  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), "statusbar");      gtk_container_set_border_width (GTK_CONTAINER (window), 0);      box1 = gtk_vbox_new (FALSE, 0);      gtk_container_add (GTK_CONTAINER (window), box1);      box2 = gtk_vbox_new (FALSE, 10);      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);      gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);      statusbar = gtk_statusbar_new ();      gtk_box_pack_end (GTK_BOX (box1), statusbar, TRUE, TRUE, 0);      gtk_signal_connect (GTK_OBJECT (statusbar),			  "text_popped",			  GTK_SIGNAL_FUNC (statusbar_popped),			  NULL);      button = gtk_widget_new (gtk_button_get_type (),			       "label", "push something",			       "visible", TRUE,			       "parent", box2,			       "signal::clicked", statusbar_push, statusbar,			       NULL);      button = gtk_widget_new (gtk_button_get_type (),			       "label", "pop",			       "visible", TRUE,			       "parent", box2,			       "signal_after::clicked", statusbar_pop, statusbar,			       NULL);      button = gtk_widget_new (gtk_button_get_type (),			       "label", "steal #4",			       "visible", TRUE,			       "parent", box2,			       "signal_after::clicked", statusbar_steal, statusbar,			       NULL);      button = gtk_widget_new (gtk_button_get_type (),			       "label", "dump stack",			       "visible", TRUE,			       "parent", box2,			       "object_signal::clicked", statusbar_dump_stack, statusbar,			       NULL);      button = gtk_widget_new (gtk_button_get_type (),			       "label", "test contexts",			       "visible", TRUE,			       "parent", box2,			       "object_signal_after::clicked", statusbar_contexts, statusbar,			       NULL);      separator = gtk_hseparator_new ();      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);      box2 = gtk_vbox_new (FALSE, 10);      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);      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);}/* * GtkTree */static voidcb_tree_destroy_event(GtkWidget* w){  sTreeButtons* tree_buttons;  /* free buttons structure associate at this tree */  tree_buttons = gtk_object_get_user_data (GTK_OBJECT (w));  g_free (tree_buttons);}static voidcb_add_new_item(GtkWidget* w, GtkTree* tree){  sTreeButtons* tree_buttons;  GList* selected_list;  GtkWidget* selected_item;  GtkWidget* subtree;  GtkWidget* item_new;  char buffer[255];  tree_buttons = gtk_object_get_user_data(GTK_OBJECT(tree));  selected_list = GTK_TREE_SELECTION(tree);  if(selected_list == NULL)    {      /* there is no item in tree */      subtree = GTK_WIDGET(tree);    }  else    {      /* list can have only one element */      selected_item = GTK_WIDGET(selected_list->data);            subtree = GTK_TREE_ITEM_SUBTREE(selected_item);      if(subtree == NULL)	{	  /* current selected item have not subtree ... create it */	  subtree = gtk_tree_new();	  gtk_tree_item_set_subtree(GTK_TREE_ITEM(selected_item), 				    subtree);	}    }  /* at this point, we know which subtree will be used to add new item */  /* create a new item */  sprintf(buffer, "item add %d", tree_buttons->nb_item_add);  item_new = gtk_tree_item_new_with_label(buffer);  gtk_tree_append(GTK_TREE(subtree), item_new);  gtk_widget_show(item_new);  tree_buttons->nb_item_add++;}static voidcb_remove_item(GtkWidget*w, GtkTree* tree){  GList* selected_list;  GList* clear_list;    selected_list = GTK_TREE_SELECTION(tree);  clear_list = NULL;      while (selected_list)     {      clear_list = g_list_prepend (clear_list, selected_list->data);      selected_list = selected_list->next;    }    clear_list = g_list_reverse (clear_list);  gtk_tree_remove_items(tree, clear_list);  g_list_free (clear_list);}static voidcb_remove_subtree(GtkWidget*w, GtkTree* tree){  GList* selected_list;  GtkTreeItem *item;    selected_list = GTK_TREE_SELECTION(tree);  if (selected_list)    {      item = GTK_TREE_ITEM (selected_list->data);      if (item->subtree)	gtk_tree_item_remove_subtree (item);    }}static voidcb_tree_changed(GtkTree* tree){  sTreeButtons* tree_buttons;  GList* selected_list;  guint nb_selected;  tree_buttons = gtk_object_get_user_data(GTK_OBJECT(tree));  selected_list = GTK_TREE_SELECTION(tree);  nb_selected = g_list_length(selected_list);  if(nb_selected == 0)     {      if(tree->children == NULL)	gtk_widget_set_sensitive(tree_buttons->add_button, TRUE);      else	gtk_widget_set_sensitive(tree_buttons->add_button, FALSE);      gtk_widget_set_sensitive(tree_buttons->remove_button, FALSE);      gtk_widget_set_sensitive(tree_buttons->subtree_button, FALSE);    }   else     {      gtk_widget_set_sensitive(tree_buttons->remove_button, TRUE);      gtk_widget_set_sensitive(tree_buttons->add_button, (nb_selected == 1));      gtk_widget_set_sensitive(tree_buttons->subtree_button, (nb_selected == 1));    }  }static void create_subtree(GtkWidget* item, guint level, guint nb_item_max, guint recursion_level_max){  GtkWidget* item_subtree;  GtkWidget* item_new;  guint nb_item;  char buffer[255];  int no_root_item;  if(level == recursion_level_max) return;  if(level == -1)    {      /* query with no root item */      level = 0;      item_subtree = item;      no_root_item = 1;    }  else    {      /* query with no root item */      /* create subtree and associate it with current item */      item_subtree = gtk_tree_new();      no_root_item = 0;    }    for(nb_item = 0; nb_item < nb_item_max; nb_item++)    {      sprintf(buffer, "item %d-%d", level, nb_item);      item_new = gtk_tree_item_new_with_label(buffer);      gtk_tree_append(GTK_TREE(item_subtree), item_new);      create_subtree(item_new, level+1, nb_item_max, recursion_level_max);      gtk_widget_show(item_new);    }  if(!no_root_item)    gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), item_subtree);}static voidcreate_tree_sample(guint selection_mode, 		   guint draw_line, guint view_line, guint no_root_item,		   guint nb_item_max, guint recursion_level_max) {  GtkWidget* window;  GtkWidget* box1;  GtkWidget* box2;  GtkWidget* separator;  GtkWidget* button;  GtkWidget* scrolled_win;  GtkWidget* root_tree;  GtkWidget* root_item;  sTreeButtons* tree_buttons;  /* create tree buttons struct */  if ((tree_buttons = g_malloc (sizeof (sTreeButtons))) == NULL)    {      g_error("can't allocate memory for tree structure !\n");      return;    }  tree_buttons->nb_item_add = 0;  /* create top level window */  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);  gtk_window_set_title(GTK_WINDOW(window), "Tree Sample");  gtk_signal_connect(GTK_OBJECT(window), "destroy",		     (GtkSignalFunc) cb_tree_destroy_event, NULL);  gtk_object_set_user_data(GTK_OBJECT(window), tree_buttons);  box1 = gtk_vbox_new(FALSE, 0);  gtk_container_add(GTK_CONTAINER(window), box1);  gtk_widget_show(box1);  /* create tree box */  box2 = gtk_vbox_new(FALSE, 0);  gtk_box_pack_start(GTK_BOX(box1), box2, TRUE, TRUE, 0);  gtk_container_set_border_width(GTK_CONTAINER(box2), 5);  gtk_widget_show(box2);

⌨️ 快捷键说明

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