Allow control+tabbing between tabs of an MDIGadget()?

Just starting out? Need help? Post your questions and find answers here.
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Allow control+tabbing between tabs of an MDIGadget()?

Post by Quin »

Normally, in MDI applications, it's possible to control+tab forward through tabs, and control+shift+tab backwards through them. You even see this in the PB IDE! However, the native MDIGadget doesn't seem to support this. Is it possible for me to implement it manually?
Thanks!
User avatar
HeX0R
Addict
Addict
Posts: 1218
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Allow control+tabbing between tabs of an MDIGadget()?

Post by HeX0R »

Sorry Quin, no solution, but something strange I discovered:
I was tinkering with KeyboardShortcuts and the MDIGadget (which I used last time, boah... 15 years ago?) to see how things can be handled here.
Seems I found some hidden feature?
My MenuItem 11 of the Keyboardshortcut below leads to nothing, but if you press CTRL+TAB a window pops up asking to which MDI child you wanna go?!
That doesn't happen when there is no Keyboard shortcut, which is a little weird.

Code: Select all

If OpenWindow(0, 0, 0, 800, 600, "MDIGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
	If CreateMenu(0, WindowID(0))
		MenuTitle("MDI windows menu")
		MDIGadget(0, 0, 0, 0, 0, 0, 2, #PB_MDI_AutoSize)
		AddGadgetItem(0, 1, "child1")
		AddGadgetItem(0, 2, "child2")
		AddGadgetItem(0, 3, "child3")
		AddGadgetItem(0, 4, "child4")
		UseGadgetList(WindowID(0))
		AddKeyboardShortcut(0, #PB_Shortcut_Tab | #PB_Shortcut_Control, 11)
	EndIf
	Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
it doesn't happen also when I use:
MDIGadget(0, 0, 0, 0, 0, 0, 1, #PB_MDI_AutoSize)
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Allow control+tabbing between tabs of an MDIGadget()?

Post by idle »

this works

Code: Select all

Procedure MDIChild() 
  Protected child 
  
  Select EventMenu() 
    Case 0 
      child = GetGadgetState(0) + 1
      If child > 4 
        child = 1
      EndIf   
    Case 1
      child = GetGadgetState(0) - 1
      If child < 1 
        child = 4
      EndIf   
  EndSelect   
    
  SetGadgetState(0,child)
EndProcedure  

If OpenWindow(0, 0, 0, 800, 600, "MDIGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
    
  If CreateMenu(0, WindowID(0))
		MenuTitle("MDI windows menu")
		MDIGadget(0, 0, 0, 0, 0, 0, 2, #PB_MDI_AutoSize)
		BindMenuEvent(0,0,@MDIChild())
		BindMenuEvent(0,1,@MDIChild()) 
		AddGadgetItem(0, 1, "child1")
		AddGadgetItem(0, 2, "child2")
		AddGadgetItem(0, 3, "child3")
		AddGadgetItem(0, 4, "child4")
		UseGadgetList(WindowID(0))
		AddKeyboardShortcut(0, #PB_Shortcut_Control | #PB_Shortcut_Tab, 0)
		AddKeyboardShortcut(0, #PB_Shortcut_Control | #PB_Shortcut_Shift | #PB_Shortcut_Tab, 1)
	EndIf
	Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
edit both ways
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Allow control+tabbing between tabs of an MDIGadget()?

Post by Quin »

I came up with this:

Code: Select all

Procedure MenuEvents()
Select EventMenu()
Case 0
SetGadgetState(0, #PB_MDI_Next)
Case 1
SetGadgetState(0, #PB_MDI_Previous)
EndSelect
EndProcedure

If OpenWindow(0, 0, 0, 800, 600, "MDIGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
If CreateMenu(0, WindowID(0))
MenuTitle("MDI windows menu")
MDIGadget(0, 0, 0, 0, 0, 0, 2, #PB_MDI_AutoSize)
AddGadgetItem(0, 1, "child1")
AddGadgetItem(0, 2, "child2")
AddGadgetItem(0, 3, "child3")
AddGadgetItem(0, 4, "child4")
UseGadgetList(WindowID(0))
AddKeyboardShortcut(0, #PB_Shortcut_Control | #PB_Shortcut_Tab, 0)
AddKeyboardShortcut(0, #PB_Shortcut_Control | #PB_Shortcut_Shift | #PB_Shortcut_Tab, 1)
BindEvent(#PB_Event_Menu, @MenuEvents())
EndIf
Repeat : Until WaitWindowEvent(1) = #PB_Event_CloseWindow
EndIf
:wink:
How does the logic in your procedure work? I.e. what are those calculations?
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Allow control+tabbing between tabs of an MDIGadget()?

Post by idle »

I guess it helps to read the manual. :D
I've never used the MDI gadget in PB so I didn't have a clue and didn't notice #PB_MDI_NEXT
I was using % mod operator so it would wrap around
User avatar
ChrisR
Addict
Addict
Posts: 1484
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Allow control+tabbing between tabs of an MDIGadget()?

Post by ChrisR »

I haven't used the MDI gadget too. Quite strange behavior with #PB_MDI_Next and #PB_MDI_Previous!
Here with Quin's example, it rolls or unrolls in the opposite direction
With Ctrl+Tab (#PB_MDI_Next): child4 -> child3 -> 2 -> 1 -> 4
And with Ctrl+Shift+Tab (#PB_MDI_Previous): child1 -> child2 -> 3 -> 4 -> 1
it's all good with idle's code snippet, It wraps in the right order.
Do you have an explanation?
Post Reply