Enabling App Menu Items when Modal Dialog Shown

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
LarryM
Earned a small fee
Earned a small fee
Posts: 11
Joined: Wed Jul 31, 2013 12:28 am

Enabling App Menu Items when Modal Dialog Shown

Postby LarryM » Tue Apr 12, 2016 8:06 pm

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

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2021
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Enabling App Menu Items when Modal Dialog Shown

Postby ONEEYEMAN » Thu Apr 14, 2016 2:14 pm

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.

LarryM
Earned a small fee
Earned a small fee
Posts: 11
Joined: Wed Jul 31, 2013 12:28 am

Re: Enabling App Menu Items when Modal Dialog Shown

Postby LarryM » Thu Apr 14, 2016 4:02 pm

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

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2021
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Enabling App Menu Items when Modal Dialog Shown

Postby ONEEYEMAN » Thu Apr 14, 2016 5:15 pm

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.

moki
Earned a small fee
Earned a small fee
Posts: 13
Joined: Mon Dec 08, 2014 1:08 pm
Location: Brive la gaillarde

Re: Enabling App Menu Items when Modal Dialog Shown

Postby moki » Wed Sep 06, 2017 12:56 pm

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 :

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;
}


Override DoPopupmenu fonction of wxDialog class :

Code: Select all

bool MyDialog::DoPopupMenu(wxMenu *menu, int x, int y)
{
#ifdef __WXOSX__
    disableOSXMenuItemAutoEnabling(menu);
#endif

    return wxDialog::DoPopupMenu(menu, x, y);
}

moki
Earned a small fee
Earned a small fee
Posts: 13
Joined: Mon Dec 08, 2014 1:08 pm
Location: Brive la gaillarde

Re: Enabling App Menu Items when Modal Dialog Shown

Postby moki » Mon Sep 11, 2017 2:23 pm

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 :

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;
}

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2021
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Enabling App Menu Items when Modal Dialog Shown

Postby ONEEYEMAN » Mon Sep 11, 2017 2:28 pm

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.

moki
Earned a small fee
Earned a small fee
Posts: 13
Joined: Mon Dec 08, 2014 1:08 pm
Location: Brive la gaillarde

Re: Enabling App Menu Items when Modal Dialog Shown

Postby moki » Mon Sep 11, 2017 2:46 pm

You are right, thanks. I will check it.


Return to “Platform Related Issues”

Who is online

Users browsing this forum: No registered users and 2 guests