Re: gtk_filesel: Showing file in file clist



On Mon, Oct 23, 2000 at 04:38:57PM -0500, Lars Clausen wrote:
> We're again trying to improve the gtk_filesel widget, this time by making
> the file clist automatically show the file that the program sets the
> selection to (if possible).  Unfortunately, it turns out to be rather
> difficult.  There is no gtk_clist_find_row_from_text, there is no
> gtk_clist_get_num_rows (which would allow us to do a binary search).  The
> best solution we can see is not very good:  Attaching a strdup() of the
> text as data to each row and use gtK_clist_find_row_from_data to find the
> row (what is the complexity on that anyway?  Linear?  Log?), being very
> careful to deallocate the data.  Surely there must be a better way to find
> rows in clists?  Any suggestions would be appreciated.
I've encountered this problem, too.
If the list is small, just iterate over the rows and use gtk_clist_get_text()
on each row.  Unfortunately, this is O(n^2), I think, because 
gtk_clist_get_text() uses g_list_nth() to look up each row index.
I really wish all of the gtk_clist_* operations operated on pointers to
row instead of row indicies, for this reason.

Looking at the GTK source, gtk_clist_find_row_from_data() does this:
  for (n = 0, list = clist->row_list; list; n++, list = list->next)
      if (GTK_CLIST_ROW (list)->data == data)
            return n;
You could modify this function slightly and use it, if you're willing
to do Bad Hacks.

(By the way:
To get the number of rows in a clist, you must access the struct directly.
This is a known problem; it is fixed in the CVS version.
	rowcount = GTK_CLIST(clist)->rows
)

Hope this helps,
Evan.

-- 
Evan Martin - eeyem u washington edu
http://students.washington.edu/eeyem




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