]> git.saurik.com Git - wxWidgets.git/blob - src/mac/scrolbar.cpp
separated modifier keys handling in order to distinct key/up down events
[wxWidgets.git] / src / mac / scrolbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: scrolbar.cpp
3 // Purpose: wxScrollBar
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 "scrolbar.h"
14 #endif
15
16 #include "wx/defs.h"
17
18 #include "wx/scrolbar.h"
19 #include "wx/mac/uma.h"
20
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
23
24 BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
25 END_EVENT_TABLE()
26
27 #endif
28
29 extern ControlActionUPP wxMacLiveScrollbarActionUPP ;
30
31 // Scrollbar
32 bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
33 const wxPoint& pos,
34 const wxSize& size, long style,
35 const wxValidator& validator,
36 const wxString& name)
37 {
38 if (!parent)
39 return FALSE;
40
41 Rect bounds ;
42 Str255 title ;
43
44 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
45
46 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , true , 0 , 0 , 100,
47 kControlScrollBarLiveProc , (long) this ) ;
48
49 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
50
51 ::SetControlAction( (ControlHandle) m_macControl , wxMacLiveScrollbarActionUPP ) ;
52
53 MacPostControlCreate() ;
54
55 return TRUE;
56 }
57
58 wxScrollBar::~wxScrollBar()
59 {
60 }
61
62 void wxScrollBar::SetThumbPosition(int viewStart)
63 {
64 ::SetControl32BitValue( (ControlHandle) m_macControl , viewStart ) ;
65 }
66
67 int wxScrollBar::GetThumbPosition() const
68 {
69 return ::GetControl32BitValue( (ControlHandle) m_macControl ) ;
70 }
71
72 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
73 bool refresh)
74 {
75 m_pageSize = pageSize;
76 m_viewSize = thumbSize;
77 m_objectSize = range;
78
79 int range1 = wxMax((m_objectSize - m_viewSize), 0) ;
80
81 SetControl32BitMaximum( (ControlHandle) m_macControl , range1 ) ;
82 SetControl32BitMinimum( (ControlHandle) m_macControl , 0 ) ;
83 SetControl32BitValue( (ControlHandle) m_macControl , position ) ;
84
85 if ( UMAGetAppearanceVersion() >= 0x0110 )
86 {
87 if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress )
88 {
89 SetControlViewSize( (ControlHandle) m_macControl , m_viewSize ) ;
90 }
91 }
92 if ( refresh )
93 MacRedrawControl() ;
94 }
95
96
97 void wxScrollBar::Command(wxCommandEvent& event)
98 {
99 SetThumbPosition(event.m_commandInt);
100 ProcessCommand(event);
101 }
102
103 void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart )
104 {
105 if ( (ControlHandle) m_macControl == NULL )
106 return ;
107
108 int position = GetControl32BitValue( (ControlHandle) m_macControl) ;
109 int minPos = GetControl32BitMinimum( (ControlHandle) m_macControl) ;
110 int maxPos = GetControl32BitMaximum( (ControlHandle) m_macControl) ;
111
112 wxEventType scrollEvent = wxEVT_NULL;
113 int nScrollInc;
114
115 switch( controlpart )
116 {
117 case kControlUpButtonPart :
118 nScrollInc = -1;
119 scrollEvent = wxEVT_SCROLL_LINEUP;
120 break ;
121 case kControlDownButtonPart :
122 nScrollInc = 1;
123 scrollEvent = wxEVT_SCROLL_LINEDOWN;
124 break ;
125 case kControlPageUpPart :
126 nScrollInc = -m_pageSize;
127 scrollEvent = wxEVT_SCROLL_PAGEUP;
128 break ;
129 case kControlPageDownPart :
130 nScrollInc = m_pageSize;
131 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
132 break ;
133 case kControlIndicatorPart :
134 nScrollInc = 0 ;
135 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
136 break ;
137 }
138
139 int new_pos = position + nScrollInc;
140
141 if (new_pos < 0)
142 new_pos = 0;
143 if (new_pos > maxPos)
144 new_pos = maxPos;
145 if ( nScrollInc )
146 SetThumbPosition(new_pos);
147
148 wxScrollEvent event(scrollEvent, m_windowId);
149 if ( m_windowStyle & wxHORIZONTAL )
150 {
151 event.SetOrientation( wxHORIZONTAL ) ;
152 }
153 else
154 {
155 event.SetOrientation( wxVERTICAL ) ;
156 }
157 event.SetPosition(new_pos);
158 event.SetEventObject( this );
159 wxWindow* window = GetParent() ;
160 if (window && window->MacIsWindowScrollbar(this) )
161 {
162 // this is hardcoded
163 window->MacOnScroll(event);
164 }
165 else
166 GetEventHandler()->ProcessEvent(event);
167 }
168