X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3d8dea7e2e10502846e18189a8d894e27effdb23..ab7ce33c563651f790f99d64ee56727706047ae3:/samples/mdi/mdi.cpp diff --git a/samples/mdi/mdi.cpp b/samples/mdi/mdi.cpp index eb98b73dee..e5833ef4e8 100644 --- a/samples/mdi/mdi.cpp +++ b/samples/mdi/mdi.cpp @@ -17,11 +17,6 @@ // headers // --------------------------------------------------------------------------- -#ifdef __VMS -#define XtDisplay XTDISPLAY -#define XtWindow XTWINDOW -#endif - // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" @@ -34,20 +29,22 @@ #include "wx/mdi.h" #endif -#include +#include "wx/toolbar.h" -#if defined(__WXGTK__) || defined(__WXMOTIF__) +#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) #include "mondrian.xpm" - #include "bitmaps/new.xpm" - #include "bitmaps/open.xpm" - #include "bitmaps/save.xpm" - #include "bitmaps/copy.xpm" - #include "bitmaps/cut.xpm" - #include "bitmaps/paste.xpm" - #include "bitmaps/print.xpm" - #include "bitmaps/help.xpm" #endif +#include "bitmaps/new.xpm" +#include "bitmaps/open.xpm" +#include "bitmaps/save.xpm" +#include "bitmaps/copy.xpm" +#include "bitmaps/cut.xpm" +#include "bitmaps/paste.xpm" +#include "bitmaps/print.xpm" +#include "bitmaps/help.xpm" + + #include "mdi.h" IMPLEMENT_APP(MyApp) @@ -89,8 +86,6 @@ BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame) EVT_MENU(MDI_CHANGE_POSITION, MyChild::OnChangePosition) EVT_MENU(MDI_CHANGE_SIZE, MyChild::OnChangeSize) - EVT_UPDATE_UI(MDI_REFRESH, MyChild::OnUpdateRefresh) - EVT_SIZE(MyChild::OnSize) EVT_MOVE(MyChild::OnMove) @@ -170,7 +165,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, @@ -240,22 +236,25 @@ void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) ) // Make a menubar wxMenu *file_menu = new wxMenu; - file_menu->Append(MDI_NEW_WINDOW, "&New window\tCtrl-N"); + file_menu->Append(MDI_NEW_WINDOW, "&New window"); file_menu->Append(MDI_CHILD_QUIT, "&Close child", "Close this window"); - file_menu->Append(MDI_QUIT, "&Exit\tAlt-X"); + file_menu->Append(MDI_QUIT, "&Exit"); wxMenu *option_menu = new wxMenu; - option_menu->Append(MDI_REFRESH, "&Refresh picture\tF5"); + 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\tF1"); + help_menu->Append(MDI_ABOUT, "&About"); 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 @@ -276,29 +275,26 @@ void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) ) subframe->Show(TRUE); } -void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event)) +void MyFrame::OnSize(wxSizeEvent& event) { int w, h; GetClientSize(&w, &h); textWindow->SetSize(0, 0, 200, h); GetClientWindow()->SetSize(200, 0, w - 200, h); + + // FIXME: On wxX11, we need the MDI frame to process this + // event, but on other platforms this should not + // be done. +#ifdef __WXX11__ + event.Skip(); +#endif } void MyFrame::InitToolBar(wxToolBar* toolBar) { wxBitmap* bitmaps[8]; -#ifdef __WXMSW__ - bitmaps[0] = new wxBitmap("icon1", wxBITMAP_TYPE_RESOURCE); - bitmaps[1] = new wxBitmap("icon2", wxBITMAP_TYPE_RESOURCE); - bitmaps[2] = new wxBitmap("icon3", wxBITMAP_TYPE_RESOURCE); - bitmaps[3] = new wxBitmap("icon4", wxBITMAP_TYPE_RESOURCE); - bitmaps[4] = new wxBitmap("icon5", wxBITMAP_TYPE_RESOURCE); - bitmaps[5] = new wxBitmap("icon6", wxBITMAP_TYPE_RESOURCE); - bitmaps[6] = new wxBitmap("icon7", wxBITMAP_TYPE_RESOURCE); - bitmaps[7] = new wxBitmap("icon8", wxBITMAP_TYPE_RESOURCE); -#else bitmaps[0] = new wxBitmap( new_xpm ); bitmaps[1] = new wxBitmap( open_xpm ); bitmaps[2] = new wxBitmap( save_xpm ); @@ -307,13 +303,8 @@ void MyFrame::InitToolBar(wxToolBar* toolBar) bitmaps[5] = new wxBitmap( paste_xpm ); bitmaps[6] = new wxBitmap( print_xpm ); bitmaps[7] = new wxBitmap( help_xpm ); -#endif -#ifdef __WXMSW__ int width = 24; -#else - int width = 16; -#endif int currentX = 5; toolBar->AddTool( MDI_NEW_WINDOW, *(bitmaps[0]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "New file"); @@ -349,7 +340,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")); @@ -412,10 +405,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() @@ -428,17 +425,22 @@ void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event)) Close(TRUE); } -void MyChild::OnUpdateRefresh(wxUpdateUIEvent& event) -{ - event.Enable( canvas && canvas->IsDirty() ); -} - 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)) +{ + SetClientSize(100, 100); +} + void MyChild::OnChangeTitle(wxCommandEvent& WXUNUSED(event)) { static wxString s_title = _T("Canvas Frame"); @@ -446,7 +448,7 @@ void MyChild::OnChangeTitle(wxCommandEvent& WXUNUSED(event)) wxString title = wxGetTextFromUser(_T("Enter the new title for MDI child"), _T("MDI sample question"), s_title, - GetParent()); + GetParent()->GetParent()); if ( !title ) return; @@ -460,6 +462,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(wxT("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(wxT("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() )