Exemplo n.º 1
0
static void
load_table(const xmlNode *table, form_element_t *parent)
{
    form_element_t T;

    GtkWidget *scroll = gtk_scrolled_window_new(NULL, NULL);
    GtkTreeModel *model = create_tree_model(table);
    T.widget = gtk_tree_view_new_with_model(model);

    table_make_columns(table, GTK_TREE_VIEW(T.widget));
    gtk_container_add(GTK_CONTAINER(scroll), T.widget);

    {
        const xmlNode *pre = find_by_path(table, "PredefinedContainedItems");

        if (pre->children) {

            form_element_t vbox, pre_box;
            vbox.widget = gtk_vbox_new(false, 0);
            vbox.box = true;

            pre_box.widget = gtk_vbox_new(false, 0);
            pre_box.box = true;

            load_form_elements(pre->children, &pre_box);

            gtk_box_pack_start(GTK_BOX(vbox.widget), pre_box.widget, false, false, 0);
            gtk_box_pack_start(GTK_BOX(vbox.widget), scroll, true, true, 0);

            scroll = vbox.widget;
        }
    }

    container_add(parent, scroll);
}
Exemplo n.º 2
0
void
CChoosebook::create_tree_model(gchar *dir,GtkTreeStore *model, GtkTreeIter *iter)
{
	GDir *dp;
	if (!(dp = g_dir_open(dir,0,NULL))) return;

	const gchar *item;
	gchar fullname[256], dirnamefile[256],*tmp1;

	while ((item = g_dir_read_name(dp)) != NULL)
	{
		strcpy(fullname, dir);
		if (fullname[strlen(fullname) - 1] != G_DIR_SEPARATOR) strcat(fullname,G_DIR_SEPARATOR_S);
		strcat(fullname, item);
		if (g_file_test(fullname,G_FILE_TEST_IS_DIR))
		{
			GtkTreeIter child_iter;
			gtk_tree_store_append (model, &child_iter,iter);
			sprintf(dirnamefile, "%s/dirname", fullname);
			if (g_file_test(dirnamefile, G_FILE_TEST_EXISTS)) {
				if (g_file_get_contents(dirnamefile, &tmp1, NULL, NULL))
					g_strstrip(tmp1);
				else
					tmp1 = NULL;
			} else {
				tmp1 = g_filename_to_utf8(item,-1,NULL,NULL,NULL);
			}
			gtk_tree_store_set (model, &child_iter,
				  0,Skin->choosebook.dir.p[0],1, tmp1,2,fullname,
				  -1);
			if (tmp1)
				g_free(tmp1);
			create_tree_model(fullname,model, &child_iter);
		}
	}
	g_dir_close(dp);
}
Exemplo n.º 3
0
int
main (int argc, char **argv)
{
    MatewnckScreen *screen;
    GtkWidget *sw;
    GtkWidget *win;

    gtk_init (&argc, &argv);

    screen = matewnck_screen_get (0);

    g_signal_connect (G_OBJECT (screen), "active_window_changed",
                      G_CALLBACK (active_window_changed_callback),
                      NULL);
    g_signal_connect (G_OBJECT (screen), "active_workspace_changed",
                      G_CALLBACK (active_workspace_changed_callback),
                      NULL);
    g_signal_connect (G_OBJECT (screen), "window_stacking_changed",
                      G_CALLBACK (window_stacking_changed_callback),
                      NULL);
    g_signal_connect (G_OBJECT (screen), "window_opened",
                      G_CALLBACK (window_opened_callback),
                      NULL);
    g_signal_connect (G_OBJECT (screen), "window_closed",
                      G_CALLBACK (window_closed_callback),
                      NULL);
    g_signal_connect (G_OBJECT (screen), "workspace_created",
                      G_CALLBACK (workspace_created_callback),
                      NULL);
    g_signal_connect (G_OBJECT (screen), "workspace_destroyed",
                      G_CALLBACK (workspace_destroyed_callback),
                      NULL);
    g_signal_connect (G_OBJECT (screen), "application_opened",
                      G_CALLBACK (application_opened_callback),
                      NULL);
    g_signal_connect (G_OBJECT (screen), "application_closed",
                      G_CALLBACK (application_closed_callback),
                      NULL);
    g_signal_connect (G_OBJECT (screen), "showing_desktop_changed",
                      G_CALLBACK (showing_desktop_changed_callback),
                      NULL);

    global_tree_model = create_tree_model ();
    global_tree_view = create_tree_view ();

    gtk_tree_view_set_model (GTK_TREE_VIEW (global_tree_view),
                             global_tree_model);

    win = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    gtk_window_set_title (GTK_WINDOW (win), "Window List");

    sw = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                    GTK_POLICY_AUTOMATIC,
                                    GTK_POLICY_AUTOMATIC);

    gtk_container_add (GTK_CONTAINER (sw), global_tree_view);
    gtk_container_add (GTK_CONTAINER (win), sw);

    gtk_window_set_default_size (GTK_WINDOW (win), 650, 550);

    /* quit on window close */
    g_signal_connect (G_OBJECT (win), "destroy",
                      G_CALLBACK (gtk_main_quit),
                      NULL);

    gtk_widget_show_all (win);

    gtk_main ();

    return 0;
}
Exemplo n.º 4
0
GtkWidget *
CChoosebook::create_tree()
{
	GtkWidget *sw;
	GtkTreeStore *model;
	GtkTreeIter iter;
	gchar *filename;
	
	model = gtk_tree_store_new (3,GDK_TYPE_PIXBUF,G_TYPE_STRING,G_TYPE_STRING);
	
	filename = g_build_filename(g_pReciteWord->userpath, "hardbooks", NULL);	
	gtk_tree_store_append (model, &iter, NULL);
	gtk_tree_store_set (model, &iter, 0,Skin->choosebook.dir.p[0],1, _("hardbooks"),2,filename, -1);
	create_tree_model(filename,model, &iter);
	g_free(filename);

	filename = g_build_filename(g_pReciteWord->userpath, "books", NULL);
	gtk_tree_store_append (model, &iter, NULL);
	gtk_tree_store_set (model, &iter, 0,Skin->choosebook.dir.p[0],1, _("my books"),2,filename, -1);
	create_tree_model(filename,model, &iter);
	g_free(filename);
	
	gtk_tree_store_append (model, &iter, NULL);
	filename = g_build_filename(reciteword_data_dir, "books", NULL);
	gtk_tree_store_set (model, &iter,
			  0,Skin->choosebook.dir.p[0],1, _("books"),2, filename,
			  -1);
	create_tree_model(filename,model, &iter);
	g_free(filename);

	
	tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE);
	g_object_unref (model);
	
	
	/*GtkTreeViewColumn *column;
	GtkCellRenderer *cell_renderer;
	     column = gtk_tree_view_column_new ();

      cell_renderer = gtk_cell_renderer_pixbuf_new ();
      gtk_tree_view_column_pack_start (column,
				       cell_renderer,
				       FALSE);
      cell_renderer = gtk_cell_renderer_text_new ();
      gtk_tree_view_column_pack_start (column,
				       cell_renderer,
				       TRUE);
      gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view),
				   column);*/
				   
	GtkCellRenderer *renderer_image;
	GtkCellRenderer *renderer_text;
	GtkTreeViewColumn *column;
	renderer_image = gtk_cell_renderer_pixbuf_new();
	renderer_text = gtk_cell_renderer_text_new ();
	//g_object_set (G_OBJECT (renderer), "xalign", 0.0, NULL);
	column = gtk_tree_view_column_new();
	gtk_tree_view_column_set_title(column,_("Directories"));
	gtk_tree_view_column_pack_start(column,renderer_image,FALSE);
	gtk_tree_view_column_add_attribute(column,
                                     renderer_image,
                                     "pixbuf",0);
	gtk_tree_view_column_pack_end(column,renderer_text,TRUE);
	gtk_tree_view_column_add_attribute(column,
                                     renderer_text,
                                     "text",1);
	gtk_tree_view_insert_column(GTK_TREE_VIEW(tree_view),column,-1);
