Re: [Fxruby-users] FXList and multiple selections
Status: Inactive
Brought to you by:
lyle
From: Lyle J. <ly...@kn...> - 2004-02-26 02:52:47
|
On Feb 25, 2004, at 5:29 PM, Matthew Miller wrote: > When selecting items in the FXList I see two different behaviors after > starting > the program: When I select one item and press and hold Ctrl, and then > select > other items and release Ctrl a message box shows that the correct > number of > items are selected. > > Conversely, before I select an item I press and hold Ctrl, and then > start > selecting items. When Ctrl is released the message box shows that zero > items > have been selected. My question is why I'm seeing this differing > behavior based > on when the first item is selected. It is a subtle problem, and has to do with the keyboard focus: when you press or release the Ctrl key, which window is going to receive those SEL_KEYPRESS and SEL_KEYRELEASE messages? In your first experiment, you start by selecting one item from the list. To do that you of course had to click somewhere in the list widget's content area, and that action assigned the keyboard focus to the list. For that reason, the list widget is the widget that "hears" the subsequent SEL_KEYPRESS and SEL_KEYRELEASE messages. In your second experiment, you pressed the Ctrl key before ever doing anything to transfer the focus to the list widget. The result is that the list widget never got that SEL_KEYPRESS message, and so it never set your @ctrlPressed attribute to true. The rest of the problems you described of course follow from that. The simplest solution is to make sure that the list gets the keyboard focus right away, by calling the list's setFocus() method somewhere in the main window's initialize() method, e.g. @list = FXList.new( frame, 0, nil, 0, LAYOUT_FILL_Y|LAYOUT_FILL_X|LIST_NORMAL ) @list.setFocus() After making this change, I think you will find that the selection count in the second experiment works as expected. Hope this helps, Lyle |