~brian-sidebotham/wxwidgets-cmake/wxpython-2.9.4

« back to all changes in this revision

Viewing changes to src/osx/carbon/slider.cpp

  • Committer: Brian Sidebotham
  • Date: 2013-08-03 14:30:08 UTC
  • Revision ID: brian.sidebotham@gmail.com-20130803143008-c7806tkych1tp6fc
Initial import into Bazaar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////////////////////
 
2
// Name:        src/osx/carbon/slider.cpp
 
3
// Purpose:     wxSlider
 
4
// Author:      Stefan Csomor
 
5
// Modified by:
 
6
// Created:     1998-01-01
 
7
// RCS-ID:      $Id: slider.cpp 67416 2011-04-08 15:09:38Z SC $
 
8
// Copyright:   (c) Stefan Csomor
 
9
// Licence:       wxWindows licence
 
10
/////////////////////////////////////////////////////////////////////////////
 
11
 
 
12
#include "wx/wxprec.h"
 
13
 
 
14
#if wxUSE_SLIDER
 
15
 
 
16
#include "wx/slider.h"
 
17
#include "wx/osx/private.h"
 
18
 
 
19
class wxMacSliderCarbonControl : public wxMacControl
 
20
{
 
21
public :
 
22
    wxMacSliderCarbonControl( wxWindowMac* peer ) : wxMacControl( peer )
 
23
    {
 
24
    }
 
25
    
 
26
    // work around an OSX bug : if the control is having the keyboard focus it cannot
 
27
    // be set to the full max/min values by dragging
 
28
    virtual bool CanFocus() const
 
29
    { 
 
30
        return false; 
 
31
    }
 
32
};
 
33
 
 
34
 
 
35
wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,
 
36
                                    wxWindowMac* parent,
 
37
                                    wxWindowID WXUNUSED(id),
 
38
                                    wxInt32 value,
 
39
                                    wxInt32 minimum,
 
40
                                    wxInt32 maximum,
 
41
                                    const wxPoint& pos,
 
42
                                    const wxSize& size,
 
43
                                    long style,
 
44
                                    long WXUNUSED(extraStyle))
 
45
{
 
46
    Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
 
47
    int tickMarks = 0;
 
48
    if ( style & wxSL_AUTOTICKS )
 
49
        tickMarks = (maximum - minimum) + 1; // +1 for the 0 value
 
50
 
 
51
    // keep the number of tickmarks from becoming unwieldly, therefore below it is ok to cast
 
52
    // it to a UInt16
 
53
    while (tickMarks > 20)
 
54
        tickMarks /= 5;
 
55
 
 
56
 
 
57
    wxMacControl* peer = new wxMacSliderCarbonControl( wxpeer );
 
58
    OSStatus err = CreateSliderControl(
 
59
        MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds,
 
60
        value, minimum, maximum,
 
61
        kControlSliderPointsDownOrRight,
 
62
        (UInt16) tickMarks, true /* liveTracking */,
 
63
        GetwxMacLiveScrollbarActionProc(),
 
64
        peer->GetControlRefAddr() );
 
65
    verify_noerr( err );
 
66
 
 
67
    return peer;
 
68
}
 
69
 
 
70
#endif // wxUSE_SLIDER