/*	col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
							    -1, "Folder",
							    renderer, "text",
							    0,
							    NULL);
	  column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);*/
	  //gtk_tree_view_column_set_visible(GTK_TREE_VIEW_COLUMN (column), FALSE);
	  gtk_tree_view_column_set_clickable (column, TRUE);
	      
	GtkTreeSelection *selection;
	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
	gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
	gtk_tree_view_expand_all(GTK_TREE_VIEW(tree_view));
	//gtk_tree_selection_set_select_function(selection,tree_selection_func,this,NULL);
	g_signal_connect (G_OBJECT (selection),
			"changed",
			G_CALLBACK (on_choosebook_tree_selection_changed),
			this);

	/*g_signal_connect (G_OBJECT (tree_view),
			"button_press_event",
			G_CALLBACK (on_choosebook_tree_button_press),
			this);*/
	
	sw = gtk_scrolled_window_new (NULL, NULL);
	gtk_widget_set_size_request(sw,Skin->choosebook.book_tree.w,Skin->choosebook.book_tree.h);
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),GTK_SHADOW_ETCHED_IN);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);	
	gtk_container_add (GTK_CONTAINER (sw), tree_view);
	gtk_widget_show(tree_view);
	
	return sw;
}
Exemplo n.º 5
0
int
main (int    argc,
      char **argv)
{
  GtkWidget *window;
  GtkWidget *sw;
  GtkWidget *tv;
  GtkWidget *box;
  GtkWidget *combo_box;
  GtkTreeModel *model;
  gint i;
  
  gtk_init (&argc, &argv);

  if (g_getenv ("RTL"))
    gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);

  our_pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) book_closed_xpm);  
  
