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