]> git.saurik.com Git - wxWidgets.git/blame - src/mac/spinbutt.cpp
added wxUSE_NOTEBOOK to include/wx/msw/setup0.h, removed wxUSE_RADIOBUTTON (we
[wxWidgets.git] / src / mac / spinbutt.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: spinbutt.cpp
3// Purpose: wxSpinButton
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 "spinbutt.h"
14#endif
15
16#include "wx/spinbutt.h"
519cb848 17#include "wx/mac/uma.h"
e9576ca5 18
e7549107
SC
19// ============================================================================
20// implementation
21// ============================================================================
22
23// ----------------------------------------------------------------------------
24// wxWin macros
25// ----------------------------------------------------------------------------
26
e7549107
SC
27 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl)
28 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent);
e9576ca5 29
e9576ca5
SC
30bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
31 long style, const wxString& name)
32{
e9576ca5
SC
33 m_min = 0;
34 m_max = 100;
35
519cb848
SC
36 if (!parent)
37 return FALSE;
38
39 Rect bounds ;
40 Str255 title ;
41
42 MacPreControlCreate( parent , id , "" , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ;
43
44 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 100,
45 kControlLittleArrowsProc , (long) this ) ;
46
47 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
48
49 MacPostControlCreate() ;
e9576ca5 50
519cb848 51 return TRUE;
e9576ca5
SC
52}
53
54wxSpinButton::~wxSpinButton()
55{
56}
57
58// Attributes
59////////////////////////////////////////////////////////////////////////////
60
61int wxSpinButton::GetValue() const
62{
519cb848 63 return m_value;
e9576ca5
SC
64}
65
66void wxSpinButton::SetValue(int val)
67{
519cb848
SC
68 m_value = val ;
69 wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, m_windowId);
70
71 event.SetPosition(m_value);
72 event.SetEventObject( this );
73 GetEventHandler()->ProcessEvent(event);
e9576ca5
SC
74}
75
76void wxSpinButton::SetRange(int minVal, int maxVal)
77{
78 m_min = minVal;
79 m_max = maxVal;
e9576ca5
SC
80}
81
519cb848
SC
82void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
83{
84 if ( m_macControl == NULL )
85 return ;
86
87 wxEventType scrollEvent = wxEVT_NULL;
88 int nScrollInc;
89
90 switch( controlpart )
91 {
92 case kControlUpButtonPart :
93 nScrollInc = 1;
94 scrollEvent = wxEVT_SCROLL_LINEUP;
95 break ;
96 case kControlDownButtonPart :
97 nScrollInc = -1;
98 scrollEvent = wxEVT_SCROLL_LINEDOWN;
99 break ;
100 }
101
102 m_value = m_value + nScrollInc;
103
104 if (m_value < m_min)
105 {
106 if ( m_windowStyle & wxSP_WRAP )
107 m_value = m_max;
108 else
109 m_value = m_min;
110 }
111
112 if (m_value > m_max)
113 {
114 if ( m_windowStyle & wxSP_WRAP )
115 m_value = m_min;
116 else
117 m_value = m_max;
118 }
119
120 wxScrollEvent event(scrollEvent, m_windowId);
121
122 event.SetPosition(m_value);
123 event.SetEventObject( this );
124 GetEventHandler()->ProcessEvent(event);
125}
126
51abe921
SC
127// ----------------------------------------------------------------------------
128// size calculation
129// ----------------------------------------------------------------------------
130
131wxSize wxSpinButton::DoGetBestSize()
132{
133 if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 )
134 {
135 // vertical control
136 return wxSize(16,
137 2*16);
138 }
139 else
140 {
141 // horizontal control
142 return wxSize(2*16,
143 16);
144 }
145}
519cb848 146