GTK+ 1.2 Tutorial
Prev | Chapter 11. CList Widget | Next

# Manipulating the list itself

It is possible to change the justification for a column, and it is done through

    void gtk_clist_set_column_justification( GtkCList         *clist,
                                             gint              column,
                                             GtkJustification  justification );

The GtkJustification type can take the following values:

- `GTK_JUSTIFY_LEFT` - The text in the column will begin from the left edge.

- `GTK_JUSTIFY_RIGHT` - The text in the column will begin from the right edge.

- `GTK_JUSTIFY_CENTER` - The text is placed in the center of the column.

- `GTK_JUSTIFY_FILL` - The text will use up all available space in the column. It is normally done by inserting extra blank spaces between words (or between individual letters if it's a single word). Much in the same way as any ordinary WYSIWYG text editor.

The next function is a very important one, and should be standard in the setup of all CList widgets. When the list is created, the width of the various columns are chosen to match their titles, and since this is seldom the right width we have to set it using

    void gtk_clist_set_column_width( GtkCList *clist,
                                     gint      column,
                                     gint      width );

Note that the width is given in pixels and not letters. The same goes for the height of the cells in the columns, but as the default value is the height of the current font this isn't as critical to the application. Still, it is done through

    void gtk_clist_set_row_height( GtkCList *clist,
                                   gint      height );

Again, note that the height is given in pixels.

We can also move the list around without user interaction, however, it does require that we know what we are looking for. Or in other words, we need the row and column of the item we want to scroll to.

    void gtk_clist_moveto( GtkCList *clist,
                           gint      row,
                           gint      column,
                           gfloat    row_align,
                           gfloat    col_align );

The gfloat row_align is pretty important to understand. It's a value between 0.0 and 1.0, where 0.0 means that we should scroll the list so the row appears at the top, while if the value of row_align is 1.0, the row will appear at the bottom instead. All other values between 0.0 and 1.0 are also valid and will place the row between the top and the bottom. The last argument, gfloat col_align works in the same way, though 0.0 marks left and 1.0 marks right instead.

Depending on the application's needs, we don't have to scroll to an item that is already visible to us. So how do we know if it is visible? As usual, there is a function to find that out as well.

    GtkVisibility gtk_clist_row_is_visible( GtkCList *clist,
                                            gint      row );

The return value is is one of the following:

      GTK_VISIBILITY_NONE
      GTK_VISIBILITY_PARTIAL
      GTK_VISIBILITY_FULL

Note that it will only tell us if a row is visible. Currently there is no way to determine this for a column. We can get partial information though, because if the return is `GTK_VISIBILITY_PARTIAL`, then some of it is hidden, but we don't know if it is the row that is being cut by the lower edge of the listbox, or if the row has columns that are outside.

We can also change both the foreground and background colors of a particular row. This is useful for marking the row selected by the user, and the two functions that is used to do it are

    void gtk_clist_set_foreground( GtkCList *clist,
                                   gint      row,
                                   GdkColor *color );

    void gtk_clist_set_background( GtkCList *clist,
                                   gint      row,
                                   GdkColor *color );

Please note that the colors must have been previously allocated.

Prev | Home | Next
Working with titles | Up | Adding rows to the list