X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/925e9792d32e353233985f53a4845f154e455a58..160f78e09db9fff2f7c3a1484514835f1d83eb8e:/samples/scrollsub/scrollsub.cpp diff --git a/samples/scrollsub/scrollsub.cpp b/samples/scrollsub/scrollsub.cpp index 4891f67dab..d1f400d426 100644 --- a/samples/scrollsub/scrollsub.cpp +++ b/samples/scrollsub/scrollsub.cpp @@ -36,10 +36,14 @@ class MyApp; class MyScrolledWindow: public wxScrolledWindow { public: - MyScrolledWindow(){}; + MyScrolledWindow() {} MyScrolledWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size ); - ~MyScrolledWindow(){}; + void OnPaint( wxPaintEvent &event ); + void OnSize( wxSizeEvent &event ); + +protected: + virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size); private: MyCanvas *m_canvas; @@ -141,7 +145,8 @@ IMPLEMENT_APP(MyApp) IMPLEMENT_DYNAMIC_CLASS(MyScrolledWindow, wxScrolledWindow) BEGIN_EVENT_TABLE(MyScrolledWindow, wxScrolledWindow) - EVT_PAINT( MyScrolledWindow::OnPaint) + EVT_PAINT( MyScrolledWindow::OnPaint) + EVT_SIZE( MyScrolledWindow::OnSize) END_EVENT_TABLE() MyScrolledWindow::MyScrolledWindow( wxWindow *parent, wxWindowID id, @@ -173,10 +178,33 @@ MyScrolledWindow::MyScrolledWindow( wxWindow *parent, wxWindowID id, mainsizer->Add( middlesizer, 1, wxEXPAND ); - SetAutoLayout( true ); SetSizer( mainsizer ); } +wxSize MyScrolledWindow::GetSizeAvailableForScrollTarget(const wxSize& size) +{ + // decrease the total size by the size of the non-scrollable parts above/to + // the left of the canvas + wxSize sizeCanvas(size); + sizeCanvas.x -= 60; + sizeCanvas.y -= 25; + return sizeCanvas; +} + +void MyScrolledWindow::OnSize( wxSizeEvent &WXUNUSED(event) ) +{ + // We need to override OnSize so that our scrolled + // window a) does call Layout() to use sizers for + // positioning the controls but b) does not query + // the sizer for their size and use that for setting + // the scrollable area as set that ourselves by + // calling SetScrollbar() further down. + + Layout(); + + AdjustScrollbars(); +} + void MyScrolledWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) { wxPaintDC dc( this ); @@ -359,9 +387,9 @@ void MyCanvas::ScrollWindow( int dx, int dy, const wxRect *rect ) // MyFrame -const int ID_QUIT = 108; +const int ID_QUIT = wxID_EXIT; const int ID_FULL = 109; -const int ID_ABOUT = 110; +const int ID_ABOUT = wxID_ABOUT; IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) @@ -406,7 +434,6 @@ MyFrame::MyFrame() topsizer->Add( m_log, 0, wxEXPAND ); #endif // wxUSE_LOG - SetAutoLayout( true ); SetSizer( topsizer ); } @@ -433,6 +460,9 @@ void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) bool MyApp::OnInit() { + if ( !wxApp::OnInit() ) + return false; + wxFrame *frame = new MyFrame(); frame->Show( true );