]> git.saurik.com Git - wxWidgets.git/blob - src/motif/scrolbar.cpp
WinCE adaptations
[wxWidgets.git] / src / motif / scrolbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: scrolbar.cpp
3 // Purpose: wxScrollBar
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "scrolbar.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #include "wx/defs.h"
20 #include "wx/scrolbar.h"
21
22 #ifdef __VMS__
23 #pragma message disable nosimpint
24 #define XtDisplay XTDISPLAY
25 #endif
26 #include <Xm/Xm.h>
27 #include <Xm/ScrollBar.h>
28 #ifdef __VMS__
29 #pragma message enable nosimpint
30 #endif
31
32 #include "wx/motif/private.h"
33
34 static void wxScrollBarCallback(Widget widget, XtPointer clientData,
35 XmScaleCallbackStruct *cbs);
36
37 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
38
39 // Scrollbar
40 bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
41 const wxPoint& pos,
42 const wxSize& size, long style,
43 const wxValidator& validator,
44 const wxString& name)
45 {
46 if( !CreateControl( parent, id, pos, size, style, validator, name ) )
47 return false;
48
49 wxSize newSize =
50 ( style & wxHORIZONTAL ) ? wxSize( 140, 16 ) : wxSize( 16, 140 );
51 if( size.x != -1 ) newSize.x = size.x;
52 if( size.y != -1 ) newSize.y = size.y;
53
54 Widget parentWidget = (Widget) parent->GetClientWidget();
55
56 m_mainWidget =
57 DoCreateScrollBar( (WXWidget)parentWidget,
58 (wxOrientation)(style & (wxHORIZONTAL|wxVERTICAL)),
59 (void (*)())wxScrollBarCallback );
60
61 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
62 pos.x, pos.y, newSize.x, newSize.y);
63 ChangeBackgroundColour();
64
65 return true;
66 }
67
68 wxScrollBar::~wxScrollBar()
69 {
70 }
71
72 void wxScrollBar::SetThumbPosition(int pos)
73 {
74 XtVaSetValues ((Widget) m_mainWidget,
75 XmNvalue, pos,
76 NULL);
77 }
78
79 int wxScrollBar::GetThumbPosition() const
80 {
81 int pos;
82 XtVaGetValues((Widget) m_mainWidget,
83 XmNvalue, &pos, NULL);
84 return pos;
85 }
86
87 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
88 bool WXUNUSED(refresh))
89 {
90 m_viewSize = pageSize;
91 m_pageSize = thumbSize;
92 m_objectSize = range;
93
94 if (range == 0)
95 range = 1;
96 if (thumbSize == 0)
97 thumbSize = 1;
98
99 XtVaSetValues((Widget) m_mainWidget,
100 XmNvalue, position,
101 XmNminimum, 0,
102 XmNmaximum, range,
103 XmNsliderSize, thumbSize,
104 XmNpageIncrement, pageSize,
105 NULL);
106 }
107
108 void wxScrollBar::Command(wxCommandEvent& event)
109 {
110 SetThumbPosition(event.GetInt());
111 ProcessCommand(event);
112 }
113
114 void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize))
115 {
116 // TODO
117 // Do anything for a scrollbar? A font will never be seen.
118 }
119
120 void wxScrollBar::ChangeBackgroundColour()
121 {
122 wxWindow::ChangeBackgroundColour();
123
124 XtVaSetValues ((Widget) GetMainWidget(),
125 XmNtroughColor, m_backgroundColour.AllocColour(XtDisplay((Widget) GetMainWidget())),
126 NULL);
127 }
128
129 static void wxScrollBarCallback(Widget widget, XtPointer clientData,
130 XmScaleCallbackStruct *cbs)
131 {
132 wxScrollBar *scrollBar = (wxScrollBar*)wxGetWindowFromTable(widget);
133 wxOrientation orientation = (wxOrientation)(int)clientData;
134 wxEventType eventType = wxEVT_NULL;
135
136 switch (cbs->reason)
137 {
138 case XmCR_INCREMENT:
139 {
140 eventType = wxEVT_SCROLL_LINEDOWN;
141 break;
142 }
143 case XmCR_DECREMENT:
144 {
145 eventType = wxEVT_SCROLL_LINEUP;
146 break;
147 }
148 case XmCR_DRAG:
149 {
150 eventType = wxEVT_SCROLL_THUMBTRACK;
151 break;
152 }
153 case XmCR_VALUE_CHANGED:
154 {
155 eventType = wxEVT_SCROLL_THUMBRELEASE;
156 break;
157 }
158 case XmCR_PAGE_INCREMENT:
159 {
160 eventType = wxEVT_SCROLL_PAGEDOWN;
161 break;
162 }
163 case XmCR_PAGE_DECREMENT:
164 {
165 eventType = wxEVT_SCROLL_PAGEUP;
166 break;
167 }
168 case XmCR_TO_TOP:
169 {
170 eventType = wxEVT_SCROLL_TOP;
171 break;
172 }
173 case XmCR_TO_BOTTOM:
174 {
175 eventType = wxEVT_SCROLL_BOTTOM;
176 break;
177 }
178 default:
179 {
180 // Should never get here
181 wxFAIL_MSG("Unknown scroll event.");
182 break;
183 }
184 }
185
186 wxScrollEvent event(eventType, scrollBar->GetId(),
187 cbs->value, orientation);
188 event.SetEventObject(scrollBar);
189 scrollBar->GetEventHandler()->ProcessEvent(event);
190 }