Author Topic: wxSmith MDI child shows on Linux not on Windows  (Read 3531 times)

Offline kathbeau

  • Multiple posting newcomer
  • *
  • Posts: 17
wxSmith MDI child shows on Linux not on Windows
« on: November 26, 2014, 08:06:02 pm »
I created a new wxSmith app, and manually changed the main form declaration from:

class TestMDIFrame: public wxFrame
to
class TestMDIFrame: public wxMDIParentFrame

From the wxSmith menu, I selected Add wxFrame and changed the base class to wxMDIChildFrame.

This gave me a header with declaration like this:

class BaseChildFrame: public wxMDIChildFrame
{
   public:

      BaseChildFrame(wxWindow* parent,wxWindowID id=wxID_ANY,const wxPoint& pos=wxDefaultPosition,const wxSize& size=wxDefaultSize);

Note that the parent is incorrectly declared as wxWindow*, but that was easy to change to wxMDIParentFrame*.

I ultimately rewrote the entire constructor to conform to the wxWidgets documentation for class wxMDIChildFrame:

class BaseChildFrame: public wxMDIChildFrame
{
   public:

      BaseChildFrame(wxMDIParentFrame* parent,
                 wxWindowID id=wxID_ANY,
                 const wxString& title=wxEmptyString,
                 const wxPoint& pos=wxDefaultPosition,
                 const wxSize& size=wxDefaultSize,
                 long style=wxDEFAULT_FRAME_STYLE,
                 const wxString &name=wxFrameNameStr);

And here is the implementation of the constructor:

BaseChildFrame::BaseChildFrame(wxMDIParentFrame* parent,
                               wxWindowID id,
                               const wxString& title,
                               const wxPoint& pos,
                               const wxSize& size,
                               long style,
                               const wxString& name)
{
   Create(parent, id, title, pos, size, style, name);
   //(*Initialize(BaseChildFrame)
   //Create(parent, id, _("BaseChildFrame"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
   SetClientSize(wxDefaultSize);
   Move(wxDefaultPosition);

   Connect(wxID_ANY,wxEVT_CLOSE_WINDOW,(wxObjectEventFunction)&BaseChildFrame::OnClose);
   //*)
}


Then I created a menu item on the wxMDIParentFrame that creates and shows instances of the BaseChildFrame:

void TestMDIFrame::OnFileNewChildItemSelected(wxCommandEvent& event)
{
    BaseChildFrame* t_child = new BaseChildFrame(this, wxID_ANY, _T("New child window"));
    if (t_child)
    {
        t_child->Show();
    }
}

When I build this for Linux, the child frames display in tabbed pages (as expected).

But when I build this for Windows, the main menu adds a Window item, and the new BaseChildFrame is listed there, but the child window does not show.

I hope that is enough information for somebody to figure out what I have implemented incorrectly.

Thanks for your help.

Kathleen




Offline kathbeau

  • Multiple posting newcomer
  • *
  • Posts: 17
[SOLVED] wxSmith MDI child shows on Linux not on Windows
« Reply #1 on: November 27, 2014, 05:11:38 pm »
So... I have found something by reading code in the wxWidgets-3.0.2\samples collections, plus hints in the book Cross-Platform GUI Programming with wxWidgets (download from http://ptgmedia.pearsoncmg.com/images/0131473816/downloads/0131473816_book.pdf) which explains that "on platforms where MDI children are contained within the parent, a wxMDIParentFrame arranges its children on a wxMDIClientWindow, which can coexist with other windows in the frame." It goes on to suggest reading the code in samples/mdi in the wxWidgets distribution.

Except the mdi sample doesn't do anything with the wxMDIClientWindow. However, the svgtest sample does.

(EDIT: I misspoke... the mdi sample shows how to designate a subsection of the frame for the MDI children.)

So I copied this code from svgtest into my wxSmith project, in the main frame (wxMDIParentFrame) EVT_SIZE handler:

void TestMDIFrame::OnResize(wxSizeEvent& event)
{
    int w, h;
    GetClientSize(&w, &h);
    GetClientWindow()->SetSize(0, 0, w, h);
    event.Skip();
}

And now I can see the MDI children on my Windows desktop. And (oh happy day), this code continues to run on Linux.

BTW, it is way cool that wxWidgets will let me designate an area of the main frame for the MDI children, rather than assuming the entire frame should be the playground.

Kathleen
« Last Edit: November 27, 2014, 05:28:18 pm by kathbeau »