Removal of previous wxValidtor code for wxOS2
[wxWidgets.git] / src / os2 / scrolbar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: scrolbar.cpp
3 // Purpose: wxScrollBar
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/15/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/defs.h"
17 #include "wx/utils.h"
18 #endif
19
20 #include "wx/scrolbar.h"
21 #include "wx/os2/private.h"
22
23 #if !USE_SHARED_LIBRARY
24 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
25
26 BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
27 #if WXWIN_COMPATIBILITY
28 EVT_SCROLL(wxScrollBar::OnScroll)
29 #endif
30 END_EVENT_TABLE()
31
32 #endif
33
34 // Scrollbar
35 bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
36 const wxPoint& pos,
37 const wxSize& size, long style,
38 #if wxUSE_VALIDATORS
39 const wxValidator& validator,
40 #endif
41 const wxString& name)
42 {
43 if (!parent)
44 return FALSE;
45 parent->AddChild(this);
46 SetName(name);
47 #if wxUSE_VALIDATORS
48 SetValidator(validator);
49 #endif
50
51 SetBackgroundColour(parent->GetBackgroundColour()) ;
52 SetForegroundColour(parent->GetForegroundColour()) ;
53 m_windowStyle = style;
54
55 if ( id == -1 )
56 m_windowId = (int)NewControlId();
57 else
58 m_windowId = id;
59
60 int x = pos.x;
61 int y = pos.y;
62 int width = size.x;
63 int height = size.y;
64
65 if (width == -1)
66 {
67 if (style & wxHORIZONTAL)
68 width = 140;
69 else
70 width = 14;
71 }
72 if (height == -1)
73 {
74 if (style & wxVERTICAL)
75 height = 140;
76 else
77 height = 14;
78 }
79
80 // TODO create scrollbar
81
82 m_pageSize = 1;
83 m_viewSize = 1;
84 m_objectSize = 1;
85
86 SetFont(parent->GetFont());
87
88 m_hWnd = 0; // TODO: (WXHWND)scroll_bar;
89
90 HWND scroll_bar = 0; // temporary
91
92 // Subclass again for purposes of dialog editing mode
93 SubclassWin((WXHWND) scroll_bar);
94
95 SetSize(x, y, width, height);
96
97 return TRUE;
98 }
99
100 wxScrollBar::~wxScrollBar()
101 {
102 }
103
104 bool wxScrollBar::OS2OnScroll(int WXUNUSED(orientation), WXWORD wParam,
105 WXWORD pos, WXHWND control)
106 {
107 // TODO:
108 /*
109 int position = ::GetScrollPos((HWND) control, SB_CTL);
110 int minPos, maxPos;
111 ::GetScrollRange((HWND) control, SB_CTL, &minPos, &maxPos);
112
113 #if defined(__WIN95__)
114 // A page size greater than one has the effect of reducing the effective
115 // range, therefore the range has already been boosted artificially - so
116 // reduce it again.
117 if ( m_pageSize > 1 )
118 maxPos -= (m_pageSize - 1);
119 #endif // __WIN95__
120
121 wxEventType scrollEvent = wxEVT_NULL;
122
123 int nScrollInc;
124 switch ( wParam )
125 {
126 case SB_TOP:
127 nScrollInc = maxPos - position;
128 scrollEvent = wxEVT_SCROLL_TOP;
129 break;
130
131 case SB_BOTTOM:
132 nScrollInc = - position;
133 scrollEvent = wxEVT_SCROLL_BOTTOM;
134 break;
135
136 case SB_LINEUP:
137 nScrollInc = -1;
138 scrollEvent = wxEVT_SCROLL_LINEUP;
139 break;
140
141 case SB_LINEDOWN:
142 nScrollInc = 1;
143 scrollEvent = wxEVT_SCROLL_LINEDOWN;
144 break;
145
146 case SB_PAGEUP:
147 nScrollInc = -GetPageSize();
148 scrollEvent = wxEVT_SCROLL_PAGEUP;
149 break;
150
151 case SB_PAGEDOWN:
152 nScrollInc = GetPageSize();
153 scrollEvent = wxEVT_SCROLL_PAGEDOWN;
154 break;
155
156 case SB_THUMBTRACK:
157 case SB_THUMBPOSITION:
158 nScrollInc = pos - position;
159 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
160 break;
161
162 default:
163 nScrollInc = 0;
164 }
165
166 if ( nScrollInc == 0 )
167 {
168 // no event to process, so don't process it
169 return FALSE;
170 }
171
172 int new_pos = position + nScrollInc;
173
174 if (new_pos < 0)
175 new_pos = 0;
176 if (new_pos > maxPos)
177 new_pos = maxPos;
178
179 SetThumbPosition(new_pos);
180 wxScrollEvent event(scrollEvent, m_windowId);
181 event.SetPosition(new_pos);
182 event.SetEventObject( this );
183
184 return GetEventHandler()->ProcessEvent(event);
185 */
186 return FALSE;
187 }
188
189 void wxScrollBar::SetThumbPosition(int viewStart)
190 {
191 // TODO
192 }
193
194 int wxScrollBar::GetThumbPosition() const
195 {
196 // TODO
197 return 0;
198 }
199
200 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
201 bool refresh)
202 {
203 m_viewSize = pageSize;
204 m_pageSize = thumbSize;
205 m_objectSize = range;
206
207 // TODO
208 }
209
210 #if WXWIN_COMPATIBILITY
211 void wxScrollBar::SetPageSize(int pageLength)
212 {
213 m_pageSize = pageLength;
214
215 // TODO:
216 }
217
218 void wxScrollBar::SetObjectLength(int objectLength)
219 {
220 m_objectSize = objectLength;
221
222 // The range (number of scroll steps) is the
223 // object length minus the view size.
224 int range = wxMax((objectLength - m_viewSize), 0) ;
225
226 // TODO:
227 }
228
229 void wxScrollBar::SetViewLength(int viewLength)
230 {
231 m_viewSize = viewLength;
232 }
233
234 void wxScrollBar::GetValues(int *viewStart, int *viewLength, int *objectLength,
235 int *pageLength) const
236 {
237 // TODO:
238 /*
239 *viewStart = ::GetScrollPos((HWND)m_hWnd, SB_CTL);
240 *viewLength = m_viewSize;
241 *objectLength = m_objectSize;
242 *pageLength = m_pageSize;
243 */
244 }
245 #endif
246
247 WXHBRUSH wxScrollBar::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
248 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
249 {
250 return 0;
251 }
252
253 void wxScrollBar::Command(wxCommandEvent& event)
254 {
255 SetThumbPosition(event.m_commandInt);
256 ProcessCommand(event);
257 }
258
259 #if WXWIN_COMPATIBILITY
260 // Backward compatibility
261 void wxScrollBar::OnScroll(wxScrollEvent& event)
262 {
263 // TODO:
264 /*
265 wxEventType oldEvent = event.GetEventType();
266 event.SetEventType( wxEVT_COMMAND_SCROLLBAR_UPDATED );
267 if ( !GetEventHandler()->ProcessEvent(event) )
268 {
269 event.SetEventType( oldEvent );
270 if (!GetParent()->GetEventHandler()->ProcessEvent(event))
271 event.Skip();
272 }
273 */
274 }
275 #endif