From 0bc0cd5d8119c86b28760d1b18f6a08b98145979 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 1 May 2001 16:40:06 +0000 Subject: [PATCH] wxScrolledWindow next take, the Gizmo controls work again and several other problem have been solved, among them at least on reported about the old implementation (wrong max size due to a rounding error). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9959 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/scrolwin.h | 3 ++ include/wx/gtk1/scrolwin.h | 3 ++ src/generic/listctrl.cpp | 2 - src/gtk/scrolwin.cpp | 99 +++++++++++++++++++++++++++++--------- src/gtk1/scrolwin.cpp | 99 +++++++++++++++++++++++++++++--------- 5 files changed, 158 insertions(+), 48 deletions(-) diff --git a/include/wx/gtk/scrolwin.h b/include/wx/gtk/scrolwin.h index 98fb2c2335..2133e8f4cc 100644 --- a/include/wx/gtk/scrolwin.h +++ b/include/wx/gtk/scrolwin.h @@ -128,6 +128,9 @@ public: // Calculate scroll increment virtual int CalcScrollInc(wxScrollWinEvent& event); + // Overridden from wxWindows due callback being static + virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ); + protected: wxWindow *m_targetWindow; int m_xScrollPixelsPerLine; diff --git a/include/wx/gtk1/scrolwin.h b/include/wx/gtk1/scrolwin.h index 98fb2c2335..2133e8f4cc 100644 --- a/include/wx/gtk1/scrolwin.h +++ b/include/wx/gtk1/scrolwin.h @@ -128,6 +128,9 @@ public: // Calculate scroll increment virtual int CalcScrollInc(wxScrollWinEvent& event); + // Overridden from wxWindows due callback being static + virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ); + protected: wxWindow *m_targetWindow; int m_xScrollPixelsPerLine; diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index c985d51346..ba33085757 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -3129,9 +3129,7 @@ void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data ) void wxListMainWindow::OnScroll(wxScrollWinEvent& event) { -#ifndef __WXGTK__ wxScrolledWindow::OnScroll( event ) ; -#endif #if wxUSE_GENERIC_LIST_EXTENSIONS diff --git a/src/gtk/scrolwin.cpp b/src/gtk/scrolwin.cpp index 40fd6bed32..2de10148a0 100644 --- a/src/gtk/scrolwin.cpp +++ b/src/gtk/scrolwin.cpp @@ -268,13 +268,13 @@ void wxScrolledWindow::SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY, m_hAdjust->upper = noUnitsX; m_hAdjust->value = xPos; m_hAdjust->step_increment = 1.0; - m_hAdjust->page_increment = 1.0; + m_hAdjust->page_increment = 2.0; m_vAdjust->lower = 0.0; m_vAdjust->upper = noUnitsY; m_vAdjust->value = yPos; m_vAdjust->step_increment = 1.0; - m_vAdjust->page_increment = 1.0; + m_vAdjust->page_increment = 2.0; AdjustScrollbars(); } @@ -294,6 +294,9 @@ void wxScrolledWindow::AdjustScrollbars() else m_vAdjust->page_size = (h / m_yScrollPixelsPerLine); + m_xScrollLinesPerPage = (int)(m_hAdjust->page_size + 0.5); + m_yScrollLinesPerPage = (int)(m_vAdjust->page_size + 0.5); + gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" ); gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" ); } @@ -348,7 +351,7 @@ void wxScrolledWindow::SetScrollPageSize(int orient, int pageSize) void wxScrolledWindow::OnScroll(wxScrollWinEvent& event) { int orient = event.GetOrientation(); - + int nScrollInc = CalcScrollInc(event); if (nScrollInc == 0) return; @@ -442,11 +445,8 @@ void wxScrolledWindow::GtkVScroll( float value ) if (y_pos == m_yScrollPosition) return; - int old_y = m_yScrollPosition; - m_yScrollPosition = y_pos; - GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); - GtkRange *range = GTK_RANGE(scrolledWindow->hscrollbar); + GtkRange *range = GTK_RANGE(scrolledWindow->vscrollbar); wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK; if (range->scroll_type == GTK_SCROLL_STEP_BACKWARD) command = wxEVT_SCROLLWIN_LINEUP; @@ -454,28 +454,30 @@ void wxScrolledWindow::GtkVScroll( float value ) else if (range->scroll_type == GTK_SCROLL_PAGE_BACKWARD) command = wxEVT_SCROLLWIN_PAGEUP; else if (range->scroll_type == GTK_SCROLL_PAGE_FORWARD) command = wxEVT_SCROLLWIN_PAGEDOWN; - wxScrollWinEvent event( command, m_yScrollPosition, wxVERTICAL ); + wxScrollWinEvent event( command, y_pos, wxVERTICAL ); event.SetEventObject( this ); GetEventHandler()->ProcessEvent( event ); +/* + int old_y = m_yScrollPosition; + m_yScrollPosition = y_pos; + m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine ); +*/ } void wxScrolledWindow::GtkHScroll( float value ) { if (!m_targetWindow) return; - + if (m_xScrollPixelsPerLine == 0) return; int x_pos = (int)(value+0.5); - + if (x_pos == m_xScrollPosition) return; - - int old_x = m_xScrollPosition; - m_xScrollPosition = x_pos; GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); GtkRange *range = GTK_RANGE(scrolledWindow->hscrollbar); @@ -486,11 +488,16 @@ void wxScrolledWindow::GtkHScroll( float value ) else if (range->scroll_type == GTK_SCROLL_PAGE_BACKWARD) command = wxEVT_SCROLLWIN_PAGEUP; else if (range->scroll_type == GTK_SCROLL_PAGE_FORWARD) command = wxEVT_SCROLLWIN_PAGEDOWN; - wxScrollWinEvent event( command, m_xScrollPosition, wxHORIZONTAL ); + wxScrollWinEvent event( command, x_pos, wxHORIZONTAL ); event.SetEventObject( this ); GetEventHandler()->ProcessEvent( event ); +/* + int old_x = m_xScrollPosition; + m_xScrollPosition = x_pos; + m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 ); +*/ } void wxScrolledWindow::EnableScrolling (bool x_scroll, bool y_scroll) @@ -589,11 +596,9 @@ int wxScrolledWindow::CalcScrollInc(wxScrollWinEvent& event) { int w, h; m_targetWindow->GetClientSize(&w, &h); - - int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine; - int noPositions = (int) ( ((nMaxWidth - w)/(double)m_xScrollPixelsPerLine) + 0.5 ); - if (noPositions < 0) - noPositions = 0; + + int noPositions = (int)(m_hAdjust->upper - m_hAdjust->page_size + 0.5); + if (noPositions < 0) noPositions = 0; if ( (m_xScrollPosition + nScrollInc) < 0 ) nScrollInc = -m_xScrollPosition; // As -ve as we can go @@ -610,10 +615,8 @@ int wxScrolledWindow::CalcScrollInc(wxScrollWinEvent& event) int w, h; m_targetWindow->GetClientSize(&w, &h); - int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine; - int noPositions = (int) ( ((nMaxHeight - h)/(double)m_yScrollPixelsPerLine) + 0.5 ); - if (noPositions < 0) - noPositions = 0; + int noPositions = (int)(m_vAdjust->upper - m_vAdjust->page_size + 0.5); + if (noPositions < 0) noPositions = 0; if ( (m_yScrollPosition + nScrollInc) < 0 ) nScrollInc = -m_yScrollPosition; // As -ve as we can go @@ -627,6 +630,56 @@ int wxScrolledWindow::CalcScrollInc(wxScrollWinEvent& event) 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) + { + float fpos = (float)pos; + if (fpos > m_hAdjust->upper - m_hAdjust->page_size) fpos = m_hAdjust->upper - m_hAdjust->page_size; + if (fpos < 0.0) fpos = 0.0; + + if (fabs(fpos-m_hAdjust->value) < 0.2) return; + m_hAdjust->value = fpos; + } + else + { + float fpos = (float)pos; + if (fpos > m_vAdjust->upper - m_vAdjust->page_size) fpos = m_vAdjust->upper - m_vAdjust->page_size; + if (fpos < 0.0) fpos = 0.0; + + if (fabs(fpos-m_vAdjust->value) < 0.2) return; + m_vAdjust->value = fpos; + } + + if (m_wxwindow->window) + { + if (orient == wxHORIZONTAL) + { + gtk_signal_disconnect_by_func( GTK_OBJECT(m_hAdjust), + (GtkSignalFunc) gtk_scrolled_window_hscroll_callback, (gpointer) this ); + + gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" ); + + gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed", + (GtkSignalFunc) gtk_scrolled_window_hscroll_callback, (gpointer) this ); + } + else + { + gtk_signal_disconnect_by_func( GTK_OBJECT(m_vAdjust), + (GtkSignalFunc) gtk_scrolled_window_vscroll_callback, (gpointer) this ); + + gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" ); + + gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed", + (GtkSignalFunc) gtk_scrolled_window_vscroll_callback, (gpointer) this ); + } + } +} + // ---------------------------------------------------------------------------- // event handlers // ---------------------------------------------------------------------------- diff --git a/src/gtk1/scrolwin.cpp b/src/gtk1/scrolwin.cpp index 40fd6bed32..2de10148a0 100644 --- a/src/gtk1/scrolwin.cpp +++ b/src/gtk1/scrolwin.cpp @@ -268,13 +268,13 @@ void wxScrolledWindow::SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY, m_hAdjust->upper = noUnitsX; m_hAdjust->value = xPos; m_hAdjust->step_increment = 1.0; - m_hAdjust->page_increment = 1.0; + m_hAdjust->page_increment = 2.0; m_vAdjust->lower = 0.0; m_vAdjust->upper = noUnitsY; m_vAdjust->value = yPos; m_vAdjust->step_increment = 1.0; - m_vAdjust->page_increment = 1.0; + m_vAdjust->page_increment = 2.0; AdjustScrollbars(); } @@ -294,6 +294,9 @@ void wxScrolledWindow::AdjustScrollbars() else m_vAdjust->page_size = (h / m_yScrollPixelsPerLine); + m_xScrollLinesPerPage = (int)(m_hAdjust->page_size + 0.5); + m_yScrollLinesPerPage = (int)(m_vAdjust->page_size + 0.5); + gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" ); gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" ); } @@ -348,7 +351,7 @@ void wxScrolledWindow::SetScrollPageSize(int orient, int pageSize) void wxScrolledWindow::OnScroll(wxScrollWinEvent& event) { int orient = event.GetOrientation(); - + int nScrollInc = CalcScrollInc(event); if (nScrollInc == 0) return; @@ -442,11 +445,8 @@ void wxScrolledWindow::GtkVScroll( float value ) if (y_pos == m_yScrollPosition) return; - int old_y = m_yScrollPosition; - m_yScrollPosition = y_pos; - GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); - GtkRange *range = GTK_RANGE(scrolledWindow->hscrollbar); + GtkRange *range = GTK_RANGE(scrolledWindow->vscrollbar); wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK; if (range->scroll_type == GTK_SCROLL_STEP_BACKWARD) command = wxEVT_SCROLLWIN_LINEUP; @@ -454,28 +454,30 @@ void wxScrolledWindow::GtkVScroll( float value ) else if (range->scroll_type == GTK_SCROLL_PAGE_BACKWARD) command = wxEVT_SCROLLWIN_PAGEUP; else if (range->scroll_type == GTK_SCROLL_PAGE_FORWARD) command = wxEVT_SCROLLWIN_PAGEDOWN; - wxScrollWinEvent event( command, m_yScrollPosition, wxVERTICAL ); + wxScrollWinEvent event( command, y_pos, wxVERTICAL ); event.SetEventObject( this ); GetEventHandler()->ProcessEvent( event ); +/* + int old_y = m_yScrollPosition; + m_yScrollPosition = y_pos; + m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine ); +*/ } void wxScrolledWindow::GtkHScroll( float value ) { if (!m_targetWindow) return; - + if (m_xScrollPixelsPerLine == 0) return; int x_pos = (int)(value+0.5); - + if (x_pos == m_xScrollPosition) return; - - int old_x = m_xScrollPosition; - m_xScrollPosition = x_pos; GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); GtkRange *range = GTK_RANGE(scrolledWindow->hscrollbar); @@ -486,11 +488,16 @@ void wxScrolledWindow::GtkHScroll( float value ) else if (range->scroll_type == GTK_SCROLL_PAGE_BACKWARD) command = wxEVT_SCROLLWIN_PAGEUP; else if (range->scroll_type == GTK_SCROLL_PAGE_FORWARD) command = wxEVT_SCROLLWIN_PAGEDOWN; - wxScrollWinEvent event( command, m_xScrollPosition, wxHORIZONTAL ); + wxScrollWinEvent event( command, x_pos, wxHORIZONTAL ); event.SetEventObject( this ); GetEventHandler()->ProcessEvent( event ); +/* + int old_x = m_xScrollPosition; + m_xScrollPosition = x_pos; + m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 ); +*/ } void wxScrolledWindow::EnableScrolling (bool x_scroll, bool y_scroll) @@ -589,11 +596,9 @@ int wxScrolledWindow::CalcScrollInc(wxScrollWinEvent& event) { int w, h; m_targetWindow->GetClientSize(&w, &h); - - int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine; - int noPositions = (int) ( ((nMaxWidth - w)/(double)m_xScrollPixelsPerLine) + 0.5 ); - if (noPositions < 0) - noPositions = 0; + + int noPositions = (int)(m_hAdjust->upper - m_hAdjust->page_size + 0.5); + if (noPositions < 0) noPositions = 0; if ( (m_xScrollPosition + nScrollInc) < 0 ) nScrollInc = -m_xScrollPosition; // As -ve as we can go @@ -610,10 +615,8 @@ int wxScrolledWindow::CalcScrollInc(wxScrollWinEvent& event) int w, h; m_targetWindow->GetClientSize(&w, &h); - int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine; - int noPositions = (int) ( ((nMaxHeight - h)/(double)m_yScrollPixelsPerLine) + 0.5 ); - if (noPositions < 0) - noPositions = 0; + int noPositions = (int)(m_vAdjust->upper - m_vAdjust->page_size + 0.5); + if (noPositions < 0) noPositions = 0; if ( (m_yScrollPosition + nScrollInc) < 0 ) nScrollInc = -m_yScrollPosition; // As -ve as we can go @@ -627,6 +630,56 @@ int wxScrolledWindow::CalcScrollInc(wxScrollWinEvent& event) 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) + { + float fpos = (float)pos; + if (fpos > m_hAdjust->upper - m_hAdjust->page_size) fpos = m_hAdjust->upper - m_hAdjust->page_size; + if (fpos < 0.0) fpos = 0.0; + + if (fabs(fpos-m_hAdjust->value) < 0.2) return; + m_hAdjust->value = fpos; + } + else + { + float fpos = (float)pos; + if (fpos > m_vAdjust->upper - m_vAdjust->page_size) fpos = m_vAdjust->upper - m_vAdjust->page_size; + if (fpos < 0.0) fpos = 0.0; + + if (fabs(fpos-m_vAdjust->value) < 0.2) return; + m_vAdjust->value = fpos; + } + + if (m_wxwindow->window) + { + if (orient == wxHORIZONTAL) + { + gtk_signal_disconnect_by_func( GTK_OBJECT(m_hAdjust), + (GtkSignalFunc) gtk_scrolled_window_hscroll_callback, (gpointer) this ); + + gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" ); + + gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed", + (GtkSignalFunc) gtk_scrolled_window_hscroll_callback, (gpointer) this ); + } + else + { + gtk_signal_disconnect_by_func( GTK_OBJECT(m_vAdjust), + (GtkSignalFunc) gtk_scrolled_window_vscroll_callback, (gpointer) this ); + + gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" ); + + gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed", + (GtkSignalFunc) gtk_scrolled_window_vscroll_callback, (gpointer) this ); + } + } +} + // ---------------------------------------------------------------------------- // event handlers // ---------------------------------------------------------------------------- -- 2.50.0