X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/45e6e6f8ab806b337dffeb3b52fec7eba3c845ef..30738aae14dfbce0c492d8696c861947228028c2:/samples/scroll/scroll.cpp diff --git a/samples/scroll/scroll.cpp b/samples/scroll/scroll.cpp index c740185ad6..c879b87686 100644 --- a/samples/scroll/scroll.cpp +++ b/samples/scroll/scroll.cpp @@ -273,6 +273,7 @@ protected: // event stuff void OnMouseLeftDown(wxMouseEvent& event); void OnMouseLeftUp(wxMouseEvent& event); void OnMouseMove(wxMouseEvent& event); + void OnMouseCaptureLost(wxMouseCaptureLostEvent& event); void OnScroll(wxScrollWinEvent& event); DECLARE_EVENT_TABLE() @@ -534,16 +535,11 @@ MyAutoScrollWindow::MyAutoScrollWindow( wxWindow *parent ) wxDefaultPosition, SMALL_BUTTON ); - // We need to do this here, because wxADJUST_MINSIZE below - // will cause the initial size to be ignored for Best/Min size. - // It would be nice to fix the sizers to handle this a little - // more cleanly. - m_button->SetSizeHints( SMALL_BUTTON.GetWidth(), SMALL_BUTTON.GetHeight() ); innersizer->Add( m_button, 0, - wxALIGN_CENTER | wxALL | wxADJUST_MINSIZE, + wxALIGN_CENTER | wxALL, 20 ); innersizer->Add( new wxStaticText( this, wxID_ANY, _T("This is just") ), @@ -743,6 +739,7 @@ BEGIN_EVENT_TABLE(MyAutoTimedScrollingWindow, wxScrolledWindow) EVT_LEFT_DOWN(MyAutoTimedScrollingWindow::OnMouseLeftDown) EVT_LEFT_UP(MyAutoTimedScrollingWindow::OnMouseLeftUp) EVT_MOTION(MyAutoTimedScrollingWindow::OnMouseMove) + EVT_MOUSE_CAPTURE_LOST(MyAutoTimedScrollingWindow::OnMouseCaptureLost) EVT_SCROLLWIN(MyAutoTimedScrollingWindow::OnScroll) END_EVENT_TABLE() @@ -937,7 +934,9 @@ void MyAutoTimedScrollingWindow::OnDraw(wxDC& dc) wxBrush selBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT) , wxSOLID); dc.SetPen(*wxTRANSPARENT_PEN); - wxString str = sm_testData; + const wxString str = sm_testData; + size_t strLength = str.length(); + wxString::const_iterator str_i; // draw the characters // 1. for each update region @@ -948,6 +947,7 @@ void MyAutoTimedScrollingWindow::OnDraw(wxDC& dc) for (int chY = updRectInGChars.y ; chY <= updRectInGChars.y + updRectInGChars.height; ++chY) { // 3. for each character in the row + bool isFirstX = true; for (int chX = updRectInGChars.x ; chX <= updRectInGChars.x + updRectInGChars.width ; ++chX) { @@ -969,10 +969,15 @@ void MyAutoTimedScrollingWindow::OnDraw(wxDC& dc) size_t charIndex = chY * sm_lineLen + chX; if (chY < sm_lineCnt && chX < sm_lineLen && - charIndex < str.Length()) + charIndex < strLength) { - dc.DrawText(str.Mid(charIndex,1), - charPos.x, charPos.y); + if (isFirstX) + { + str_i = str.begin() + charIndex; + isFirstX = false; + } + dc.DrawText(*str_i, charPos.x, charPos.y); + ++str_i; } } } @@ -1013,6 +1018,12 @@ void MyAutoTimedScrollingWindow::OnMouseMove(wxMouseEvent& event) } } +void MyAutoTimedScrollingWindow::OnMouseCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event)) +{ + // we only capture mouse for timed scrolling, so nothing is needed here + // other than making sure to not call event.Skip() +} + void MyAutoTimedScrollingWindow::OnScroll(wxScrollWinEvent& event) { // need to move the cursor when autoscrolling