Ooops
November 25, 2020, 04:32:32 AM

Author Topic: [bb] Gadget Tabber by Mr Brine [ 1+ years ago ]  (Read 550 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Gadget Tabber by Mr Brine [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Gadget Tabber
Author : Mr Brine
Posted : 1+ years ago

Description : See the code!  

thanx to Soja for info on getfocus()


Code :
Code: BlitzBasic
  1. ; (c)oded by Mr Brine
  2. ;
  3. ; Press tab/shift tab to iterate through the os objects
  4. ;
  5. ;
  6. ; User Libs
  7. ; =========
  8. ;
  9. ; .lib "user32.dll"
  10. ;
  11. ; GetFocus():"GetFocus"
  12. ;
  13.  
  14.  
  15. test()
  16.  
  17.  
  18. Function Test()
  19.  
  20.         ; create some test data
  21.  
  22.         win = CreateWindow("tab test", 100, 100, 300, 300, 0)
  23.        
  24.         tf = CreateTextField(0, 0, 100, 22, win)
  25.         ta = CreateTextArea(0, 30, 100, 70, win)
  26.         lb = CreateListBox(0, 110, 100, 100, win)
  27.         AddGadgetItem lb, "1", True
  28.         AddGadgetItem lb, "2"
  29.         AddGadgetItem lb, "3"
  30.         AddGadgetItem lb, "4"
  31.         bt = CreateButton("button", 110,  0, 100, 22, win)
  32.         cb = CreateButton("check", 110, 30, 100, 22, win, 2)
  33.         rd = CreateButton("radio", 110, 60, 100, 22, win, 3)
  34.         tv = CreateTreeView(110, 90, 100, 100, win)
  35.        
  36.         t = AddTreeViewNode("1", TreeViewRoot(tv))
  37.         AddTreeViewNode("1-1", t)
  38.         AddTreeViewNode("1-2", t)      
  39.         AddTreeViewNode("1-3", t)      
  40.                        
  41.         ; add gadgets to tab list
  42.                        
  43.         tablist = Tab_Add(0, tf)
  44.         tablist = Tab_Add(tablist, ta)
  45.         tablist = Tab_Add(tablist, lb)                 
  46.         tablist = Tab_Add(tablist, bt)
  47.         tablist = Tab_Add(tablist, cb)
  48.         tablist = Tab_Add(tablist, rd)
  49.         tablist = Tab_Add(tablist, tv)
  50.                                
  51.         ; set up hot key events to scan for 'tab' & 'shift-tab'                
  52.         ; the event id's for the hotkeys can be any value      
  53.  
  54.         HotKeyEvent 15, 0, $8888
  55.         HotKeyEvent 15, 1, $8889
  56.        
  57.         Repeat
  58.        
  59.                 WaitEvent()
  60.                
  61.                 Select EventID()
  62.                
  63.                         Case $8888
  64.  
  65.                                 HotKeyEvent 15, 0, $8888        ; resinitialise hot key events
  66.                                 HotKeyEvent 15, 1, $8889
  67.                                
  68.                                 Tab_Process(tablist, 1)         ; goto next os object in tab list
  69.                                
  70.                         Case $8889
  71.  
  72.                                 HotKeyEvent 15, 0, $8888        ; resinitialise hot key events
  73.                                 HotKeyEvent 15, 1, $8889
  74.        
  75.                                 Tab_Process(tablist, -1)        ; goto prev os object in tab list
  76.                                        
  77.                         Case $803
  78.                        
  79.                                 Exit
  80.                                
  81.                 End Select
  82.        
  83.         Forever
  84.  
  85.         FreeBank tablist
  86.         FreeGadget win
  87.  
  88. End Function
  89.  
  90.  
  91.  
  92.  
  93. ; ----------------------------------------------------------------------------------------------------
  94.  
  95.  
  96. ; tablist       = tab list (pass 0 if no tablist yet defined)
  97. ; oh            = os object to assign to tablist
  98. ;
  99. ; returns a pointer to tablist
  100. ;
  101. Function Tab_Add(tablist, oh)
  102.        
  103.         If(oh <> 0)
  104.        
  105.                 If(tablist = 0)
  106.                
  107.                         tablist = CreateBank(4)
  108.                
  109.                 Else    
  110.                
  111.                         ResizeBank tablist, BankSize(tablist) + 4
  112.                        
  113.                
  114.                 End If
  115.                
  116.                 PokeInt tablist, BankSize(tablist) - 4, oh
  117.        
  118.         End If
  119.        
  120.         Return tablist
  121.  
  122. End Function
  123.  
  124.  
  125.  
  126.  
  127. ; tablist       - tablist to work from
  128. ; dir           - direction tabber to go
  129. ;
  130. Function Tab_Process(tablist, dir)
  131.  
  132.         If(tablist = 0) Return
  133.         If(BankSize(tablist) = 0) Return
  134.  
  135.         Local   lo = 0
  136.        
  137.         While lo < BankSize(tablist)
  138.  
  139.                 If(QueryObject(PeekInt(tablist, lo), 1) = GetFocus()) Exit
  140.                 lo = lo + 4
  141.                
  142.         Wend
  143.        
  144.         If(lo => BankSize(tablist))
  145.        
  146.                 lo = 0                                                  ; current focus not in tab list
  147.        
  148.         Else
  149.        
  150.                 lo = lo + dir * 4                               ; current focus is in tab list
  151.                
  152.         End If
  153.        
  154.         While lo < 0
  155.        
  156.                 lo = lo + BankSize(tablist)
  157.                
  158.         Wend  
  159.        
  160.         lo = lo Mod BankSize(tablist)
  161.  
  162.         ActivateGadget PeekInt(tablist, lo)
  163.  
  164. End Function


Comments :


gman(Posted 1+ years ago)

 works well but i cannot get it to tab past a combobox.  the TAB and SHIFT-TAB events dont seem to generate when performed on this gadget.  has anyone worked around this problem?


Gabriel(Posted 1+ years ago)

 It doesn't work in TextAreas either, because it reads the tab and puts that in the TextArea. Heck, the example itself demonstrates this. It's not the author's fault, of course, it just goes to show that BlitzPlus is so horribly inadequate that even workarounds are mostly pointless and half-working is about as good as you can get.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal