Panel/Tab and focus event

Just starting out? Need help? Post your questions and find answers here.
HarryO
User
User
Posts: 42
Joined: Wed May 07, 2003 4:25 am
Location: Palatine,IL.,USA

Panel/Tab and focus event

Post by HarryO »

Hello,

For reference: PureBasic v4.02 (Windows - x86) / Win-XP Pro-SP2

I am trying some code for when a tab in one of several panels get focus.

The only related thread I found is:

http://www.purebasic.fr/english/viewtopic.php?t=8876

Old and no help.

I know that:

Code: Select all


  Type   = EventType()
  
;The following values are possible, 
;if an event of the type #PB_Event_Gadget (library Gadget) or 
;                        #PB_Event_SysTray (library Systray) occurs: 
;
;  #PB_EventType_LeftClick       : Left mouse button click
;  #PB_EventType_RightClick      : right mouse button click
;  #PB_EventType_LeftDoubleClick : Left mouse button double click
;  #PB_EventType_RightDoubleClick: Right mouse button double click
;  #PB_EventType_Focus           : Get the focus.
;  #PB_EventType_LostFocus       : Lose the focus.
;  #PB_EventType_Change          : Content change.
;

So I would have thought that when a change in focus occurs, that would generate an event that would be captured by:

Code: Select all

  
  Event  = WaitWindowEvent()
  
;  Case #PB_Event_Menu           : a menu has been selected
;  Case #PB_Event_Gadget         : a gadget has been pushed
;  Case #PB_Event_SysTray        : an icon in the systray zone was clicked
;  Case #PB_Event_CloseWindow    : the window close gadget has been pushed
;  Case #PB_Event_Repaint        : the window content has been destroyed And must be repained (useful For 2D graphics operations)
;  Case #PB_Event_SizeWindow     : the window has been resized
;  Case #PB_Event_MoveWindow     : the window has been moved
;  Case #PB_Event_ActivateWindow : the window has been activated (got the focus)

  Gadget = EventGadget()
  Window = EventWindow()
  Type   = EventType()

This does not seem to be the case.

I have posted my code below and since I am not a full time programmer, maybe I missed something.

What happens is that when you click/select 'Tab 1' and then 'Tab 4' nothing happens.

Select another tab and you will see the changes in the debug window.

Code follows:

Code: Select all


Global Window_0, Panel_0, Panel_1

;
;		Start Enumeration for gadget's
;

Enumeration 1
	#WindowID0
	#PanelID0
	#PanelID1
	#Max_Obj_ID				; This Constant is always last, used for DIM of structured array
EndEnumeration

Structure VisualDesignerGadgets
  Handle_ID.l
  EventFunction.l
EndStructure

