wxWidgets / wxWidgets

Cross-Platform C++ GUI Library
https://www.wxwidgets.org/
6.08k stars 1.76k forks source link

wxDialog::ShowModal() does not set focus to the dialog box frame in wxGTK 2.9.x #14441

Open wxtrac opened 12 years ago

wxtrac commented 12 years ago

Issue migrated from trac ticket # 14441

component: wxGTK | priority: normal | keywords: wxDialog ShowModal focus

2012-06-28 05:23:43: mawicks0930 (Mark A. Wicks) created the issue


For custom dialog boxes derived from wxDialog, ShowModal() does not give focus to the dialog box unless a "standard" dialog box is displayed first. This did not occur in wxWidgets 2.8.x.

The following code shows the problem using a minimal version of OnInit() with the MyModalDialog class from samples/dialogs/dialogs.cpp):

include <wx/wx.h>

class MyApp: public wxApp { public: MyApp() { }

virtual bool OnInit();

};

// A custom modal dialog class MyModalDialog : public wxDialog { public: MyModalDialog(wxWindow *parent);

private: wxButton* m_btn; };

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit() { if ( !wxApp::OnInit() ) return false;

wxFrame *frame = new wxFrame(NULL, wxID_ANY, wxT("wxWidgets example"));

frame->Show(true);

SetTopWindow(frame);

_ Define AVOID_BUG and everything works fine. Without AVOIDBUG, the MyModalDialog doesn't get focus.

ifdef AVOID_BUG

wxMessageDialog msgdialog(0, wxT("test"), wxT("test"));
msgdialog.ShowModal();

endif

MyModalDialog dialog(0);
dialog.ShowModal();

return true;

} ---------------------------------------------------------------------------- MyModalDialog // ----------------------------------------------------------------------------

MyModalDialog::MyModalDialog(wxWindow parent) : wxDialog(parent, wxID_ANY, wxString(wxT("Modal dialog"))) { wxBoxSizer sizerTop = new wxBoxSizer(wxHORIZONTAL);

m_btn = new wxButton(this, wxID_ANY, wxT("A Button"));

sizerTop->Add(m_btn, 0, wxALIGN_CENTER | wxALL, 5);
sizerTop->Add(new wxButton(this, wxID_CLOSE), 0, wxALIGN_CENTER | wxALL, 5);

SetSizerAndFit(sizerTop);

SetEscapeId(wxID_CLOSE);

m_btn->SetFocus();
m_btn->SetDefault();

}

wxtrac commented 12 years ago

2012-06-28 05:26:43: mawicks0930 (Mark A. Wicks) changed component from GUI-all to wxGTK

wxtrac commented 12 years ago

2012-06-28 05:28:01: mawicks0930 (Mark A. Wicks) changed title from wxDialog::ShowModal() does not set focus to the dialog box frame in GTK in 2.9.x to wxDialog::ShowModal() does not set focus to the dialog box frame in wxGTK 2.9.x

wxtrac commented 12 years ago

2012-06-28 07:58:03: @paulcor changed status from new to confirmed

2012-06-28 07:58:03: @paulcor commented

This is due to the deferred show mechanism wxTopLevelWindow now uses to determine window decoration sizes. Note that this only happens if you show a dialog before your frame is actually visible.

wxtrac commented 12 years ago

2012-06-28 16:24:43: mawicks0930 (Mark A. Wicks) commented


That's good to know. Called Raise() on the main frame (in addition to Show()) before calling ShowModal() on the dialog box seems to be a work-around.