]> git.saurik.com Git - wxWidgets.git/blame - src/msw/scrolbar.cpp
Add EVT_RIBBONGALLERY_CLICKED event.
[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
f0a126fe 30#if wxUSE_EXTENDED_RTTI
bc9fb572
JS
31WX_DEFINE_FLAGS( wxScrollBarStyle )
32
3ff066a4 33wxBEGIN_FLAGS( wxScrollBarStyle )
bc9fb572
JS
34 // new style border flags, we put them first to
35 // use them for streaming out
3ff066a4
SC
36 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
37 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
38 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
39 wxFLAGS_MEMBER(wxBORDER_RAISED)
40 wxFLAGS_MEMBER(wxBORDER_STATIC)
41 wxFLAGS_MEMBER(wxBORDER_NONE)
57f4f925 42
bc9fb572 43 // old style border flags
3ff066a4
SC
44 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
45 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
46 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
47 wxFLAGS_MEMBER(wxRAISED_BORDER)
48 wxFLAGS_MEMBER(wxSTATIC_BORDER)
cb0afb26 49 wxFLAGS_MEMBER(wxBORDER)
bc9fb572
JS
50
51 // standard window styles
3ff066a4
SC
52 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
53 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
54 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
55 wxFLAGS_MEMBER(wxWANTS_CHARS)
cb0afb26 56 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
3ff066a4
SC
57 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
58 wxFLAGS_MEMBER(wxVSCROLL)
59 wxFLAGS_MEMBER(wxHSCROLL)
bc9fb572 60
3ff066a4
SC
61 wxFLAGS_MEMBER(wxSB_HORIZONTAL)
62 wxFLAGS_MEMBER(wxSB_VERTICAL)
bc9fb572 63
3ff066a4 64wxEND_FLAGS( wxScrollBarStyle )
bc9fb572 65
f0a126fe
SC
66IMPLEMENT_DYNAMIC_CLASS_XTI(wxScrollBar, wxControl,"wx/scrolbar.h")
67
3ff066a4 68wxBEGIN_PROPERTIES_TABLE(wxScrollBar)
cbc85508 69 wxEVENT_RANGE_PROPERTY( Scroll , wxEVT_SCROLL_TOP , wxEVT_SCROLL_CHANGED , wxScrollEvent )
c5ca409b 70
3ff066a4 71 wxPROPERTY( ThumbPosition , int , SetThumbPosition, GetThumbPosition, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
57f4f925
WS
72 wxPROPERTY( Range , int , SetRange, GetRange, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
73 wxPROPERTY( ThumbSize , int , SetThumbSize, GetThumbSize, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
74 wxPROPERTY( PageSize , int , SetPageSize, GetPageSize, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
af498247 75 wxPROPERTY_FLAGS( WindowStyle , wxScrollBarStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
3ff066a4 76wxEND_PROPERTIES_TABLE()
2bda0e17 77
3ff066a4
SC
78wxBEGIN_HANDLERS_TABLE(wxScrollBar)
79wxEND_HANDLERS_TABLE()
066f1b7a 80
3ff066a4 81wxCONSTRUCTOR_5( wxScrollBar , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
f0a126fe
SC
82#else
83IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
84#endif
2bda0e17
KB
85
86// Scrollbar
debe6624 87bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
2bda0e17 88 const wxPoint& pos,
debe6624 89 const wxSize& size, long style,
720afa24 90 const wxValidator& validator,
2bda0e17
KB
91 const wxString& name)
92{
720afa24 93 if ( !CreateControl(parent, id, pos, size, style, validator, name) )
57f4f925 94 return false;
33ac7e6f 95
720afa24
DS
96 if (!MSWCreateControl(wxT("ScrollBar"), wxEmptyString, pos, size))
97 return false;
2bda0e17 98
720afa24 99 SetScrollbar(0, 1, 2, 1, false);
2bda0e17 100
57f4f925 101 return true;
2bda0e17
KB
102}
103
104wxScrollBar::~wxScrollBar(void)
105{
106}
107
a23fd0e1 108bool wxScrollBar::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
8ae8032c 109 WXWORD WXUNUSED(pos), WXHWND WXUNUSED(control))
2bda0e17 110{
8ae8032c
VZ
111 // don't use pos parameter because it is limited to 16 bits, get the full
112 // 32 bit position from the control itself instead
113 WinStruct<SCROLLINFO> scrollInfo;
114 scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_TRACKPOS;
2b5f62a0 115
8ae8032c 116 if ( !::GetScrollInfo(GetHwnd(), SB_CTL, &scrollInfo) )
2b5f62a0 117 {
8ae8032c
VZ
118 wxLogLastError(wxT("GetScrollInfo"));
119 return false;
2b5f62a0 120 }
8ae8032c 121
8ae8032c 122 int maxPos = scrollInfo.nMax;
a23fd0e1 123
a23fd0e1
VZ
124 // A page size greater than one has the effect of reducing the effective
125 // range, therefore the range has already been boosted artificially - so
126 // reduce it again.
127 if ( m_pageSize > 1 )
128 maxPos -= (m_pageSize - 1);
2bda0e17 129
57a4b972 130 int position = scrollInfo.nPos;
7798a18e 131 wxEventType scrollEvent = wxEVT_NULL;
2bda0e17
KB
132 switch ( wParam )
133 {
97ca4fe4 134 case SB_TOP:
57a4b972 135 position = 0;
a23fd0e1
VZ
136 scrollEvent = wxEVT_SCROLL_TOP;
137 break;
138
97ca4fe4 139 case SB_BOTTOM:
57a4b972 140 position = maxPos;
a23fd0e1
VZ
141 scrollEvent = wxEVT_SCROLL_BOTTOM;
142 break;
143
144 case SB_LINEUP:
57a4b972 145 position--;
a23fd0e1
VZ
146 scrollEvent = wxEVT_SCROLL_LINEUP;
147 break;
148
149 case SB_LINEDOWN:
57a4b972 150 position++;
a23fd0e1
VZ
151 scrollEvent = wxEVT_SCROLL_LINEDOWN;
152 break;
153
154 case SB_PAGEUP:
57a4b972 155 position -= GetPageSize();
a23fd0e1
VZ
156 scrollEvent = wxEVT_SCROLL_PAGEUP;
157 break;
158
159 case SB_PAGEDOWN:
57a4b972 160 position += GetPageSize();
a23fd0e1
VZ
161 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
162 break;
163
a23fd0e1 164 case SB_THUMBPOSITION:
feda3011 165 case SB_THUMBTRACK:
57a4b972 166 position = scrollInfo.nTrackPos;
8ae8032c
VZ
167 scrollEvent = wParam == SB_THUMBPOSITION ? wxEVT_SCROLL_THUMBRELEASE
168 : wxEVT_SCROLL_THUMBTRACK;
a23fd0e1
VZ
169 break;
170
e8b669d3 171 case SB_ENDSCROLL:
cbc85508 172 scrollEvent = wxEVT_SCROLL_CHANGED;
e8b669d3 173 break;
2bda0e17
KB
174 }
175
57a4b972 176 if ( position != scrollInfo.nPos )
2bda0e17 177 {
e8b669d3
VZ
178 if ( position < 0 )
179 position = 0;
180 if ( position > maxPos )
181 position = maxPos;
a23fd0e1 182
e8b669d3
VZ
183 SetThumbPosition(position);
184 }
185 else if ( scrollEvent != wxEVT_SCROLL_THUMBRELEASE &&
cbc85508 186 scrollEvent != wxEVT_SCROLL_CHANGED )
e8b669d3
VZ
187 {
188 // don't process the event if there is no displacement,
189 // unless this is a thumb release or end scroll event.
57f4f925 190 return false;
e8b669d3 191 }
a23fd0e1 192
a23fd0e1 193 wxScrollEvent event(scrollEvent, m_windowId);
27e229f5 194 event.SetOrientation(IsVertical() ? wxVERTICAL : wxHORIZONTAL);
e8b669d3 195 event.SetPosition(position);
a23fd0e1
VZ
196 event.SetEventObject( this );
197
937013e0 198 return HandleWindowEvent(event);
2bda0e17
KB
199}
200
4fabb575 201void wxScrollBar::SetThumbPosition(int viewStart)
2bda0e17 202{
2b5f62a0
VZ
203 SCROLLINFO info;
204 info.cbSize = sizeof(SCROLLINFO);
205 info.nPage = 0;
206 info.nMin = 0;
207 info.nPos = viewStart;
208 info.fMask = SIF_POS ;
209
210 ::SetScrollInfo((HWND) GetHWND(), SB_CTL, &info, TRUE);
2bda0e17
KB
211}
212
4fabb575 213int wxScrollBar::GetThumbPosition(void) const
2bda0e17 214{
4676948b
JS
215 SCROLLINFO scrollInfo;
216 wxZeroMemory(scrollInfo);
217 scrollInfo.cbSize = sizeof(SCROLLINFO);
218 scrollInfo.fMask = SIF_POS;
f0a126fe 219
4676948b
JS
220 if ( !::GetScrollInfo(GetHwnd(), SB_CTL, &scrollInfo) )
221 {
9a83f860 222 wxLogLastError(wxT("GetScrollInfo"));
4676948b
JS
223 }
224 return scrollInfo.nPos;
2bda0e17
KB
225}
226
debe6624
JS
227void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
228 bool refresh)
2bda0e17 229{
a71d815b
WS
230 m_viewSize = pageSize;
231 m_pageSize = thumbSize;
232 m_objectSize = range;
233
234 // The range (number of scroll steps) is the
235 // object length minus the page size.
236 int range1 = wxMax((m_objectSize - m_pageSize), 0) ;
237
238 // Try to adjust the range to cope with page size > 1
239 // (see comment for SetPageLength)
240 if ( m_pageSize > 1 )
241 {
242 range1 += (m_pageSize - 1);
243 }
244
245 SCROLLINFO info;
246 info.cbSize = sizeof(SCROLLINFO);
247 info.nPage = m_pageSize;
248 info.nMin = 0;
249 info.nMax = range1;
250 info.nPos = position;
251
252 info.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
253
254 ::SetScrollInfo((HWND) GetHWND(), SB_CTL, &info, refresh);
2bda0e17
KB
255}
256
2bda0e17
KB
257void wxScrollBar::Command(wxCommandEvent& event)
258{
687706f5 259 SetThumbPosition(event.GetInt());
2bda0e17
KB
260 ProcessCommand(event);
261}
262
caafd082
DS
263wxSize wxScrollBar::DoGetBestSize() const
264{
265 int w = 100;
266 int h = 100;
267
268 if ( IsVertical() )
269 {
270 w = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
271 }
272 else
273 {
274 h = wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
275 }
276
31582e4e
RD
277 wxSize best(w, h);
278 CacheBestSize(best);
279 return best;
caafd082
DS
280}
281
720afa24
DS
282WXDWORD wxScrollBar::MSWGetStyle(long style, WXDWORD *exstyle) const
283{
284 // we never have an external border
285 WXDWORD msStyle = wxControl::MSWGetStyle
286 (
287 (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle
288 );
289
290 // SBS_HORZ is 0 anyhow, but do mention it explicitly for clarity
291 msStyle |= style & wxSB_HORIZONTAL ? SBS_HORZ : SBS_VERT;
292
293 return msStyle;
294}
295
0cf11995 296WXHBRUSH wxScrollBar::MSWControlColor(WXHDC pDC, WXHWND hWnd)
123865f2 297{
0cf11995
VZ
298 // unless we have an explicitly set bg colour, use default (gradient under
299 // XP) brush instead of GetBackgroundColour() one as the base class would
300 //
301 // note that fg colour isn't used for a scrollbar
302 return UseBgCol() ? wxControl::MSWControlColor(pDC, hWnd) : NULL;
123865f2
JS
303}
304
1e6feb95 305#endif // wxUSE_SCROLLBAR