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