Page 1 of 1

How can I add an image gadget to the tab-stop order?

Posted: Tue Feb 24, 2009 10:49 pm
by Demivec
I am working on a custom control.

It is implemented using the ImageGadget. The gadget choice accomplishes all of my needs thus far with one notable exception. I can't navigate to the gadget by tabbing from other gadgets.

I have reviewed forum threads regarding changing z-order positions that determine the sequence for gadgets and their activations (code posted by Sparkie).

The challenge seems to be not in changing the z-order, but in adding a gadget to the z-order. I know certain gadgets don't seem to be added to the z-order, such as ImageGadgets, and TextGadgets, because they don't need to be interacted with. Is there a way to add this functionality for the purpose of enabling keyboard input on those gadgets? I can already receive mouse input, and once selected with the mouse I can set them up to receive keyboard input until they lose focus. I looking for a way for them to be placed in the tab-stop order so that they can be selected with the tab key and then interacted with by the keyboard.

This is my first attempt at subclassing a control. I've tried going about subclassing other gadgets that already allow tab-stops and keyboard interaction but ran into snags in the controls interactions with the mouse for instance. I ran across the ImageGadget idea (from Xombie). It works great. I just need this one feature solved and it would remove the remaining obstacles for rounding out this customization.

I want to implement any changes in the callback for the specific control and not in a PureBasic event loop. This would make the control usable in more situations without having to heavily customize the event loop to make it function.

Any ideas?

Posted: Tue Feb 24, 2009 11:45 pm
by srod
Just set the tabstop style.

Code: Select all

Global goldProc

Procedure.i Proc(hwnd, uMsg, wParam, lParam) 
  Select uMsg
    Case #WM_KEYDOWN
      Debug "KeyDown on umage gadget!"
  EndSelect
  ProcedureReturn CallWindowProc_(goldProc, hwnd, uMsg, wParam, lParam) 
EndProcedure


If OpenWindow(0, 0, 0, 245, 105, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    StringGadget(0, 10, 10, 80, 20, "Press tab")
    ImageGadget(1, 130, 10, 100, 83, 0, #PB_Image_Border)     ; imagegadget with border
    goldProc = SetWindowLong_(GadgetID(1), #GWL_WNDPROC, @Proc())
    SetWindowLong_(GadgetID(1), #GWL_STYLE, GetWindowLong_(GadgetID(1), #GWL_STYLE)|#WS_TABSTOP)

    SetActiveGadget(0)
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Posted: Wed Feb 25, 2009 12:56 am
by Demivec
Thanks srod, it works wonderfully. :D

I'll be posting the custom gadget to the Tricks n' Tips forum in about a week.

I appreciate your help.