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.
28 #include "scrollbar_render.h"
33 #include <wx/dcgraph.h>
34 #include <wx/graphics.h>
35 #include <wx/renderer.h>
36 #include <wx/window.h>
38 #include <wx/msw/private.h>
39 #include <wx/msw/uxtheme.h>
44 #define SP_THUMBVERT 3
45 #define SP_TRACKENDHOR 4
46 #define SP_TRACKENDVERT 7
47 #define SP_GRIPPERHOR 8
48 #define SP_GRIPPERVERT 9
55 #define TS_UP_BUTTON 0
56 #define TS_DOWN_BUTTON 4
57 #define TS_LEFT_BUTTON 8
58 #define TS_RIGHT_BUTTON 12
60 #if wxUSE_GRAPHICS_CONTEXT
61 // TODO remove this dependency (gdiplus needs the macros)
62 // we need to undef because the macros are being defined in WebCorePrefix.h
63 // but GdiPlus.h is not accepting them
65 #define max(a,b) (((a) > (b)) ? (a) : (b))
68 #define min(a,b) (((a) < (b)) ? (a) : (b))
70 #include <wx/dcgraph.h>
72 using namespace Gdiplus;
73 #endif // wxUSE_GRAPHICS_CONTEXT
80 #if wxUSE_GRAPHICS_CONTEXT && (!defined(wxUSE_CAIRO) || !wxUSE_CAIRO)
82 wxGCDC* gcdc = wxDynamicCast(dc, wxGCDC);
84 m_graphics = (Graphics*)gcdc->GetGraphicsContext()->GetNativeContext();
85 m_hdc = m_graphics->GetHDC();
89 m_hdc = GetHdcOf(*dc);
94 #if wxUSE_GRAPHICS_CONTEXT && (!defined(wxUSE_CAIRO) || !wxUSE_CAIRO)
96 m_graphics->ReleaseHDC(m_hdc);
100 operator HDC() const { return m_hdc; }
104 #if wxUSE_GRAPHICS_CONTEXT && (!defined(wxUSE_CAIRO) || !wxUSE_CAIRO)
105 Graphics* m_graphics;
109 int getTSStateForPart(wxScrollbarPart part, wxScrollbarPart focusPart, wxScrollbarPart hoverPart, int flags = 0)
111 int xpState = TS_NORMAL;
112 if (flags & wxCONTROL_DISABLED)
113 xpState = TS_DISABLED;
114 else if (part == focusPart)
116 else if (part == hoverPart)
122 void wxRenderer_DrawScrollbar(wxWindow* window, wxDC& dc,
123 const wxRect& rect, wxOrientation orient, int current, wxScrollbarPart focusPart, wxScrollbarPart hoverPart, int max, int step, int flags)
125 wxUxThemeEngine *engine = wxUxThemeEngine::Get();
126 HTHEME hTheme = (HTHEME)engine->OpenThemeData(0, L"SCROLLBAR");
128 bool horiz = orient == wxHORIZONTAL;
131 part = SP_TRACKENDHOR;
133 part = SP_TRACKENDVERT;
135 int xpState = TS_NORMAL;
136 wxRect transRect = rect;
138 #if USE(WXGC) && !defined(wxUSE_CAIRO) || !wxUSE_CAIRO
139 // when going from GdiPlus -> Gdi, any GdiPlus transformations are lost
140 // so we need to alter the coordinates to reflect their transformed point.
144 wxGCDC* gcdc = wxDynamicCast(&dc, wxGCDC);
145 wxGraphicsContext* gc = gcdc->GetGraphicsContext();
146 gc->GetTransform().TransformPoint(&xtrans, &ytrans);
148 transRect.x += (int)xtrans;
149 transRect.y += (int)ytrans;
155 wxCopyRectToRECT(transRect, r);
157 // Unlike Mac, on MSW you draw the scrollbar piece by piece.
158 // so we draw the track first, then the buttons
161 engine->DrawThemeBackground(hTheme, GraphicsHDC(&dc), part, xpState, &r, 0);
166 xpState = getTSStateForPart(wxSCROLLPART_BACKBTNSTART, focusPart, hoverPart, flags);
167 xpState += horiz ? TS_LEFT_BUTTON : TS_UP_BUTTON;
169 buttonRect.bottom = buttonRect.top + buttonSize;
170 buttonRect.right = buttonRect.left + buttonSize;
171 engine->DrawThemeBackground(hTheme, GraphicsHDC(&dc), part, xpState, &buttonRect, 0);
173 xpState = getTSStateForPart(wxSCROLLPART_FWDBTNEND, focusPart, hoverPart, flags);
174 xpState += horiz ? TS_RIGHT_BUTTON : TS_DOWN_BUTTON;
176 buttonRect.top = buttonRect.bottom - buttonSize;
177 buttonRect.left = buttonRect.right - buttonSize;
178 engine->DrawThemeBackground(hTheme, GraphicsHDC(&dc), part, xpState, &buttonRect, 0);
180 part = horiz ? SP_THUMBHOR : SP_THUMBVERT;
182 int physicalLength = horiz ? rect.width : rect.height;
183 physicalLength -= buttonSize*2;
186 calcThumbStartAndLength(physicalLength, max,
187 current, step, &thumbStart, &thumbLength);
190 buttonRect.left = buttonRect.left + thumbStart + buttonSize;
191 buttonRect.right = buttonRect.left + thumbLength;
193 buttonRect.top = buttonRect.top + thumbStart + buttonSize;
194 buttonRect.bottom = buttonRect.top + thumbLength;
197 xpState = getTSStateForPart(wxSCROLLPART_THUMB, focusPart, hoverPart, flags);
198 engine->DrawThemeBackground(hTheme, GraphicsHDC(&dc), part, xpState, &buttonRect, 0);
201 int thickness = ::GetSystemMetrics(SM_CXVSCROLL) / 2;
203 buttonRect.left += ((buttonRect.right - buttonRect.left) - thickness) / 2;
204 buttonRect.top += ((buttonRect.bottom - buttonRect.top) - thickness) / 2;
205 buttonRect.right = buttonRect.left + thickness;
206 buttonRect.bottom = buttonRect.top + thickness;
209 part = SP_GRIPPERHOR;
211 part = SP_GRIPPERVERT;
215 engine->DrawThemeBackground(hTheme, GraphicsHDC(&dc), part, xpState, &buttonRect, 0);