-void wxToolBarBase::OnScroll(wxScrollEvent& event)
-{
- int orient = event.GetOrientation();
-
- int nScrollInc = CalcScrollInc(event);
- if (nScrollInc == 0)
- return;
-
- if (orient == wxHORIZONTAL)
- {
- int newPos = m_xScrollPosition + nScrollInc;
- SetScrollPos(wxHORIZONTAL, newPos, TRUE );
- }
- else
- {
- int newPos = m_yScrollPosition + nScrollInc;
- SetScrollPos(wxVERTICAL, newPos, TRUE );
- }
-
- if (orient == wxHORIZONTAL)
- {
- if (m_xScrollingEnabled)
- ScrollWindow(-m_xScrollPixelsPerLine * nScrollInc, 0, NULL);
- else
- Refresh();
- }
- else
- {
- if (m_yScrollingEnabled)
- ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, NULL);
- else
- Refresh();
- }
-
- if (orient == wxHORIZONTAL)
- {
- m_xScrollPosition += nScrollInc;
- }
- else
- {
- m_yScrollPosition += nScrollInc;
- }
-
-}
-
-int wxToolBarBase::CalcScrollInc(wxScrollEvent& event)
-{
- int pos = event.GetPosition();
- int orient = event.GetOrientation();
-
- int nScrollInc = 0;
- switch (event.GetEventType())
- {
- case wxEVT_SCROLL_TOP:
- {
- if (orient == wxHORIZONTAL)
- nScrollInc = - m_xScrollPosition;
- else
- nScrollInc = - m_yScrollPosition;
- break;
- }
- case wxEVT_SCROLL_BOTTOM:
- {
- if (orient == wxHORIZONTAL)
- nScrollInc = m_xScrollLines - m_xScrollPosition;
- else
- nScrollInc = m_yScrollLines - m_yScrollPosition;
- break;
- }
- case wxEVT_SCROLL_LINEUP:
- {
- nScrollInc = -1;
- break;
- }
- case wxEVT_SCROLL_LINEDOWN:
- {
- nScrollInc = 1;
- break;
- }
- case wxEVT_SCROLL_PAGEUP:
- {
- if (orient == wxHORIZONTAL)
- nScrollInc = -GetScrollPageSize(wxHORIZONTAL);
- else
- nScrollInc = -GetScrollPageSize(wxVERTICAL);
- break;
- }
- case wxEVT_SCROLL_PAGEDOWN:
- {
- if (orient == wxHORIZONTAL)
- nScrollInc = GetScrollPageSize(wxHORIZONTAL);
- else
- nScrollInc = GetScrollPageSize(wxVERTICAL);
- break;
- }
- case wxEVT_SCROLL_THUMBTRACK:
- {
- if (orient == wxHORIZONTAL)
- nScrollInc = pos - m_xScrollPosition;
- else
- nScrollInc = pos - m_yScrollPosition;
- break;
- }
- default:
- {
- break;
- }
- }
- if (orient == wxHORIZONTAL)
- {
- int w, h;
- GetClientSize(&w, &h);
-
- int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine;
- int noPositions = (int) ( ((nMaxWidth - w)/(float)m_xScrollPixelsPerLine) + 0.5 );
- if (noPositions < 0)
- noPositions = 0;
-
- if ( (m_xScrollPosition + nScrollInc) < 0 )
- nScrollInc = -m_xScrollPosition; // As -ve as we can go
- else if ( (m_xScrollPosition + nScrollInc) > noPositions )
- nScrollInc = noPositions - m_xScrollPosition; // As +ve as we can go
-
- return nScrollInc;
- }
- else
- {
- int w, h;
- GetClientSize(&w, &h);
-
- int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine;
- int noPositions = (int) ( ((nMaxHeight - h)/(float)m_yScrollPixelsPerLine) + 0.5 );
- if (noPositions < 0)
- noPositions = 0;
-
- if ( (m_yScrollPosition + nScrollInc) < 0 )
- nScrollInc = -m_yScrollPosition; // As -ve as we can go
- else if ( (m_yScrollPosition + nScrollInc) > noPositions )
- nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go
-
- return nScrollInc;
- }
-}
-
-// Adjust the scrollbars - new version.
-void wxToolBarBase::AdjustScrollbars()
-{
- int w, h;
- GetClientSize(&w, &h);
-
- // Recalculate scroll bar range and position
- if (m_xScrollLines > 0)
- {
- int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine;
- int newRange = (int) ( ((nMaxWidth)/(float)m_xScrollPixelsPerLine) + 0.5 );
- if (newRange < 0)
- newRange = 0;
-
- m_xScrollPosition = wxMin(newRange, m_xScrollPosition);
-
- // Calculate page size i.e. number of scroll units you get on the
- // current client window
- int noPagePositions = (int) ( (w/(float)m_xScrollPixelsPerLine) + 0.5 );
- if (noPagePositions < 1)
- noPagePositions = 1;
-
- SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, newRange);
- SetScrollPageSize(wxHORIZONTAL, noPagePositions);
- }
- if (m_yScrollLines > 0)
- {
- int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine;
- int newRange = (int) ( ((nMaxHeight)/(float)m_yScrollPixelsPerLine) + 0.5 );
- if (newRange < 0)
- newRange = 0;
-
- m_yScrollPosition = wxMin(newRange, m_yScrollPosition);
-
- // Calculate page size i.e. number of scroll units you get on the
- // current client window
- int noPagePositions = (int) ( (h/(float)m_yScrollPixelsPerLine) + 0.5 );
- if (noPagePositions < 1)
- noPagePositions = 1;
-
- SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, newRange);
- SetScrollPageSize(wxVERTICAL, noPagePositions);
- }
-}
-
-// Default OnSize resets scrollbars, if any
-void wxToolBarBase::OnSize(wxSizeEvent& WXUNUSED(event))
-{
-#if wxUSE_CONSTRAINTS
- if (GetAutoLayout())
- Layout();
-#endif
-
- AdjustScrollbars();