if (inOnScroll)
return;
inOnScroll = TRUE;
-
+
int orient = event.GetOrientation();
int nScrollInc = CalcScrollInc(event);
// 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);
void GtkVScroll( float value );
void GtkHScroll( float value );
+ // Calculate scroll increment
+ virtual int CalcScrollInc(wxScrollWinEvent& event);
+
protected:
wxWindow *m_targetWindow;
int m_xScrollPixelsPerLine;
int m_yScrollLines;
int m_xScrollLinesPerPage;
int m_yScrollLinesPerPage;
+
+ double m_scaleY,m_scaleX;
private:
DECLARE_EVENT_TABLE()
// 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);
void GtkVScroll( float value );
void GtkHScroll( float value );
+ // Calculate scroll increment
+ virtual int CalcScrollInc(wxScrollWinEvent& event);
+
protected:
wxWindow *m_targetWindow;
int m_xScrollPixelsPerLine;
int m_yScrollLines;
int m_xScrollLinesPerPage;
int m_yScrollLinesPerPage;
+
+ double m_scaleY,m_scaleX;
private:
DECLARE_EVENT_TABLE()
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxScrolledWindow, wxPanel)
+ EVT_SCROLLWIN(wxScrolledWindow::OnScroll)
EVT_SIZE(wxScrolledWindow::OnSize)
EVT_PAINT(wxScrolledWindow::OnPaint)
EVT_CHAR(wxScrolledWindow::OnChar)
m_xScrollLinesPerPage = 0;
m_yScrollLinesPerPage = 0;
m_targetWindow = (wxWindow*) NULL;
+ m_scaleX = 1.0;
+ m_scaleY = 1.0;
}
bool wxScrolledWindow::Create(wxWindow *parent,
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)
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" );
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" );
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 );
}
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 );
}
*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
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxScrolledWindow, wxPanel)
+ EVT_SCROLLWIN(wxScrolledWindow::OnScroll)
EVT_SIZE(wxScrolledWindow::OnSize)
EVT_PAINT(wxScrolledWindow::OnPaint)
EVT_CHAR(wxScrolledWindow::OnChar)
m_xScrollLinesPerPage = 0;
m_yScrollLinesPerPage = 0;
m_targetWindow = (wxWindow*) NULL;
+ m_scaleX = 1.0;
+ m_scaleY = 1.0;
}
bool wxScrolledWindow::Create(wxWindow *parent,
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)
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" );
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" );
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 );
}
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 );
}
*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
// ----------------------------------------------------------------------------