Two windows but can only see one menubar

Mac OSX specific forum
WilliamL
Addict
Addict
Posts: 1255
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Two windows but can only see one menubar

Post by WilliamL »

I tried rescator's example of opening two windows with menubars and moving between them in thread :

http://www.purebasic.fr/english/viewtop ... wrong+menu

I could only access the menubar from window 2. He said the code worked so I can only guess that the Mac version of pb doesn't work correctly.

Can anyone verify that the Mac version doesn't work?

William
MacBook Pro-M1 (2021), Tahoe 26.1, PB 6.30b2
Fred
Administrator
Administrator
Posts: 18397
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

On MacOS you can only have one menu bar, it's by design for OS X applications, so you will have to adapt it if needed.
WilliamL
Addict
Addict
Posts: 1255
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Post by WilliamL »

Thanks Fred... you saved me endless debugging and wondering if I made a simple mistake!

My program opens an unknown number of windows, and since menubars can only be created with a window number, I have to create a menubar in each window so that the last window opened is the active menubar (and they all have to be the same). I can work with this setup but I'm wondering if there is a simpler way? Also, maybe the manual should be updated to explain how to do this?

William

PS Have you been reading my other posts?
MacBook Pro-M1 (2021), Tahoe 26.1, PB 6.30b2
aaron
Enthusiast
Enthusiast
Posts: 267
Joined: Mon Apr 19, 2004 3:04 am
Location: Canada
Contact:

Post by aaron »

I'm not exactly following what you are doing. OSX is setup so that one program has one menubar, regardless of how many windows it opens. In purebasic terms, this means that the last menu that you've created in code is the only menu that will appear.

It sounds like you want the menubar to change based on which window is active? But then you mention that "(and they all have to be the same)"... which makes it sound like you actually only want a single menu?

Ok, so my first suggestion is that if you are opening multiple windows, follow the OSX standard... one menu regardless of how many windows you have open. It makes sense from a user standpoint - to them, your program is a single program just split amongst multiple viewpoints. They shouldn't have to activate one window in order to make it do things.

My second suggestion is that if you have special functions that each window is capable of, place a small icon bar at the top of each window with the particular functions that it is able to do.
WilliamL
Addict
Addict
Posts: 1255
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Post by WilliamL »

Interesting. It sounds to me that I could just make a menubar with the 'first window only' and it will work when I'm in any other window (also). I'm going to have to try it and see what happens. I was trying to follow the examples in the Help files. If this (menubar in first window only) works it will be much easier.

Thank aaron

William
MacBook Pro-M1 (2021), Tahoe 26.1, PB 6.30b2
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Post by michel51 »

WilliamL wrote:Interesting. It sounds to me that I could just make a menubar with the 'first window only' and it will work when I'm in any other window (also). I'm going to have to try it and see what happens. I was trying to follow the examples in the Help files. If this (menubar in first window only) works it will be much easier.

Thank aaron

William
I built a small example quickly.
See the code.

Code: Select all

; 2 Windows - 2 Menus

Enumeration
   #Main_Menu
   #File_001
   #File_002
   #File_003
   #File_004
   #File_005
   #File_006
   #File_007
   #Button
   #GadGet_Window
   #GadGet_Window_Menu
EndEnumeration

Procedure CreateMainMenu()
   If CreateMenu(#Main_menu,WindowID(#Main_Menu))
      MenuTitle("File")
      MenuItem(#File_001, "New"       )
      MenuItem(#File_002, "Open..."   )
      MenuBar()
      MenuItem(#File_003, "Close"     )
      MenuItem(#File_004, "Save"      )
      MenuItem(#File_005, "Save As...")
   EndIf
EndProcedure

Procedure GadGet_Window_Open()
   Protected Quit
   If OpenWindow(#GadGet_Window, 60,90,500, 400, "Gadget Features", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget)
      If CreateMenu(#GadGet_Window_Menu,WindowID(#GadGet_Window))
         MenuTitle("GadgetMenu")
         MenuItem(#File_006, "New 1"       )
         MenuItem(#File_007, "Open recent..."   )
      EndIf
   EndIf
   Repeat
      If (WaitWindowEvent() = #PB_Event_CloseWindow) And (EventWindow() = #GadGet_Window)
         FreeMenu(#GadGet_Window_Menu)
         Quit = 1
         ;    HideMenu(#GadGet_Window_Menu, 1)
         CloseWindow(#GadGet_Window)
         SetActiveWindow(#Main_Menu)
         CreateMainMenu()
      EndIf
   Until Quit = 1
   
EndProcedure

If OpenWindow(#Main_Menu, 0,0,500, 500, "Main Menu", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   
   If CreateGadgetList(WindowID(#Main_Menu))
      ButtonGadget(#Button, 10, 10, 100, 30, "New Window")
   EndIf
   CreateMainMenu()
EndIf

Repeat
   evnt = WaitWindowEvent()
   gad = EventGadget()
   
   If evnt
      If gad
         GadGet_Window_Open()
      EndIf
   EndIf
Until evnt = #PB_Event_CloseWindow
You'll see, that with the 2. window the menu is changed.
Closing this window will show the first menu.
Not tested the availability of the menuitems, but normaly it has to work.
And it's not perfect :-)

Good Luck!
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
WilliamL
Addict
Addict
Posts: 1255
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Post by WilliamL »

Long story short... (simple version)

Create the menubar once and don't close that window. (till your at the End)
MacBook Pro-M1 (2021), Tahoe 26.1, PB 6.30b2
Post Reply