GTK v1.2 Tutorial(英文)
Please note that the colors must have been previously allocated. 11.5 Adding rows to the list We can add rows in three ways. They can be prepended or appended to the list using
The return value of these two functions indicate the index of the row that was just added. We can insert a row at a given place using
In these calls we have to provide a collection of pointers that are the texts we want to put in the columns. The number of pointers should equal the number of columns in the list. If the text[] argument is NULL, then there will be no text in the columns of the row. This is useful, for example, if we want to add pixmaps instead (something that has to be done manually). Also, please note that the numbering of both rows and columns start at 0. To remove an individual row we use
There is also a call that removes all rows in the list. This is a lot faster than calling gtk_clist_remove once for each row, which is the only alternative.
There are also two convenience functions that should be used when a lot of changes have to be made to the list. This is to prevent the list flickering while being repeatedly updated, which may be highly annoying to the user. So instead it is a good idea to freeze the list, do the updates to it, and finally thaw it which causes the list to be updated on the screen.
11.6 Setting text and pixmaps in the cells A cell can contain a pixmap, text or both. To set them the following functions are used.
It's quite straightforward. All the calls have the CList as the first argument, followed by the row and column of the cell, followed by the data to be set. The spacing argument in gtk_clist_set_pixtext is the number of pixels between the pixmap and the beginning of the text. In all cases the data is copied into the widget. To read back the data, we instead use
The returned pointers are all pointers to the data stored within the widget, so the referenced data should not be modified or released. It isn't necessary to read it all back in case you aren't interested. Any of the pointers that are meant for return values (all except the clist) can be NULL. So if we want to read back only the text from a cell that is of type pixtext, then we would do the following, assuming that clist, row and column already exist:
There is one more call that is related to what's inside a cell in the clist, and that's
|