wxDialog is not modal after 3 level on MacOS

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.
Anil8753
Experienced Solver
Experienced Solver
Posts: 80
Joined: Sat Jan 16, 2016 5:57 am

wxDialog is not modal after 3 level on MacOS

Postby Anil8753 » Fri Aug 17, 2018 11:07 am

Launch a wxDialog::ShowModal() from wxFrame.
Launch 2nd wxDialog::ShowModal() from 1st wxDialog
Launch 3rd wxDialog::ShowModal() from 2nd wxDialog

Result: 3rd wxDialog is not Modal anymore.
Note* This issue is with wx3.1 and MacOS. It is 64 bit wxWidgets dll.

Instead of 3rd wxDialog, we can launch wxMessageBox/wxMessageDialog. Issue is there with these popup also

Sample minimal.cpp

Code: Select all

/////////////////////////////////////////////////////////////////////////////
// Name:        minimal.cpp
// Purpose:     Minimal wxWidgets sample
// Author:      Julian Smart
// Modified by:
// Created:     04/01/98
// Copyright:   (c) Julian Smart
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

// ============================================================================
// declarations
// ============================================================================

// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

// ----------------------------------------------------------------------------
// resources
// ----------------------------------------------------------------------------

// the application icon (under Windows it is in resources and even
// though we could still include the XPM here it would be unused)
#ifndef wxHAS_IMAGES_IN_RESOURCES
    #include "../sample.xpm"
#endif

// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------

// Define a new application type, each program should derive a class from wxApp
class MyApp : public wxApp
{
public:
    // override base class virtuals
    // ----------------------------

    // this one is called on application startup and is a good place for the app
    // initialization (doing it here and not in the ctor allows to have an error
    // return: if OnInit() returns false, the application terminates)
    virtual bool OnInit() wxOVERRIDE;
};

// Define a new frame type: this is going to be our main frame
class MyFrame : public wxFrame
{
public:
    // ctor(s)
    MyFrame(const wxString& title);
    virtual ~MyFrame(){}
    // event handlers (these functions should _not_ be virtual)
    void OnClick(wxCommandEvent& event);

private:

};


wxIMPLEMENT_APP(MyApp);

// ============================================================================
// implementation
// ============================================================================

// ----------------------------------------------------------------------------
// the application class
// ----------------------------------------------------------------------------

// 'Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit()
{
    // call the base class initialization method, currently it only parses a
    // few common command-line options but it could be do more in the future
    if ( !wxApp::OnInit() )
        return false;

    // create the main application window
    MyFrame *frame = new MyFrame("Minimal wxWidgets App");

    // and show it (the frames, unlike simple controls, are not shown when
    // created initially)
    frame->Show(true);

    // success: wxApp::OnRun() will be called which will enter the main message
    // loop and the application will run. If we returned false here, the
    // application would exit immediately.
    return true;
}

// Sample Dialog Test
static int count = 1;

class MyDialog: public wxDialog
{
public:
    MyDialog(wxWindow* parent)
    : wxDialog(parent, wxID_ANY, wxString::Format("My Dialog %d", count))
    {
        count++;
        wxSizer* pSizer = new wxBoxSizer(wxVERTICAL);
        pSizer->AddSpacer(30);
       
        wxButton* pButton = new wxButton(this, wxID_ANY, "Click Button");
        pButton->Bind(wxEVT_BUTTON, & MyDialog::OnClick, this);
        pSizer->Add(pButton);
       
        SetSizer(pSizer);
        Layout();
    }
   
    virtual ~MyDialog()
    {
       
    }

 private:
    void OnClick(wxCommandEvent& event)
    {
        MyDialog dlg(this);
        dlg.ShowModal();
        event.Skip();
    }
};

// ----------------------------------------------------------------------------
// main frame
// ----------------------------------------------------------------------------

// frame constructor
MyFrame::MyFrame(const wxString& title)
       : wxFrame(NULL, wxID_ANY, title)
{
    wxSizer* pSizer = new wxBoxSizer(wxVERTICAL);
    pSizer->AddSpacer(30);
   
    wxButton* pButton = new wxButton(this, wxID_ANY, "Click Button");
    pButton->Bind(wxEVT_BUTTON, & MyFrame::OnClick, this);
    pSizer->Add(pButton);
   
    SetSizer(pSizer);
    Layout();
}

void MyFrame::OnClick(wxCommandEvent& event)
{
    MyDialog dlg(this);
    dlg.ShowModal();
    event.Skip();
}

Last edited by Anil8753 on Wed Aug 22, 2018 7:23 am, edited 3 times in total.

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

Re: wxDialog is not modal after 3 level on MacOS

Postby ONEEYEMAN » Fri Aug 17, 2018 2:29 pm

Hi,
What is your current wx version?
Which OSX you're testing it under?
How did you configured the library exactly?
Are all those dialogs custom-made or there are a standard one somewhere?

Thank you.

Anil8753
Experienced Solver
Experienced Solver
Posts: 80
Joined: Sat Jan 16, 2016 5:57 am

Re: wxDialog is not modal after 3 level on MacOS

Postby Anil8753 » Fri Aug 17, 2018 6:06 pm

I tested on Mac OS 10.11 and 10.13. I am using wxDialog class as base class. If you have Mac machine, may try creating 3 dialog.
It is 64 bit wxWidget dlls

Anil8753
Experienced Solver
Experienced Solver
Posts: 80
Joined: Sat Jan 16, 2016 5:57 am

Re: wxDialog is not modal after 3 level on MacOS

Postby Anil8753 » Wed Aug 22, 2018 7:24 am

Added the minimal.cpp in the original question.
I am not able to find the root cause of the issue. wx3.0 works fine, I can see many changes have been done related to modal event loop.


Return to “Platform Related Issues”

Who is online

Users browsing this forum: No registered users and 5 guests