#if 0
  models[MODEL_TYPES] = GTK_TREE_MODEL (gtk_tree_model_types_new ());
#endif
  models[MODEL_LIST] = create_list_model ();
  models[MODEL_TREE] = create_tree_model ();

  model = create_list_model ();
  models[MODEL_SORTED_LIST] = gtk_tree_model_sort_new_with_model (model);
  g_object_unref (model);

  model = create_tree_model ();
  models[MODEL_SORTED_TREE] = gtk_tree_model_sort_new_with_model (model);
  g_object_unref (model);

  models[MODEL_EMPTY_LIST] = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_INT));
  models[MODEL_EMPTY_TREE] = GTK_TREE_MODEL (gtk_tree_store_new (1, G_TYPE_INT));
  
  models[MODEL_NULL] = NULL;

  run_automated_tests ();
  
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
  gtk_window_set_default_size (GTK_WINDOW (window), 430, 400);

  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);

  gtk_container_add (GTK_CONTAINER (window), box);

  tv = gtk_tree_view_new_with_model (models[0]);
  
  gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (tv),
					  GDK_BUTTON1_MASK,
					  row_targets,
					  G_N_ELEMENTS (row_targets),
					  GDK_ACTION_MOVE | GDK_ACTION_COPY);

  gtk_tree_view_enable_model_drag_dest (GTK_TREE_VIEW (tv),
					row_targets,
					G_N_ELEMENTS (row_targets),
					GDK_ACTION_MOVE | GDK_ACTION_COPY);
  
  /* Model menu */
  combo_box = gtk_combo_box_text_new ();
  gtk_widget_set_halign (combo_box, GTK_ALIGN_CENTER);
  for (i = 0; i < MODEL_LAST; i++)
      gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), model_names[i]);

  gtk_container_add (GTK_CONTAINER (box), combo_box);
  g_signal_connect (combo_box,
                    "changed",
                    G_CALLBACK (model_selected),
		    tv);
  
  /* Columns menu */
  combo_box = gtk_combo_box_text_new ();
  gtk_widget_set_halign (combo_box, GTK_ALIGN_CENTER);
  for (i = 0; i < COLUMNS_LAST; i++)
      gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), column_type_names[i]);

  gtk_container_add (GTK_CONTAINER (box), combo_box);

  set_columns_type (GTK_TREE_VIEW (tv), COLUMNS_LOTS);
  gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), COLUMNS_LOTS);

  g_signal_connect (combo_box,
                    "changed",
                    G_CALLBACK (columns_selected),
                    tv);
  
  sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_set_hexpand (sw, TRUE);
  gtk_widget_set_vexpand (sw, TRUE);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                  GTK_POLICY_AUTOMATIC,
                                  GTK_POLICY_AUTOMATIC);
  
  gtk_container_add (GTK_CONTAINER (box), sw);
  
  gtk_container_add (GTK_CONTAINER (sw), tv);
  
  create_prop_editor (G_OBJECT (tv), GTK_TYPE_TREE_VIEW);
  create_prop_editor (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (tv))), GTK_TYPE_TREE_SELECTION);

  gtk_widget_show_all (window);
  
  gtk_main ();

  return 0;
}
Exemplo n.º 6
0
int
main (int    argc,
      char **argv)
{
  GtkWidget *window;
  GtkWidget *sw;
  GtkWidget *tv;
  GtkWidget *table;
  GtkWidget *om;
  GtkWidget *menu;
  GtkTreeModel *model;
  gint i;
  
  gtk_init (&argc, &argv);

  our_pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) book_closed_xpm);  
  
