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