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