O5B-->

About GNOME · Download · Support · Community · Developers · Foundation · Contact




GNOME Support Forums
GNOME Desktop user support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using gtk listview widget

 
Post new topic   Reply to topic    GNOME Support Forums Forum Index -> Development
View previous topic :: View next topic  
Author Message
goran
Guest





PostPosted: Sat Apr 12, 2003 10:27 am    Post subject: Using gtk listview widget Reply with quote

Where I can find some informations (discluding official API) about new tree and list view widgets in gtk2? I started "thinking on gtk" but I cannot figure this out. Can anyone help me by giving me simple code for this (i looked at gtk-demo but it didnt helped to me). thank you in advance,

Goran Rakic
C/C++ developer
Back to top
jauco
Guru
Guru


Joined: 01 Dec 2002
Posts: 653
Location: The country that was built by man. (And I'm not talking about Australia)

PostPosted: Sat Apr 12, 2003 10:45 am    Post subject: Reply with quote

I have no Idea myself, but I asked this question as well not long ago...

So does anyone know? Surprised
_________________
I'm no developer.
Back to top
View user's profile Send private message Visit poster's website
goran
Guest





PostPosted: Sat Apr 12, 2003 11:30 am    Post subject: Reply with quote

Just to say that I did it! I made my first listview Wink. I will write some nice toutorial for beginers from beginer if you like.
Back to top
dbrody
Guru
Guru


Joined: 30 Nov 2002
Posts: 2670
Location: Israel (temporarly in Detroit,MI)

PostPosted: Sat Apr 12, 2003 11:16 pm    Post subject: Reply with quote

go here:
http://developer.gnome.org/doc/API/2.0/gtk/TreeWidgetObjects.html
and read the overview, it has a nice intro to it.
_________________
Distro: FC1
Gnome Version: Nyquist's 2.5.x
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
goran
Guest





PostPosted: Mon Apr 14, 2003 1:51 pm    Post subject: Reply with quote

After that you can view my small app recnik (dictionary for translating gnome enviroment on serbian). (http://www.devbase.net/recnik/recnik.tar.gz)

In file src/interface.c you can find code for generating and packing list widget called lista. In file src/callback.c you can find small callback function on_click_nadji that calls another callback function from sqlite that generates store data (store pointer is transfered to another function). After we create our store model, we apply it t our widget that has columns and is packed to container. after that we can see nice two-column list view.

So what we need to do to generate list view:
First, you will need the new GtkWidget so we write:
Code:

 GtkWidget *lista;

After that you will need the GtkTreeStore for sotring data for the list. Note that you can update store for the list latter from the code so the list can be dynamic. Store need to have data about our columns.
Code:

  GtkTreeStore *store = gtk_tree_store_new (2,
                                          G_TYPE_STRING,
                                          G_TYPE_STRING);

That means that our list will have two columns, and both will be text type. But API recomends the other way, by generating global numerated list that we can access from all callbacks. That adds some data encapsulation to the code, and cannot be bad. So the enum will be like this:
Code:

enum
{
   ENG,             // column 1 - 0
   SRP,             // column 2 - 1
   COL_NUMBER   // number of columns - 2, zar ne?
};

You have two columns and the added element COL_NUMBER will have the value of number of columns, what is very practical.

In that aspect, we will use this code for store:
Code:

  GtkTreeStore *store = gtk_tree_store_new (BR_KOLONA,
                                          G_TYPE_STRING,
                                          G_TYPE_STRING);

Now we need to populate store with data. But, we donot need to do that, remember that we can stop here, create widget from the given store structure (pointed by a store pointer), called model, pack a widget and latter, from callback generate a new store (based on our global numerated list). Than all we need to do is to apply the new store to the list that will delete store and put the new one in the widget.

But, for practical reasons I will put data here. So this is the way:

First, we need to have a GtkIter instance, that can be used as a parent parameter to generate a TreeView Widget, but we will not use this here:
Code:

   GtkTreeIter   iter;

    gtk_tree_store_append (store, &iter, NULL);  // get the new iter...
    gtk_tree_store_set (store, &iter,
                    ENG, "Text data for the first column",
                    SRP, "Text data for the second column",

                    -1);

That will add data to column with numer 0, and number 1, or ENG and SRP in our numerated list. -1 means that the item will be top item. This can be value of some earlier Iter (we will need to use two neasted Iters for that, example is in API) but we will keep this -1 for now.

Now we can make more data, or skip that... Wink

Now create real widget with our earlier generated Model:
Code:

   lista = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));

We can delete store now, as we donot need that. We can get the store from the list with coresponding function if we need the data later.
Code:

   g_object_unref (G_OBJECT (store));

We are creating cell renderers that will specifies how our data from store will be displayed. GTK provides three various renderers, go to API for more info. As we used text data, we will need to use, guess what?, text renderer. Cell renderer is specified for each column and than applyed to our listview widget.
Code:

  renderer = gtk_cell_renderer_text_new ();
  column = gtk_tree_view_column_new_with_attributes ("This is header for the first column",
                                                   renderer,
                                                   "text", ENG,
                                                   NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (lista), column);

And now repeat the process for the second column:
Code:

  renderer = gtk_cell_renderer_text_new ();
  column = gtk_tree_view_column_new_with_attributes ("Header for the second column",
                                                   renderer,
                                                   "text", SRP,
                                                   NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (lista), column);

All that is now need is to pack our listview to some container, or direct to the window that I assume that you know how to create.
Code:

    gtk_container_add (GTK_CONTAINER (prostor), lista);
    gtk_widget_show (lista);
    gtk_widget_set_name (lista, "lista");

... where "prostor" is our container

Do you need more info?

PS - You can use lookup_widget(GTK_WIDGET(button), "lista"); for finding widget, and gtk_tree_view_set_model and gtk_tree_view_get_model for accessing store model of the list.

Goran Rakic
C/C++ programmer[/code]
Back to top
jauco
Guru
Guru


Joined: 01 Dec 2002
Posts: 653
Location: The country that was built by man. (And I'm not talking about Australia)

PostPosted: Tue Apr 15, 2003 2:26 am    Post subject: Reply with quote

thanks for the replies Smile

I'll start with it this afternoon after school.
_________________
I'm no developer.
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Sun Jul 27, 2003 5:20 pm    Post subject: Reply with quote

goran wrote:
Just to say that I did it! I made my first listview Wink. I will write some nice toutorial for beginers from beginer if you like.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GNOME Support Forums Forum Index -> Development All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


FootNotes | Official GNOME Website | GnomeSupport.org

Add to Mozilla Sidebar

Powered by phpBB © 2001, 2005 phpBB Group