Page 1 of 1

Crossplatform RemoveSubMenu [Resolved]

Posted: Sun Feb 08, 2026 12:20 pm
by Kwai chang caine
Hello at all 8)

I need to remove sub menu and see with surprise FRED haven't planned this function :shock:

https://www.purebasic.com/documentation/menu/index.html

Surely because LINUX and/or MAC haven't this style of API (I don't know anything about it :oops:)

So for the moment, and only for WINDOWS, i replace by the API

Code: Select all

RemoveMenu_(MenuID(#MENU), x,0)
and that works 8)

But for one time since my begining to PB, i need a crosspatform function, Windows/Linux/Mac
Have you a solution for do that ?

Have a good day

Re: Crossplatform RemoveSubMenu

Posted: Mon Feb 09, 2026 12:21 pm
by SMaag
My way is to free the complete menu and recreate it!

under Linux GTK maybe this:

gtk_container_remove(menu, submenu)

GtkMenu inherits from GtkContainer, so any of the GtkContainer methods also work on the menu.

Re: Crossplatform RemoveSubMenu

Posted: Mon Feb 09, 2026 12:45 pm
by Kwai chang caine
Hello SMAAG 8)

It's already a good idea... :idea:
Because I only did a cursory look online, since I've never used Linux for programming, and I quickly realized it wasn't going to be easy, perhaps even impossible. :cry:

It's surely for that FRED not implement this fonction.

It's too much often complicate with LINUX
I think I'll stick with Windows; I already have enough trouble with it. Linux is for the "TRUE" :oops:

Thanks a lot MASTER for your precious help 8)

Re: Crossplatform RemoveSubMenu

Posted: Tue Feb 10, 2026 9:50 am
by BarryG
SMaag wrote: Mon Feb 09, 2026 12:21 pmMy way is to free the complete menu and recreate it
That's okay for small simple menus, but not good for large menus with disabled text, icons, checkmarks, etc. You'd need to recreate all that, which is too much work. A cross-platform command to remove a menu item would be much better.

Re: Crossplatform RemoveSubMenu

Posted: Tue Feb 10, 2026 10:40 am
by Kwai chang caine
BarryG wrote: Tue Feb 10, 2026 9:50 am That's okay for small simple menus, but not good for large menus with disabled text, icons, checkmarks, etc. You'd need to recreate all that, which is too much work. A cross-platform command to remove a menu item would be much better.
Hello BarryG
It's exactely what i have thinking when SMAAG have the kindness 8) to give to me already ONE, radical solution :shock:

But i'm affraid he have right, if you search in internet "LINUX remove submenu" it's the desert of GERGOVIE :shock:" and again...event not a camel :lol:
Apparently...in LINUX the programmer never need to remove it :|
And like I don't understand a single word about LINUX :oops: i prefer abandon me too to do a LINUX version of my works :|

I think also...perhaps FRED is one of the BEST....but for the miracle...create something not exist....or with 3 pages of code for doing that..it's not really a good idea and also in the policy of PB "Power and Simplicity"

Apparently LINUX is really not also "open" that WINDOWS, i'm not sure there are as much API that WINDOWS (It's just my mind in the unknow word :oops: )
And again, see in WINDOWS, why the EDITOR not have event simple management, just change, focus, etc ... :shock: you must passed by callback or subclassing :shock: , why him and nearly only him ???

I know...perhaps Bill Gates not love SPIDERMAN when he is young, and hate his bad boss EDITOR :mrgreen:

Image

Re: Crossplatform RemoveSubMenu [Resolved]

Posted: Wed Feb 11, 2026 11:46 am
by SMaag
BarryG wrote: Tue Feb 10, 2026 9:50 am
That's okay for small simple menus, but not good for large menus with disabled text, icons, checkmarks, etc. You'd need to recreate all that, which is too much work. A cross-platform command to remove a menu item would be much better.
For lager Menus I have 2 ways to do:

1. Make a CreateMenu(Flags) or better spilt it into seperated CreatMenuTitle(Flags)
you have at least 32 Flags to hide different Menus, when creating.

Flags like: #mnu_LastFile01_Hide, #mnu_LastFile02_Hide

2. This a very new Methode and it exists at the moment only as a ProofOfConcept code

Creating the Menu directly from a DataSection:
That means: the comlete Menu is defined in a Datasection.
From there I create a ListStructure with all MenuEntries. Each entry has flags for Checked, Disabled, Hide

With the List I create the Menu and I can automatically create PureBasic Code for the Event Procs.

Now it is very easy to recreate complete MenuTitles with a new setting!

here the DataSection Example for the PB-IDE File Menu

