1231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block/* 2231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * Copyright (C) 2009 Kevin Ollivier All rights reserved. 3231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * 4231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * Redistribution and use in source and binary forms, with or without 5231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * modification, are permitted provided that the following conditions 6231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * are met: 7231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * 1. Redistributions of source code must retain the above copyright 8231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * notice, this list of conditions and the following disclaimer. 9231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * 2. Redistributions in binary form must reproduce the above copyright 10231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * notice, this list of conditions and the following disclaimer in the 11231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * documentation and/or other materials provided with the distribution. 12231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * 13231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block */ 25231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 26231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 27231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "config.h" 28231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 29231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "scrollbar_render.h" 30231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 31231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include <wx/defs.h> 32231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include <wx/dc.h> 33231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include <wx/dcgraph.h> 34231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include <wx/renderer.h> 35231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 36231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include <Carbon/Carbon.h> 37231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 38231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockstatic int wxScrollbarPartToHIPressedState(wxScrollbarPart part) 39231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block{ 40231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block switch (part) { 41231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block case wxSCROLLPART_BACKBTNSTART: 42231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block return kThemeTopOutsideArrowPressed; 43231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block case wxSCROLLPART_BACKBTNEND: 44231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block return kThemeTopOutsideArrowPressed; // This does not make much sense. For some reason the outside constant is required. 45231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block case wxSCROLLPART_FWDBTNSTART: 46231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block return kThemeTopInsideArrowPressed; 47231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block case wxSCROLLPART_FWDBTNEND: 48231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block return kThemeBottomOutsideArrowPressed; 49231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block case wxSCROLLPART_THUMB: 50231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block return kThemeThumbPressed; 51231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block default: 52231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block return 0; 53231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block } 54231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block} 55231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 56231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockvoid wxRenderer_DrawScrollbar(wxWindow* WXUNUSED(window), wxDC& dc, 57231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block const wxRect& rect, wxOrientation orient, int current, 58231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block wxScrollbarPart focusPart, wxScrollbarPart hoverPart, int max, int step, int flags) 59231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block{ 60231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block const wxCoord x = rect.x; 61231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block const wxCoord y = rect.y; 62231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block const wxCoord w = rect.width; 63231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block const wxCoord h = rect.height; 64231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 65231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block dc.SetBrush( *wxWHITE_BRUSH ); 66231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block dc.SetPen( *wxTRANSPARENT_PEN ); 67231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block dc.DrawRectangle(rect); 68231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 69231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block dc.SetBrush( *wxTRANSPARENT_BRUSH ); 70231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 71231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block HIRect hiRect = CGRectMake( x, y, w, h ); 72231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 73231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block CGContextRef cgContext = NULL; 74231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block wxGraphicsContext* gc = NULL; 75231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#if wxCHECK_VERSION(2,9,0) 76231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block wxGCDCImpl *impl = dynamic_cast<wxGCDCImpl*> (dc.GetImpl()); 77231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block if (impl) 78231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block gc = impl->GetGraphicsContext(); 79231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#else 80231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block gc = dc.GetGraphicsContext(); 81231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#endif 82231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block if (gc) 83231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block cgContext = (CGContextRef) gc->GetNativeContext(); 84231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 85231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block if (cgContext) 86231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block { 87231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block HIThemeTrackDrawInfo trackInfo; 88231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block trackInfo.version = 0; 89231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block trackInfo.kind = kThemeMediumScrollBar; 90231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block trackInfo.bounds = hiRect; 91231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block trackInfo.min = 0; 92231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block trackInfo.max = max; 93231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block trackInfo.value = current; 94231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block trackInfo.trackInfo.scrollbar.viewsize = step; 95231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block trackInfo.attributes = 0; 96231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block if (orient == wxHORIZONTAL) 97231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block trackInfo.attributes |= kThemeTrackHorizontal; 98231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block trackInfo.enableState = (flags & wxCONTROL_FOCUSED) ? kThemeTrackActive : kThemeTrackInactive; 99231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block trackInfo.trackInfo.scrollbar.pressState = wxScrollbarPartToHIPressedState(focusPart); 100231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block trackInfo.attributes |= kThemeTrackShowThumb; 101231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 102231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block if (flags & wxCONTROL_DISABLED) 103231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block trackInfo.enableState = kThemeTrackDisabled; 104231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 105231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block HIThemeDrawTrack(&trackInfo, 0, cgContext, kHIThemeOrientationNormal); 106231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block } 107231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block} 108