X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/df61c0097160f84ba840e6648b147d3fa29141ea..bcb7cc7693846151a179c6f199105c19df2c77a2:/samples/mdi/mdi.cpp?ds=inline diff --git a/samples/mdi/mdi.cpp b/samples/mdi/mdi.cpp index 7774866d6d..f3077f4ade 100644 --- a/samples/mdi/mdi.cpp +++ b/samples/mdi/mdi.cpp @@ -31,7 +31,7 @@ #include -#if defined(__WXGTK__) || defined(__WXMOTIF__) +#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) #include "mondrian.xpm" #include "bitmaps/new.xpm" #include "bitmaps/open.xpm" @@ -80,6 +80,12 @@ END_EVENT_TABLE() BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame) EVT_MENU(MDI_CHILD_QUIT, MyChild::OnQuit) EVT_MENU(MDI_REFRESH, MyChild::OnRefresh) + EVT_MENU(MDI_CHANGE_TITLE, MyChild::OnChangeTitle) + EVT_MENU(MDI_CHANGE_POSITION, MyChild::OnChangePosition) + EVT_MENU(MDI_CHANGE_SIZE, MyChild::OnChangeSize) + + EVT_SIZE(MyChild::OnSize) + EVT_MOVE(MyChild::OnMove) EVT_CLOSE(MyChild::OnClose) END_EVENT_TABLE() @@ -123,11 +129,11 @@ bool MyApp::OnInit() // Make a menubar wxMenu *file_menu = new wxMenu; - file_menu->Append(MDI_NEW_WINDOW, "&New window", "Create a new child window"); - file_menu->Append(MDI_QUIT, "&Exit", "Quit the program"); + file_menu->Append(MDI_NEW_WINDOW, "&New window\tCtrl-N", "Create a new child window"); + file_menu->Append(MDI_QUIT, "&Exit\tAlt-X", "Quit the program"); wxMenu *help_menu = new wxMenu; - help_menu->Append(MDI_ABOUT, "&About"); + help_menu->Append(MDI_ABOUT, "&About\tF1"); wxMenuBar *menu_bar = new wxMenuBar; @@ -157,7 +163,8 @@ MyFrame::MyFrame(wxWindow *parent, const wxPoint& pos, const wxSize& size, const long style) - : wxMDIParentFrame(parent, id, title, pos, size, style) + : wxMDIParentFrame(parent, id, title, pos, size, + style | wxNO_FULL_REPAINT_ON_RESIZE) { textWindow = new wxTextCtrl(this, -1, "A help window", wxDefaultPosition, wxDefaultSize, @@ -233,8 +240,11 @@ void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) ) wxMenu *option_menu = new wxMenu; - // Dummy option option_menu->Append(MDI_REFRESH, "&Refresh picture"); + option_menu->Append(MDI_CHANGE_TITLE, "Change &title...\tCtrl-T"); + option_menu->AppendSeparator(); + option_menu->Append(MDI_CHANGE_POSITION, "Move frame\tCtrl-M"); + option_menu->Append(MDI_CHANGE_SIZE, "Resize frame\tCtrl-S"); wxMenu *help_menu = new wxMenu; help_menu->Append(MDI_ABOUT, "&About"); @@ -242,12 +252,15 @@ void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) ) wxMenuBar *menu_bar = new wxMenuBar; menu_bar->Append(file_menu, "&File"); - menu_bar->Append(option_menu, "&Options"); + menu_bar->Append(option_menu, "&Child"); menu_bar->Append(help_menu, "&Help"); // Associate the menu bar with the frame subframe->SetMenuBar(menu_bar); + subframe->CreateStatusBar(); + subframe->SetStatusText(title); + int width, height; subframe->GetClientSize(&width, &height); MyCanvas *canvas = new MyCanvas(subframe, wxPoint(0, 0), wxSize(width, height)); @@ -257,9 +270,6 @@ void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) ) // Give it scrollbars canvas->SetScrollbars(20, 20, 50, 50); - subframe->CreateStatusBar(); - subframe->SetStatusText(title); - subframe->Show(TRUE); } @@ -336,7 +346,9 @@ void MyFrame::InitToolBar(wxToolBar* toolBar) // Define a constructor for my canvas MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size) : wxScrolledWindow(parent, -1, pos, size, - wxSUNKEN_BORDER|wxVSCROLL|wxHSCROLL) + wxSUNKEN_BORDER | + wxNO_FULL_REPAINT_ON_RESIZE | + wxVSCROLL | wxHSCROLL) { SetBackgroundColour(wxColour("WHITE")); @@ -357,7 +369,9 @@ void MyCanvas::OnDraw(wxDC& dc) dc.DrawRoundedRectangle(150, 150, 100, 50, 20); dc.DrawEllipse(250, 250, 100, 50); +#if wxUSE_SPLINES dc.DrawSpline(50, 200, 50, 100, 200, 10); +#endif // wxUSE_SPLINES dc.DrawLine(50, 230, 200, 230); dc.DrawText("This is a test string", 50, 230); @@ -397,10 +411,14 @@ void MyCanvas::OnEvent(wxMouseEvent& event) MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, const long style) - : wxMDIChildFrame(parent, -1, title, pos, size, style) + : wxMDIChildFrame(parent, -1, title, pos, size, + style | wxNO_FULL_REPAINT_ON_RESIZE) { canvas = (MyCanvas *) NULL; my_children.Append(this); + + // this should work for MDI frames as well as for normal ones + SetSizeHints(100, 100); } MyChild::~MyChild() @@ -413,9 +431,35 @@ void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event)) Close(TRUE); } -void MyChild::OnRefresh(wxCommandEvent& event) +void MyChild::OnRefresh(wxCommandEvent& WXUNUSED(event)) +{ + if ( canvas ) + canvas->Refresh(); +} + +void MyChild::OnChangePosition(wxCommandEvent& WXUNUSED(event)) +{ + Move(10, 10); +} + +void MyChild::OnChangeSize(wxCommandEvent& WXUNUSED(event)) { - Refresh(); + SetClientSize(100, 100); +} + +void MyChild::OnChangeTitle(wxCommandEvent& WXUNUSED(event)) +{ + static wxString s_title = _T("Canvas Frame"); + + wxString title = wxGetTextFromUser(_T("Enter the new title for MDI child"), + _T("MDI sample question"), + s_title, + GetParent()->GetParent()); + if ( !title ) + return; + + s_title = title; + SetTitle(s_title); } void MyChild::OnActivate(wxActivateEvent& event) @@ -424,6 +468,33 @@ void MyChild::OnActivate(wxActivateEvent& event) canvas->SetFocus(); } +void MyChild::OnMove(wxMoveEvent& event) +{ + // VZ: here everything is totally wrong under MSW, the positions are + // different and both wrong (pos2 is off by 2 pixels for me which seems + // to be the width of the MDI canvas border) + wxPoint pos1 = event.GetPosition(), + pos2 = GetPosition(); + wxLogStatus("position from event: (%d, %d), from frame (%d, %d)", + pos1.x, pos1.y, pos2.x, pos2.y); + + event.Skip(); +} + +void MyChild::OnSize(wxSizeEvent& event) +{ + // VZ: under MSW the size event carries the client size (quite + // unexpectedly) *except* for the very first one which has the full + // size... what should it really be? TODO: check under wxGTK + wxSize size1 = event.GetSize(), + size2 = GetSize(), + size3 = GetClientSize(); + wxLogStatus("size from event: %dx%d, from frame %dx%d, client %dx%d", + size1.x, size1.y, size2.x, size2.y, size3.x, size3.y); + + event.Skip(); +} + void MyChild::OnClose(wxCloseEvent& event) { if ( canvas && canvas->IsDirty() )