add convenient GetViewStart() and Scroll() overloads taking wxPoint instead of 2 int[ pointer]s

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57527 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-12-24 15:11:00 +00:00
parent 9675a49d4e
commit 0b0f6f87d5
6 changed files with 44 additions and 36 deletions

View File

@@ -27,7 +27,6 @@ public:
int xPos = 0, int yPos = 0, int xPos = 0, int yPos = 0,
bool noRefresh = false); bool noRefresh = false);
virtual void AdjustScrollbars(); virtual void AdjustScrollbars();
virtual void Scroll(int x, int y);
protected: protected:
// this does (each) half of AdjustScrollbars() work // this does (each) half of AdjustScrollbars() work
@@ -60,10 +59,12 @@ protected:
} }
// and this does the same for Scroll() // and this does the same for Scroll()
void DoScroll(int orient, void DoScrollOneDir(int orient,
int pos, int pos,
int pixelsPerLine, int pixelsPerLine,
int *posOld); int *posOld);
virtual void DoScroll(int x, int y);
private: private:
DECLARE_NO_COPY_CLASS(wxScrollHelperNative) DECLARE_NO_COPY_CLASS(wxScrollHelperNative)

View File

@@ -62,13 +62,14 @@ public:
bool noRefresh = false ); bool noRefresh = false );
// scroll to the given (in logical coords) position // scroll to the given (in logical coords) position
virtual void Scroll(int x, int y); void Scroll(int x, int y) { DoScroll(x, y); }
void Scroll(const wxPoint& pt) { DoScroll(pt.x, pt.y); }
// get/set the page size for this orientation (wxVERTICAL/wxHORIZONTAL) // get/set the page size for this orientation (wxVERTICAL/wxHORIZONTAL)
int GetScrollPageSize(int orient) const; int GetScrollPageSize(int orient) const;
void SetScrollPageSize(int orient, int pageSize); void SetScrollPageSize(int orient, int pageSize);
// get the number of lines the window can scroll, // get the number of lines the window can scroll,
// returns 0 if no scrollbars are there. // returns 0 if no scrollbars are there.
int GetScrollLines( int orient ) const; int GetScrollLines( int orient ) const;
@@ -87,7 +88,14 @@ public:
virtual void EnableScrolling(bool x_scrolling, bool y_scrolling); virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
// Get the view start // Get the view start
virtual void GetViewStart(int *x, int *y) const; void GetViewStart(int *x, int *y) const { DoGetViewStart(x, y); }
wxPoint GetViewStart() const
{
wxPoint pt;
DoGetViewStart(&pt.x, &pt.y);
return pt;
}
// Set the scale factor, used in PrepareDC // Set the scale factor, used in PrepareDC
void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; } void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; }
@@ -191,6 +199,10 @@ protected:
*h = size.y; *h = size.y;
} }
// implementation of public methods with the same name
virtual void DoGetViewStart(int *x, int *y) const;
virtual void DoScroll(int x, int y);
// implementations of various wxWindow virtual methods which should be // implementations of various wxWindow virtual methods which should be
// forwarded to us (this can be done by WX_FORWARD_TO_SCROLL_HELPER()) // forwarded to us (this can be done by WX_FORWARD_TO_SCROLL_HELPER())
bool ScrollLayout(); bool ScrollLayout();

View File

