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