GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GtkTreeView URIs

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
ramesh
GTK+ Guru


Joined: 16 Nov 2006
Posts: 173
Location: INDIA

PostPosted: Fri Sep 05, 2008 5:16 am    Post subject: GtkTreeView URIs Reply with quote

split from here http://gtkforums.com/viewtopic.php?t=1669 -dreblen

dreblen wrote:
Yes, it has long been deprecated in favor of GtkTreeView, see here:
http://library.gnome.org/devel/gtk/stable/GtkCList.html#GtkCList.description
There's a very good GtkTreeView tutorial here:
http://scentric.net/tutorial/treeview-tutorial.html
However, if you still need to use GtkCList, you can find its documentation here:
http://library.gnome.org/devel/gtk/stable/GtkCList.html
and here's the GTK 1.2 tutorial's section on it:
http://www.gtk.org/tutorial1.2/gtk_tut-11.html


thats great tutorials.
can we have 3 elements in the treeview like this.
EX:
1 2 3
(an xpm or icon) (name) (http://www.gtkforums.com(any link, if we click on this link browser should open))

any help it should be appreciable
Back to top
dreblen
Never Seen the Sunlight


Joined: 14 Jun 2007
Posts: 526
Location: Falun, WI USA

PostPosted: Fri Sep 05, 2008 3:40 pm    Post subject: Reply with quote

you might be able to use gtk_show_uri (or one of the functions it replaces) to do this,
http://library.gnome.org/devel/gtk/stable/gtk-Filesystem-utilities.html#gtk-show-uri
it's a new function in GTK 2.14, so it may not be available to you yet.
Also, I haven't been able to get it to work in windows properly, but I'm still looking into it.
Here's what I'm working with:
Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <gtk/gtk.h>

#define FILENAME    "test.png"

enum
{
    COL_PBUF = 0,
    COL_TEXT,
    COL_URI,
    N_COLS,
};

void row_activated_cb(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer user_data)
{
    GtkTreeViewColumn *compare;
    GtkTreeModel *model;
    GtkTreeIter iter;
    gchar *uri;
    GError *err;

    err = NULL;

    /* make sure we double-clicked on the uri column */
   
compare = gtk_tree_view_get_column(view, COL_URI);
    if(col != compare)
        return;

    model = gtk_tree_view_get_model(view);
    gtk_tree_model_get_iter(model, &iter, path);

    gtk_tree_model_get(model, &iter, COL_URI, &uri, -1);

    gtk_show_uri(gdk_screen_get_default(), uri, GDK_CURRENT_TIME, &err);
    if(err != NULL)
    {
        g_warning(err->message);
        g_error_free(err);
        return;
    }
}

GtkWidget *create_view(void)
{
    GtkTreeModel *model;
    GtkTreeIter iter;
    GtkWidget *view;
    GtkCellRenderer *pbuf_cell;
    GtkCellRenderer *text_cell;
    GdkPixbuf *pbuf;
    GError *err;

    err = NULL;

    model = GTK_TREE_MODEL(gtk_list_store_new(N_COLS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING));

    view = gtk_tree_view_new_with_model(model);

    pbuf_cell = gtk_cell_renderer_pixbuf_new();
    text_cell = gtk_cell_renderer_text_new();

    gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, "Picture", pbuf_cell, "pixbuf", COL_PBUF, NULL);
    gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, "Text", text_cell, "text", COL_TEXT, NULL);
    gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, "URI", text_cell, "text", COL_URI, NULL);

    pbuf = gdk_pixbuf_new_from_file(FILENAME, &err);
    if(err != NULL)
    {
        g_warning(err->message);
        g_error_free(err);
        return NULL;
    }

    gtk_list_store_append(GTK_LIST_STORE(model), &iter);
    gtk_list_store_set(GTK_LIST_STORE(model), &iter, COL_PBUF, pbuf, COL_TEXT, "This is text", COL_URI, "http://gnome.org", -1);

    return view;
}

int main(int argc, char **argv)
{
    GtkWidget *win;
    GtkWidget *view;

    gtk_init(&argc, &argv);

    win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(win, "delete-event", G_CALLBACK(gtk_main_quit), NULL);

    view = create_view();
    g_signal_connect(view, "row-activated", G_CALLBACK(row_activated_cb), NULL);
    gtk_container_add(GTK_CONTAINER(win), view);
    gtk_widget_show(view);

    gtk_widget_show(win);

    gtk_main();

    return 0;
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP