wxOSX : Preventing a nested modal dialog to exit previous native modal

222 views
Skip to first unread message

Toinou Dorni

unread,
Jun 28, 2017, 8:07:45 PM6/28/17
to wx-users
Hi there,

I have a little issue with wxWidgets on OSX / Cocoa. I've described the probleme here : https://forums.wxwidgets.org/viewtopic.php?f=23&t=43603
I'm developing a plugin for a native application, in this host there's a button and when it's pressed one of my function is called. In this function I create a modal dialog with a null parent and run it with ShowModal(). Everything works fine until the EndModal() function is called : it exits both my dialog but also the native host dialog (where there's the button) !
Does anyone know why it's doing this ? (it seems that wxWidgets in evtloop.mm calls [NSApp endModalSession::(NSModalSession)m_modalSession line 545]
Maybe I should create a dialog with a WindowRef ? Or maybe I should create my own event loop without NSApp stuff ?

Thanks !

Toinou Dorni

unread,
Jul 1, 2017, 12:13:52 PM7/1/17
to wx-users
Is there a Cocoa / OSX expert I can hire here for this issue ?

Gunter Königsmann

unread,
Jul 1, 2017, 12:40:25 PM7/1/17
to wx-u...@googlegroups.com
No expert in Cocoa. But are you sure that your dialogue needs to be modal (meaning it suppresses all input to the parent dialogue)?
Often Plug-Ins can be written in a way that they don't stop the calling application while they are running.
If not I think your guess is correct and your dialogue needs to know which parent window to prevent from getting focus while it is running.

Kind regards,

    Gunter.

Am 01.07.2017 6:13 nachm. schrieb "Toinou Dorni" <tto...@gmail.com>:
Is there a Cocoa / OSX expert I can hire here for this issue ?

Toinou Dorni

unread,
Jul 1, 2017, 3:41:26 PM7/1/17
to wx-users
Hi Gunter,

Thank you for answering.
I want my dialog to be modal but I'm not required to use wxWidgets' ShowModal()/EndModal().
Here's a working code : https://github.com/fnordware/openexrAE/blob/master/src/mac/OpenEXR_UI_Cocoa.mm from line 40 to 100
I guess instead of doing

modal_result = [NSApp runModalSession:modal_session];
dialog_result = [ui_controller getResult];

I should plug here wxWidgets own functions


On Saturday, July 1, 2017 at 12:40:25 PM UTC-4, Gunter Königsmann wrote:
No expert in Cocoa. But are you sure that your dialogue needs to be modal (meaning it suppresses all input to the parent dialogue)?
Often Plug-Ins can be written in a way that they don't stop the calling application while they are running.
If not I think your guess is correct and your dialogue needs to know which parent window to prevent from getting focus while it is running.

Kind regards,

    Gunter.
Am 01.07.2017 6:13 nachm. schrieb "Toinou Dorni" <tto...@gmail.com>:
Is there a Cocoa / OSX expert I can hire here for this issue ?

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
 

Toinou Dorni

unread,
Jul 12, 2017, 11:34:43 AM7/12/17
to wx-users
Here is a working sample : https://gitlab.com/ttoinou/dsAfterCodecsAE_Modal_OSX
EndModal calls wxDialog->m_eventLoop->Exit
which calls [NSApp abortModal] which exits both native modal dialog :-(

Stefan Csomor

unread,
Jul 12, 2017, 2:26:51 PM7/12/17
to wx-u...@googlegroups.com
Hi

>Here is a working sample : https://gitlab.com/ttoinou/dsAfterCodecsAE_Modal_OSX
>EndModal calls wxDialog->m_eventLoop->Exit
>which calls [NSApp abortModal] which exits both native modal dialog :-(

Thanks for spotting this, I think the problem is that base class wxEventLoopBase::Exit calls ScheduleExit which on wxOSX in the end calls [NSApp abortModal] which is fine for aborting all loops, but not good when just calling Exit, so how about overriding Exit in wxCFEventLoop:

void wxCFEventLoop::Exit(int rc)
{
    m_exitcode = rc;
    m_shouldExit = true;
}

could you please try whether this solves your problem ?

Thanks,

Stefan


Toinou Dorni

unread,
Jul 12, 2017, 4:10:59 PM7/12/17
to wx-users
Hi Stefan,
Commenting the line and recompiling wxWidgets works ! ( However now the native dialog is out of focus I have move it manually so that it gains focus :S )

How could we find a way to integrate this in wxWidgets ? So that I'm using the true wxWidgets library and not a hack of it ?

Thanks!
Antoine

Stefan Csomor

unread,
Jul 13, 2017, 1:12:19 AM7/13/17
to wx-u...@googlegroups.com
Hi Antoine

> Commenting the line and recompiling wxWidgets works ! ( However now the native dialog is out of focus I have move it manually so that it gains focus :S )

thanks for reporting back

actually I wanted to keep ScheduleExit as it is and add an override for Exit which lacks the Stop

void wxCFEventLoop::Exit(int rc)
{
m_exitcode = rc;
m_shouldExit = true;
}

> How could we find a way to integrate this in wxWidgets ? So that I'm using the true wxWidgets library and not a hack of it ?

I’ll add a PushRequest and ask for a review, to make sure I haven’t overlooked something in this approach, so that code written on the other platforms would break on OSX because of this.

Best,

Stefan



Toinou Dorni

unread,
Jul 13, 2017, 11:59:54 AM7/13/17
to wx-users
The code was wxMac specific I doubt it could break things (maybe in iphone stuff ?).
I don't understand why ScheduleExit would call abortModal but not Exit ?

Antoine

Stefan Csomor

unread,
Jul 14, 2017, 2:33:07 AM7/14/17
to wx-u...@googlegroups.com

Hi

 

The code was wxMac specific I doubt it could break things (maybe in iphone stuff ?).

 

The issue would be code that expected Exit to behave like it did before


I don't understand why ScheduleExit would call abortModal but not Exit ?

Because according to the docs ScheduleExit would cause the outer event loop to exit as soon as its nested ones are done, while Exit should only finish the innermost running event loop. But I’ll have to try to find out what exactely was the reason for starting with abortModal at all, instead of just ending the modal session. IIRC there were cases where the modal loop would not be terminated, and abortModal was the thing working back then. But perhaps this error wouldn’t occur anyway anymore, because of fixes in the OS. I’ll try to find out..

 

Best,

 

Stefan

Toinou Dorni

unread,
Jul 14, 2017, 11:18:07 AM7/14/17
to wx-users
Great thanks for your help Stefan !

Antoine

Toinou Dorni

unread,
Jul 14, 2017, 5:12:13 PM7/14/17
to wx-users
The only issue there's left is that the native modal dialog is not focused when the wxDialog has exited and it takes like 5 seconds to get it focused...
If I put a breakpoint on the function 

void wxGUIEventLoop::EndModalSession()

{


in evtloop.mm then I can see that this function is not called immediately (seems to take the same amount of time that for the native modal to get focused !)
Is there any way to force the loop to exit way before ? 5 seconds is a lot, seems like a bug to me

Thanks,
Antoine

Stefan Csomor

unread,
Jul 15, 2017, 2:56:30 AM7/15/17
to wx-u...@googlegroups.com
Hi

>The only issue there's left is that the native modal dialog is not focused when the wxDialog has exited and it takes like 5 seconds to get it focused...

focusing the native dialog could be a problem from within wx, I’d guess you’d have to do this from the caller’s site

>If I put a breakpoint on the function 
>void wxGUIEventLoop::EndModalSession()
>{
>
>in evtloop.mm then I can see that this function is not called immediately (seems to take the same amount of time that for the native modal to get focused !)
>Is there any way to force the loop to exit way before ? 5 seconds is a lot, seems like a bug to me

it’s probably idling until a timeout occurs, only then the loop determines that its exit state has been set, we have to post a dummy event in Exit() somewhere, try adding a WakeUp() as the last method in Exit, does this fix it ?

HTH,

Stefan



Toinou Dorni

unread,
Jul 17, 2017, 11:05:37 AM7/17/17
to wx-users
Hi Stefan,
This doesn't work, EndModalSession is still called 4-8 secs later and the same for the native dialog focusing :( 
Antoine

Toinou Dorni

unread,
Jul 19, 2017, 11:24:32 AM7/19/17
to wx-users
Is there a way to increase frequency checks inside the event loop, so that 5 seconds becomes less than 1 second ?
Reply all
Reply to author
Forward
0 new messages