Show select itens of tree_view



It would like to know as to show in the screen itens selected of tree_view. As new_function will have is the function to execute this task and to show itens selected in the screen through the function g_print.

The source code that will have to be modified is below

Very Obliged

#include <stdio.h>
#include <gtk/gtk.h>

void new_function()
{
   /* Function for show the selected itens in screen with g_print */
}

int main(int argc, char **argv)
{
   int i;
GtkWidget *main_window; GtkWidget *fixed_mw; GtkWidget *tree_view;
   GtkWidget *scrolled_window;
   GtkListStore *model;
   GtkTreeIter iter;
   GtkCellRenderer *cell;
   GtkTreeViewColumn *column;
   GtkWidget *btn;

   gtk_init(&argc, &argv);

   main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title(GTK_WINDOW(main_window), "MyTitleMyTitleMyTitle");
   gtk_widget_set_usize(main_window, 650, 350);
g_signal_connect(G_OBJECT(main_window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

   fixed_mw = gtk_fixed_new();
   gtk_container_add(GTK_CONTAINER(main_window), fixed_mw);

   model = gtk_list_store_new(1, G_TYPE_STRING);
tree_view = gtk_tree_view_new(); gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view), GTK_TREE_MODEL(model));

scrolled_window = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
   gtk_fixed_put(GTK_FIXED(fixed_mw), scrolled_window, 5, 50);
   gtk_widget_set_usize(scrolled_window, 640, 300);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), GTK_WIDGET(tree_view)); GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree_view)); gtk_tree_selection_set_mode (GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE); for (i=0;i<20;i++)
   {
       gchar *msg = g_strdup_printf ("Item%d", i+1);
       gtk_list_store_append(GTK_LIST_STORE(model), &iter);
       gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, msg, -1);
       g_free(msg);
   }
cell = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes("Itens", cell, "text", 0, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), GTK_TREE_VIEW_COLUMN(column));

   btn = gtk_button_new_with_label("Selecteds");
   gtk_fixed_put(GTK_FIXED(fixed_mw), btn, 5, 5);
g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(new_function), NULL);
   gtk_widget_show(btn);

   gtk_widget_show(scrolled_window);
   gtk_widget_show(tree_view);
   gtk_widget_show(fixed_mw);
   gtk_widget_show(main_window);
gtk_main(); return 0;
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]