]> git.saurik.com Git - wxWidgets.git/blame - src/motif/scrolbar.cpp
fixing focus, fixes #11911
[wxWidgets.git] / src / motif / scrolbar.cpp
CommitLineData
4bb6408c 1/////////////////////////////////////////////////////////////////////////////
355b4d3d 2// Name: src/motif/scrolbar.cpp
4bb6408c
JS
3// Purpose: wxScrollBar
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
1248b41f
MB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
4bb6408c
JS
15#include "wx/scrolbar.h"
16
338dd992
JJ
17#ifdef __VMS__
18#pragma message disable nosimpint
19#endif
47bc1060 20#include <Xm/Xm.h>
47bc1060 21#include <Xm/ScrollBar.h>
338dd992
JJ
22#ifdef __VMS__
23#pragma message enable nosimpint
24#endif
47bc1060 25
3096bd2f 26#include "wx/motif/private.h"
47bc1060 27
8aa04e8b 28static void wxScrollBarCallback(Widget widget, XtPointer clientData,
47bc1060
JS
29 XmScaleCallbackStruct *cbs);
30
4bb6408c 31IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
4bb6408c
JS
32
33// Scrollbar
34bool 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{
6c33b24c
MB
40 if( !CreateControl( parent, id, pos, size, style, validator, name ) )
41 return false;
105fbe1f 42 PreCreation();
47bc1060 43
6c33b24c
MB
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;
47bc1060 48
6c33b24c 49 Widget parentWidget = (Widget) parent->GetClientWidget();
47bc1060 50
6c33b24c
MB
51 m_mainWidget =
52 DoCreateScrollBar( (WXWidget)parentWidget,
53 (wxOrientation)(style & (wxHORIZONTAL|wxVERTICAL)),
54 (void (*)())wxScrollBarCallback );
47bc1060 55
105fbe1f 56 PostCreation();
6c33b24c
MB
57 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
58 pos.x, pos.y, newSize.x, newSize.y);
47bc1060 59
6c33b24c 60 return true;
4bb6408c
JS
61}
62
63wxScrollBar::~wxScrollBar()
64{
65}
66
4fabb575 67void wxScrollBar::SetThumbPosition(int pos)
4bb6408c 68{
6c33b24c
MB
69 XtVaSetValues ((Widget) m_mainWidget,
70 XmNvalue, pos,
71 NULL);
4bb6408c
JS
72}
73
4fabb575 74int wxScrollBar::GetThumbPosition() const
4bb6408c 75{
6c33b24c
MB
76 int pos;
77 XtVaGetValues((Widget) m_mainWidget,
78 XmNvalue, &pos, NULL);
79 return pos;
4bb6408c
JS
80}
81
82void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
af111fc3 83 bool WXUNUSED(refresh))
4bb6408c
JS
84{
85 m_viewSize = pageSize;
86 m_pageSize = thumbSize;
87 m_objectSize = range;
88
47bc1060
JS
89 if (range == 0)
90 range = 1;
91 if (thumbSize == 0)
92 thumbSize = 1;
4bb6408c 93
47bc1060
JS
94 XtVaSetValues((Widget) m_mainWidget,
95 XmNvalue, position,
96 XmNminimum, 0,
97 XmNmaximum, range,
98 XmNsliderSize, thumbSize,
99 XmNpageIncrement, pageSize,
100 NULL);
101}
4bb6408c
JS
102
103void wxScrollBar::Command(wxCommandEvent& event)
104{
687706f5 105 SetThumbPosition(event.GetInt());
4bb6408c
JS
106 ProcessCommand(event);
107}
108
af111fc3 109void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize))
0d57be45
JS
110{
111 // TODO
b412f9be 112 // Do anything for a scrollbar? A font will never be seen.
0d57be45
JS
113}
114
115void wxScrollBar::ChangeBackgroundColour()
116{
b412f9be 117 wxWindow::ChangeBackgroundColour();
15d5ab67
JS
118
119 XtVaSetValues ((Widget) GetMainWidget(),
120 XmNtroughColor, m_backgroundColour.AllocColour(XtDisplay((Widget) GetMainWidget())),
121 NULL);
0d57be45
JS
122}
123
6c33b24c
MB
124static void wxScrollBarCallback(Widget widget, XtPointer clientData,
125 XmScaleCallbackStruct *cbs)
47bc1060 126{
6c33b24c 127 wxScrollBar *scrollBar = (wxScrollBar*)wxGetWindowFromTable(widget);
9a83f860 128 wxCHECK_RET( scrollBar, wxT("invalid widget in scrollbar callback") );
29014baa 129
a4588fd1 130 wxOrientation orientation = (wxOrientation)wxPtrToUInt(clientData);
47bc1060 131 wxEventType eventType = wxEVT_NULL;
bdeca1d1 132
47bc1060
JS
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 {
bdeca1d1 152 eventType = wxEVT_SCROLL_THUMBRELEASE;
47bc1060
JS
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
6c33b24c
MB
183 wxScrollEvent event(eventType, scrollBar->GetId(),
184 cbs->value, orientation);
47bc1060 185 event.SetEventObject(scrollBar);
937013e0 186 scrollBar->HandleWindowEvent(event);
47bc1060 187}