#if 0
  models[MODEL_TYPES] = GTK_TREE_MODEL (gtk_tree_model_types_new ());
#endif
  models[MODEL_LIST] = create_list_model ();
  models[MODEL_TREE] = create_tree_model ();

  model = create_list_model ();
  models[MODEL_SORTED_LIST] = gtk_tree_model_sort_new_with_model (model);
  g_object_unref (model);

  model = create_tree_model ();
  models[MODEL_SORTED_TREE] = gtk_tree_model_sort_new_with_model (model);
  g_object_unref (model);

  models[MODEL_EMPTY_LIST] = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_INT));
  models[MODEL_EMPTY_TREE] = GTK_TREE_MODEL (gtk_tree_store_new (1, G_TYPE_INT));
  
  models[MODEL_NULL] = NULL;

  run_automated_tests ();
  
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
  gtk_window_set_default_size (GTK_WINDOW (window), 430, 400);

  table = gtk_table_new (3, 1, FALSE);

  gtk_container_add (GTK_CONTAINER (window), table);

  tv = gtk_tree_view_new_with_model (models[0]);
  
  gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (tv),
					  GDK_BUTTON1_MASK,
					  row_targets,
					  G_N_ELEMENTS (row_targets),
					  GDK_ACTION_MOVE | GDK_ACTION_COPY);

  gtk_tree_view_enable_model_drag_dest (GTK_TREE_VIEW (tv),
					row_targets,
					G_N_ELEMENTS (row_targets),
					GDK_ACTION_MOVE | GDK_ACTION_COPY);
  
  /* Model menu */

  menu = gtk_menu_new ();
  
  i = 0;
  while (i < MODEL_LAST)
    {
      GtkWidget *mi;
      const char *name;

      name = model_names[i];
      
      mi = gtk_menu_item_new_with_label (name);

      gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);

#if 0
      window = create_prop_editor (G_OBJECT (models[i]));

      gtk_window_set_title (GTK_WINDOW (window),                            
                            name);
#endif

      ++i;
    }
  gtk_widget_show_all (menu);
  
  om = gtk_option_menu_new ();
  gtk_option_menu_set_menu (GTK_OPTION_MENU (om), menu);
  
  gtk_table_attach (GTK_TABLE (table), om,
                    0, 1, 0, 1,
                    0, 0, 
                    0, 0);

  g_signal_connect (om,
                    "changed",
                    G_CALLBACK (model_selected),
		    tv);
  
  /* Columns menu */

  menu = gtk_menu_new ();
  
  i = 0;
  while (i < COLUMNS_LAST)
    {
      GtkWidget *mi;
      const char *name;

      name = column_type_names[i];
      
      mi = gtk_menu_item_new_with_label (name);

      gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);

      ++i;
    }
  gtk_widget_show_all (menu);
  
  om = gtk_option_menu_new ();
  gtk_option_menu_set_menu (GTK_OPTION_MENU (om), menu);
  
  gtk_table_attach (GTK_TABLE (table), om,
                    0, 1, 1, 2,
                    0, 0, 
                    0, 0);

  set_columns_type (GTK_TREE_VIEW (tv), COLUMNS_LOTS);
  gtk_option_menu_set_history (GTK_OPTION_MENU (om), COLUMNS_LOTS);
  
  g_signal_connect (om,
                    "changed",
                    G_CALLBACK (columns_selected),
                    tv);
  
  sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                  GTK_POLICY_AUTOMATIC,
                                  GTK_POLICY_AUTOMATIC);
  
  gtk_table_attach (GTK_TABLE (table), sw,
                    0, 1, 2, 3,
                    GTK_EXPAND | GTK_FILL,
                    GTK_EXPAND | GTK_FILL,
                    0, 0);
  
  gtk_container_add (GTK_CONTAINER (sw), tv);
  
  gtk_widget_show_all (window);
  
  gtk_main ();

  return 0;
}