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