Code: Select all

  DataSection
    mnuFile:
    Data$ "mnuFile", "File"
    Data$   "_New",  "New", "[Ctrl+N]"
    Data$   "_Open", "Open...", "[Ctrl+O]"
    Data$   "_Save", "Save", "[Ctrl+S]"
    Data$   "_SaveAs", "Save As..."
    Data$   "_SaveAll", "Save All"
    Data$   "_Reload", "Reload"
    Data$   "_Close", "Close", "[Ctrl+W]"
    Data$   "_CloseAll", "Close All"
    Data$   "_ViewChanges", "View Changes"
    Data$   "-"
    Data$   "_ShowInFolder", "Show in Folder"
    Data$   "-"
    Data$   #LF$, "_FileFormat", "File Format"
    Data$     "_EncodingPlainText", "Encoding: Plain Text"
    Data$     "_EncodingUtf8", "Encoding Utf8"
    Data$     "-"
    Data$     "_NewLineCRLF", "Newline: Windows (CRLF)"
    Data$     "_NewLineLF", "Newline: Linux (LF)"
    Data$     "_NewlineCR", "Newline: MaxOS (CR)"       
    Data$   #CR$
    Data$   "-" 
    Data$   "_Prferences", "Preferences..."
    Data$   "-"
    Data$   "_SessionHistory", "Session History"
    Data$   #LF$, "_RecentFiles", "Recent Files"
    Data$     "_File01", "File 1", "%\h"
    Data$     "_File02", "File 2", "%\h"  
    Data$     "_File03", "File 3", "%\h"  
    Data$     "_File04", "File 4", "%\h"  
    Data$     "_File05", "File 5", "%\h"  
    Data$     "_File06", "File 6", "%\h"  
    Data$     "_File07", "File 7", "%\h"  
    Data$     "_File08", "File 8", "%\h"  
    Data$     "_File09", "File 9", "%\h"  
    Data$     "_File10", "File 10", "%\h"  
    Data$   #CR$
    Data$   "-"
    Data$   "_Quit", "Quit"
    Data$ #EOT$
 EndDataSection

Re: Crossplatform RemoveSubMenu [Resolved]

Posted: Wed Feb 11, 2026 12:08 pm
by SMaag
Apparently LINUX is really not also "open" that WINDOWS, i'm not sure there are as much API that WINDOWS (It's just my mind in the unknow word :oops: )
under Linux there are 1000's of API functions. The problem is: the GUI is not Linux itself! So we have different API functions for the grafics library.

GTK2, GTK3, Qt

Then additional API for the Desktops like Gnome, KDE ...
It's terrible!

Until know PB needs the GTK Framework installed!

Writing a real Cross Platform Application for Windows and different Linux distributions it's a difficult task!

Re: Crossplatform RemoveSubMenu [Resolved]

Posted: Wed Feb 11, 2026 12:57 pm
by Kwai chang caine
You have right, i have not thinking of this history of differents GUI, and i don't know that there was several library :shock:
I see the now, the enormous difficulty :shock:
I admire you all, who knows how turn around of these different worlds of computing, apparently without difficulty :shock:

Image

(LINUX, WINDOWS, ASM, C langage, etc ...) 8)

Since several decades i use PB, never i imagine this difficulty because i always programming for WINDOWS :oops:
But this time, I felt somewhat forced to try for all the users of PB, for my addings of IDE, but it's already enough difficult and "buggy possibility" with WINDOWS i know a little bit, for adding two OS furthermore also difficult :oops: I'd rather give up than do something stupid.
Just one time there are a long time ago, i have install and running the IDE on LINUX just by curiosity...
I say : "Ooooooh amazing, my favourite IDE...i'm in my home here too !!!" 8) and click on the cross in the right corner for the life :mrgreen:

Thanks a lot MASTER SMAAG for your kindness and precious explanations and the interest for little KCC :oops:

Re: Crossplatform RemoveSubMenu [Resolved]

Posted: Mon Feb 16, 2026 6:37 pm
by SMaag
I played arround with the issues RemoveMenuItem and AddMenuItem.

In Purebasic under Windows:
It is possible to remove a MenuItem, But it is not possible to Add it again.
If you try to Add it again it will be added as MenuTitel not as Item.

In Purebasic under Linux
RemoveMenuItem do not work because we cant get the widgetID for the MenuItem
It seems this could be the ReturnValue of MenuItem() what do not exist in Purebasic.

here the code what shows the Problem

Code: Select all

EnableExplicit

Enumeration Window
  #Window_Main 
EndEnumeration

Enumeration Menu
  #Menu_Main
EndEnumeration

