I’m working on the keyboard interface for a small application. The app
has several controls on a Panel. One of those controls is a Notebook
with 4 pages, each of which is another panel. Three of the tab panels
contain ListCtrls, the fourth has only StaticText controls.
The Notebook is in the middle of the tab order. When one of the ListCtrl
tabs is selected, the tab order progresses normally: through each
control before the notebook, then to the notebook’s tab, then to the
control(s) on that page of the notebook, then back off the notebook to
the controls later in the tab order. (The progression with shift-tab is
a bit weird – always to the tab first, then backwards through the
controls on that page, then back through the controls before the
notebook. But I can live with that.)
The problem is with the fourth tab that has only StaticText controls. If
that tab is visible, the tab progression stops once the notebook is
reached. The focus goes to the tab itself like normal, then the next tab
key entry makes the focus disappear, and further tab keystrokes do
nothing.
Sample code below demonstrates the problem. I hadn’t noticed it in my
real app, but in this sample it looks like the focus is going to one of
the controls on the other, hidden page of the notebook, then getting
stuck, presumably since that control is hidden and not supposed to
accept keystrokes.
Is there something I’m doing wrong? Is there some window other than a
Panel that is better for holding controls in Notebooks? Or is this just
the way the Notebook widget works, and I have to live with it? (I know I
could put a control that accepts keystrokes on that page to work around
the problem, but that would have no useful function on the page in
question in the actual app.)
David Peoples
#!/usr/bin/env ruby
require ‘wx’
include Wx
class MainFrame < Frame
def initialize(title)
super(nil, :title => title)
panel_1 = Panel.new(self)
box_1 = BoxSizer.new(VERTICAL)
panel_1.sizer = box_1
box_1.add(TextCtrl.new(panel_1, ID_ANY), 0, ALIGN_LEFT | ALL, 10)
box_1.add(TextCtrl.new(panel_1, ID_ANY), 0, ALIGN_LEFT | ALL, 10)
nb_1 = Notebook.new(panel_1, ID_ANY, DEFAULT_POSITION, DEFAULT_SIZE,
NB_TOP, “notebook_1”)
box_1.add(nb_1, 0, ALIGN_LEFT | ALL, 10)
panel_n1 = Panel.new(nb_1)
box_n1 = BoxSizer.new(VERTICAL)
panel_n1.sizer = box_n1
box_n1.add(TextCtrl.new(panel_n1, ID_ANY), 0, ALIGN_LEFT | ALL, 10)
box_n1.add(TextCtrl.new(panel_n1, ID_ANY), 0, ALIGN_LEFT | ALL, 10)
panel_n2 = Panel.new(nb_1)
box_n2 = BoxSizer.new(VERTICAL)
panel_n2.sizer = box_n2
box_n2.add(StaticText.new(panel_n2, ID_ANY, 'Text 1'), 0, ALIGN_LEFT
| ALL, 10)
box_n2.add(StaticText.new(panel_n2, ID_ANY, ‘Text 2’), 0, ALIGN_LEFT
| ALL, 10)
nb_1.add_page(panel_n1, "Tab 1", true)
nb_1.add_page(panel_n2, "Tab 2", false)
box_1.add(TextCtrl.new(panel_1, ID_ANY), 0, ALIGN_LEFT | ALL, 10)
end
end
Wx::App.run do
self.app_name = ‘TestNotebook’
frame = MainFrame.new(“Test notebook tab order”)
frame.show
end