Global Dim EventProcedures.VisualDesignerGadgets(#Max_Obj_ID)

Procedure Panel_1_Event(Window, Event, Gadget, Type)
  Which_Panel.l 
  Which_Tab.l
  Debug "Panel_1"
	Which_Panel = gadget
	Which_Tab = GetGadgetState(gadget)
  Debug "Panel(GadgetID) = " + Str(which_panel) + ", Tab = " + Str(Which_Tab) + " and Type = " + Str(type) + " ."
EndProcedure

Procedure Panel_0_Event(Window, Event, Gadget, Type)
  Which_Panel.l 
  Which_Tab.l
  Debug "Panel_0"
	Which_Panel = gadget
	Which_Tab = GetGadgetState(gadget)
  Debug "Panel(GadgetID) = " + Str(which_panel) + ", Tab = " + Str(Which_Tab) + " and Type = " + Str(type) + " ."
EndProcedure

Procedure RegisterGadgetEvent(Gadget, *Function, HandleID)
  
    EventProcedures(Gadget)\Handle_ID     = HandleID
    EventProcedures(Gadget)\EventFunction = *Function
  
EndProcedure

Procedure CallEventFunction(Window, Event, Gadget, Type)
  
      CallFunctionFast(EventProcedures(Gadget)\EventFunction, Window, Event, Gadget, Type)
  
EndProcedure

Procedure Open_Window_0()
  
  Window_0 = OpenWindow(#WindowID0, 235, 105, 400, 200, "Window 0",  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_WindowCentered )
  
  If Window_0
    If CreateGadgetList(WindowID(#WindowID0))
      Panel_0 = PanelGadget(#PanelID0, 12, 90, 1230, 660)
	      AddGadgetItem(#PanelID0, 1, "Tab 1")
		      Panel_1 = PanelGadget(#PanelID1, 6, 8, 1210, 620)
			      AddGadgetItem(#PanelID1, 1, "Tab 4")
			      AddGadgetItem(#PanelID1, 2, "Tab 5")
		      CloseGadgetList()
		      Panel_1 = GadgetID(#PanelID1)
		      RegisterGadgetEvent(#PanelID1, @Panel_1_Event(),Panel_1)
	      AddGadgetItem(#PanelID0, 2, "Tab 2")
	      AddGadgetItem(#PanelID0, 3, "Tab 3")
      CloseGadgetList()
      Panel_0 = GadgetID(#PanelID0)
      RegisterGadgetEvent(#PanelID0, @Panel_0_Event(),Panel_0)
      
    EndIf
  EndIf
EndProcedure

Open_Window_0()

Repeat
  
  Event  = WaitWindowEvent()
  Gadget = EventGadget()
  Window = EventWindow()
  Type   = EventType()
 
  Select Event

    Case #PB_Event_Gadget

      CallEventFunction(Window, Event, Gadget, Type)
      
  EndSelect
  
Until Event = #PB_Event_CloseWindow

End
I have tried the debug code inline with the main loop and get the same results.

I really don't think I have found a bug with such a basic capability.

I must be missing something here.

I thank you in advance for any insight to this.

Harry0
HarryO
User
User
Posts: 42
Joined: Wed May 07, 2003 4:25 am
Location: Palatine,IL.,USA

Guess I should have read the docs....

Post by HarryO »

Hello,

Sorry for the above post.

After reading the docs futher, a panelgadget is not supported as a gadget that works with EventType().

So, that does bring up the question: is it possible to capture when a tab in a panel gets focus?

HarryO
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Give this a try:

Code: Select all

Global oldproc, lastgadget, lastitem

Procedure WindowProc(hwnd, msg, wparam, lparam)
  Select msg
    Case #TCM_GETITEM

      gadget = GetDlgCtrlID_(hwnd)
      item = wparam
      If gadget<>lastgadget Or item<>lastitem
        lastgadget = gadget
        lastitem = item
        Debug "Gadget: "+Str(gadget)+", item: "+Str(item)
      EndIf

  EndSelect
        
 ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
EndProcedure


  If OpenWindow(0, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
       PanelGadget (1, 10, 20, 290, 180)
          AddGadgetItem(1, -1, "Sub-Panel 1")
          AddGadgetItem(1, -1, "Sub-Panel 2")
          AddGadgetItem(1, -1, "Sub-Panel 3")
          AddGadgetItem(1, -1, "Sub-Panel 4")
        CloseGadgetList()
 
    oldproc = SetWindowLong_(GadgetID(1), #GWL_WNDPROC, @WindowProc())
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
BERESHEIT
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

This method avoids subclassing:

Code: Select all

If OpenWindow(0, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  PanelGadget (1, 10, 20, 290, 180) 
    AddGadgetItem(1, -1, "Sub-Panel 1") 
    AddGadgetItem(1, -1, "Sub-Panel 2") 
    AddGadgetItem(1, -1, "Sub-Panel 3") 
    AddGadgetItem(1, -1, "Sub-Panel 4") 
  CloseGadgetList() 
EndIf  

Repeat
  Select WaitWindowEvent()
  Case #PB_Event_Gadget
    Select EventGadget()
    Case 1 ; Panel gadget
      Debug "Sub-Panel "+Str(GetGadgetState(1)+1)+" selected"
    EndSelect
  Case #PB_Event_CloseWindow
    End
  EndSelect
ForEver
Anthony Jordan
Post Reply