Custom ComboboxGadget - problem setting dropdown window active

Just starting out? Need help? Post your questions and find answers here.
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Custom ComboboxGadget - problem setting dropdown window active

Post by firace »

I am experimenting with my own comboboxGadget variant, to have more freedom with colors and style.
It internally uses a ListIconGadget (among others) and works decently well, except for keyboard navigation. Keyboard events (up-down arrows) within the ListIconGadget are not being detected. They do work if I comment this line, but then I have problems keeping the main window in focus when clicking an entry in the dropdown box. Thanks for any suggestions (preferably not involving a window callback if possible)

Code: Select all

 SetWindowLongPtr_(WindowID(2),#GWL_STYLE, $44A09041 & ~#WS_VSCROLL & ~#WS_BORDER) 

Code: Select all

;-- CUSTOM GADGET DEFINITION START

#PB_Event_CustomGadget = 999

Procedure OnCustomGadgetResizeHandler()
  ga = 3
  ResizeWindow(2, WindowX(0)+GadgetX(ga)+3, WindowY(0)+GadgetY(ga)+54, GadgetWidth(ga), 150)
EndProcedure

Procedure OnMainWindowActivateHandler()
  Debug "-"
  If EventWindow() = 0 And IsWindow(2)
    HideWindow(2, 1)
  EndIf 
EndProcedure   

Procedure OnCustomGadgetClickHandler()
  If IsWindowVisible_(WindowID(2))
    HideWindow(2, 1)
  Else
    HideWindow(2, 0, #PB_Window_NoActivate)
  EndIf
EndProcedure   

Procedure OnCustomGadgetSelChangeHandler()
  Shared ga
  SetGadgetText(ga, GetGadgetItemText(900+ga, GetGadgetState(900+ga)) )
  PostEvent(#PB_Event_CustomGadget)
  HideWindow(2, 1)
EndProcedure   

Procedure ComboBoxGadget2(g, x, y, w, h)
  Shared ga : ga = g
  ContainerGadget(3, x, y, w, h, #PB_Container_Flat)            : SetGadgetColor(3, #PB_Gadget_BackColor, $FBE3E3)
  TextGadget(g, 6, 6, w-30, h, "Choose Radio", #SS_NOTIFY)      : SetGadgetColor(g, #PB_Gadget_BackColor, $FBE3E3)
  TextGadget(5, GadgetWidth(3) - 24 ,6,24,24," ", #SS_NOTIFY)  : SetGadgetColor(5, #PB_Gadget_BackColor, $FBE3E3)
  CloseGadgetList()
  
  OpenWindow(2, WindowX(0)+GadgetX(3)+3, WindowY(0)+GadgetY(3)+54, GadgetWidth(3), 150, "CustomComboBoxDropDown", #PB_Window_Invisible | #PB_Window_NoActivate , WindowID(0))
  SetWindowLongPtr_(WindowID(2),#GWL_STYLE, $44A09041 & ~#WS_VSCROLL & ~#WS_BORDER)

  ListIconGadget(900+ga, 0, 0,   GadgetWidth(3), 150, "", GadgetWidth(3), #LVS_NOCOLUMNHEADER | #LVS_NOSCROLL )
  SetGadgetColor(900+ga, #PB_Gadget_BackColor, $FBE3E3)
  SetWindowColor(2, $FBE3E3)
  HideWindow(2, 1)
  SetWindowTheme_(GadgetID(900+ga), @"Explorer", 0)
  UseGadgetList(WindowID(0))
  
  BindGadgetEvent(900+ga, @OnCustomGadgetSelChangeHandler(), #PB_EventType_LeftClick)
  BindGadgetEvent(g, @OnCustomGadgetClickHandler())
  BindGadgetEvent(5, @OnCustomGadgetClickHandler())
  
  BindEvent(#PB_Event_MoveWindow,       @OnCustomGadgetResizeHandler())
  BindEvent(#PB_Event_ActivateWindow,   @OnMainWindowActivateHandler())
  BindEvent(#PB_Event_DeactivateWindow, @OnMainWindowActivateHandler())
  BindEvent(#PB_Event_LeftClick,        @OnMainWindowActivateHandler())
EndProcedure

Procedure ComboBoxGadget2AddItem(g, position, text$)
  AddGadgetItem(900+g, position, text$)
EndProcedure   

;-- CUSTOM GADGET DEFINITION END 


OpenWindow(0, #PB_Any, #PB_Any, 500, 130, "Test App",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0, $FBE3E3)

ComboBoxGadget2(99, 60, 50, 240, 30)      
ComboBoxGadget2AddItem(99, -1, "WZBC Radio")
ComboBoxGadget2AddItem(99, -1, "Radio 4")


Repeat
  e = WaitWindowEvent()
  Select e
    Case  #PB_Event_CustomGadget
      Debug GetGadgetText(99)  
    Case  #PB_Event_CloseWindow : End
  EndSelect
Forever
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Re: Custom ComboboxGadget - problem setting dropdown window active

Post by firace »

Hehe, I might have found a very interesting solution, but couldn't confirm it yet, as I'm still trying to learn... I found a very old related discussion in a Russian forum (a 19-year-old thread!):

https://forum.ixbt.com/topic.cgi?id=40:600

So it seems that the secret trick (used by Windows itself in its comboboxes) is to make the dropdown box a child of the desktop.
Post Reply