Here's one I wrote. It doesn't rely on you to actively keep track of the focus, and it is very easy to add/subtract/rearrange items in the tab cycle order, so that might make it a little easier. But, it doesn't have the text selection stuff built-in like Syntax Error's, and there are other problems, but I think they're Blitz issues.
;------------------------------
; USERLIB DECLARATIONS
;
; .lib "user32.dll"
; GetFocus%():"GetFocus"
;------------------------------
; CONSTS
Const evWindowClose = $803 ; "Real" Blitz event
Const evTab = $104 ; "Made up" event for HotKeyEvent
Const vkTab = 15 ; Scancode for Tab key
;------------------------------
; TYPES
Type TabCycleGadget
Field hgadget% ; Windows handle
Field gadget% ; Blitz handle
End Type
;------------------------------
; GLOBALS
Global wnd%, txt%, txt2%, button%, txtarea%, listbox%, tree%, button2%
;------------------------------
; MAIN PROGRAM
InitGUI()
InitTabCycle()
While WaitEvent()
Select EventID()
Case evWindowClose : End
Case evTab : PerformTabCycle(GetFocus(), EventData())
End Select
Wend
;------------------------------
; FUNCTIONS
Function InitGUI()
; Create Window
width% = 320 : height% = 240
x% = (ClientWidth(Desktop()) - width) / 2
y% = (ClientHeight(Desktop()) - height) / 2
wnd = CreateWindow("Tab Cycle Demo", x, y, width, height, 0, 1)
; Create Gadgets
txt = CreateTextField(5, 5, 200, 20, wnd,2)
txt2 = CreateTextField(5, 30, 200, 20, wnd)
button = CreateButton("Button", 5, 55, 80, 25, wnd)
txtarea = CreateTextArea(5, 85, 200, 95, wnd)
listbox = CreateListBox(210, 5, 100, 75, wnd)
tree = CreateTreeView(210, 85, 100, 65, wnd)
button2 = CreateButton("Button2", 210, 155, 80, 25, wnd)
; Configure Gadgets
AddGadgetItem listbox, "ListItem1"
AddGadgetItem listbox, "ListItem2"
SelectGadgetItem listbox, 1
AddTreeViewNode("Node1", TreeViewRoot(tree))
AddTreeViewNode("Node2", TreeViewRoot(tree))
End Function
Function InitTabCycle()
; Set up Forward Tab Hotkey
HotKeyEvent vkTab, 0, evTab
; Set up Backward Tab Hotkey
HotKeyEvent vkTab, 1, evTab, 1
; Set up tab cycling in this order (empty list is ok)
; i.e. to change tab order, just cut and paste!
CreateTabCycleGadget(txt)
CreateTabCycleGadget(txt2)
CreateTabCycleGadget(button)
CreateTabCycleGadget(txtarea)
CreateTabCycleGadget(listbox)
CreateTabCycleGadget(tree)
CreateTabCycleGadget(button2)
End Function
Function CreateTabCycleGadget(g%)
t.TabCycleGadget = New TabCycleGadget
t\gadget = g
t\hgadget = QueryObject(g, 1)
End Function
Function PerformTabCycle(g%, bBackwards%)
Local t.TabCycleGadget = First TabCycleGadget
If g <> 0 And t <> Null Then
; Find out if current focused gadget is in tab cycle list
While (g <> t\hgadget) And (t <> Last TabCycleGadget) t = After t : Wend
; Change focus
If t <> Null Then
; Change from current focused gadget
If bBackwards Then
; Go backwards in cycle (SHIFT-TAB)
If t = First TabCycleGadget Then
t = Last TabCycleGadget
ActivateGadget(t\gadget)
Else
t = Before t
ActivateGadget(t\gadget)
EndIf
Else
; Go forwards in cycle (normal TAB)
If t = Last TabCycleGadget Then
t = First TabCycleGadget
ActivateGadget(t\gadget)
Else
t = After t
ActivateGadget(t\gadget)
EndIf
EndIf
Else
; Activate first gadget in cycle (no current focused gadget)
t = First TabCycleGadget
ActivateGadget(t\gadget)
EndIf
EndIf
End Function
|