]>
Commit | Line | Data |
---|---|---|
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 | PreCreation(); | |
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 | PostCreation(); | |
58 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, | |
59 | pos.x, pos.y, newSize.x, newSize.y); | |
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.GetInt()); | |
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 | wxCHECK_RET( scrollBar, _T("invalid widget in scrollbar callback") ); | |
130 | ||
131 | wxOrientation orientation = (wxOrientation)wxPtrToUInt(clientData); | |
132 | wxEventType eventType = wxEVT_NULL; | |
133 | ||
134 | switch (cbs->reason) | |
135 | { | |
136 | case XmCR_INCREMENT: | |
137 | { | |
138 | eventType = wxEVT_SCROLL_LINEDOWN; | |
139 | break; | |
140 | } | |
141 | case XmCR_DECREMENT: | |
142 | { | |
143 | eventType = wxEVT_SCROLL_LINEUP; | |
144 | break; | |
145 | } | |
146 | case XmCR_DRAG: | |
147 | { | |
148 | eventType = wxEVT_SCROLL_THUMBTRACK; | |
149 | break; | |
150 | } | |
151 | case XmCR_VALUE_CHANGED: | |
152 | { | |
153 | eventType = wxEVT_SCROLL_THUMBRELEASE; | |
154 | break; | |
155 | } | |
156 | case XmCR_PAGE_INCREMENT: | |
157 | { | |
158 | eventType = wxEVT_SCROLL_PAGEDOWN; | |
159 | break; | |
160 | } | |
161 | case XmCR_PAGE_DECREMENT: | |
162 | { | |
163 | eventType = wxEVT_SCROLL_PAGEUP; | |
164 | break; | |
165 | } | |
166 | case XmCR_TO_TOP: | |
167 | { | |
168 | eventType = wxEVT_SCROLL_TOP; | |
169 | break; | |
170 | } | |
171 | case XmCR_TO_BOTTOM: | |
172 | { | |
173 | eventType = wxEVT_SCROLL_BOTTOM; | |
174 | break; | |
175 | } | |
176 | default: | |
177 | { | |
178 | // Should never get here | |
179 | wxFAIL_MSG("Unknown scroll event."); | |
180 | break; | |
181 | } | |
182 | } | |
183 | ||
184 | wxScrollEvent event(eventType, scrollBar->GetId(), | |
185 | cbs->value, orientation); | |
186 | event.SetEventObject(scrollBar); | |
187 | scrollBar->GetEventHandler()->ProcessEvent(event); | |
188 | } |