| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: slider.cpp |
| 3 | // Purpose: wxSlider |
| 4 | // Author: AUTHOR |
| 5 | // Modified by: |
| 6 | // Created: ??/??/98 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) AUTHOR |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | #ifdef __GNUG__ |
| 13 | #pragma implementation "slider.h" |
| 14 | #endif |
| 15 | |
| 16 | #include "wx/slider.h" |
| 17 | #include "wx/mac/uma.h" |
| 18 | |
| 19 | IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) |
| 20 | |
| 21 | BEGIN_EVENT_TABLE(wxSlider, wxControl) |
| 22 | END_EVENT_TABLE() |
| 23 | |
| 24 | |
| 25 | |
| 26 | // Slider |
| 27 | wxSlider::wxSlider() |
| 28 | { |
| 29 | m_pageSize = 1; |
| 30 | m_lineSize = 1; |
| 31 | m_rangeMax = 0; |
| 32 | m_rangeMin = 0; |
| 33 | m_tickFreq = 0; |
| 34 | } |
| 35 | |
| 36 | extern ControlActionUPP wxMacLiveScrollbarActionUPP ; |
| 37 | |
| 38 | bool wxSlider::Create(wxWindow *parent, wxWindowID id, |
| 39 | int value, int minValue, int maxValue, |
| 40 | const wxPoint& pos, |
| 41 | const wxSize& size, long style, |
| 42 | const wxValidator& validator, |
| 43 | const wxString& name) |
| 44 | { |
| 45 | Rect bounds ; |
| 46 | Str255 title ; |
| 47 | |
| 48 | MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ; |
| 49 | |
| 50 | m_macMinimumStatic = NULL ; |
| 51 | |
| 52 | m_lineSize = 1; |
| 53 | m_tickFreq = 0; |
| 54 | |
| 55 | m_rangeMax = maxValue; |
| 56 | m_rangeMin = minValue; |
| 57 | |
| 58 | m_pageSize = (int)((maxValue-minValue)/10); |
| 59 | if ( m_width == -1 ) |
| 60 | { |
| 61 | m_width = 20 ; |
| 62 | if ( style & wxSL_LABELS && style & wxSL_VERTICAL ) |
| 63 | m_width += 24 ; |
| 64 | bounds.right = bounds.left + m_width ; |
| 65 | } |
| 66 | if ( m_height == -1 ) |
| 67 | { |
| 68 | m_height = 20 ; |
| 69 | if ( style & wxSL_LABELS && style & wxSL_HORIZONTAL ) |
| 70 | m_height += 24 ; |
| 71 | bounds.bottom = bounds.top + m_height ; |
| 72 | } |
| 73 | |
| 74 | if ( style & wxSL_LABELS && style & wxSL_HORIZONTAL ) |
| 75 | { |
| 76 | bounds.top += 12 ; |
| 77 | bounds.right -= 24 ; |
| 78 | } |
| 79 | |
| 80 | if ( style & wxSL_LABELS && style & wxSL_VERTICAL ) |
| 81 | { |
| 82 | bounds.left += 24 ; |
| 83 | bounds.top += 12 ; |
| 84 | } |
| 85 | |
| 86 | m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , value , minValue , maxValue, |
| 87 | kControlSliderProc + kControlSliderLiveFeedback + ( ( style & wxSL_AUTOTICKS ) ? kControlSliderHasTickMarks : 0 ) , (long) this ) ; |
| 88 | |
| 89 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; |
| 90 | |
| 91 | ::SetControlAction( m_macControl , wxMacLiveScrollbarActionUPP ) ; |
| 92 | |
| 93 | MacPostControlCreate() ; |
| 94 | |
| 95 | if ( style & wxSL_LABELS ) |
| 96 | { |
| 97 | if ( style & wxSL_HORIZONTAL ) |
| 98 | { |
| 99 | wxSize size( 24 , 12 ) ; |
| 100 | wxPoint leftpos( 0 , 0 ) ; |
| 101 | wxPoint rightpos( m_width - 2 * 12 , 0 ) ; |
| 102 | wxPoint valuepos( m_width - 12 , 20 ) ; |
| 103 | wxString valuestring ; |
| 104 | |
| 105 | valuestring.Printf( "%d" , minValue ) ; |
| 106 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , leftpos , size ) ; |
| 107 | valuestring.Printf( "%d" , maxValue ) ; |
| 108 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , rightpos , size ) ; |
| 109 | valuestring.Printf( "%d" , value ) ; |
| 110 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , valuepos , size ) ; |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | wxSize size( 24 , 12 ) ; |
| 115 | wxPoint toppos( 0 , 12 ) ; |
| 116 | wxPoint bottompos( 0 , m_height - 12 ) ; |
| 117 | wxPoint valuepos( 20 , 0 ) ; |
| 118 | wxString valuestring ; |
| 119 | |
| 120 | valuestring.Printf( "%d" , minValue ) ; |
| 121 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , bottompos , size ) ; |
| 122 | valuestring.Printf( "%d" , maxValue ) ; |
| 123 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , toppos , size ) ; |
| 124 | valuestring.Printf( "%d" , value ) ; |
| 125 | m_macMinimumStatic = new wxStaticText( this , -1 , valuestring , valuepos , size ) ; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | return TRUE; |
| 130 | |
| 131 | } |
| 132 | |
| 133 | wxSlider::~wxSlider() |
| 134 | { |
| 135 | } |
| 136 | |
| 137 | int wxSlider::GetValue() const |
| 138 | { |
| 139 | return GetControlValue( m_macControl) ; |
| 140 | } |
| 141 | |
| 142 | void wxSlider::SetValue(int value) |
| 143 | { |
| 144 | wxString valuestring ; |
| 145 | valuestring.Printf( "%d" , value ) ; |
| 146 | if ( m_macMinimumStatic ) |
| 147 | m_macMinimumStatic->SetLabel( valuestring ) ; |
| 148 | SetControlValue( m_macControl , value ) ; |
| 149 | } |
| 150 | |
| 151 | void wxSlider::SetRange(int minValue, int maxValue) |
| 152 | { |
| 153 | m_rangeMin = minValue; |
| 154 | m_rangeMax = maxValue; |
| 155 | |
| 156 | // TODO |
| 157 | } |
| 158 | |
| 159 | // For trackbars only |
| 160 | void wxSlider::SetTickFreq(int n, int pos) |
| 161 | { |
| 162 | // TODO |
| 163 | m_tickFreq = n; |
| 164 | } |
| 165 | |
| 166 | void wxSlider::SetPageSize(int pageSize) |
| 167 | { |
| 168 | // TODO |
| 169 | m_pageSize = pageSize; |
| 170 | } |
| 171 | |
| 172 | int wxSlider::GetPageSize() const |
| 173 | { |
| 174 | return m_pageSize; |
| 175 | } |
| 176 | |
| 177 | void wxSlider::ClearSel() |
| 178 | { |
| 179 | // TODO |
| 180 | } |
| 181 | |
| 182 | void wxSlider::ClearTicks() |
| 183 | { |
| 184 | // TODO |
| 185 | } |
| 186 | |
| 187 | void wxSlider::SetLineSize(int lineSize) |
| 188 | { |
| 189 | m_lineSize = lineSize; |
| 190 | // TODO |
| 191 | } |
| 192 | |
| 193 | int wxSlider::GetLineSize() const |
| 194 | { |
| 195 | // TODO |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | int wxSlider::GetSelEnd() const |
| 200 | { |
| 201 | // TODO |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | int wxSlider::GetSelStart() const |
| 206 | { |
| 207 | // TODO |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | void wxSlider::SetSelection(int minPos, int maxPos) |
| 212 | { |
| 213 | // TODO |
| 214 | } |
| 215 | |
| 216 | void wxSlider::SetThumbLength(int len) |
| 217 | { |
| 218 | // TODO |
| 219 | } |
| 220 | |
| 221 | int wxSlider::GetThumbLength() const |
| 222 | { |
| 223 | // TODO |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | void wxSlider::SetTick(int tickPos) |
| 228 | { |
| 229 | // TODO |
| 230 | } |
| 231 | |
| 232 | void wxSlider::Command (wxCommandEvent & event) |
| 233 | { |
| 234 | SetValue (event.GetInt()); |
| 235 | ProcessCommand (event); |
| 236 | } |
| 237 | |
| 238 | bool wxSlider::Show( bool show ) |
| 239 | { |
| 240 | return wxWindow::Show( show ) ; |
| 241 | } |
| 242 | |
| 243 | void wxSlider::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) |
| 244 | { |
| 245 | SInt16 value = ::GetControlValue( m_macControl ) ; |
| 246 | |
| 247 | SetValue( value ) ; |
| 248 | |
| 249 | wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId); |
| 250 | event.SetPosition(GetControlValue( m_macControl) ); |
| 251 | event.SetEventObject( this ); |
| 252 | |
| 253 | #if WXWIN_COMPATIBILITY |
| 254 | |
| 255 | wxEventType oldEvent = event.GetEventType(); |
| 256 | event.SetEventType( wxEVT_COMMAND_SLIDER_UPDATED ); |
| 257 | if ( !GetEventHandler()->ProcessEvent(event) ) |
| 258 | { |
| 259 | event.SetEventType( oldEvent ); |
| 260 | if (!GetParent()->GetEventHandler()->ProcessEvent(event)) |
| 261 | event.Skip(); |
| 262 | } |
| 263 | #else |
| 264 | GetEventHandler()->ProcessEvent(event); |
| 265 | #endif |
| 266 | } |