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