Re: [gtk-list] Clists (Feature request)
- From: Frank v Waveren <fvw var cx>
- To: "Rene' Seindal" <rene seindal dk>
- Cc: gtk-list redhat com
- Subject: Re: [gtk-list] Clists (Feature request)
- Date: Sun, 6 Feb 2000 03:07:53 +0100
Ah, thanks. I was trying to do it in gtk itself, but this looks a lot easier.
On Sun, Feb 06, 2000 at 12:57:15AM +0100, Rene' Seindal wrote:
> Here are some notes about how I have done that.
>
> --
> René Seindal (rene@seindal.dk) http://www.seindal.dk/rene/
> Return-Path: <gtk-list-request@redhat.com>
> Received: from mail
> by localhost with POP3 (fetchmail-5.1.2)
> for rene@localhost (single-drop); Mon, 03 Jan 2000 20:07:18 +0100 (CET)
> Received: from lists.redhat.com (lists.redhat.com [199.183.24.247])
> by www.mtp.dk (8.9.3/8.9.0) with SMTP id MAA20924
> for <rene@seindal.dk>; Mon, 3 Jan 2000 12:24:59 +0100
> Received: (qmail 17169 invoked by uid 501); 3 Jan 2000 11:24:50 -0000
> Resent-Date: 3 Jan 2000 11:24:50 -0000
> Resent-Cc: recipient list not shown: ;
> MBOX-Line: From gtk-list-request@redhat.com Mon Jan 3 06:24:50 2000
> Sender: rene@seindal.dk
> Message-ID: <38701045.B3D2E16@seindal.dk>
> Date: Mon, 03 Jan 2000 03:58:14 +0100
> From: "Rene' Seindal" <rene@seindal.dk>
> Organization: Seindal Consult, Copenhagen, Denmark
> X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.13 i586)
> X-Accept-Language: da, en, it
> MIME-Version: 1.0
> To: gtk-list@redhat.com
> References: <m3d7rkxo06.fsf@k0817.kampsax.dtu.dk>
> Content-Type: text/plain; charset=iso-8859-1
> Content-Transfer-Encoding: 8bit
> Resent-Message-ID: <"iuKp82.0.wB4.2S8Su"@lists.redhat.com>
> Resent-From: gtk-list@redhat.com
> Reply-To: gtk-list@redhat.com
> X-Mailing-List: <gtk-list@redhat.com> archive/latest/1966
> X-Loop: gtk-list@redhat.com
> Precedence: list
> Resent-Sender: gtk-list-request@redhat.com
> X-URL: http://archive.redhat.com/gtk-list/
> Subject: [gtk-list] Re: GtkCList focus
> X-Mozilla-Status2: 00000000
>
> Anders Melchiorsen wrote:
> >
> > I am trying to get GtkCList to work like e.g. Windows lists where
> > pressing a key will move the focus to a row starting with that letter.
> > If the focus is already on such a row, the focus should move to the
> > next row starting with that letter.
> >
> > I have a hard time doing this. For one thing, is the ->focus_row
> > member public? I see no accessor function for getting the contents of
> > the focused row (not the selection). Thus, I think that I need to use
> > focus_row combined with gtk_clist_get_text() calls to get the
> > functionality that I want.
> >
> > Is there an easier and/or better way?
>
> I have done that in an application. Here are some pieces of the code,
> it should be fairly decifrable, though not complete.
>
> This is an utility function to set the current focus row.
>
> void
> gtk_clist_set_focus_row(GtkCList *list, guint row)
> {
> g_return_if_fail(list != NULL);
> g_return_if_fail(row >= 0);
> g_return_if_fail(row < list->rows);
>
> list->focus_row = row;
> }
>
> This is the key_press event handler for the clist. Ignore the
> PersonSelector stuff, it is structure that contains the clist, among
> other things.
>
> gboolean
> on_person_selector_list_key_press_event (GtkWidget *widget,
> GdkEventKey *event,
> gpointer user_data)
> {
> PersonSelector *sel;
>
> #ifdef DEBUG
> g_print("on_person_selector_list_key_press_event\n");
> #endif
>
> if (event->state != 0)
> return FALSE;
>
> sel = widget_get_person_selector(GTK_WIDGET(user_data));
> return person_selector_search(sel,
> gdk_keyval_to_lower(event->keyval));
> }
>
>
> gboolean
> person_selector_search(PersonSelector *sel, guint keyval)
> {
> GtkCList *list = sel->list;
> guint row;
> gchar *name;
>
> keyval = (guchar)keyval;
> if (! isprint(keyval))
> return FALSE;
>
> #ifdef DEBUG
> g_print("person_selector_search: key %c\n", keyval);
> #endif /* DEBUG */
>
> row = (list->focus_row + 1) % list->rows;
> while (row != list->focus_row) {
> gtk_clist_get_text(list, row, 0, &name);
>
> #ifdef DEBUG
> g_print("person_selector_search: row %d match %.20s\n", row, name);
> #endif /* DEBUG */
>
> if (tolower(*name) == keyval) {
> gtk_clist_set_focus_row(list, row);
>
> if (gtk_clist_row_is_visible(list, row) != GTK_VISIBILITY_FULL)
> gtk_clist_moveto(list, row, 0, 0.5, 0.0);
> gtk_widget_queue_draw(GTK_WIDGET(list));
>
> #ifdef DEBUG
> g_print("person_selector_search: got row %d\n", row);
> #endif /* DEBUG */
> return TRUE;
> }
> row = (row + 1) % list->rows;
> }
>
> #ifdef DEBUG
> g_print("person_selector_search: not found\n");
> #endif /* DEBUG */
>
> return FALSE;
> }
>
> --
> René Seindal (rene@seindal.dk) http://www.seindal.dk/rene/
>
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
>
--
Frank v Waveren
fvw@var.cx
ICQ# 10074100
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]