how to get the parent wxFrame pointer in subdialog
I make a program to realize some function. I have an wxFrame, wxMenubar,wxScrolledWindow,wxListBox. By click some menu of the menubar, i create several dlgs for information input, maybe have several levels(after dlg create, also create sub dlgs) i want to manipulate the wxFrame's wxScrolledWindow's display content in the dliaogue . My qustion is: how to get the wxFrame pointer in the dlg. typically the dlg my create is like this,
class Qgis2wxDbSourceSelectDlg : public wxDialog
Qgis2wxDbSourceSelectDlg( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Add PostGIS Table(s)"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 269,286 ), long style = wxDEFAULT_DIALOG_STYLE );
I want to have the wxFrame pointer in the Qgis2wxDbSourceSelectDlg, how should i do?
Should I make the Qgis2wxDbSourceSelectDlg also inheritated from wxFrame? and how to transfer to wxFrame pointer to the Qgis2wxDbSourceSelectDlg?
There's different solutions:
The dirtiest way is to cast the parent of Qgis2wxDbSourceSelectDlg
into a wxFrame
. This is possible because every wxDialog
has a GetParent
function that returns a wxWindow*
. wxFrame* frame = dynamic_cast< wxFrame* >(this->GetParent())
Another option is to pass the wxFrame
in the constructor (you can replace wxWindow* parent
within the constructor. Then you have to add a member parent
in your Qgis2wxDbSourceSelectDlg
The last option which I recommend is to have a controller that has access to all the windows/dialogs, starting with the main frame. It will be handling call backs and create the dialogs, react to user input (etc...).