]> git.saurik.com Git - wxWidgets.git/blob - src/motif/scrolbar.cpp
Added DnD guard
[wxWidgets.git] / src / motif / scrolbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include "wx/scrolbar.h"
16
17 #ifdef __VMS__
18 #pragma message disable nosimpint
19 #define XtDisplay XTDISPLAY
20 #endif
21 #include <Xm/Xm.h>
22 #include <Xm/ScrollBar.h>
23 #ifdef __VMS__
24 #pragma message enable nosimpint
25 #endif
26
27 #include "wx/motif/private.h"
28
29 static void wxScrollBarCallback(Widget widget, XtPointer clientData,
30 XmScaleCallbackStruct *cbs);
31
32 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
33
34 // Scrollbar
35 bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
36 const wxPoint& pos,
37 const wxSize& size, long style,
38 const wxValidator& validator,
39 const wxString& name)
40 {
41 if( !CreateControl( parent, id, pos, size, style, validator, name ) )
42 return false;
43
44 wxSize newSize =
45 ( style & wxHORIZONTAL ) ? wxSize( 140, 16 ) : wxSize( 16, 140 );
46 if( size.x != -1 ) newSize.x = size.x;
47 if( size.y != -1 ) newSize.y = size.y;
48
49 Widget parentWidget = (Widget) parent->GetClientWidget();
50
51 m_mainWidget =
52 DoCreateScrollBar( (WXWidget)parentWidget,
53 (wxOrientation)(style & (wxHORIZONTAL|wxVERTICAL)),
54 (void (*)())wxScrollBarCallback );
55
56 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
57 pos.x, pos.y, newSize.x, newSize.y);
58 ChangeBackgroundColour();
59
60 return true;
61 }
62
63 wxScrollBar::~wxScrollBar()
64 {
65 }
66
67 void wxScrollBar::SetThumbPosition(int pos)
68 {
69 XtVaSetValues ((Widget) m_mainWidget,
70 XmNvalue, pos,
71 NULL);
72 }
73
74 int wxScrollBar::GetThumbPosition() const
75 {
76 int pos;
77 XtVaGetValues((Widget) m_mainWidget,
78 XmNvalue, &pos, NULL);
79 return pos;
80 }
81
82 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
83 bool WXUNUSED(refresh))
84 {
85 m_viewSize = pageSize;
86 m_pageSize = thumbSize;
87 m_objectSize = range;
88
89 if (range == 0)
90 range = 1;
91 if (thumbSize == 0)
92 thumbSize = 1;
93
94 XtVaSetValues((Widget) m_mainWidget,
95 XmNvalue, position,
96 XmNminimum, 0,
97 XmNmaximum, range,
98 XmNsliderSize, thumbSize,
99 XmNpageIncrement, pageSize,
100 NULL);
101 }
102
103 void wxScrollBar::Command(wxCommandEvent& event)
104 {
105 SetThumbPosition(event.GetInt());
106 ProcessCommand(event);
107 }
108
109 void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize))
110 {
111 // TODO
112 // Do anything for a scrollbar? A font will never be seen.
113 }
114
115 void wxScrollBar::ChangeBackgroundColour()
116 {
117 wxWindow::ChangeBackgroundColour();
118
119 XtVaSetValues ((Widget) GetMainWidget(),
120 XmNtroughColor, m_backgroundColour.AllocColour(XtDisplay((Widget) GetMainWidget())),
121 NULL);
122 }
123
124 static void wxScrollBarCallback(Widget widget, XtPointer clientData,
125 XmScaleCallbackStruct *cbs)
126 {
127 wxScrollBar *scrollBar = (wxScrollBar*)wxGetWindowFromTable(widget);
128 wxOrientation orientation = (wxOrientation)wxPtrToUInt(clientData);
129 wxEventType eventType = wxEVT_NULL;
130
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 {
150 eventType = wxEVT_SCROLL_THUMBRELEASE;
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
181 wxScrollEvent event(eventType, scrollBar->GetId(),
182 cbs->value, orientation);
183 event.SetEventObject(scrollBar);
184 scrollBar->GetEventHandler()->ProcessEvent(event);
185 }