X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8ce63e9d6604178f8c13e6a0e9bb33c3800a0c28..302aa842e96914fb11dd86972c3e6d79f35bc44d:/samples/minifram/test.cpp diff --git a/samples/minifram/test.cpp b/samples/minifram/test.cpp index e7ee047849..1470996901 100644 --- a/samples/minifram/test.cpp +++ b/samples/minifram/test.cpp @@ -44,6 +44,7 @@ IMPLEMENT_APP(MyApp) MyMainFrame *main_frame = (MyMainFrame*) NULL; MyMiniFrame *mini_frame = (MyMiniFrame*) NULL; +bool mini_frame_exists = FALSE; wxButton *button = (wxButton*) NULL; // The `main program' equivalent, creating the windows and returning the @@ -53,6 +54,7 @@ bool MyApp::OnInit(void) // Create the mini frame window mini_frame = new MyMiniFrame((wxFrame *) NULL, -1, "wxMiniFrame sample", wxPoint(100, 100), wxSize(205, 100)); + mini_frame_exists = TRUE; mini_frame->CreateToolBar(wxNO_BORDER|wxHORIZONTAL|wxTB_FLAT, ID_TOOLBAR); InitToolbar(mini_frame->GetToolBar()); @@ -131,7 +133,7 @@ bool MyApp::InitToolbar(wxToolBar* toolBar) toolBar->AddTool(wxID_PASTE, *(toolBarBitmaps[5]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Paste"); currentX += width + 5; toolBar->AddSeparator(); - toolBar->AddTool(wxID_PRINT, *(toolBarBitmaps[6]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Print"); + toolBar->AddTool(wxID_PRINT, *(toolBarBitmaps[6]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Reparent the button"); currentX += width + 5; toolBar->AddSeparator(); toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Help"); @@ -153,6 +155,7 @@ bool MyApp::InitToolbar(wxToolBar* toolBar) BEGIN_EVENT_TABLE(MyMiniFrame, wxMiniFrame) EVT_CLOSE ( MyMiniFrame::OnCloseWindow) EVT_BUTTON (ID_REPARENT, MyMiniFrame::OnReparent) + EVT_MENU (wxID_PRINT, MyMiniFrame::OnReparent) END_EVENT_TABLE() MyMiniFrame::MyMiniFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, @@ -163,6 +166,8 @@ MyMiniFrame::MyMiniFrame(wxFrame* parent, wxWindowID id, const wxString& title, void MyMiniFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) { + // make it known that the miniframe is no more + mini_frame_exists = FALSE; Destroy(); } @@ -176,6 +181,7 @@ void MyMiniFrame::OnReparent(wxCommandEvent& WXUNUSED(event)) BEGIN_EVENT_TABLE(MyMainFrame, wxFrame) EVT_CLOSE ( MyMainFrame::OnCloseWindow) EVT_BUTTON (ID_REPARENT, MyMainFrame::OnReparent) + EVT_MENU (wxID_PRINT, MyMainFrame::OnReparent) END_EVENT_TABLE() MyMainFrame::MyMainFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, @@ -191,7 +197,14 @@ void MyMainFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) void MyMainFrame::OnReparent(wxCommandEvent& WXUNUSED(event)) { - button->Reparent( mini_frame ); + // practical jokers might find satisfaction in reparenting the button + // after closing the mini_frame. We'll have the last laugh. + if (! mini_frame_exists) + wxMessageBox("The miniframe no longer exists.\n" + "You don't want to make this button an orphan, do you?", + "You got to be kidding"); + else + button->Reparent( mini_frame ); }