From d9a4f62064559ddf7b88afb1bdcfbdf22893d9a5 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 1 May 2001 14:32:41 +0000 Subject: [PATCH] wxScrolledWindow now emits wxScrollWinEvents. Something does not work yet as desried, though. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9954 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/src/gizmos/splittree.cpp | 2 +- include/wx/gtk/scrolwin.h | 11 ++ include/wx/gtk1/scrolwin.h | 11 ++ src/gtk/scrolwin.cpp | 180 ++++++++++++++++++++++++++++++- src/gtk1/scrolwin.cpp | 180 ++++++++++++++++++++++++++++++- 5 files changed, 377 insertions(+), 7 deletions(-) diff --git a/contrib/src/gizmos/splittree.cpp b/contrib/src/gizmos/splittree.cpp index a99b6733c8..d1911ee8e3 100644 --- a/contrib/src/gizmos/splittree.cpp +++ b/contrib/src/gizmos/splittree.cpp @@ -573,7 +573,7 @@ void wxSplitterScrolledWindow::OnScroll(wxScrollWinEvent& event) if (inOnScroll) return; inOnScroll = TRUE; - + int orient = event.GetOrientation(); int nScrollInc = CalcScrollInc(event); diff --git a/include/wx/gtk/scrolwin.h b/include/wx/gtk/scrolwin.h index 391dadb28e..98fb2c2335 100644 --- a/include/wx/gtk/scrolwin.h +++ b/include/wx/gtk/scrolwin.h @@ -111,7 +111,13 @@ public: // Adjust the scrollbars virtual void AdjustScrollbars(); + // Set the scale factor, used in PrepareDC + void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; } + double GetScaleX() const { return m_scaleX; } + double GetScaleY() const { return m_scaleY; } + // implementation from now on + void OnScroll(wxScrollWinEvent& event); void OnSize(wxSizeEvent& event); void OnPaint(wxPaintEvent& event); void OnChar(wxKeyEvent& event); @@ -119,6 +125,9 @@ public: void GtkVScroll( float value ); void GtkHScroll( float value ); + // Calculate scroll increment + virtual int CalcScrollInc(wxScrollWinEvent& event); + protected: wxWindow *m_targetWindow; int m_xScrollPixelsPerLine; @@ -131,6 +140,8 @@ protected: int m_yScrollLines; int m_xScrollLinesPerPage; int m_yScrollLinesPerPage; + + double m_scaleY,m_scaleX; private: DECLARE_EVENT_TABLE() diff --git a/include/wx/gtk1/scrolwin.h b/include/wx/gtk1/scrolwin.h index 391dadb28e..98fb2c2335 100644 --- a/include/wx/gtk1/scrolwin.h +++ b/include/wx/gtk1/scrolwin.h @@ -111,7 +111,13 @@ public: // Adjust the scrollbars virtual void AdjustScrollbars(); + // Set the scale factor, used in PrepareDC + void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; } + double GetScaleX() const { return m_scaleX; } + double GetScaleY() const { return m_scaleY; } + // implementation from now on + void OnScroll(wxScrollWinEvent& event); void OnSize(wxSizeEvent& event); void OnPaint(wxPaintEvent& event); void OnChar(wxKeyEvent& event); @@ -119,6 +125,9 @@ public: void GtkVScroll( float value ); void GtkHScroll( float value ); + // Calculate scroll increment + virtual int CalcScrollInc(wxScrollWinEvent& event); + protected: wxWindow *m_targetWindow; int m_xScrollPixelsPerLine; @@ -131,6 +140,8 @@ protected: int m_yScrollLines; int m_xScrollLinesPerPage; int m_yScrollLinesPerPage; + + double m_scaleY,m_scaleX; private: DECLARE_EVENT_TABLE() diff --git a/src/gtk/scrolwin.cpp b/src/gtk/scrolwin.cpp index 548a400065..40fd6bed32 100644 --- a/src/gtk/scrolwin.cpp +++ b/src/gtk/scrolwin.cpp @@ -42,6 +42,7 @@ // ---------------------------------------------------------------------------- BEGIN_EVENT_TABLE(wxScrolledWindow, wxPanel) + EVT_SCROLLWIN(wxScrolledWindow::OnScroll) EVT_SIZE(wxScrolledWindow::OnSize) EVT_PAINT(wxScrolledWindow::OnPaint) EVT_CHAR(wxScrolledWindow::OnChar) @@ -134,6 +135,8 @@ wxScrolledWindow::wxScrolledWindow() m_xScrollLinesPerPage = 0; m_yScrollLinesPerPage = 0; m_targetWindow = (wxWindow*) NULL; + m_scaleX = 1.0; + m_scaleY = 1.0; } bool wxScrolledWindow::Create(wxWindow *parent, @@ -342,9 +345,49 @@ void wxScrolledWindow::SetScrollPageSize(int orient, int pageSize) m_yScrollLinesPerPage = pageSize; } -/* - * Scroll to given position (scroll position, not pixel position) - */ +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 ) { if (!m_targetWindow) @@ -359,6 +402,11 @@ void wxScrolledWindow::Scroll( int x_pos, int y_pos ) m_xScrollPosition = x_pos; m_hAdjust->value = x_pos; + wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK; + wxScrollWinEvent event( command, m_xScrollPosition, wxHORIZONTAL ); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent( event ); + m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 ); gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" ); @@ -370,6 +418,11 @@ void wxScrolledWindow::Scroll( int x_pos, int y_pos ) m_yScrollPosition = y_pos; m_vAdjust->value = y_pos; + wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK; + wxScrollWinEvent event( command, m_yScrollPosition, wxVERTICAL ); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent( event ); + m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine ); gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" ); @@ -392,6 +445,19 @@ void wxScrolledWindow::GtkVScroll( float value ) int old_y = m_yScrollPosition; m_yScrollPosition = y_pos; + GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); + GtkRange *range = GTK_RANGE(scrolledWindow->hscrollbar); + + wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK; + if (range->scroll_type == GTK_SCROLL_STEP_BACKWARD) command = wxEVT_SCROLLWIN_LINEUP; + else if (range->scroll_type == GTK_SCROLL_STEP_FORWARD) command = wxEVT_SCROLLWIN_LINEDOWN; + 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 ); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent( event ); + m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine ); } @@ -411,6 +477,19 @@ void wxScrolledWindow::GtkHScroll( float value ) int old_x = m_xScrollPosition; m_xScrollPosition = x_pos; + GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); + GtkRange *range = GTK_RANGE(scrolledWindow->hscrollbar); + + wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK; + if (range->scroll_type == GTK_SCROLL_STEP_BACKWARD) command = wxEVT_SCROLLWIN_LINEUP; + else if (range->scroll_type == GTK_SCROLL_STEP_FORWARD) command = wxEVT_SCROLLWIN_LINEDOWN; + 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 ); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent( event ); + m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 ); } @@ -453,6 +532,101 @@ void wxScrolledWindow::CalcUnscrolledPosition(int x, int y, int *xx, int *yy) co *yy = y + m_yScrollPosition * m_yScrollPixelsPerLine; } +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 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; + + 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 + } + else + m_targetWindow->Refresh(); + } + else + { + if (m_yScrollPixelsPerLine > 0) + { + 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; + + 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 + } + else + m_targetWindow->Refresh(); + } + + return nScrollInc; +} + // ---------------------------------------------------------------------------- // event handlers // ---------------------------------------------------------------------------- diff --git a/src/gtk1/scrolwin.cpp b/src/gtk1/scrolwin.cpp index 548a400065..40fd6bed32 100644 --- a/src/gtk1/scrolwin.cpp +++ b/src/gtk1/scrolwin.cpp @@ -42,6 +42,7 @@ // ---------------------------------------------------------------------------- BEGIN_EVENT_TABLE(wxScrolledWindow, wxPanel) + EVT_SCROLLWIN(wxScrolledWindow::OnScroll) EVT_SIZE(wxScrolledWindow::OnSize) EVT_PAINT(wxScrolledWindow::OnPaint) EVT_CHAR(wxScrolledWindow::OnChar) @@ -134,6 +135,8 @@ wxScrolledWindow::wxScrolledWindow() m_xScrollLinesPerPage = 0; m_yScrollLinesPerPage = 0; m_targetWindow = (wxWindow*) NULL; + m_scaleX = 1.0; + m_scaleY = 1.0; } bool wxScrolledWindow::Create(wxWindow *parent, @@ -342,9 +345,49 @@ void wxScrolledWindow::SetScrollPageSize(int orient, int pageSize) m_yScrollLinesPerPage = pageSize; } -/* - * Scroll to given position (scroll position, not pixel position) - */ +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 ) { if (!m_targetWindow) @@ -359,6 +402,11 @@ void wxScrolledWindow::Scroll( int x_pos, int y_pos ) m_xScrollPosition = x_pos; m_hAdjust->value = x_pos; + wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK; + wxScrollWinEvent event( command, m_xScrollPosition, wxHORIZONTAL ); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent( event ); + m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 ); gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" ); @@ -370,6 +418,11 @@ void wxScrolledWindow::Scroll( int x_pos, int y_pos ) m_yScrollPosition = y_pos; m_vAdjust->value = y_pos; + wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK; + wxScrollWinEvent event( command, m_yScrollPosition, wxVERTICAL ); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent( event ); + m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine ); gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" ); @@ -392,6 +445,19 @@ void wxScrolledWindow::GtkVScroll( float value ) int old_y = m_yScrollPosition; m_yScrollPosition = y_pos; + GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); + GtkRange *range = GTK_RANGE(scrolledWindow->hscrollbar); + + wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK; + if (range->scroll_type == GTK_SCROLL_STEP_BACKWARD) command = wxEVT_SCROLLWIN_LINEUP; + else if (range->scroll_type == GTK_SCROLL_STEP_FORWARD) command = wxEVT_SCROLLWIN_LINEDOWN; + 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 ); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent( event ); + m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine ); } @@ -411,6 +477,19 @@ void wxScrolledWindow::GtkHScroll( float value ) int old_x = m_xScrollPosition; m_xScrollPosition = x_pos; + GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); + GtkRange *range = GTK_RANGE(scrolledWindow->hscrollbar); + + wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK; + if (range->scroll_type == GTK_SCROLL_STEP_BACKWARD) command = wxEVT_SCROLLWIN_LINEUP; + else if (range->scroll_type == GTK_SCROLL_STEP_FORWARD) command = wxEVT_SCROLLWIN_LINEDOWN; + 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 ); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent( event ); + m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 ); } @@ -453,6 +532,101 @@ void wxScrolledWindow::CalcUnscrolledPosition(int x, int y, int *xx, int *yy) co *yy = y + m_yScrollPosition * m_yScrollPixelsPerLine; } +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 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; + + 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 + } + else + m_targetWindow->Refresh(); + } + else + { + if (m_yScrollPixelsPerLine > 0) + { + 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; + + 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 + } + else + m_targetWindow->Refresh(); + } + + return nScrollInc; +} + // ---------------------------------------------------------------------------- // event handlers // ---------------------------------------------------------------------------- -- 2.45.2