moved wxScrollBar geometry methods out of wxRenderer, they are common for all themes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42716 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2006-10-30 12:33:25 +00:00
parent 6236b8b477
commit 561955046e
8 changed files with 299 additions and 376 deletions

View File

@@ -56,7 +56,6 @@ class WXDLLEXPORT wxScrollBar;
#include "wx/string.h" #include "wx/string.h"
#include "wx/gdicmn.h" #include "wx/gdicmn.h"
#include "wx/icon.h" #include "wx/icon.h"
#include "wx/scrolbar.h" // for wxScrollBar::Element
// helper class used by wxMenu-related functions // helper class used by wxMenu-related functions
class WXDLLEXPORT wxMenuGeometryInfo class WXDLLEXPORT wxMenuGeometryInfo
@@ -382,30 +381,8 @@ public:
virtual void AdjustSize(wxSize *size, const wxWindow *window) = 0; virtual void AdjustSize(wxSize *size, const wxWindow *window) = 0;
#if wxUSE_SCROLLBAR #if wxUSE_SCROLLBAR
// get the size of a scrollbar arrow // get the size of a scrollbar arrow
virtual wxSize GetScrollbarArrowSize() const = 0; virtual wxSize GetScrollbarArrowSize() const = 0;
// gets the bounding box for a scrollbar element for the given (by default
// - current) thumb position
virtual wxRect GetScrollbarRect(const wxScrollBar *scrollbar,
wxScrollBar::Element elem,
int thumbPos = -1) const = 0;
// returns the size of the scrollbar shaft excluding the arrows
virtual wxCoord GetScrollbarSize(const wxScrollBar *scrollbar) = 0;
// returns one of wxHT_SCROLLBAR_XXX constants
virtual wxHitTest HitTestScrollbar(const wxScrollBar *scrollbar,
const wxPoint& pt) const = 0;
// translate the scrollbar position (in logical units) into physical
// coordinate (in pixels) and the other way round
virtual wxCoord ScrollbarToPixel(const wxScrollBar *scrollbar,
int thumbPos = -1) = 0;
virtual int PixelToScrollbar(const wxScrollBar *scrollbar,
wxCoord coord) = 0;
#endif // wxUSE_SCROLLBAR #endif // wxUSE_SCROLLBAR
// get the height of a listbox item from the base font height // get the height of a listbox item from the base font height
@@ -787,21 +764,6 @@ public:
#if wxUSE_SCROLLBAR #if wxUSE_SCROLLBAR
virtual wxSize GetScrollbarArrowSize() const virtual wxSize GetScrollbarArrowSize() const
{ return m_renderer->GetScrollbarArrowSize(); } { return m_renderer->GetScrollbarArrowSize(); }
virtual wxRect GetScrollbarRect(const wxScrollBar *scrollbar,
wxScrollBar::Element elem,
int thumbPos = -1) const
{ return m_renderer->GetScrollbarRect(scrollbar, elem, thumbPos); }
virtual wxCoord GetScrollbarSize(const wxScrollBar *scrollbar)
{ return m_renderer->GetScrollbarSize(scrollbar); }
virtual wxHitTest HitTestScrollbar(const wxScrollBar *scrollbar,
const wxPoint& pt) const
{ return m_renderer->HitTestScrollbar(scrollbar, pt); }
virtual wxCoord ScrollbarToPixel(const wxScrollBar *scrollbar,
int thumbPos = -1)
{ return m_renderer->ScrollbarToPixel(scrollbar, thumbPos); }
virtual int PixelToScrollbar(const wxScrollBar *scrollbar,
wxCoord coord)
{ return m_renderer->PixelToScrollbar(scrollbar, coord); }
#endif // wxUSE_SCROLLBAR #endif // wxUSE_SCROLLBAR
virtual wxCoord GetListboxItemHeight(wxCoord fontHeight) virtual wxCoord GetListboxItemHeight(wxCoord fontHeight)

View File

