0
votes

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?

1

1 Answers

1
votes

There's different solutions:

  1. 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())

  2. 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

  3. 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...).