Procedure RemoveMenuItem(hMenu, MenuID)
  
  CompilerSelect #PB_Compiler_OS
      
    CompilerCase #PB_OS_Windows
      RemoveMenu_(hMenu, MenuID, #MF_BYCOMMAND) ; Menüpunkt entfernen
      DrawMenuBar_(WindowID(#Window_Main))       ; Menüleiste aktualisieren
      
    CompilerCase #PB_OS_Linux
     ; hMenu = GtkMenu / GtkMenuBar, MenuID = GtkMenuItem
      Protected containter, widget
      containter = hMenu
      
      ; widget = MenuTitel() 
      
      ; Does not work because we can't get the widget. For that a ReturnValue of MenuItem() is needed
      ; what do not exist in Purebasic!
      
      ; gtk_container_remove_(containter, widget)
      
      ; redraw Menu
      gtk_widget_show_all_(WindowID(#Window_Main))
      
    CompilerCase #PB_OS_MacOS
      
  CompilerEndSelect

EndProcedure

Procedure AddMenuItem(hMenu, MenuID, Text$, Position)
  ; Add a Menu Titel, not a SubItem
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
       
      Protected mii.MENUITEMINFO
      With mii
        \cbSize      = SizeOf(MENUITEMINFO) 
        \fMask       = #MIIM_ID | #MIIM_STRING
        \fType       = 0
        \fState      = 0
        \wID         = MenuID
        \hSubMenu    = 0
        \hbmpChecked = 0
        \hbmpUnchecked = 0
        \dwItemData  = 0
        \dwTypeData  = @Text$        ; Zeiger auf den Text
        \cch         = Len(Text$)  
      EndWith  
     
      ; Insert Menu
      ; This does not work! It insertes the save menu as MenuTitel
      ; The Problem is: Purebasic does not deliver a ReturnValue with MenuItem.
      ; seems it is only an internal value for PB.
      InsertMenuItem_(hMenu, Position, #MF_BYPOSITION, @mii)
      
      ; Redraw Menu
      DrawMenuBar_(WindowID(#Window_Main))
      
    CompilerCase #PB_OS_Linux
      
  CompilerEndSelect 
EndProcedure

; Fenster erstellen
If OpenWindow(#Window_Main, 100, 100, 400, 300, "Mein PureBasic Fenster", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

  ; Menü erstellen und Handle speichern
  Define hMenu, xMenu_Save_Hide
  hMenu = CreateMenu(#Menu_Main, WindowID(#Window_Main))
  
  MenuTitle("File")
    MenuItem(1, "New")
    MenuItem(2, "Open...")
    MenuItem(3, "Save")
    MenuItem(4, "-") ; Trennlinie
    MenuItem(5, "Exit")
  
  MenuTitle("Edit")
    MenuItem(6, "undo")
    MenuItem(7, "copy")
    MenuItem(8, "paste")
  
   MenuTitle("Help")
    MenuItem(9, "Über")
  
  ; Button for remove Menu save
  ButtonGadget(0, 20, 220, 120, 30, "remove save")


  ; Event-Loop
  Repeat
    Define Event = WaitWindowEvent()
    
    Select Event
      Case #PB_Event_Menu
        Select EventMenu()
          Case 1: MessageRequester("Info", "new")
          Case 2: MessageRequester("Info", "open")
          Case 3: MessageRequester("Info", "save")
          Case 5: End
          Case 6: MessageRequester("Info", "undo")
          Case 7: MessageRequester("Info", "copy")
          Case 8: MessageRequester("Info", "insert")
          Case 9: MessageRequester("Info", "PureBasic Example")
        EndSelect

      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0 ; Button pressed
            If xMenu_Save_Hide
              AddMenuItem(hMenu, 3, "save", 2)
              SetGadgetText(0, "remove save")
            Else
              RemoveMenuItem(hMenu, 3)        
              SetGadgetText(0, "add save")
            EndIf
            xMenu_Save_Hide !1
         EndSelect
    EndSelect
    
  Until Event = #PB_Event_CloseWindow
EndIf


Re: Crossplatform RemoveSubMenu [Resolved]

Posted: Mon Feb 16, 2026 11:45 pm
by BarryG
SMaag wrote: Wed Feb 11, 2026 11:46 amFrom there I create a ListStructure with all MenuEntries. Each entry has flags for Checked, Disabled, Hide
That's not enough flags. For each menu item you want to recreate, you may need all these: Text, Icon, Checked, Disabled, Hidden, MenuBar.

So if you've got a large menu with any of these flags set, it's a pain to free it and recreate it all from scratch. :(

Re: Crossplatform RemoveSubMenu [Resolved]

Posted: Tue Feb 17, 2026 6:05 pm
by AZJIO
Instead of deleting the recent files menu, I want to reserve empty items and then rename them (SetMenuItemText), for example:

file1
file2
empty (+DisableMenuItem)
empty
empty
empty
empty
empty
empty
empty
SMaag wrote: Wed Feb 11, 2026 12:08 pm GTK2, GTK3, Qt
Yesterday I installed Manjaro + Wayland. 20-30% of my programs do not start. I had to use qt to get them to work.