]> git.saurik.com Git - wxWidgets.git/blame - src/motif/scrolbar.cpp
added a cast to wxDecodeSurrogate() to fix wxMSW cross-compilation
[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
f6045f99 15#include "wx/defs.h"
4bb6408c
JS
16#include "wx/scrolbar.h"
17
338dd992
JJ
18#ifdef __VMS__
19#pragma message disable nosimpint
c698eae5 20#define XtDisplay XTDISPLAY
338dd992 21#endif
47bc1060 22#include <Xm/Xm.h>
47bc1060 23#include <Xm/ScrollBar.h>
338dd992
JJ
24#ifdef __VMS__
25#pragma message enable nosimpint
26#endif
47bc1060 27
3096bd2f 28#include "wx/motif/private.h"
47bc1060 29
8aa04e8b 30static void wxScrollBarCallback(Widget widget, XtPointer clientData,
47bc1060
JS
31 XmScaleCallbackStruct *cbs);
32
4bb6408c 33IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
4bb6408c
JS
34
35// Scrollbar
36bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
37 const wxPoint& pos,
38 const wxSize& size, long style,
39 const wxValidator& validator,
40 const wxString& name)
41{
6c33b24c
MB
42 if( !CreateControl( parent, id, pos, size, style, validator, name ) )
43 return false;
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
6c33b24c
MB
57 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
58 pos.x, pos.y, newSize.x, newSize.y);
0d57be45 59 ChangeBackgroundColour();
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);
a4588fd1 129 wxOrientation orientation = (wxOrientation)wxPtrToUInt(clientData);
47bc1060 130 wxEventType eventType = wxEVT_NULL;
bdeca1d1 131
47bc1060
JS
132 switch (cbs->reason)
133 {
134 case XmCR_INCREMENT:
135 {
136 eventType = wxEVT_SCROLL_LINEDOWN;
137 break;
138 }
139 case XmCR_DECREMENT:
140 {
141 eventType = wxEVT_SCROLL_LINEUP;
142 break;
143 }
144 case XmCR_DRAG:
145 {
146 eventType = wxEVT_SCROLL_THUMBTRACK;
147 break;
148 }
149 case XmCR_VALUE_CHANGED:
150 {
bdeca1d1 151 eventType = wxEVT_SCROLL_THUMBRELEASE;
47bc1060
JS
152 break;
153 }
154 case XmCR_PAGE_INCREMENT:
155 {
156 eventType = wxEVT_SCROLL_PAGEDOWN;
157 break;
158 }
159 case XmCR_PAGE_DECREMENT:
160 {
161 eventType = wxEVT_SCROLL_PAGEUP;
162 break;
163 }
164 case XmCR_TO_TOP:
165 {
166 eventType = wxEVT_SCROLL_TOP;
167 break;
168 }
169 case XmCR_TO_BOTTOM:
170 {
171 eventType = wxEVT_SCROLL_BOTTOM;
172 break;
173 }
174 default:
175 {
176 // Should never get here
177 wxFAIL_MSG("Unknown scroll event.");
178 break;
179 }
180 }
181
6c33b24c
MB
182 wxScrollEvent event(eventType, scrollBar->GetId(),
183 cbs->value, orientation);
47bc1060 184 event.SetEventObject(scrollBar);
47bc1060 185 scrollBar->GetEventHandler()->ProcessEvent(event);
47bc1060 186}