At least a missing documentation ... (#PB_Menu_...)

Mac OSX specific forum
infratec
Always Here
Always Here
Posts: 6866
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

At least a missing documentation ... (#PB_Menu_...)

Post by infratec »

My main program starts with a hidden window, the window in foreground has a webgadget inside.
(It has nothing to do with hidden, it happens always if I there are multiple windows)

#PB_Menu_Quit (inside window 0) was not working anymore.
After some debugging I found out the the return value of EventWindow() is -1 in this case.
So I needed:

Code: Select all

OpenWindow(0, 0, 0, 10, 10, "", #PB_Window_Invisible)
OpenWindow(1, 0, 0, 300, 200, "Foreground", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

Repeat
  Event = WaitWindowEvent()
  Select EventWindow()
    Case -1
      Select EventMenu()
        Case #PB_Menu_Quit
          Debug "macOS menu quit"
          Exit = #True
      EndSelect
    Case 0
      Select Event
        Case #PB_Event_CloseWindow
          Exit = #True
      EndSelect
    Case 1
      Select Event
        Case #PB_Event_CloseWindow
          PostEvent(#PB_Event_CloseWindow, 0, 0)
      EndSelect
  EndSelect
Until Exit
If this is the correct way, it should be noted in the documentation.
Is this the correct way :?:

I have a program where it is working after case #MainWindow (where #MainWindow is 0) strange ...

Ok, one step further:
If I use CreateMenu() in window 0 the macOS menu event returns in window 0 and not -1
But without a program menu it is definately -1.
Fred
Administrator
Administrator
Posts: 16664
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: At least a missing documentation ... (#PB_Menu_...)

Post by Fred »

You need to create a menu with the correct MenuItem() to be able to use the constants. It's mentioned here, but may be it's not very well explained: https://www.purebasic.com/documentation ... uitem.html
User avatar
mk-soft
Always Here
Always Here
Posts: 5386
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: At least a missing documentation ... (#PB_Menu_...)

Post by mk-soft »

I use this way ...

To use (activate) the About and Preferences menus, they must first be added.
But you cannot change the text of the MenuItem immediately (Maybe a bug?).

Code: Select all

;-TOP

#ProgramTitle = "Main Window"
#ProgramVersion = "v1.01.0"

Enumeration Windows
  #Main
EndEnumeration

Enumeration MenuBar
  #MainMenu
EndEnumeration

Enumeration MenuItems
  
EndEnumeration

Enumeration Gadgets
  
EndEnumeration

Enumeration StatusBar
  #MainStatusBar
EndEnumeration

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar); - MenuHeight()
  ; Resize gadgets
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
    ; Menu
    CreateMenu(#MainMenu, WindowID(#Main))
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
      ; Enable macOS Menu About and Preferences
      MenuItem(#PB_Menu_About, "")
      MenuItem(#PB_Menu_Preferences, "")
      ; Rename Menu Entry
      SetMenuItemText(#MainMenu, #PB_Menu_About, "Über " + GetFilePart(ProgramFilename(), #PB_FileSystem_NoExtension))
      SetMenuItemText(#MainMenu, #PB_Menu_Preferences, "Einstellungen")
    CompilerEndIf
    
    ; StatusBar
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar); - MenuHeight()
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    ; Event Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #Main
              Break
              
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                PostEvent(#PB_Event_CloseWindow, #Main, #Null)
                
            CompilerEndIf
              
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply