2 * Copyright (C) 2009 Kevin Ollivier All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "scrollbar_render.h"
33 #include <wx/dcgraph.h>
34 #include <wx/renderer.h>
36 #include <Carbon/Carbon.h>
38 static int wxScrollbarPartToHIPressedState(wxScrollbarPart part)
41 case wxSCROLLPART_BACKBTNSTART:
42 return kThemeTopOutsideArrowPressed;
43 case wxSCROLLPART_BACKBTNEND:
44 return kThemeTopOutsideArrowPressed; // This does not make much sense. For some reason the outside constant is required.
45 case wxSCROLLPART_FWDBTNSTART:
46 return kThemeTopInsideArrowPressed;
47 case wxSCROLLPART_FWDBTNEND:
48 return kThemeBottomOutsideArrowPressed;
49 case wxSCROLLPART_THUMB:
50 return kThemeThumbPressed;
56 void wxRenderer_DrawScrollbar(wxWindow* WXUNUSED(window), wxDC& dc,
57 const wxRect& rect, wxOrientation orient, int current,
58 wxScrollbarPart focusPart, wxScrollbarPart hoverPart, int max, int step, int flags)
60 const wxCoord x = rect.x;
61 const wxCoord y = rect.y;
62 const wxCoord w = rect.width;
63 const wxCoord h = rect.height;
65 dc.SetBrush( *wxWHITE_BRUSH );
66 dc.SetPen( *wxTRANSPARENT_PEN );
67 dc.DrawRectangle(rect);
69 dc.SetBrush( *wxTRANSPARENT_BRUSH );
71 HIRect hiRect = CGRectMake( x, y, w, h );
73 CGContextRef cgContext = NULL;
74 wxGraphicsContext* gc = NULL;
75 #if wxCHECK_VERSION(2,9,0)
76 wxGCDCImpl *impl = dynamic_cast<wxGCDCImpl*> (dc.GetImpl());
78 gc = impl->GetGraphicsContext();
80 gc = dc.GetGraphicsContext();
83 cgContext = (CGContextRef) gc->GetNativeContext();
87 HIThemeTrackDrawInfo trackInfo;
88 trackInfo.version = 0;
89 trackInfo.kind = kThemeMediumScrollBar;
90 trackInfo.bounds = hiRect;
93 trackInfo.value = current;
94 trackInfo.trackInfo.scrollbar.viewsize = step;
95 trackInfo.attributes = 0;
96 if (orient == wxHORIZONTAL)
97 trackInfo.attributes |= kThemeTrackHorizontal;
98 trackInfo.enableState = (flags & wxCONTROL_FOCUSED) ? kThemeTrackActive : kThemeTrackInactive;
99 trackInfo.trackInfo.scrollbar.pressState = wxScrollbarPartToHIPressedState(focusPart);
100 trackInfo.attributes |= kThemeTrackShowThumb;
102 if (flags & wxCONTROL_DISABLED)
103 trackInfo.enableState = kThemeTrackDisabled;
105 HIThemeDrawTrack(&trackInfo, 0, cgContext, kHIThemeOrientationNormal);