@@ -121,6 +121,9 @@ public:
// for wxControlRenderer::DrawScrollbar() only // for wxControlRenderer::DrawScrollbar() only
const wxScrollArrows& GetArrows() const { return m_arrows; } const wxScrollArrows& GetArrows() const { return m_arrows; }
// returns one of wxHT_SCROLLBAR_XXX constants
wxHitTest HitTestBar(const wxPoint& pt) const;
// idle processing // idle processing
virtual void OnInternalIdle(); virtual void OnInternalIdle();
@@ -141,6 +144,30 @@ protected:
// is this scrollbar attached to a window or a standalone control? // is this scrollbar attached to a window or a standalone control?
bool IsStandalone() const; bool IsStandalone() const;
// scrollbar geometry methods:
// gets the bounding box for a scrollbar element for the given (by default
// - current) thumb position
wxRect GetScrollbarRect(wxScrollBar::Element elem, int thumbPos = -1) const;
// returns the size of the scrollbar shaft excluding the arrows
wxCoord GetScrollbarSize() const;
// translate the scrollbar position (in logical units) into physical
// coordinate (in pixels) and the other way round
wxCoord ScrollbarToPixel(int thumbPos = -1);
int PixelToScrollbar(wxCoord coord);
// return the starting and ending positions, in pixels, of the thumb of a
// scrollbar with the given logical position, thumb size and range and the
// given physical length
static void GetScrollBarThumbSize(wxCoord length,
int thumbPos,
int thumbSize,
int range,
wxCoord *thumbStart,
wxCoord *thumbEnd);
private: private:
// total range of the scrollbar in logical units // total range of the scrollbar in logical units
int m_range; int m_range;
@@ -165,6 +192,9 @@ private:
// the object handling the arrows // the object handling the arrows
wxScrollArrows m_arrows; wxScrollArrows m_arrows;
friend WXDLLEXPORT class wxControlRenderer; // for geometry methods
friend class wxStdScrollBarInputHandler; // for geometry methods
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxScrollBar) DECLARE_DYNAMIC_CLASS(wxScrollBar)
}; };

View File

