- m_targetWindow->GetClientSize( &w, &h );
- m_targetWindow->GetVirtualSize( &vw, &vh );
-
- if (m_xScrollPixelsPerLine == 0)
- {
- m_hAdjust->upper = 1.0;
- m_hAdjust->page_increment = 1.0;
- m_hAdjust->page_size = 1.0;
- }
- else
- {
- m_hAdjust->upper = vw / m_xScrollPixelsPerLine;
- m_hAdjust->page_increment = (w / m_xScrollPixelsPerLine);
- m_hAdjust->page_size = m_hAdjust->page_increment;
-
- // If the scrollbar hits the right side, move the window
- // right to keep it from over extending.
-
- if ((m_hAdjust->value != 0.0) && (m_hAdjust->value + m_hAdjust->page_size > m_hAdjust->upper))
- {
- m_hAdjust->value = m_hAdjust->upper - m_hAdjust->page_size;
- if (m_hAdjust->value < 0.0)
- m_hAdjust->value = 0.0;
-
- if (GetChildren().GetCount() == 0)
- m_xScrollPosition = (int)m_hAdjust->value; // This is enough without child windows
- else
- gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" ); // Actually scroll window
- }
- }
-
- if (m_yScrollPixelsPerLine == 0)
- {
- m_vAdjust->upper = 1.0;
- m_vAdjust->page_increment = 1.0;
- m_vAdjust->page_size = 1.0;
- }
- else
- {
- m_vAdjust->upper = vh / m_yScrollPixelsPerLine;
- m_vAdjust->page_increment = (h / m_yScrollPixelsPerLine);
- m_vAdjust->page_size = m_vAdjust->page_increment;
-
- if ((m_vAdjust->value != 0.0) && (m_vAdjust->value + m_vAdjust->page_size > m_vAdjust->upper))
- {
- m_vAdjust->value = m_vAdjust->upper - m_vAdjust->page_size;
- if (m_vAdjust->value < 0.0)
- m_vAdjust->value = 0.0;
-
- if (GetChildren().GetCount() == 0)
- m_yScrollPosition = (int)m_vAdjust->value;
- else
- gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" );
- }
- }
-
- m_xScrollLinesPerPage = (int)(m_hAdjust->page_increment + 0.5);
- m_yScrollLinesPerPage = (int)(m_vAdjust->page_increment + 0.5);
-
- gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
- gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
-}
-
-
-// ----------------------------------------------------------------------------
-// target window handling
-// ----------------------------------------------------------------------------
-
-void wxScrolledWindow::SetTargetWindow( wxWindow *target, bool WXUNUSED(pushEventHandler) )
-{
- wxASSERT_MSG( target, wxT("target window must not be NULL") );
- m_targetWindow = target;
-}
-
-wxWindow *wxScrolledWindow::GetTargetWindow() const
-{
- return m_targetWindow;
-}
-
-// Override this function if you don't want to have wxScrolledWindow
-// automatically change the origin according to the scroll position.
-void wxScrolledWindow::DoPrepareDC(wxDC& dc)
-{
- dc.SetDeviceOrigin( -m_xScrollPosition * m_xScrollPixelsPerLine,
- -m_yScrollPosition * m_yScrollPixelsPerLine );
-}
-
-void wxScrolledWindow::SetScrollRate( int xstep, int ystep )
-{
- int old_x = m_xScrollPixelsPerLine * m_xScrollPosition;
- int old_y = m_yScrollPixelsPerLine * m_yScrollPosition;
-
- m_xScrollPixelsPerLine = xstep;
- m_yScrollPixelsPerLine = ystep;
-
- int new_x = m_xScrollPixelsPerLine * m_xScrollPosition;
- int new_y = m_yScrollPixelsPerLine * m_yScrollPosition;
-
- m_targetWindow->ScrollWindow( old_x - new_x, old_y - new_y );
-
- AdjustScrollbars();
-}
-
-void wxScrolledWindow::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const
-{
- if ( x_unit )
- *x_unit = m_xScrollPixelsPerLine;
- if ( y_unit )
- *y_unit = m_yScrollPixelsPerLine;
-}
-
-int wxScrolledWindow::GetScrollPageSize(int orient) const
-{
- if ( orient == wxHORIZONTAL )
- return m_xScrollLinesPerPage;
- else
- return m_yScrollLinesPerPage;
-}
-
-void wxScrolledWindow::SetScrollPageSize(int orient, int pageSize)
-{
- if ( orient == wxHORIZONTAL )
- m_xScrollLinesPerPage = pageSize;
- else
- m_yScrollLinesPerPage = pageSize;
-}
-
-void wxScrolledWindow::OnScroll(wxScrollWinEvent& 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)
- {
- m_xScrollPosition += nScrollInc;
- }
- else
- {
- m_yScrollPosition += nScrollInc;
- }
-
- if (orient == wxHORIZONTAL)
- {
- if (m_xScrollingEnabled)
- m_targetWindow->ScrollWindow(-m_xScrollPixelsPerLine * nScrollInc, 0, (const wxRect *) NULL);
- else
- m_targetWindow->Refresh();
- }
- else
- {
- if (m_yScrollingEnabled)
- m_targetWindow->ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, (const wxRect *) NULL);
- else
- m_targetWindow->Refresh();
- }
-}
-
-void wxScrolledWindow::Scroll( int x_pos, int y_pos )
-{
- wxASSERT_MSG( m_targetWindow != 0, _T("No target window") );
-
- if (((x_pos == -1) || (x_pos == m_xScrollPosition)) &&
- ((y_pos == -1) || (y_pos == m_yScrollPosition))) return;
-
- if ((x_pos != -1) && (m_xScrollPixelsPerLine))
- {
- int max = (int)(m_hAdjust->upper - m_hAdjust->page_size + 0.5);
- if (max < 0) max = 0;
- if (x_pos > max) x_pos = max;
- if (x_pos < 0) x_pos = 0;
-
- int old_x = m_xScrollPosition;
- m_xScrollPosition = x_pos;
- m_hAdjust->value = x_pos;
-
- m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 );
-
- // Just update the scrollbar, don't send any wxWidgets event
- GtkHDisconnectEvent();
- gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" );
- GtkHConnectEvent();
- }
-
- if ((y_pos != -1) && (m_yScrollPixelsPerLine))