Re: CList selection and focus
| From: | André Jansen | Date: | Tue, 01 Jun 2004 00:41:14 +0000 |
| Subject: | Re: CList selection and focus | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-4596@lists.php.net to get a copy of this message | ||
On 31 May 2004 at 15:58, nathan@the-ring.homelinux.net wrote:
> > The handler uses the select_row() method, and it works. BUT:
> > Even when the list is in Browse mode, the keyboard focus does not follow
> > the selection (as it does when navigating the list with the up/down
> > arrow keys).
> >
> > Is there some way to move the focus along with the selection?
>
> hi andré,
> you can use the clist::moveto method to do that.
> http://gtk.php.net/manual/fr/gtk.gtkclist.method.moveto.php
>
> nathan
I have used the clist::moveto method for the purpose of moving
(scrolling) the selected entry into the visible portion of the list, but
it does not seem to have any effect on keyboard focus.
Maybe I should explain myself better:
With the list used in GTK_SELECTION_BROWSE mode, selection will follow
keyboard focus when navigating the list with the arrow keys or PgUp/PgDn.
That is, the row having keyboard focus is always selected.
When clist::select_row is used however, it selects the designated row but
the keyboard focus remains on the previously selected item.
Here's the code of the handler:
function list_scan($list,$key)
{
$kv = $key->keyval;
if ($kv < 48 || $kv > 122) return; // don't bother with irrelevant keys
$n = $list->get_data('count'); // the number of items in the list
$i = $list->selection[0];
$c = strtolower(chr($kv));
for ($j = 0; $j < $n; $j++) {
$i++;
if ($i == $n) $i = 0; // wrap around
$cc = strtolower(substr($list->get_text($i,1),0,1));
if ($cc == $c) break; // gotcha!
}
$list->select_row($i,1);
if ($list->row_is_visible($i) != 2) {
$list->moveto($i,1,0.0,0.0);
}
}
Consider an alphabetically sorted list, with the top item selected.
I press the "m" key, and the handler finds the first item in the list
starting with "m" - about halfway down the list - and selects it.
If the selected item is outside the visible range, clist::moveto is
called to scroll it into view. The focus however, is still on the top
item, and if I press the down arrow key at this point, the item that will
be selected is NOT the one that's below the "m" item selected by the
handler, but the second item in the list... This is what I'm trying to
solve.
--
André
============================================================
I'm out of my mind, but feel free to leave a message...