@@ -136,21 +136,6 @@ public:
virtual wxCoord GetListboxItemHeight(wxCoord fontHeight); virtual wxCoord GetListboxItemHeight(wxCoord fontHeight);
#if wxUSE_SCROLLBAR
virtual wxRect GetScrollbarRect(const wxScrollBar *scrollbar,
wxScrollBar::Element elem,
int thumbPos = -1) const;
virtual wxCoord GetScrollbarSize(const wxScrollBar *scrollbar);
virtual wxHitTest HitTestScrollbar(const wxScrollBar *scrollbar,
const wxPoint& pt) const;
virtual wxCoord ScrollbarToPixel(const wxScrollBar *scrollbar,
int thumbPos = -1);
virtual int PixelToScrollbar(const wxScrollBar *scrollbar, wxCoord coord);
#endif // wxUSE_SCROLLBAR
#if wxUSE_STATUSBAR #if wxUSE_STATUSBAR
virtual void DrawStatusField(wxDC& dc, virtual void DrawStatusField(wxDC& dc,
const wxRect& rect, const wxRect& rect,
@@ -349,16 +334,6 @@ protected:
virtual int GetTextBorderWidth(const wxTextCtrl *text) const; virtual int GetTextBorderWidth(const wxTextCtrl *text) const;
#endif // wxUSE_TEXTCTRL #endif // wxUSE_TEXTCTRL
// return the starting and ending positions, in pixels, of the thumb of a
// scrollbar with the given logical position, thumb size and range and the
// given physical length
static void GetScrollBarThumbSize(wxCoord length,
int thumbPos,
int thumbSize,
int range,
wxCoord *thumbStart,
wxCoord *thumbEnd);
// GDI objects we often use // GDI objects we often use
wxPen m_penBlack, wxPen m_penBlack,
m_penDarkGrey, m_penDarkGrey,

View File

@@ -243,7 +243,7 @@ void wxControlRenderer::DrawScrollbar(const wxScrollBar *scrollbar,
wxScrollBar::Element elem = wxScrollBar::Element elem =
(wxScrollBar::Element)(wxScrollBar::Element_Bar_1 + nBar); (wxScrollBar::Element)(wxScrollBar::Element_Bar_1 + nBar);
wxRect rectBar = m_renderer->GetScrollbarRect(scrollbar, elem); wxRect rectBar = scrollbar->GetScrollbarRect(elem);
if ( rgnUpdate.Contains(rectBar) ) if ( rgnUpdate.Contains(rectBar) )
{ {
@@ -268,7 +268,7 @@ void wxControlRenderer::DrawScrollbar(const wxScrollBar *scrollbar,
wxScrollBar::Element elem = wxScrollBar::Element elem =
(wxScrollBar::Element)(wxScrollBar::Element_Arrow_Line_1 + nArrow); (wxScrollBar::Element)(wxScrollBar::Element_Arrow_Line_1 + nArrow);
wxRect rectArrow = m_renderer->GetScrollbarRect(scrollbar, elem); wxRect rectArrow = scrollbar->GetScrollbarRect(elem);
if ( rgnUpdate.Contains(rectArrow) ) if ( rgnUpdate.Contains(rectArrow) )
{ {
wxLogTrace(_T("scrollbar"), wxLogTrace(_T("scrollbar"),
@@ -293,7 +293,7 @@ void wxControlRenderer::DrawScrollbar(const wxScrollBar *scrollbar,
// and the thumb // and the thumb
wxScrollBar::Element elem = wxScrollBar::Element_Thumb; wxScrollBar::Element elem = wxScrollBar::Element_Thumb;
wxRect rectThumb = m_renderer->GetScrollbarRect(scrollbar, elem); wxRect rectThumb = scrollbar->GetScrollbarRect(elem);
if ( rectThumb.width && rectThumb.height && rgnUpdate.Contains(rectThumb) ) if ( rectThumb.width && rectThumb.height && rgnUpdate.Contains(rectThumb) )
{ {
wxLogTrace(_T("scrollbar"), wxLogTrace(_T("scrollbar"),

View File

@@ -300,7 +300,7 @@ wxSize wxScrollBar::DoGetBestClientSize() const
wxScrollArrows::Arrow wxScrollBar::HitTestArrow(const wxPoint& pt) const wxScrollArrows::Arrow wxScrollBar::HitTestArrow(const wxPoint& pt) const
{ {
switch ( m_renderer->HitTestScrollbar(this, pt) ) switch ( HitTestBar(pt) )
{ {
case wxHT_SCROLLBAR_ARROW_LINE_1: case wxHT_SCROLLBAR_ARROW_LINE_1:
return wxScrollArrows::Arrow_First; return wxScrollArrows::Arrow_First;
@@ -313,6 +313,259 @@ wxScrollArrows::Arrow wxScrollBar::HitTestArrow(const wxPoint& pt) const
} }
} }
wxHitTest wxScrollBar::HitTestBar(const wxPoint& pt) const
{
// we only need to work with either x or y coord depending on the
// orientation, choose one (but still check the other one to verify if the
// mouse is in the window at all)
const wxSize sizeArrowSB = m_renderer->GetScrollbarArrowSize();
wxCoord coord, sizeArrow, sizeTotal;
wxSize size = GetSize();
if ( GetWindowStyle() & wxVERTICAL )
{
if ( pt.x < 0 || pt.x > size.x )
return wxHT_NOWHERE;
coord = pt.y;
sizeArrow = sizeArrowSB.y;
sizeTotal = size.y;
}
else // horizontal
{
if ( pt.y < 0 || pt.y > size.y )
return wxHT_NOWHERE;
coord = pt.x;
sizeArrow = sizeArrowSB.x;
sizeTotal = size.x;
}
// test for the arrows first as it's faster
if ( coord < 0 || coord > sizeTotal )
{
return wxHT_NOWHERE;
}
else if ( coord < sizeArrow )
{
return wxHT_SCROLLBAR_ARROW_LINE_1;
}
else if ( coord > sizeTotal - sizeArrow )
{
return wxHT_SCROLLBAR_ARROW_LINE_2;
}
else
{
// calculate the thumb position in pixels
sizeTotal -= 2*sizeArrow;
wxCoord thumbStart, thumbEnd;
int range = GetRange();
if ( !range )
{
// clicking the scrollbar without range has no effect
return wxHT_NOWHERE;
}
else
{
GetScrollBarThumbSize(sizeTotal,
GetThumbPosition(),
GetThumbSize(),
range,
&thumbStart,
&thumbEnd);
}
// now compare with the thumb position
coord -= sizeArrow;
if ( coord < thumbStart )
return wxHT_SCROLLBAR_BAR_1;
else if ( coord > thumbEnd )
return wxHT_SCROLLBAR_BAR_2;
else
return wxHT_SCROLLBAR_THUMB;
}
}
/* static */
void wxScrollBar::GetScrollBarThumbSize(wxCoord length,
int thumbPos,
int thumbSize,
int range,
wxCoord *thumbStart,
wxCoord *thumbEnd)
{
// the thumb can't be made less than this number of pixels
static const wxCoord thumbMinWidth = 8; // FIXME: should be configurable
*thumbStart = (length*thumbPos) / range;
*thumbEnd = (length*(thumbPos + thumbSize)) / range;
if ( *thumbEnd - *thumbStart < thumbMinWidth )
{
// adjust the end if possible
if ( *thumbStart <= length - thumbMinWidth )
{
// yes, just make it wider
*thumbEnd = *thumbStart + thumbMinWidth;
}
else // it is at the bottom of the scrollbar
{
// so move it a bit up
*thumbStart = length - thumbMinWidth;
*thumbEnd = length;
}
}
}
wxRect wxScrollBar::GetScrollbarRect(wxScrollBar::Element elem,
int thumbPos) const
{
if ( thumbPos == -1 )
{
thumbPos = GetThumbPosition();
}
const wxSize sizeArrow = m_renderer->GetScrollbarArrowSize();
wxSize sizeTotal = GetClientSize();
wxCoord *start, *width;
wxCoord length, arrow;
wxRect rect;
if ( IsVertical() )
{
rect.x = 0;
rect.width = sizeTotal.x;
length = sizeTotal.y;
start = &rect.y;
width = &rect.height;
arrow = sizeArrow.y;
}
else // horizontal
{
rect.y = 0;
rect.height = sizeTotal.y;
length = sizeTotal.x;
start = &rect.x;
width = &rect.width;
arrow = sizeArrow.x;
}
switch ( elem )
{
case wxScrollBar::Element_Arrow_Line_1:
*start = 0;
*width = arrow;
break;
case wxScrollBar::Element_Arrow_Line_2:
*start = length - arrow;
*width = arrow;
break;
case wxScrollBar::Element_Arrow_Page_1:
case wxScrollBar::Element_Arrow_Page_2:
// we don't have them at all
break;
case wxScrollBar::Element_Thumb:
case wxScrollBar::Element_Bar_1:
case wxScrollBar::Element_Bar_2:
// we need to calculate the thumb position - do it
{
length -= 2*arrow;
wxCoord thumbStart, thumbEnd;
int range = GetRange();
if ( !range )
{
thumbStart =
thumbEnd = 0;
}
else
{
GetScrollBarThumbSize(length,
thumbPos,
GetThumbSize(),
range,
&thumbStart,
&thumbEnd);
}
if ( elem == wxScrollBar::Element_Thumb )
{
*start = thumbStart;
*width = thumbEnd - thumbStart;
}
else if ( elem == wxScrollBar::Element_Bar_1 )
{
*start = 0;
*width = thumbStart;
}
else // elem == wxScrollBar::Element_Bar_2
{
*start = thumbEnd;
*width = length - thumbEnd;
}
// everything is relative to the start of the shaft so far
*start += arrow;
}
break;
case wxScrollBar::Element_Max:
default:
wxFAIL_MSG( _T("unknown scrollbar element") );
}
return rect;
}
wxCoord wxScrollBar::GetScrollbarSize() const
{
const wxSize sizeArrowSB = m_renderer->GetScrollbarArrowSize();
wxCoord sizeArrow, sizeTotal;
if ( GetWindowStyle() & wxVERTICAL )
{
sizeArrow = sizeArrowSB.y;
sizeTotal = GetSize().y;
}
else // horizontal
{
sizeArrow = sizeArrowSB.x;
sizeTotal = GetSize().x;
}
return sizeTotal - 2*sizeArrow;
}
wxCoord wxScrollBar::ScrollbarToPixel(int thumbPos)
{
int range = GetRange();
if ( !range )
{
// the only valid position anyhow
return 0;
}
if ( thumbPos == -1 )
{
// by default use the current thumb position
thumbPos = GetThumbPosition();
}
const wxSize sizeArrow = m_renderer->GetScrollbarArrowSize();
return (thumbPos * GetScrollbarSize()) / range
+ (IsVertical() ? sizeArrow.y : sizeArrow.x);
}
int wxScrollBar::PixelToScrollbar(wxCoord coord)
{
const wxSize sizeArrow = m_renderer->GetScrollbarArrowSize();
return ((coord - (IsVertical() ? sizeArrow.y : sizeArrow.x)) *
GetRange() ) / GetScrollbarSize();
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// drawing // drawing
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -331,7 +584,7 @@ void wxScrollBar::UpdateThumb()
{ {
if ( m_elementsState[n] & wxCONTROL_DIRTY ) if ( m_elementsState[n] & wxCONTROL_DIRTY )
{ {
wxRect rect = GetRenderer()->GetScrollbarRect(this, (Element)n); wxRect rect = GetScrollbarRect((Element)n);
if ( rect.width && rect.height ) if ( rect.width && rect.height )
{ {
@@ -365,9 +618,7 @@ void wxScrollBar::UpdateThumb()
} }
#else // efficient version: only repaint the area occupied by #else // efficient version: only repaint the area occupied by
// the thumb previously - we can't do better than this // the thumb previously - we can't do better than this
rect = GetRenderer()->GetScrollbarRect(this, rect = GetScrollbarRect(Element_Thumb, m_thumbPosOld);
Element_Thumb,
m_thumbPosOld);
#endif // 0/1 #endif // 0/1
} }
@@ -706,7 +957,7 @@ void wxStdScrollBarInputHandler::HandleThumbMove(wxScrollBar *scrollbar,
const wxMouseEvent& event) const wxMouseEvent& event)
{ {
int thumbPos = GetMouseCoord(scrollbar, event) - m_ofsMouse; int thumbPos = GetMouseCoord(scrollbar, event) - m_ofsMouse;
thumbPos = m_renderer->PixelToScrollbar(scrollbar, thumbPos); thumbPos = scrollbar->PixelToScrollbar(thumbPos);
scrollbar->PerformAction(wxACTION_SCROLL_THUMB_MOVE, thumbPos); scrollbar->PerformAction(wxACTION_SCROLL_THUMB_MOVE, thumbPos);
} }
@@ -750,11 +1001,7 @@ bool wxStdScrollBarInputHandler::HandleMouse(wxInputConsumer *consumer,
{ {
// determine which part of the window mouse is in // determine which part of the window mouse is in
wxScrollBar *scrollbar = wxStaticCast(consumer->GetInputWindow(), wxScrollBar); wxScrollBar *scrollbar = wxStaticCast(consumer->GetInputWindow(), wxScrollBar);
wxHitTest ht = m_renderer->HitTestScrollbar wxHitTest ht = scrollbar->HitTest(event.GetPosition());
(
scrollbar,
event.GetPosition()
);
// when the mouse is pressed on any scrollbar element, we capture it // when the mouse is pressed on any scrollbar element, we capture it
// and hold capture until the same mouse button is released // and hold capture until the same mouse button is released
@@ -792,7 +1039,7 @@ bool wxStdScrollBarInputHandler::HandleMouse(wxInputConsumer *consumer,
case wxHT_SCROLLBAR_THUMB: case wxHT_SCROLLBAR_THUMB:
consumer->PerformAction(wxACTION_SCROLL_THUMB_DRAG); consumer->PerformAction(wxACTION_SCROLL_THUMB_DRAG);
m_ofsMouse = GetMouseCoord(scrollbar, event) - m_ofsMouse = GetMouseCoord(scrollbar, event) -
m_renderer->ScrollbarToPixel(scrollbar); scrollbar->ScrollbarToPixel();
// fall through: there is no immediate action // fall through: there is no immediate action
@@ -875,11 +1122,7 @@ bool wxStdScrollBarInputHandler::HandleMouseMove(wxInputConsumer *consumer,
if ( event.Dragging() ) if ( event.Dragging() )
{ {
wxHitTest ht = m_renderer->HitTestScrollbar wxHitTest ht = scrollbar->HitTestBar(event.GetPosition());
(
scrollbar,
event.GetPosition()
);
if ( ht == m_htLast ) if ( ht == m_htLast )
{ {
// nothing changed // nothing changed

View File

@@ -837,270 +837,6 @@ void wxStdRenderer::DrawScrollCorner(wxDC& dc, const wxRect& rect)
DrawSolidRect(dc, wxSCHEME_COLOUR(m_scheme, CONTROL), rect); DrawSolidRect(dc, wxSCHEME_COLOUR(m_scheme, CONTROL), rect);
} }
// ----------------------------------------------------------------------------
// scrollbars geometry
// ----------------------------------------------------------------------------
#if wxUSE_SCROLLBAR
/* static */
void wxStdRenderer::GetScrollBarThumbSize(wxCoord length,
int thumbPos,
int thumbSize,
int range,
wxCoord *thumbStart,
wxCoord *thumbEnd)
{
// the thumb can't be made less than this number of pixels
static const wxCoord thumbMinWidth = 8; // FIXME: should be configurable
*thumbStart = (length*thumbPos) / range;
*thumbEnd = (length*(thumbPos + thumbSize)) / range;
if ( *thumbEnd - *thumbStart < thumbMinWidth )
{
// adjust the end if possible
if ( *thumbStart <= length - thumbMinWidth )
{
// yes, just make it wider
*thumbEnd = *thumbStart + thumbMinWidth;
}
else // it is at the bottom of the scrollbar
{
// so move it a bit up
*thumbStart = length - thumbMinWidth;
*thumbEnd = length;
}
}
}
wxRect wxStdRenderer::GetScrollbarRect(const wxScrollBar *scrollbar,
wxScrollBar::Element elem,
int thumbPos) const
{
if ( thumbPos == -1 )
{
thumbPos = scrollbar->GetThumbPosition();
}
const wxSize sizeArrow = GetScrollbarArrowSize();
wxSize sizeTotal = scrollbar->GetClientSize();
wxCoord *start, *width;
wxCoord length, arrow;
wxRect rect;
if ( scrollbar->IsVertical() )
{
rect.x = 0;
rect.width = sizeTotal.x;
length = sizeTotal.y;
start = &rect.y;
width = &rect.height;
arrow = sizeArrow.y;
}
else // horizontal
{
rect.y = 0;
rect.height = sizeTotal.y;
length = sizeTotal.x;
start = &rect.x;
width = &rect.width;
arrow = sizeArrow.x;
}
switch ( elem )
{
case wxScrollBar::Element_Arrow_Line_1:
*start = 0;
*width = arrow;
break;
case wxScrollBar::Element_Arrow_Line_2:
*start = length - arrow;
*width = arrow;
break;
case wxScrollBar::Element_Arrow_Page_1:
case wxScrollBar::Element_Arrow_Page_2:
// we don't have them at all
break;
case wxScrollBar::Element_Thumb:
case wxScrollBar::Element_Bar_1:
case wxScrollBar::Element_Bar_2:
// we need to calculate the thumb position - do it
{
length -= 2*arrow;
wxCoord thumbStart, thumbEnd;
int range = scrollbar->GetRange();
if ( !range )
{
thumbStart =
thumbEnd = 0;
}
else
{
GetScrollBarThumbSize(length,
thumbPos,
scrollbar->GetThumbSize(),
range,
&thumbStart,
&thumbEnd);
}
if ( elem == wxScrollBar::Element_Thumb )
{
*start = thumbStart;
*width = thumbEnd - thumbStart;
}
else if ( elem == wxScrollBar::Element_Bar_1 )
{
*start = 0;
*width = thumbStart;
}
else // elem == wxScrollBar::Element_Bar_2
{
*start = thumbEnd;
*width = length - thumbEnd;
}
// everything is relative to the start of the shaft so far
*start += arrow;
}
break;
case wxScrollBar::Element_Max:
default:
wxFAIL_MSG( _T("unknown scrollbar element") );
}
return rect;
}
wxCoord wxStdRenderer::GetScrollbarSize(const wxScrollBar *scrollbar)
{
const wxSize sizeArrowSB = GetScrollbarArrowSize();
wxCoord sizeArrow, sizeTotal;
if ( scrollbar->GetWindowStyle() & wxVERTICAL )
{
sizeArrow = sizeArrowSB.y;
sizeTotal = scrollbar->GetSize().y;
}
else // horizontal
{
sizeArrow = sizeArrowSB.x;
sizeTotal = scrollbar->GetSize().x;
}
return sizeTotal - 2*sizeArrow;
}
wxHitTest
wxStdRenderer::HitTestScrollbar(const wxScrollBar *scrollbar, const wxPoint& pt) const
{
// we only need to work with either x or y coord depending on the
// orientation, choose one (but still check the other one to verify if the
// mouse is in the window at all)
const wxSize sizeArrowSB = GetScrollbarArrowSize();
wxCoord coord, sizeArrow, sizeTotal;
wxSize size = scrollbar->GetSize();
if ( scrollbar->GetWindowStyle() & wxVERTICAL )
{
if ( pt.x < 0 || pt.x > size.x )
return wxHT_NOWHERE;
coord = pt.y;
sizeArrow = sizeArrowSB.y;
sizeTotal = size.y;
}
else // horizontal
{
if ( pt.y < 0 || pt.y > size.y )
return wxHT_NOWHERE;
coord = pt.x;
sizeArrow = sizeArrowSB.x;
sizeTotal = size.x;
}
// test for the arrows first as it's faster
if ( coord < 0 || coord > sizeTotal )
{
return wxHT_NOWHERE;
}
else if ( coord < sizeArrow )
{
return wxHT_SCROLLBAR_ARROW_LINE_1;
}
else if ( coord > sizeTotal - sizeArrow )
{
return wxHT_SCROLLBAR_ARROW_LINE_2;
}
else
{
// calculate the thumb position in pixels
sizeTotal -= 2*sizeArrow;
wxCoord thumbStart, thumbEnd;
int range = scrollbar->GetRange();
if ( !range )
{
// clicking the scrollbar without range has no effect
return wxHT_NOWHERE;
}
else
{
GetScrollBarThumbSize(sizeTotal,
scrollbar->GetThumbPosition(),
scrollbar->GetThumbSize(),
range,
&thumbStart,
&thumbEnd);
}
// now compare with the thumb position
coord -= sizeArrow;
if ( coord < thumbStart )
return wxHT_SCROLLBAR_BAR_1;
else if ( coord > thumbEnd )
return wxHT_SCROLLBAR_BAR_2;
else
return wxHT_SCROLLBAR_THUMB;
}
}
wxCoord
wxStdRenderer::ScrollbarToPixel(const wxScrollBar *scrollbar, int thumbPos)
{
int range = scrollbar->GetRange();
if ( !range )
{
// the only valid position anyhow
return 0;
}
if ( thumbPos == -1 )
{
// by default use the current thumb position
thumbPos = scrollbar->GetThumbPosition();
}
const wxSize sizeArrow = GetScrollbarArrowSize();
return (thumbPos*GetScrollbarSize(scrollbar)) / range
+ (scrollbar->IsVertical() ? sizeArrow.y : sizeArrow.x);
}
int wxStdRenderer::PixelToScrollbar(const wxScrollBar *scrollbar, wxCoord coord)
{
const wxSize sizeArrow = GetScrollbarArrowSize();
return ((coord - (scrollbar->IsVertical() ? sizeArrow.y : sizeArrow.x)) *
scrollbar->GetRange() ) / GetScrollbarSize(scrollbar);
}
#endif // wxUSE_SCROLLBAR
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// status bar // status bar
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -197,12 +197,9 @@ public:
virtual void AdjustSize(wxSize *size, const wxWindow *window); virtual void AdjustSize(wxSize *size, const wxWindow *window);
// geometry and hit testing // geometry and hit testing
#if wxUSE_SCROLLBAR
virtual wxSize GetScrollbarArrowSize() const virtual wxSize GetScrollbarArrowSize() const
{ return m_sizeScrollbarArrow; } { return m_sizeScrollbarArrow; }
#if wxUSE_SCROLLBAR
virtual wxRect GetScrollbarRect(const wxScrollBar *scrollbar,
wxScrollBar::Element elem,
int thumbPos = -1) const;
#endif // wxUSE_SCROLLBAR #endif // wxUSE_SCROLLBAR
virtual wxSize GetCheckBitmapSize() const virtual wxSize GetCheckBitmapSize() const
@@ -2229,24 +2226,6 @@ void wxGTKRenderer::DrawScrollbarShaft(wxDC& dc,
DrawSolidRect(dc, wxSCHEME_COLOUR(m_scheme, SCROLLBAR), rectBar); DrawSolidRect(dc, wxSCHEME_COLOUR(m_scheme, SCROLLBAR), rectBar);
} }
#if wxUSE_SCROLLBAR
wxRect wxGTKRenderer::GetScrollbarRect(const wxScrollBar *scrollbar,
wxScrollBar::Element elem,
int thumbPos) const
{
// as GTK scrollbars can't be disabled, it makes no sense to remove the
// thumb for a scrollbar with range 0 - instead, make it fill the entire
// scrollbar shaft
if ( (elem == wxScrollBar::Element_Thumb) && !scrollbar->GetRange() )
{
elem = wxScrollBar::Element_Bar_2;
}
return wxStdRenderer::GetScrollbarRect(scrollbar, elem, thumbPos);
}
#endif // wxUSE_SCROLLBAR
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// size adjustments // size adjustments
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -3229,13 +3229,11 @@ bool wxWin32ScrollBarInputHandler::OnScrollTimer(wxScrollBar *scrollbar,
bool stop = false; bool stop = false;
if ( action == wxACTION_SCROLL_PAGE_DOWN ) if ( action == wxACTION_SCROLL_PAGE_DOWN )
{ {
stop = m_renderer->HitTestScrollbar(scrollbar, m_ptStartScrolling) stop = scrollbar->HitTestBar(m_ptStartScrolling) != wxHT_SCROLLBAR_BAR_2;
!= wxHT_SCROLLBAR_BAR_2;
} }
else if ( action == wxACTION_SCROLL_PAGE_UP ) else if ( action == wxACTION_SCROLL_PAGE_UP )
{ {
stop = m_renderer->HitTestScrollbar(scrollbar, m_ptStartScrolling) stop = scrollbar->HitTestBar(m_ptStartScrolling) != wxHT_SCROLLBAR_BAR_1;
!= wxHT_SCROLLBAR_BAR_1;
} }
if ( stop ) if ( stop )
@@ -3297,7 +3295,7 @@ bool wxWin32ScrollBarInputHandler::HandleMouseMove(wxInputConsumer *control,
return false; return false;
} }
ht = m_renderer->HitTestScrollbar(scrollbar, event.GetPosition()); ht = scrollbar->HitTestBar(event.GetPosition());
if ( ht == m_htLast ) if ( ht == m_htLast )
{ {
// yes it did, resume scrolling // yes it did, resume scrolling
@@ -3327,7 +3325,7 @@ bool wxWin32ScrollBarInputHandler::HandleMouseMove(wxInputConsumer *control,
// Always let thumb jump back if we leave the scrollbar // Always let thumb jump back if we leave the scrollbar
if ( event.Moving() ) if ( event.Moving() )
{ {
ht = m_renderer->HitTestScrollbar(scrollbar, event.GetPosition()); ht = scrollbar->HitTestBar(event.GetPosition());
} }
else // event.Leaving() else // event.Leaving()
{ {
@@ -3346,7 +3344,7 @@ bool wxWin32ScrollBarInputHandler::HandleMouseMove(wxInputConsumer *control,
if (pos.y > -40 && pos.y < scrollbar->GetSize().y+40) if (pos.y > -40 && pos.y < scrollbar->GetSize().y+40)
pos.y = 5; pos.y = 5;
} }
ht = m_renderer->HitTestScrollbar(scrollbar, pos ); ht = scrollbar->HitTestBar(pos);
#endif #endif
// if we're dragging the thumb and the mouse stays in the scrollbar, it // if we're dragging the thumb and the mouse stays in the scrollbar, it