]>
Commit | Line | Data |
---|---|---|
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::OSXHandleClicked( 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 | } | |
127 | ||
128 | void wxScrollBar::TriggerScrollEvent( wxEventType scrollEvent ) | |
129 | { | |
130 | int position = m_peer->GetValue(); | |
131 | int minPos = 0 ; | |
132 | int maxPos = m_peer->GetMaximum(); | |
133 | int nScrollInc = 0; | |
134 | ||
135 | if ( scrollEvent == wxEVT_SCROLL_LINEUP ) | |
136 | { | |
137 | nScrollInc = -1; | |
138 | } | |
139 | else if ( scrollEvent == wxEVT_SCROLL_LINEDOWN ) | |
140 | { | |
141 | nScrollInc = 1; | |
142 | } | |
143 | else if ( scrollEvent == wxEVT_SCROLL_PAGEUP ) | |
144 | { | |
145 | nScrollInc = -m_pageSize; | |
146 | } | |
147 | else if ( scrollEvent == wxEVT_SCROLL_PAGEDOWN ) | |
148 | { | |
149 | nScrollInc = m_pageSize; | |
150 | } | |
151 | ||
152 | int new_pos = position + nScrollInc; | |
153 | ||
154 | if (new_pos < minPos) | |
155 | new_pos = minPos; | |
156 | else if (new_pos > maxPos) | |
157 | new_pos = maxPos; | |
158 | ||
159 | if ( nScrollInc ) | |
160 | SetThumbPosition( new_pos ); | |
161 | ||
162 | wxScrollEvent event( scrollEvent, m_windowId ); | |
163 | if ( m_windowStyle & wxHORIZONTAL ) | |
164 | event.SetOrientation( wxHORIZONTAL ); | |
165 | else | |
166 | event.SetOrientation( wxVERTICAL ); | |
167 | ||
168 | event.SetPosition( new_pos ); | |
169 | event.SetEventObject( this ); | |
170 | ||
171 | wxWindow* window = GetParent(); | |
172 | if (window && window->MacIsWindowScrollbar( this )) | |
173 | // this is hardcoded | |
174 | window->MacOnScroll( event ); | |
175 | else | |
176 | HandleWindowEvent( event ); | |
177 | } |