Handling the menu when opening child windows

Mac OSX specific forum
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Handling the menu when opening child windows

Post by coco2 »

Since learning that hiding a menu is not really something you need to do on a Mac I started figuring out what is supposed to happen when you open a child window. The menu on the parent should be freed and a new menu should be opened. However I've come across something odd when doing this the application menu seems to change to the name of the first menu on the parent window (File). Does anyone know how to get this to work, so than when you go to File > Open, the menu disappears leaving just the application menu?

Code: Select all

Enumeration
  #MenuOpen
  #MenuQuit
EndEnumeration
Procedure ShowMainMenu()
  CreateMenu(0, WindowID(0))
  MenuTitle("File")
  MenuItem(#MenuOpen, "Open...")
  MenuItem(#MenuQuit, "Quit")
  MenuItem(#PB_Menu_About, "About")
  MenuItem(#PB_Menu_Preferences, "Preferences")
  MenuItem(#PB_Menu_Quit, "Quit")  
EndProcedure
Define quit.i = 0
OpenWindow(0, 0, 0, 400, 300, "Test macOS Menu", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
ShowMenu()
Define event.i    
Repeat
  event = WaitWindowEvent(10)
  Select event
    Case #PB_Event_Menu
      Select EventMenu()
        Case #MenuOpen
          FreeMenu(0)
          OpenFileRequester("Open", "", "All files (*.*)|*.*", 0)
          ShowMainMenu()
        Case #MenuQuit
          quit = 1
      EndSelect
  EndSelect
Until event = #PB_Event_CloseWindow Or quit
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Handling the menu when opening child windows

Post by coco2 »

Solution found:

Code: Select all

Enumeration
  #MenuOpen
  #MenuQuit
EndEnumeration
Procedure ShowMainMenu()
  CreateMenu(0, WindowID(0))
  MenuTitle("File")
  MenuItem(#MenuOpen, "Open...")
  MenuItem(#MenuQuit, "Quit")
  MenuItem(#PB_Menu_About, "About")
  MenuItem(#PB_Menu_Preferences, "Preferences")
  MenuItem(#PB_Menu_Quit, "Quit")  
EndProcedure
Procedure ShowOpenMenu()
  CreateMenu(0, WindowID(0))
  MenuItem(#PB_Menu_About, "About")
  MenuItem(#PB_Menu_Preferences, "Preferences")
  MenuItem(#PB_Menu_Quit, "Quit")  
EndProcedure
Define quit.i = 0
OpenWindow(0, 0, 0, 400, 300, "Test macOS Menu", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
ShowMainMenu()
Define event.i    
Repeat
  event = WaitWindowEvent(10)
  Select event
    Case #PB_Event_Menu
      Select EventMenu()
        Case #MenuOpen
          FreeMenu(0)
          ShowOpenMenu()
          OpenFileRequester("Open", "", "All files (*.*)|*.*", 0)
          FreeMenu(0)
          ShowMainMenu()
        Case #MenuQuit
          quit = 1
      EndSelect
  EndSelect
Until event = #PB_Event_CloseWindow Or quit
Last edited by coco2 on Thu May 23, 2024 10:31 pm, edited 1 time in total.
User avatar
Piero
Addict
Addict
Posts: 923
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Handling the menu when opening child windows

Post by Piero »

Thanks! (even if I still did not test it on my Mac, and you there seem to like pineapple pizza)

You made me remember I noticed I cannot paste (⌘V) on save dialogs…
…also when you paste on Mac (again ⌘V) you should see the menu flashing, but not in PB…
Hope this can help implement "shortcuts" better, to avoid problems……
Post Reply