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