Enabling App Menu Items when Modal Dialog Shown
Enabling App Menu Items when Modal Dialog Shown
In my wxWidgets OSX/Cocoa (3.0.1) app, all menu items are always disabled (ie. grayed out) during calls to wxDialog::ShowModal(). I want to enable some menu items while modal dialogs are shown, but nothing I have tried works at all. The application's EVT_UPDATE_UI_RANGE method is never called when modal dialogs are shown, so I defined a method on the wxMenu subclass, but that is not called either. Can someone here please tell me how to enable application menu items while wxDialog::ShowModal() is active on Cocoa?
Thank You
Larry
Thank You
Larry
Re: Enabling App Menu Items when Modal Dialog Shown
Hi, Larry,
The point of making dialog modal is that everything is disabled on your app until you close the dialog.
If you want to keep the main application responsive - use wxDialog::Show().
Thank you.
The point of making dialog modal is that everything is disabled on your app until you close the dialog.
If you want to keep the main application responsive - use wxDialog::Show().
Thank you.
Re: Enabling App Menu Items when Modal Dialog Shown
ONEEYEMAN wrote:Hi, Larry,
The point of making dialog modal is that everything is disabled on your app until you close the dialog.
If you want to keep the main application responsive - use wxDialog::Show().
Thank you.
I realize that, but on Mac OS, the "Cut", "Copy", "Paste", "Select", and "Undo" menu items are expected to be active for editable text controls, even in modal dialogs.
Thank You
Larry
Re: Enabling App Menu Items when Modal Dialog Shown
LarryM,
Can you reproduce it with the latest 3.1 ore even Git HEAD?
Also, did you try the dialogs sample to see if it exists there?
If you can check the trac.wxwidgets.org if such issue exists and if not open a new ticket.
Can you reproduce it with the latest 3.1 ore even Git HEAD?
Also, did you try the dialogs sample to see if it exists there?
If you can check the trac.wxwidgets.org if such issue exists and if not open a new ticket.
Re: Enabling App Menu Items when Modal Dialog Shown
For information, the bug is still present in the 3.1 but has just been fixed in the HEAD revision (https://trac.wxwidgets.org/ticket/17459).
For users who don't want to use head revision, here is the way I fix the problem without patching the wxWidgets :
In a .mm file :
Override DoPopupmenu fonction of wxDialog class :
For users who don't want to use head revision, here is the way I fix the problem without patching the wxWidgets :
In a .mm file :
Code: Select all
bool disableOSXMenuItemAutoEnabling(wxMenu *menu)
{
if (!menu)
return false;
// Retrieve Objective C raw object and set option
wxMenuImpl *menu_impl = menu->GetPeer();
if (!menu_impl)
return false;
WXHMENU ns_menu = menu_impl->GetHMenu();
if (!ns_menu)
return false;
[ns_menu setAutoenablesItems:NO];
// Do recursively the same for all submenus
wxMenuItemList menu_items = menu->GetMenuItems();
for (wxMenuItemList::iterator it = menu_items.begin();
it != menu_items.end(); it++)
{
wxMenu *sub_menu = (*it)->GetSubMenu();
if (sub_menu)
disableOSXMenuItemAutoEnabling(sub_menu);
}
return true;
}
Code: Select all
bool MyDialog::DoPopupMenu(wxMenu *menu, int x, int y)
{
#ifdef __WXOSX__
disableOSXMenuItemAutoEnabling(menu);
#endif
return wxDialog::DoPopupMenu(menu, x, y);
}
Re: Enabling App Menu Items when Modal Dialog Shown
My previous post is not relevant anymore as the bug as been reopened (because of side effects).
Here is the patch I finally applied to my application (in a .mm file), without any wxWidgets library modification :
Here is the patch I finally applied to my application (in a .mm file), without any wxWidgets library modification :
Code: Select all
#include <wx/menu.h>
#include <wx/osx/core/private.h>
bool popUpOSXMenu(wxMenu *menu, wxWindow *win, int x, int y)
{
// Retrieve Objective C raw object and set option
wxMenuImpl *menu_impl = menu->GetPeer();
if (!menu_impl)
return false;
WXHMENU ns_menu = menu_impl->GetHMenu();
if (!ns_menu)
return false;
// Fix bad menu position with default coordinates
wxPoint pt = wxGetMousePosition();
if (x == wxDefaultCoord)
x = pt.x;
if (y == wxDefaultCoord)
y = pt.y;
win->ScreenToClient(&x, &y);
// Show menu
NSView *view = win->GetPeer()->GetWXWidget();
NSView *tempView = [[NSView alloc] initWithFrame:NSMakeRect(x, y, 1, 1)];
[view addSubview:tempView];
NSPopUpButtonCell *popUpButtonCell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO];
[popUpButtonCell setAutoenablesItems:NO];
[popUpButtonCell setAltersStateOfSelectedItem:NO];
[popUpButtonCell setMenu:ns_menu];
[popUpButtonCell selectItem:nil];
[popUpButtonCell performClickWithFrame:NSMakeRect(0, 0, 1, 1) inView:tempView];
[popUpButtonCell release];
[tempView removeFromSuperview];
[tempView release];
return true;
}
Re: Enabling App Menu Items when Modal Dialog Shown
Hi,
I believe Stefan fixed it in the Git HEAD.
Please try to compile the latest Git sources and check if it was fixed.
Thank you.
I believe Stefan fixed it in the Git HEAD.
Please try to compile the latest Git sources and check if it was fixed.
Thank you.
Re: Enabling App Menu Items when Modal Dialog Shown
You are right, thanks. I will check it.
Re: Enabling App Menu Items when Modal Dialog Shown
I'm now hitting this bug in wx 3.1.5 on the Mac.
Your function displays the menu ok for me, but the events do not trigger. Am I doing anything obviously wrong (code below).
Thanks in advance,
Tony.
Your function displays the menu ok for me, but the events do not trigger. Am I doing anything obviously wrong (code below).
Thanks in advance,
Tony.
Code: Select all
wxMenu _popupMenu;
_popupMenu.Append(ID_MENU_ID, "Do something));
_popupMenu.Bind(wxEVT_MENU, &MyClass::MyFunction, this, ID_MENU_ID);
wxPoint _pt = wxGetMousePosition();
bool bSelected = popUpOSXMenu(&_popupMenu, this, _pt.x, _pt.y);
Re: Enabling App Menu Items when Modal Dialog Shown
Hi,
Are you running an Application Bundle?
And is "minimal" sample works for you?
Thank you.
Are you running an Application Bundle?
And is "minimal" sample works for you?
Thank you.
Re: Enabling App Menu Items when Modal Dialog Shown
I'm not running in an app bundle as still debugging.
Also, this is when I right click on a wxScrolled<wxPanel> window. I only need a popup menu with two entries, but they are disabled (they work fine on Windows).
I haven't tried the minimal bundle yet, time is a little tight on this one (I need to get a fix out tomorrow if I can).
Also, this is when I right click on a wxScrolled<wxPanel> window. I only need a popup menu with two entries, but they are disabled (they work fine on Windows).
I haven't tried the minimal bundle yet, time is a little tight on this one (I need to get a fix out tomorrow if I can).
Re: Enabling App Menu Items when Modal Dialog Shown
Hi,
You can still debug in a Bundle.
You can run:
lldb <myapp.app>
and the application will execute.
Thank you,
P.S.: If its a context menu - try the "menu" sample.
Also, make sure there is no UPDATE_UI event that disables the menu.
You can still debug in a Bundle.
You can run:
lldb <myapp.app>
and the application will execute.
Thank you,
P.S.: If its a context menu - try the "menu" sample.
Also, make sure there is no UPDATE_UI event that disables the menu.
Re: Enabling App Menu Items when Modal Dialog Shown
Creating the app bundle to debug with is not really an option for me at the moment. I'm really not a MacOS programmer. The app bundle is created when I do a full release build.
Strangely, if I do the following, it works and triggers the events.
But doing this, I get the menu appearing twice.
Strangely, if I do the following, it works and triggers the events.
Code: Select all
bool bSelected = popUpOSXMenu(&_popupMenu, this, _pt.x, _pt.y);
PopupMenu(&_popupMenu, _pt);
Re: Enabling App Menu Items when Modal Dialog Shown
In case it helps anyone else, I've modified the function above to return the index of the clicked menu item. I can now work out which function to call based on the return value.
Here is the code,
Here is the code,
Code: Select all
int popUpOSXMenu(wxMenu *menu, wxWindow *win, int x, int y)
{
// Retrieve Objective C raw object and set option
wxMenuImpl *menu_impl = menu->GetPeer();
if (!menu_impl)
return -1;
WXHMENU ns_menu = menu_impl->GetHMenu();
if (!ns_menu)
return -1;
// Fix bad menu position with default coordinates
wxPoint pt = wxGetMousePosition();
if (x == wxDefaultCoord)
x = pt.x;
if (y == wxDefaultCoord)
y = pt.y;
// win->ScreenToClient(&x, &y);
// Show menu
NSView *view = win->GetPeer()->GetWXWidget();
NSView *tempView = [[NSView alloc] initWithFrame:NSMakeRect(x, y, 1, 1)];
[view addSubview:tempView];
NSPopUpButtonCell *popUpButtonCell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO];
[popUpButtonCell setAutoenablesItems:NO];
[popUpButtonCell setAltersStateOfSelectedItem:NO];
[popUpButtonCell setMenu:ns_menu];
[popUpButtonCell selectItem:nil];
[popUpButtonCell performClickWithFrame:NSMakeRect(0, 0, 1, 1) inView:tempView];
[popUpButtonCell release];
[tempView removeFromSuperview];
[tempView release];
return [popUpButtonCell indexOfSelectedItem];
// return true;
}