wxDialog loses stay on top attribute

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
yukomkom
Earned a small fee
Earned a small fee
Posts: 12
Joined: Mon Nov 07, 2016 10:19 am

wxDialog loses stay on top attribute

Post by yukomkom »

Hi guys,

I have 2 wxDialogs with the button which makes each of them top most dialog(wxSTAY_ON_TOP) after button click.

Workflow:
1. I make one of them top most, checked - dialog become top most.
2. I clicked once more and dialog become not top most, checked - ok.
3. Made both of them top most, checked - ok, both top most.
4. Made one of them not top most after step 3, checked - accordinly to logs 1 - top most, another is not top most, but if I click somewhere both behaves like not top most. I have tried with wxFrame, with more than 2 wxDialogs - result same. Maybe I missing something or threre is a bug. Please help.

wxWidgets 3.0.2, Windows

Code: Select all

class Frame : public wxFrame
{
public:
    Frame()  : wxFrame(nullptr, wxID_ANY, wxEmptyString, wxPoint(1100, 300), wxSize(200, 200))
    {
        wxBoxSizer* sz = new wxBoxSizer(wxVERTICAL);
        wxStaticText* text = new wxStaticText(this, wxID_ANY, "Parent Frame");
        sz->Add(text, 0, wxALL, 5);
        SetSizer(sz);
        Layout();
    }
};

Code: Select all

class Dialog  : public wxDialog
{
public:
    Dialog(wxWindow* parent, wxPoint pos)
        : wxDialog(parent, wxID_ANY, "", pos, wxSize(200, 200), wxFRAME_NO_TASKBAR | wxTAB_TRAVERSAL | wxBORDER_NONE)
    {
        wxBoxSizer* mainS = new wxBoxSizer(wxVERTICAL);
        wxButton* button = new wxButton(this, wxID_ANY, "Top Most");
        mainS->Add(button, 0, wxALL, 5);
        SetSizer(mainS);
        Layout();
        button->Bind(wxEVT_BUTTON, &Dialog::onButton, this);
    }

    void onButton(wxCommandEvent&)
    {
        bool isTopMost = (GetWindowStyle() & wxSTAY_ON_TOP) != 0;
        if (isTopMost)
            SetWindowStyle(GetWindowStyle() & ~wxSTAY_ON_TOP); // Makes not top most dynamically
        else
            SetWindowStyle(GetWindowStyle() | wxSTAY_ON_TOP); // Makes top most dynamically
    }
};

Code: Select all

class WxguiApp : public wxApp
{
public:
    bool OnInit() override
    {
        Frame* mainWnd = new Frame();
        mainWnd->Show();
        SetTopWindow(mainWnd);

        Dialog* dlg1 = new Dialog(mainWnd, wxPoint(500, 300));
        dlg1->Show();
        Dialog* dlg2 = new Dialog(mainWnd, wxPoint(800, 300));
        dlg2->Show();

        return true;
    }
};

IMPLEMENT_APP(WxguiApp);
Post Reply