]> git.saurik.com Git - wxWidgets.git/blame - src/msw/scrolbar.cpp
supporting full style mask
[wxWidgets.git] / src / msw / scrolbar.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
a71d815b 2// Name: src/msw/scrolbar.cpp
2bda0e17
KB
3// Purpose: wxScrollBar
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
2bda0e17
KB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
1e6feb95 16 #pragma hdrstop
2bda0e17
KB
17#endif
18
1e6feb95
VZ
19#if wxUSE_SCROLLBAR
20
851dee09
WS
21#include "wx/scrolbar.h"
22
2bda0e17 23#ifndef WX_PRECOMP
1e6feb95 24 #include "wx/utils.h"
9eddec69 25 #include "wx/settings.h"
2bda0e17
KB
26#endif
27
2bda0e17
KB
28#include "wx/msw/private.h"
29
2bda0e17 30// Scrollbar
debe6624 31bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
2bda0e17 32 const wxPoint& pos,
debe6624 33 const wxSize& size, long style,
720afa24 34 const wxValidator& validator,
2bda0e17
KB
35 const wxString& name)
36{
720afa24 37 if ( !CreateControl(parent, id, pos, size, style, validator, name) )
57f4f925 38 return false;
33ac7e6f 39
720afa24
DS
40 if (!MSWCreateControl(wxT("ScrollBar"), wxEmptyString, pos, size))
41 return false;
2bda0e17 42
720afa24 43 SetScrollbar(0, 1, 2, 1, false);
2bda0e17 44
57f4f925 45 return true;
2bda0e17
KB
46}
47
48wxScrollBar::~wxScrollBar(void)
49{
50}
51
a23fd0e1 52bool wxScrollBar::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
8ae8032c 53 WXWORD WXUNUSED(pos), WXHWND WXUNUSED(control))
2bda0e17 54{
8ae8032c
VZ
55 // don't use pos parameter because it is limited to 16 bits, get the full
56 // 32 bit position from the control itself instead
57 WinStruct<SCROLLINFO> scrollInfo;
58 scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_TRACKPOS;
2b5f62a0 59
8ae8032c 60 if ( !::GetScrollInfo(GetHwnd(), SB_CTL, &scrollInfo) )
2b5f62a0 61 {
8ae8032c
VZ
62 wxLogLastError(wxT("GetScrollInfo"));
63 return false;
2b5f62a0 64 }
8ae8032c 65
8ae8032c 66 int maxPos = scrollInfo.nMax;
a23fd0e1 67
a23fd0e1
VZ
68 // A page size greater than one has the effect of reducing the effective
69 // range, therefore the range has already been boosted artificially - so
70 // reduce it again.
71 if ( m_pageSize > 1 )
72 maxPos -= (m_pageSize - 1);
2bda0e17 73
57a4b972 74 int position = scrollInfo.nPos;
7798a18e 75 wxEventType scrollEvent = wxEVT_NULL;
2bda0e17
KB
76 switch ( wParam )
77 {
97ca4fe4 78 case SB_TOP:
57a4b972 79 position = 0;
a23fd0e1
VZ
80 scrollEvent = wxEVT_SCROLL_TOP;
81 break;
82
97ca4fe4 83 case SB_BOTTOM:
57a4b972 84 position = maxPos;
a23fd0e1
VZ
85 scrollEvent = wxEVT_SCROLL_BOTTOM;
86 break;
87
88 case SB_LINEUP:
57a4b972 89 position--;
a23fd0e1
VZ
90 scrollEvent = wxEVT_SCROLL_LINEUP;
91 break;
92
93 case SB_LINEDOWN:
57a4b972 94 position++;
a23fd0e1
VZ
95 scrollEvent = wxEVT_SCROLL_LINEDOWN;
96 break;
97
98 case SB_PAGEUP:
57a4b972 99 position -= GetPageSize();
a23fd0e1
VZ
100 scrollEvent = wxEVT_SCROLL_PAGEUP;
101 break;
102
103 case SB_PAGEDOWN:
57a4b972 104 position += GetPageSize();
a23fd0e1
VZ
105 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
106 break;
107
a23fd0e1 108 case SB_THUMBPOSITION:
feda3011 109 case SB_THUMBTRACK:
57a4b972 110 position = scrollInfo.nTrackPos;
8ae8032c
VZ
111 scrollEvent = wParam == SB_THUMBPOSITION ? wxEVT_SCROLL_THUMBRELEASE
112 : wxEVT_SCROLL_THUMBTRACK;
a23fd0e1
VZ
113 break;
114
e8b669d3 115 case SB_ENDSCROLL:
cbc85508 116 scrollEvent = wxEVT_SCROLL_CHANGED;
e8b669d3 117 break;
2bda0e17
KB
118 }
119
57a4b972 120 if ( position != scrollInfo.nPos )
2bda0e17 121 {
e8b669d3
VZ
122 if ( position < 0 )
123 position = 0;
124 if ( position > maxPos )
125 position = maxPos;
a23fd0e1 126
e8b669d3
VZ
127 SetThumbPosition(position);
128 }
129 else if ( scrollEvent != wxEVT_SCROLL_THUMBRELEASE &&
cbc85508 130 scrollEvent != wxEVT_SCROLL_CHANGED )
e8b669d3
VZ
131 {
132 // don't process the event if there is no displacement,
133 // unless this is a thumb release or end scroll event.
57f4f925 134 return false;
e8b669d3 135 }
a23fd0e1 136
a23fd0e1 137 wxScrollEvent event(scrollEvent, m_windowId);
27e229f5 138 event.SetOrientation(IsVertical() ? wxVERTICAL : wxHORIZONTAL);
e8b669d3 139 event.SetPosition(position);
a23fd0e1
VZ
140 event.SetEventObject( this );
141
937013e0 142 return HandleWindowEvent(event);
2bda0e17
KB
143}
144
4fabb575 145void wxScrollBar::SetThumbPosition(int viewStart)
2bda0e17 146{
2b5f62a0
VZ
147 SCROLLINFO info;
148 info.cbSize = sizeof(SCROLLINFO);
149 info.nPage = 0;
150 info.nMin = 0;
151 info.nPos = viewStart;
152 info.fMask = SIF_POS ;
153
154 ::SetScrollInfo((HWND) GetHWND(), SB_CTL, &info, TRUE);
2bda0e17
KB
155}
156
4fabb575 157int wxScrollBar::GetThumbPosition(void) const
2bda0e17 158{
4676948b
JS
159 SCROLLINFO scrollInfo;
160 wxZeroMemory(scrollInfo);
161 scrollInfo.cbSize = sizeof(SCROLLINFO);
162 scrollInfo.fMask = SIF_POS;
f0a126fe 163
4676948b
JS
164 if ( !::GetScrollInfo(GetHwnd(), SB_CTL, &scrollInfo) )
165 {
9a83f860 166 wxLogLastError(wxT("GetScrollInfo"));
4676948b
JS
167 }
168 return scrollInfo.nPos;
2bda0e17
KB
169}
170
debe6624
JS
171void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
172 bool refresh)
2bda0e17 173{
a71d815b
WS
174 m_viewSize = pageSize;
175 m_pageSize = thumbSize;
176 m_objectSize = range;
177
178 // The range (number of scroll steps) is the
179 // object length minus the page size.
180 int range1 = wxMax((m_objectSize - m_pageSize), 0) ;
181
182 // Try to adjust the range to cope with page size > 1
183 // (see comment for SetPageLength)
184 if ( m_pageSize > 1 )
185 {
186 range1 += (m_pageSize - 1);
187 }
188
189 SCROLLINFO info;
190 info.cbSize = sizeof(SCROLLINFO);
191 info.nPage = m_pageSize;
192 info.nMin = 0;
193 info.nMax = range1;
194 info.nPos = position;
195
196 info.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
197
198 ::SetScrollInfo((HWND) GetHWND(), SB_CTL, &info, refresh);
2bda0e17
KB
199}
200
2bda0e17
KB
201void wxScrollBar::Command(wxCommandEvent& event)
202{
687706f5 203 SetThumbPosition(event.GetInt());
2bda0e17
KB
204 ProcessCommand(event);
205}
206
caafd082
DS
207wxSize wxScrollBar::DoGetBestSize() const
208{
209 int w = 100;
210 int h = 100;
211
212 if ( IsVertical() )
213 {
214 w = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
215 }
216 else
217 {
218 h = wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
219 }
220
31582e4e
RD
221 wxSize best(w, h);
222 CacheBestSize(best);
223 return best;
caafd082
DS
224}
225
720afa24
DS
226WXDWORD wxScrollBar::MSWGetStyle(long style, WXDWORD *exstyle) const
227{
228 // we never have an external border
229 WXDWORD msStyle = wxControl::MSWGetStyle
230 (
231 (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle
232 );
233
234 // SBS_HORZ is 0 anyhow, but do mention it explicitly for clarity
235 msStyle |= style & wxSB_HORIZONTAL ? SBS_HORZ : SBS_VERT;
236
237 return msStyle;
238}
239
0cf11995 240WXHBRUSH wxScrollBar::MSWControlColor(WXHDC pDC, WXHWND hWnd)
123865f2 241{
0cf11995
VZ
242 // unless we have an explicitly set bg colour, use default (gradient under
243 // XP) brush instead of GetBackgroundColour() one as the base class would
244 //
245 // note that fg colour isn't used for a scrollbar
246 return UseBgCol() ? wxControl::MSWControlColor(pDC, hWnd) : NULL;
123865f2
JS
247}
248
1e6feb95 249#endif // wxUSE_SCROLLBAR