@@ -251,6 +251,7 @@ public:
*/ */
void GetScrollPixelsPerUnit(int* xUnit, int* yUnit) const; void GetScrollPixelsPerUnit(int* xUnit, int* yUnit) const;
//@{
/** /**
Get the position at which the visible portion of the window starts. Get the position at which the visible portion of the window starts.
@@ -268,9 +269,11 @@ public:
have to multiply by the number of pixels per scroll have to multiply by the number of pixels per scroll
increment. increment.
@see SetScrollbars() @see SetScrollbars(), Scroll()
*/ */
void GetViewStart(int* x, int* y) const; void GetViewStart(int* x, int* y) const;
wxPoint GetViewStart() const;
//@}
/** /**
Gets the size in device units of the scrollable window area (as Gets the size in device units of the scrollable window area (as
@@ -313,6 +316,7 @@ public:
*/ */
void PrepareDC(wxDC& dc); void PrepareDC(wxDC& dc);
//@{
/** /**
Scrolls a window so the view start is at the given point. Scrolls a window so the view start is at the given point.
@@ -323,13 +327,15 @@ public:
@remarks The positions are in scroll units, not pixels, so to convert to @remarks The positions are in scroll units, not pixels, so to convert to
pixels you will have to multiply by the number of pixels you will have to multiply by the number of
pixels per scroll increment. If either parameter is -1, pixels per scroll increment. If either parameter is
that position will be ignored (no change in that wxDefaultCoord (-1), that position will be ignored (no change
direction). in that direction).
@see SetScrollbars(), GetScrollPixelsPerUnit() @see SetScrollbars(), GetScrollPixelsPerUnit()
*/ */
void Scroll(int x, int y); void Scroll(int x, int y);
void Scroll(const wxPoint& pt);
//@}
/** /**
Set the horizontal and vertical scrolling increment only. See the Set the horizontal and vertical scrolling increment only. See the

View File

@@ -493,10 +493,7 @@ private:
{ {
m_inDoSync = true; m_inDoSync = true;
int x, y; m_winSync->Scroll(GetViewStart());
GetViewStart(&x, &y);
m_winSync->Scroll(x, y);
m_inDoSync = false; m_inDoSync = false;
} }
@@ -771,9 +768,7 @@ void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) )
{ {
wxLogMessage("Scrolling 2 units up.\n" wxLogMessage("Scrolling 2 units up.\n"
"The white square and the controls should move equally!"); "The white square and the controls should move equally!");
int x,y; Scroll( wxDefaultCoord, GetViewStart().y+2 );
GetViewStart( &x, &y );
Scroll( wxDefaultCoord, y+2 );
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1059,20 +1054,14 @@ MyAutoScrollingWindow::DeviceCoordsToGraphicalChars(wxPoint pos) const
{ {
pos.x /= m_fontW; pos.x /= m_fontW;
pos.y /= m_fontH; pos.y /= m_fontH;
int vX, vY; pos += GetViewStart();
GetViewStart(&vX, &vY);
pos.x += vX;
pos.y += vY;
return pos; return pos;
} }
wxPoint wxPoint
MyAutoScrollingWindow::GraphicalCharToDeviceCoords(wxPoint pos) const MyAutoScrollingWindow::GraphicalCharToDeviceCoords(wxPoint pos) const
{ {
int vX, vY; pos -= GetViewStart();
GetViewStart(&vX, &vY);
pos.x -= vX;
pos.y -= vY;
pos.x *= m_fontW; pos.x *= m_fontW;
pos.y *= m_fontH; pos.y *= m_fontH;
return pos; return pos;

View File

@@ -894,7 +894,7 @@ void wxScrollHelper::SetScrollPageSize(int orient, int pageSize)
/* /*
* Scroll to given position (scroll position, not pixel position) * Scroll to given position (scroll position, not pixel position)
*/ */
void wxScrollHelper::Scroll( int x_pos, int y_pos ) void wxScrollHelper::DoScroll( int x_pos, int y_pos )
{ {
if (!m_targetWindow) if (!m_targetWindow)
return; return;
@@ -973,7 +973,7 @@ void wxScrollHelper::EnableScrolling (bool x_scroll, bool y_scroll)
} }
// Where the current view starts from // Where the current view starts from
void wxScrollHelper::GetViewStart (int *x, int *y) const void wxScrollHelper::DoGetViewStart (int *x, int *y) const
{ {
if ( x ) if ( x )
*x = m_xScrollPosition; *x = m_xScrollPosition;

View File

@@ -163,10 +163,10 @@ void wxScrollHelperNative::AdjustScrollbars()
} }
} }
void wxScrollHelperNative::DoScroll(int orient, void wxScrollHelperNative::DoScrollOneDir(int orient,
int pos, int pos,
int pixelsPerLine, int pixelsPerLine,
int *posOld) int *posOld)
{ {
if ( pos != -1 && pos != *posOld && pixelsPerLine ) if ( pos != -1 && pos != *posOld && pixelsPerLine )
{ {
@@ -181,10 +181,10 @@ void wxScrollHelperNative::DoScroll(int orient,
} }
} }
void wxScrollHelperNative::Scroll( int x_pos, int y_pos ) void wxScrollHelperNative::DoScroll( int x_pos, int y_pos )
{ {
wxCHECK_RET( m_targetWindow != 0, _T("No target window") ); wxCHECK_RET( m_targetWindow != 0, _T("No target window") );
DoScroll(wxHORIZONTAL, x_pos, m_xScrollPixelsPerLine, &m_xScrollPosition); DoScrollOneDir(wxHORIZONTAL, x_pos, m_xScrollPixelsPerLine, &m_xScrollPosition);
DoScroll(wxVERTICAL, y_pos, m_yScrollPixelsPerLine, &m_yScrollPosition); DoScrollOneDir(wxVERTICAL, y_pos, m_yScrollPixelsPerLine, &m_yScrollPosition);
} }