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