macOS Fl_Sys_Menu_Bar's clear()

18 views
Skip to first unread message

Gonzalo Garramuno

unread,
May 13, 2022, 6:49:36 AM5/13/22
to fltkc...@googlegroups.com

According to the documentation, calling clear should set the menu to NULL. However, when I try it with no items yet, it crashes the application. Is the documentation wrong or am I using it incorrectly?


Gonzalo Garramuno
ggar...@gmail.com




Gonzalo Garramuno

unread,
May 13, 2022, 7:06:00 AM5/13/22
to fltkc...@googlegroups.com

> El 13 may. 2022, a las 07:49, Gonzalo Garramuno <ggar...@gmail.com> escribió:
>
> According to the documentation, calling clear should set the menu to NULL. However, when I try it with no items yet, it crashes the application. Is the documentation wrong or am I using it incorrectly?
>

Never mind me. It was crashing due to a dangling pointer in my code.


Gonzalo Garramuno
ggar...@gmail.com




Gonzalo Garramuno

unread,
May 13, 2022, 7:17:53 AM5/13/22
to fltkc...@googlegroups.com


> El 13 may. 2022, a las 08:05, Gonzalo Garramuno <ggar...@gmail.com> escribió:
>
>
>> El 13 may. 2022, a las 07:49, Gonzalo Garramuno <ggar...@gmail.com> escribió:
>>
>> According to the documentation, calling clear should set the menu to NULL.
>

However, the Fl_Sys_Menu_Bar is not cleared. I cannot get it to refresh upon my program changing states (after loading a file, for example).


Gonzalo Garramuno
ggar...@gmail.com




Manolo

unread,
May 13, 2022, 10:01:44 AM5/13/22
to fltk.coredev
The menubar demo program calls Fl_Sys_Menu_Bar::clear() when switching from the Fl_Sys_Menu_bar mode
to the Fl_Menu_Bar mode. The effect is that all macOS menus do disappear. Only the application menu remains, but that's a feature because an app should always have an application menu.

Please, describe in more detail the program you use that create the problem you report.

Gonzalo Garramuno

unread,
May 13, 2022, 8:16:05 PM5/13/22
to fltkc...@googlegroups.com
I confirm that the demo program works. However, in my use case, it doesn’t. I have a function that is used to fill both a RMB Fl_Menu_Button and the Fl_Menu_Bar (in this case Fl_Sys_Menu_Bar). I fill the menu using the base class Fl_Menu_, like:


void ImageView::fill_menu( Fl_Menu_* menu )
{
menu->clear();

int idx = 1;

menu->add( _("File/Open/Movie or Sequence"),
kOpenImage.hotkey(),
(Fl_Callback*)open_cb, browser() );

menu->add( _("File/Open/Single Image"), kOpenSingleImage.hotkey(),
(Fl_Callback*)open_single_cb, browser() );

mrv::media fg = foreground();
if ( !fg )
{
menu->add( _("File/Open/Directory"), kOpenDirectory.hotkey(),
(Fl_Callback*)open_dir_cb, browser() );
menu->add( _("File/Open/Session"),
kOpenSession.hotkey(),
(Fl_Callback*)open_session_cb, browser() );
}

….etc….
}


What happens is that the Fl_Sys_Menu_Bar is filled once, but when the function is called again, it does not clear it.

Gonzalo Garramuno

unread,
May 13, 2022, 8:26:12 PM5/13/22
to fltkc...@googlegroups.com


> El 13 may. 2022, a las 21:15, Gonzalo Garramuno <ggar...@gmail.com> escribió:
>
>
>
>> El 13 may. 2022, a las 11:01, Manolo <manol...@gmail.com> escribió:
>>
>> The menubar demo program calls Fl_Sys_Menu_Bar::clear() when switching from the Fl_Sys_Menu_bar mode
>> to the Fl_Menu_Bar mode. The effect is that all macOS menus do disappear. Only the application menu remains, but that's a feature because an app should always have an application menu.
>>
>> Please, describe in more detail the program you use that create the problem you report.
>
> I confirm that the demo program works. However, in my use case, it doesn’t. I have a function that is used to fill both a RMB Fl_Menu_Button and the Fl_Menu_Bar (in this case Fl_Sys_Menu_Bar). I fill the menu using the base class Fl_Menu_, like:
>

Okay. I see what the problem is. Fl_Menu_ does not define clear(), add(), etc. as virtual functions, so calling them from Fl_Menu_ has no effect. Fl_Menu_Button and Fl_Menu_Bar are just define as Fl_Menu_.
It is not clear to me why it works the first time I run the code on Fl_Sys_Menu_Bar, as it should never work.

May I request an enhancement to turn the Fl_Menu_ functions into virtuals?


Gonzalo Garramuno
ggar...@gmail.com




Manolo

unread,
May 14, 2022, 2:35:07 AM5/14/22
to fltk.coredev
Le samedi 14 mai 2022 à 02:26:12 UTC+2, ggar...@gmail.com a écrit :
Okay. I see what the problem is. Fl_Menu_ does not define clear(), add(), etc. as virtual functions, so calling them from Fl_Menu_ has no effect. Fl_Menu_Button and Fl_Menu_Bar are just define as Fl_Menu_.
It is not clear to me why it works the first time I run the code on Fl_Sys_Menu_Bar, as it should never work.

May I request an enhancement to turn the Fl_Menu_ functions into virtuals?
Virtual function Fl_Menu_Bar::update() can be used to transfer to an Fl_Sys_Menu_Bar object operations done to it
using other, non-virtual, member functions.

Gonzalo Garramuno

unread,
May 14, 2022, 2:17:14 PM5/14/22
to fltkc...@googlegroups.com


> El 14 may. 2022, a las 03:35, Manolo <manol...@gmail.com> escribió:
>
> Virtual function Fl_Menu_Bar::update() can be used to transfer to an Fl_Sys_Menu_Bar object operations done to it
> using other, non-virtual, member functions.
>

Thanks, Manolo. That worked!


Gonzalo Garramuno
ggar...@gmail.com




Reply all
Reply to author
Forward
0 new messages