+int wxScrolledWindow::CalcScrollInc(wxScrollWinEvent& event)
+{
+ int pos = event.GetPosition();
+ int orient = event.GetOrientation();
+
+ int nScrollInc = 0;
+ if (event.GetEventType() == wxEVT_SCROLLWIN_TOP)
+ {
+ if (orient == wxHORIZONTAL)
+ nScrollInc = - m_xScrollPosition;
+ else
+ nScrollInc = - m_yScrollPosition;
+ } else
+ if (event.GetEventType() == wxEVT_SCROLLWIN_BOTTOM)
+ {
+ if (orient == wxHORIZONTAL)
+ nScrollInc = m_xScrollLines - m_xScrollPosition;
+ else
+ nScrollInc = m_yScrollLines - m_yScrollPosition;
+ } else
+ if (event.GetEventType() == wxEVT_SCROLLWIN_LINEUP)
+ {
+ nScrollInc = -1;
+ } else
+ if (event.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN)
+ {
+ nScrollInc = 1;
+ } else
+ if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEUP)
+ {
+ if (orient == wxHORIZONTAL)
+ nScrollInc = -GetScrollPageSize(wxHORIZONTAL);
+ else
+ nScrollInc = -GetScrollPageSize(wxVERTICAL);
+ } else
+ if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN)
+ {
+ if (orient == wxHORIZONTAL)
+ nScrollInc = GetScrollPageSize(wxHORIZONTAL);
+ else
+ nScrollInc = GetScrollPageSize(wxVERTICAL);
+ } else
+ if ((event.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK) ||
+ (event.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE))
+ {
+ if (orient == wxHORIZONTAL)
+ nScrollInc = pos - m_xScrollPosition;
+ else
+ nScrollInc = pos - m_yScrollPosition;
+ }
+
+ if (orient == wxHORIZONTAL)
+ {
+ if (m_xScrollPixelsPerLine > 0)
+ {
+ int max = (int)(m_hAdjust->upper - m_hAdjust->page_size + 0.5);
+ if (max < 0) max = 0;
+
+ if ( (m_xScrollPosition + nScrollInc) < 0 )
+ nScrollInc = -m_xScrollPosition; // As -ve as we can go
+ else if ( (m_xScrollPosition + nScrollInc) > max )
+ nScrollInc = max - m_xScrollPosition; // As +ve as we can go
+ }
+ else
+ m_targetWindow->Refresh();
+ }
+ else
+ {
+ if (m_yScrollPixelsPerLine > 0)
+ {
+ int max = (int)(m_vAdjust->upper - m_vAdjust->page_size + 0.5);
+ if (max < 0) max = 0;
+
+ if ( (m_yScrollPosition + nScrollInc) < 0 )
+ nScrollInc = -m_yScrollPosition; // As -ve as we can go
+ else if ( (m_yScrollPosition + nScrollInc) > max )
+ nScrollInc = max - m_yScrollPosition; // As +ve as we can go
+ }
+ else
+ m_targetWindow->Refresh();
+ }
+
+ return nScrollInc;
+}
+
+void wxScrolledWindow::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) )
+{
+ wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
+
+ wxCHECK_RET( m_wxwindow != NULL, wxT("window needs client area for scrolling") );
+
+ if (orient == wxHORIZONTAL)
+ {
+ int max = (int)(m_hAdjust->upper - m_hAdjust->page_size + 0.5);
+ if (max < 0) max = 0;
+
+ if (pos > max) pos = 0;
+ if (pos < 0) pos = 0;
+
+ if (pos == (int)(m_hAdjust->value+0.5)) return;
+ m_hAdjust->value = pos;
+ }
+ else
+ {
+ int max = (int)(m_vAdjust->upper - m_vAdjust->page_size + 0.5);
+ if (max < 0) max = 0;
+
+ if (pos > max) pos = 0;
+ if (pos < 0) pos = 0;
+
+ if (pos == (int)(m_vAdjust->value+0.5)) return;
+ m_vAdjust->value = pos;
+ }
+
+ if (m_wxwindow->window)
+ {
+ if (orient == wxHORIZONTAL)
+ {
+ // Just update the scrollbar, don't send any wxWindows event
+ GtkHDisconnectEvent();
+ gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" );
+ GtkHConnectEvent();
+ }
+ else
+ {
+ // Just update the scrollbar, don't send any wxWindows event
+ GtkVDisconnectEvent();
+ gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" );
+ GtkVConnectEvent();
+ }
+ }
+}
+
+void wxScrolledWindow::GtkVConnectEvent()
+{
+ gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed",
+ (GtkSignalFunc) gtk_scrolled_window_vscroll_callback, (gpointer) this );
+}
+
+void wxScrolledWindow::GtkHConnectEvent()
+{
+ gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed",
+ (GtkSignalFunc) gtk_scrolled_window_hscroll_callback, (gpointer) this );
+}
+
+void wxScrolledWindow::GtkHDisconnectEvent()
+{
+ gtk_signal_disconnect_by_func( GTK_OBJECT(m_hAdjust),
+ (GtkSignalFunc) gtk_scrolled_window_hscroll_callback, (gpointer) this );
+}
+
+void wxScrolledWindow::GtkVDisconnectEvent()
+{
+ gtk_signal_disconnect_by_func( GTK_OBJECT(m_vAdjust),
+ (GtkSignalFunc) gtk_scrolled_window_vscroll_callback, (gpointer) this );
+}
+