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