]> git.saurik.com Git - wxWidgets.git/blob - src/osx/scrolbar_osx.cpp
minor fixes; replace references to Windows95 with references to wxMSW where possible
[wxWidgets.git] / src / osx / scrolbar_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/scrolbar.cpp
3 // Purpose: wxScrollBar
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id: scrolbar.cpp 54129 2008-06-11 19:30:52Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/scrolbar.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/intl.h"
18 #include "wx/log.h"
19 #include "wx/settings.h"
20 #endif
21
22 #include "wx/osx/private.h"
23
24 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
25
26 BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
27 END_EVENT_TABLE()
28
29
30 bool wxScrollBar::Create( wxWindow *parent,
31 wxWindowID id,
32 const wxPoint& pos,
33 const wxSize& size,
34 long style,
35 const wxValidator& validator,
36 const wxString& name )
37 {
38 m_macIsUserPane = false;
39
40 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
41 return false;
42
43 m_peer = wxWidgetImpl::CreateScrollBar( this, parent, id, pos, size, style, GetExtraStyle() );
44
45 MacPostControlCreate( pos, size );
46
47 return true;
48 }
49
50 wxScrollBar::~wxScrollBar()
51 {
52 }
53
54 void wxScrollBar::SetThumbPosition( int viewStart )
55 {
56 m_peer->SetScrollThumb( viewStart, m_viewSize );
57 }
58
59 int wxScrollBar::GetThumbPosition() const
60 {
61 return m_peer->GetValue();
62 }
63
64 void wxScrollBar::SetScrollbar( int position,
65 int thumbSize,
66 int range,
67 int pageSize,
68 bool WXUNUSED(refresh) )
69 {
70 m_pageSize = pageSize;
71 m_viewSize = thumbSize;
72 m_objectSize = range;
73
74 int range1 = wxMax( (m_objectSize - m_viewSize), 0 );
75
76 m_peer->SetMaximum( range1 );
77 m_peer->SetScrollThumb( position, m_viewSize );
78 }
79
80 void wxScrollBar::Command( wxCommandEvent& event )
81 {
82 SetThumbPosition( event.GetInt() );
83 ProcessCommand( event );
84 }
85
86 bool wxScrollBar::HandleClicked( double timestampsec )
87 {
88 int new_pos = m_peer->GetValue();
89
90 wxScrollEvent event( wxEVT_SCROLL_THUMBRELEASE, m_windowId );
91 if ( m_windowStyle & wxHORIZONTAL )
92 event.SetOrientation( wxHORIZONTAL );
93 else
94 event.SetOrientation( wxVERTICAL );
95
96 event.SetPosition( new_pos );
97 event.SetEventObject( this );
98 wxWindow* window = GetParent();
99 if (window && window->MacIsWindowScrollbar( this ))
100 // this is hardcoded
101 window->MacOnScroll( event );
102 else
103 HandleWindowEvent( event );
104
105 return true;
106 }
107
108
109 wxSize wxScrollBar::DoGetBestSize() const
110 {
111 int w = 100;
112 int h = 100;
113
114 if ( IsVertical() )
115 {
116 w = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
117 }
118 else
119 {
120 h = wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
121 }
122
123 wxSize best(w, h);
124 CacheBestSize(best);
125 return best;
126 }