]> git.saurik.com Git - wxWidgets.git/blame - src/motif/scrolbar.cpp
* Apply patch #735595. Add miminumAcceptable{Height,Width}
[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
31528cd3 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "scrolbar.h"
14#endif
15
f6045f99
GD
16#include "wx/defs.h"
17
4bb6408c
JS
18#include "wx/scrolbar.h"
19
338dd992
JJ
20#ifdef __VMS__
21#pragma message disable nosimpint
22#endif
47bc1060
JS
23#include <X11/IntrinsicP.h>
24#include <Xm/Xm.h>
25#include <Xm/RowColumn.h>
26#include <Xm/ScrollBar.h>
338dd992
JJ
27#ifdef __VMS__
28#pragma message enable nosimpint
29#endif
47bc1060 30
3096bd2f 31#include "wx/motif/private.h"
47bc1060 32
8aa04e8b 33static void wxScrollBarCallback(Widget widget, XtPointer clientData,
47bc1060
JS
34 XmScaleCallbackStruct *cbs);
35
4bb6408c 36IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
4bb6408c
JS
37
38// Scrollbar
39bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
40 const wxPoint& pos,
41 const wxSize& size, long style,
42 const wxValidator& validator,
43 const wxString& name)
44{
45 if (!parent)
46 return FALSE;
47 parent->AddChild(this);
48 SetName(name);
0d57be45
JS
49 m_backgroundColour = parent->GetBackgroundColour();
50 m_foregroundColour = parent->GetForegroundColour();
51 SetValidator(validator);
31528cd3 52
4bb6408c
JS
53 m_windowStyle = style;
54
55 if ( id == -1 )
31528cd3 56 m_windowId = (int)NewControlId();
4bb6408c 57 else
31528cd3 58 m_windowId = id;
4bb6408c 59
47bc1060
JS
60 int x = pos.x;
61 int y = pos.y;
62 int width = size.x;
63 int height = size.y;
64
65 if (width == -1)
66 {
67 if (style & wxHORIZONTAL)
68 width = 140;
69 else
70 width = 12;
71 }
72 if (height == -1)
73 {
74 if (style & wxVERTICAL)
75 height = 140;
76 else
77 height = 12;
78 }
79
80 Widget parentWidget = (Widget) parent->GetClientWidget();
81 int direction = (style & wxHORIZONTAL) ? XmHORIZONTAL: XmVERTICAL;
82
83 Widget scrollBarWidget = XtVaCreateManagedWidget("scrollBarWidget",
84 xmScrollBarWidgetClass, parentWidget,
85 XmNorientation, direction,
86 NULL);
87
88 m_mainWidget = (Widget) scrollBarWidget;
89
bdeca1d1 90 XtAddCallback(scrollBarWidget, XmNvalueChangedCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
47bc1060
JS
91 XtAddCallback(scrollBarWidget, XmNdragCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
92 XtAddCallback(scrollBarWidget, XmNdecrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
93 XtAddCallback(scrollBarWidget, XmNincrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
94 XtAddCallback(scrollBarWidget, XmNpageDecrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
95 XtAddCallback(scrollBarWidget, XmNpageIncrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
96 XtAddCallback(scrollBarWidget, XmNtoTopCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
97 XtAddCallback(scrollBarWidget, XmNtoBottomCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
98
47bc1060 99 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y, width, height);
0d57be45 100 ChangeBackgroundColour();
47bc1060 101
4bb6408c
JS
102 return TRUE;
103}
104
105wxScrollBar::~wxScrollBar()
106{
107}
108
4fabb575 109void wxScrollBar::SetThumbPosition(int pos)
4bb6408c 110{
47bc1060
JS
111 if (m_mainWidget)
112 {
113 XtVaSetValues ((Widget) m_mainWidget,
114 XmNvalue, pos,
115 NULL);
116 }
4bb6408c
JS
117}
118
4fabb575 119int wxScrollBar::GetThumbPosition() const
4bb6408c 120{
47bc1060
JS
121 if (m_mainWidget)
122 {
123 int pos;
124 XtVaGetValues((Widget) m_mainWidget,
125 XmNvalue, &pos, NULL);
126 return pos;
127 }
128 else
129 return 0;
4bb6408c
JS
130}
131
132void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
af111fc3 133 bool WXUNUSED(refresh))
4bb6408c
JS
134{
135 m_viewSize = pageSize;
136 m_pageSize = thumbSize;
137 m_objectSize = range;
138
47bc1060
JS
139 if (range == 0)
140 range = 1;
141 if (thumbSize == 0)
142 thumbSize = 1;
4bb6408c 143
47bc1060
JS
144 XtVaSetValues((Widget) m_mainWidget,
145 XmNvalue, position,
146 XmNminimum, 0,
147 XmNmaximum, range,
148 XmNsliderSize, thumbSize,
149 XmNpageIncrement, pageSize,
150 NULL);
151}
4bb6408c
JS
152
153void wxScrollBar::Command(wxCommandEvent& event)
154{
c0ed460c 155 SetThumbPosition(event.m_commandInt);
4bb6408c
JS
156 ProcessCommand(event);
157}
158
af111fc3 159void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize))
0d57be45
JS
160{
161 // TODO
b412f9be 162 // Do anything for a scrollbar? A font will never be seen.
0d57be45
JS
163}
164
165void wxScrollBar::ChangeBackgroundColour()
166{
b412f9be 167 wxWindow::ChangeBackgroundColour();
15d5ab67
JS
168
169 XtVaSetValues ((Widget) GetMainWidget(),
170 XmNtroughColor, m_backgroundColour.AllocColour(XtDisplay((Widget) GetMainWidget())),
171 NULL);
0d57be45
JS
172}
173
174void wxScrollBar::ChangeForegroundColour()
175{
b412f9be 176 wxWindow::ChangeForegroundColour();
0d57be45
JS
177}
178
af111fc3 179static void wxScrollBarCallback(Widget WXUNUSED(widget), XtPointer clientData,
47bc1060
JS
180 XmScaleCallbackStruct *cbs)
181{
182 wxScrollBar *scrollBar = (wxScrollBar *)clientData;
47bc1060 183 wxEventType eventType = wxEVT_NULL;
bdeca1d1 184
47bc1060
JS
185 switch (cbs->reason)
186 {
187 case XmCR_INCREMENT:
188 {
189 eventType = wxEVT_SCROLL_LINEDOWN;
190 break;
191 }
192 case XmCR_DECREMENT:
193 {
194 eventType = wxEVT_SCROLL_LINEUP;
195 break;
196 }
197 case XmCR_DRAG:
198 {
199 eventType = wxEVT_SCROLL_THUMBTRACK;
200 break;
201 }
202 case XmCR_VALUE_CHANGED:
203 {
bdeca1d1 204 eventType = wxEVT_SCROLL_THUMBRELEASE;
47bc1060
JS
205 break;
206 }
207 case XmCR_PAGE_INCREMENT:
208 {
209 eventType = wxEVT_SCROLL_PAGEDOWN;
210 break;
211 }
212 case XmCR_PAGE_DECREMENT:
213 {
214 eventType = wxEVT_SCROLL_PAGEUP;
215 break;
216 }
217 case XmCR_TO_TOP:
218 {
219 eventType = wxEVT_SCROLL_TOP;
220 break;
221 }
222 case XmCR_TO_BOTTOM:
223 {
224 eventType = wxEVT_SCROLL_BOTTOM;
225 break;
226 }
227 default:
228 {
229 // Should never get here
230 wxFAIL_MSG("Unknown scroll event.");
231 break;
232 }
233 }
234
235 wxScrollEvent event(eventType, scrollBar->GetId());
236 event.SetEventObject(scrollBar);
237 event.SetPosition(cbs->value);
238 scrollBar->GetEventHandler()->ProcessEvent(event);
239/*
240 if (!scrollBar->inSetValue)
241 scrollBar->ProcessCommand(event);
242*/
243}
244