]> git.saurik.com Git - wxWidgets.git/blame - src/generic/scrlwing.cpp
Applied patch [ 668155 ] Refresh problem when msgbox is shown
[wxWidgets.git] / src / generic / scrlwing.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
d80cd92a 2// Name: generic/scrolwin.cpp
fa3541bd 3// Purpose: wxGenericScrolledWindow implementation
c801d85f 4// Author: Julian Smart
566d84a7
RL
5// Modified by: Vadim Zeitlin on 31.08.00: wxScrollHelper allows to implement.
6// Ron Lee on 10.4.02: virtual size / auto scrollbars et al.
c801d85f
KB
7// Created: 01/02/97
8// RCS-ID: $Id$
1e6feb95 9// Copyright: (c) wxWindows team
a58a12e9 10// Licence: wxWindows license
c801d85f
KB
11/////////////////////////////////////////////////////////////////////////////
12
d80cd92a
VZ
13// ============================================================================
14// declarations
15// ============================================================================
16
17// ----------------------------------------------------------------------------
18// headers
19// ----------------------------------------------------------------------------
20
c801d85f 21#ifdef __GNUG__
3a8c693a 22 #pragma implementation "genscrolwin.h"
c801d85f
KB
23#endif
24
bcd055ae
JJ
25#ifdef __VMS
26#define XtDisplay XTDISPLAY
27#endif
28
c801d85f
KB
29// For compilers that support precompilation, includes "wx.h".
30#include "wx/wxprec.h"
31
c801d85f 32#ifdef __BORLANDC__
d80cd92a 33 #pragma hdrstop
c801d85f
KB
34#endif
35
3a8c693a
VZ
36#if !defined(__WXGTK__) || defined(__WXUNIVERSAL__)
37
d80cd92a
VZ
38#include "wx/utils.h"
39#include "wx/dcclient.h"
40
1e6feb95 41#include "wx/scrolwin.h"
053f9cc1 42#include "wx/panel.h"
1e6feb95 43#include "wx/timer.h"
95d60b24 44#include "wx/sizer.h"
c801d85f 45
48d1144b 46#ifdef __WXMSW__
1e6feb95 47 #include <windows.h> // for DLGC_WANTARROWS
48d1144b
JS
48#endif
49
a91b47e8
JS
50#ifdef __WXMOTIF__
51// For wxRETAINED implementation
338dd992
JJ
52#ifdef __VMS__ //VMS's Xm.h is not (yet) compatible with C++
53 //This code switches off the compiler warnings
54# pragma message disable nosimpint
55#endif
a91b47e8 56#include <Xm/Xm.h>
338dd992
JJ
57#ifdef __VMS__
58# pragma message enable nosimpint
59#endif
a91b47e8
JS
60#endif
61
fa3541bd 62IMPLEMENT_CLASS(wxScrolledWindow, wxGenericScrolledWindow)
fa3541bd 63
d80cd92a 64// ----------------------------------------------------------------------------
1e6feb95
VZ
65// wxScrollHelperEvtHandler: intercept the events from the window and forward
66// them to wxScrollHelper
d80cd92a
VZ
67// ----------------------------------------------------------------------------
68
349efbaa 69class WXDLLEXPORT wxScrollHelperEvtHandler : public wxEvtHandler
1e6feb95
VZ
70{
71public:
72 wxScrollHelperEvtHandler(wxScrollHelper *scrollHelper)
73 {
74 m_scrollHelper = scrollHelper;
75 }
d80cd92a 76
1e6feb95
VZ
77 virtual bool ProcessEvent(wxEvent& event);
78
349efbaa
VZ
79 void ResetDrawnFlag() { m_hasDrawnWindow = FALSE; }
80
1e6feb95
VZ
81private:
82 wxScrollHelper *m_scrollHelper;
349efbaa
VZ
83
84 bool m_hasDrawnWindow;
22f3361e
VZ
85
86 DECLARE_NO_COPY_CLASS(wxScrollHelperEvtHandler)
1e6feb95
VZ
87};
88
89// ----------------------------------------------------------------------------
90// wxAutoScrollTimer: the timer used to generate a stream of scroll events when
91// a captured mouse is held outside the window
92// ----------------------------------------------------------------------------
93
94class wxAutoScrollTimer : public wxTimer
95{
96public:
97 wxAutoScrollTimer(wxWindow *winToScroll, wxScrollHelper *scroll,
98 wxEventType eventTypeToSend,
99 int pos, int orient);
100
101 virtual void Notify();
102
103private:
104 wxWindow *m_win;
105 wxScrollHelper *m_scrollHelper;
106 wxEventType m_eventType;
107 int m_pos,
108 m_orient;
22f3361e
VZ
109
110 DECLARE_NO_COPY_CLASS(wxAutoScrollTimer)
1e6feb95 111};
d80cd92a
VZ
112
113// ============================================================================
114// implementation
115// ============================================================================
116
117// ----------------------------------------------------------------------------
1e6feb95 118// wxAutoScrollTimer
d80cd92a
VZ
119// ----------------------------------------------------------------------------
120
1e6feb95
VZ
121wxAutoScrollTimer::wxAutoScrollTimer(wxWindow *winToScroll,
122 wxScrollHelper *scroll,
123 wxEventType eventTypeToSend,
124 int pos, int orient)
c801d85f 125{
1e6feb95
VZ
126 m_win = winToScroll;
127 m_scrollHelper = scroll;
128 m_eventType = eventTypeToSend;
129 m_pos = pos;
130 m_orient = orient;
c801d85f
KB
131}
132
1e6feb95 133void wxAutoScrollTimer::Notify()
c801d85f 134{
1e6feb95
VZ
135 // only do all this as long as the window is capturing the mouse
136 if ( wxWindow::GetCapture() != m_win )
137 {
138 Stop();
139 }
140 else // we still capture the mouse, continue generating events
141 {
142 // first scroll the window if we are allowed to do it
143 wxScrollWinEvent event1(m_eventType, m_pos, m_orient);
144 event1.SetEventObject(m_win);
145 if ( m_scrollHelper->SendAutoScrollEvents(event1) &&
146 m_win->GetEventHandler()->ProcessEvent(event1) )
147 {
148 // and then send a pseudo mouse-move event to refresh the selection
149 wxMouseEvent event2(wxEVT_MOTION);
150 wxGetMousePosition(&event2.m_x, &event2.m_y);
151
152 // the mouse event coordinates should be client, not screen as
153 // returned by wxGetMousePosition
154 wxWindow *parentTop = m_win;
155 while ( parentTop->GetParent() )
156 parentTop = parentTop->GetParent();
157 wxPoint ptOrig = parentTop->GetPosition();
158 event2.m_x -= ptOrig.x;
159 event2.m_y -= ptOrig.y;
160
161 event2.SetEventObject(m_win);
162
163 // FIXME: we don't fill in the other members - ok?
164
165 m_win->GetEventHandler()->ProcessEvent(event2);
166 }
167 else // can't scroll further, stop
168 {
169 Stop();
170 }
171 }
172}
173
174// ----------------------------------------------------------------------------
175// wxScrollHelperEvtHandler
176// ----------------------------------------------------------------------------
177
178bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event)
179{
9a268018 180 wxEventType evType = event.GetEventType();
2feed004 181
349efbaa
VZ
182 // the explanation of wxEVT_PAINT processing hack: for historic reasons
183 // there are 2 ways to process this event in classes deriving from
184 // wxScrolledWindow. The user code may
185 //
186 // 1. override wxScrolledWindow::OnDraw(dc)
187 // 2. define its own OnPaint() handler
188 //
189 // In addition, in wxUniversal wxWindow defines OnPaint() itself and
190 // always processes the draw event, so we can't just try the window
191 // OnPaint() first and call our HandleOnPaint() if it doesn't process it
192 // (the latter would never be called in wxUniversal).
193 //
194 // So the solution is to have a flag telling us whether the user code drew
195 // anything in the window. We set it to true here but reset it to false in
196 // wxScrolledWindow::OnPaint() handler (which wouldn't be called if the
197 // user code defined OnPaint() in the derived class)
198 m_hasDrawnWindow = TRUE;
199
ff186591
VZ
200 // pass it on to the real handler
201 bool processed = wxEvtHandler::ProcessEvent(event);
202
203 // always process the size events ourselves, even if the user code handles
204 // them as well, as we need to AdjustScrollbars()
205 //
206 // NB: it is important to do it after processing the event in the normal
207 // way as HandleOnSize() may generate a wxEVT_SIZE itself if the
208 // scrollbar[s] (dis)appear and it should be seen by the user code
209 // after this one
210 if ( evType == wxEVT_SIZE )
211 {
212 m_scrollHelper->HandleOnSize((wxSizeEvent &)event);
213
214 return TRUE;
215 }
216
217 if ( processed )
349efbaa
VZ
218 {
219 // normally, nothing more to do here - except if it was a paint event
220 // which wasn't really processed, then we'll try to call our
221 // OnDraw() below (from HandleOnPaint)
993cfa87 222 if ( m_hasDrawnWindow )
349efbaa
VZ
223 {
224 return TRUE;
225 }
226 }
2feed004 227
1e6feb95
VZ
228 // reset the skipped flag to FALSE as it might have been set to TRUE in
229 // ProcessEvent() above
230 event.Skip(FALSE);
231
e421922f
VZ
232 if ( evType == wxEVT_PAINT )
233 {
234 m_scrollHelper->HandleOnPaint((wxPaintEvent &)event);
235 return TRUE;
236 }
1e6feb95 237
e421922f
VZ
238 if ( evType == wxEVT_SCROLLWIN_TOP ||
239 evType == wxEVT_SCROLLWIN_BOTTOM ||
240 evType == wxEVT_SCROLLWIN_LINEUP ||
241 evType == wxEVT_SCROLLWIN_LINEDOWN ||
242 evType == wxEVT_SCROLLWIN_PAGEUP ||
243 evType == wxEVT_SCROLLWIN_PAGEDOWN ||
244 evType == wxEVT_SCROLLWIN_THUMBTRACK ||
245 evType == wxEVT_SCROLLWIN_THUMBRELEASE )
246 {
247 m_scrollHelper->HandleOnScroll((wxScrollWinEvent &)event);
1e6feb95 248 return !event.GetSkipped();
e421922f 249 }
1e6feb95 250
e421922f
VZ
251 if ( evType == wxEVT_ENTER_WINDOW )
252 {
253 m_scrollHelper->HandleOnMouseEnter((wxMouseEvent &)event);
254 }
255 else if ( evType == wxEVT_LEAVE_WINDOW )
256 {
257 m_scrollHelper->HandleOnMouseLeave((wxMouseEvent &)event);
258 }
259#if wxUSE_MOUSEWHEEL
260 else if ( evType == wxEVT_MOUSEWHEEL )
261 {
262 m_scrollHelper->HandleOnMouseWheel((wxMouseEvent &)event);
263 }
264#endif // wxUSE_MOUSEWHEEL
e421922f
VZ
265 else if ( evType == wxEVT_CHAR )
266 {
267 m_scrollHelper->HandleOnChar((wxKeyEvent &)event);
268 return !event.GetSkipped();
1e6feb95
VZ
269 }
270
271 return FALSE;
272}
273
274// ----------------------------------------------------------------------------
275// wxScrollHelper construction
276// ----------------------------------------------------------------------------
277
278wxScrollHelper::wxScrollHelper(wxWindow *win)
279{
280 m_xScrollPixelsPerLine =
281 m_yScrollPixelsPerLine =
282 m_xScrollPosition =
283 m_yScrollPosition =
284 m_xScrollLines =
285 m_yScrollLines =
286 m_xScrollLinesPerPage =
139adb6a 287 m_yScrollLinesPerPage = 0;
1e6feb95
VZ
288
289 m_xScrollingEnabled =
290 m_yScrollingEnabled = TRUE;
291
292 m_scaleX =
139adb6a 293 m_scaleY = 1.0;
24ce4c18 294#if wxUSE_MOUSEWHEEL
d2c52078 295 m_wheelRotation = 0;
24ce4c18 296#endif
a58a12e9 297
1e6feb95
VZ
298 m_win =
299 m_targetWindow = (wxWindow *)NULL;
139adb6a 300
1e6feb95 301 m_timerAutoScroll = (wxTimer *)NULL;
d7da9756 302
349efbaa
VZ
303 m_handler = NULL;
304
1e6feb95
VZ
305 if ( win )
306 SetWindow(win);
307}
d7da9756 308
1e6feb95 309wxScrollHelper::~wxScrollHelper()
d80cd92a 310{
1e6feb95
VZ
311 StopAutoScrolling();
312
349efbaa 313 DeleteEvtHandler();
d80cd92a
VZ
314}
315
316// ----------------------------------------------------------------------------
317// setting scrolling parameters
318// ----------------------------------------------------------------------------
319
1e6feb95
VZ
320void wxScrollHelper::SetScrollbars(int pixelsPerUnitX,
321 int pixelsPerUnitY,
322 int noUnitsX,
323 int noUnitsY,
324 int xPos,
325 int yPos,
326 bool noRefresh)
c801d85f 327{
b0486e0d
SN
328 int xpos, ypos;
329
330 CalcUnscrolledPosition(xPos, yPos, &xpos, &ypos);
139adb6a
RR
331 bool do_refresh =
332 (
c801d85f 333 (noUnitsX != 0 && m_xScrollLines == 0) ||
566d84a7 334 (noUnitsX < m_xScrollLines && xpos > pixelsPerUnitX * noUnitsX) ||
b0486e0d 335
c801d85f 336 (noUnitsY != 0 && m_yScrollLines == 0) ||
566d84a7 337 (noUnitsY < m_yScrollLines && ypos > pixelsPerUnitY * noUnitsY) ||
c801d85f 338 (xPos != m_xScrollPosition) ||
b0486e0d 339 (yPos != m_yScrollPosition)
139adb6a 340 );
a58a12e9 341
139adb6a
RR
342 m_xScrollPixelsPerLine = pixelsPerUnitX;
343 m_yScrollPixelsPerLine = pixelsPerUnitY;
344 m_xScrollPosition = xPos;
345 m_yScrollPosition = yPos;
a91b47e8 346
2b5f62a0
VZ
347 // For better backward compatibility we set persisting limits
348 // here not just the size. It makes SetScrollbars 'sticky'
349 // emulating the old non-autoscroll behaviour.
350
01565945
JS
351 wxSize sz = m_targetWindow->GetClientSize();
352#if 1
353 int x = wxMax(noUnitsX * pixelsPerUnitX, sz.x);
354 int y = wxMax(noUnitsY * pixelsPerUnitY, sz.y);
355#else
356 int x = noUnitsX * pixelsPerUnitX;
357 int y = noUnitsY * pixelsPerUnitY;
358#endif
d0604192 359 m_targetWindow->SetVirtualSizeHints( x, y );
a58a12e9 360
2b5f62a0
VZ
361 // The above should arguably be deprecated, this however we still need.
362
d0604192 363 m_targetWindow->SetVirtualSize( x, y );
dc429f89 364
a58a12e9 365 if (do_refresh && !noRefresh)
1e6feb95 366 m_targetWindow->Refresh(TRUE, GetRect());
a58a12e9 367
03d1ae17
JS
368 // TODO: check if we can use AdjustScrollbars always.
369#ifdef __WXUNIVERSAL__
370 AdjustScrollbars();
371#else
372 // This is also done by AdjustScrollbars, above
7c74e7fe 373#ifdef __WXMAC__
d80cd92a 374 m_targetWindow->MacUpdateImmediately() ;
c801d85f 375#endif
03d1ae17 376#endif
c801d85f
KB
377}
378
d80cd92a 379// ----------------------------------------------------------------------------
af4088f1 380// [target] window handling
d80cd92a 381// ----------------------------------------------------------------------------
ecab4dba 382
349efbaa 383void wxScrollHelper::DeleteEvtHandler()
ecab4dba 384{
248d771c
VZ
385 // search for m_handler in the handler list
386 if ( m_win && m_handler )
349efbaa 387 {
74f6bbf9 388 if ( m_win->RemoveEventHandler(m_handler) )
248d771c 389 {
74f6bbf9 390 delete m_handler;
248d771c 391 }
74f6bbf9
VZ
392 //else: something is very wrong, so better [maybe] leak memory than
393 // risk a crash because of double deletion
248d771c 394
74f6bbf9 395 m_handler = NULL;
349efbaa
VZ
396 }
397}
398
399void wxScrollHelper::SetWindow(wxWindow *win)
400{
401 wxCHECK_RET( win, _T("wxScrollHelper needs a window to scroll") );
402
403 m_win = win;
404
af4088f1
VZ
405 // by default, the associated window is also the target window
406 DoSetTargetWindow(win);
349efbaa
VZ
407}
408
af4088f1 409void wxScrollHelper::DoSetTargetWindow(wxWindow *target)
349efbaa 410{
ecab4dba 411 m_targetWindow = target;
349efbaa
VZ
412
413 // install the event handler which will intercept the events we're
af4088f1
VZ
414 // interested in (but only do it for our real window, not the target window
415 // which we scroll - we don't need to hijack its events)
416 if ( m_targetWindow == m_win )
13ff9344 417 {
248d771c
VZ
418 // if we already have a handler, delete it first
419 DeleteEvtHandler();
420
13ff9344
JS
421 m_handler = new wxScrollHelperEvtHandler(this);
422 m_targetWindow->PushEventHandler(m_handler);
423 }
349efbaa
VZ
424}
425
af4088f1 426void wxScrollHelper::SetTargetWindow(wxWindow *target)
349efbaa
VZ
427{
428 wxCHECK_RET( target, wxT("target window must not be NULL") );
429
430 if ( target == m_targetWindow )
431 return;
432
af4088f1 433 DoSetTargetWindow(target);
ecab4dba
RR
434}
435
1e6feb95 436wxWindow *wxScrollHelper::GetTargetWindow() const
ecab4dba
RR
437{
438 return m_targetWindow;
439}
440
d80cd92a
VZ
441// ----------------------------------------------------------------------------
442// scrolling implementation itself
443// ----------------------------------------------------------------------------
444
1e6feb95 445void wxScrollHelper::HandleOnScroll(wxScrollWinEvent& event)
c801d85f 446{
139adb6a 447 int nScrollInc = CalcScrollInc(event);
1e6feb95 448 if ( nScrollInc == 0 )
139adb6a 449 {
1e6feb95
VZ
450 // can't scroll further
451 event.Skip();
452
453 return;
139adb6a 454 }
c801d85f 455
1e6feb95 456 int orient = event.GetOrientation();
139adb6a
RR
457 if (orient == wxHORIZONTAL)
458 {
459 m_xScrollPosition += nScrollInc;
5f3286d1 460 m_win->SetScrollPos(wxHORIZONTAL, m_xScrollPosition);
139adb6a 461 }
c801d85f 462 else
139adb6a
RR
463 {
464 m_yScrollPosition += nScrollInc;
5f3286d1 465 m_win->SetScrollPos(wxVERTICAL, m_yScrollPosition);
139adb6a 466 }
a58a12e9 467
1e6feb95
VZ
468 bool needsRefresh = FALSE;
469 int dx = 0,
470 dy = 0;
139adb6a
RR
471 if (orient == wxHORIZONTAL)
472 {
1e6feb95
VZ
473 if ( m_xScrollingEnabled )
474 {
475 dx = -m_xScrollPixelsPerLine * nScrollInc;
476 }
139adb6a 477 else
1e6feb95
VZ
478 {
479 needsRefresh = TRUE;
480 }
139adb6a 481 }
c801d85f 482 else
139adb6a 483 {
1e6feb95
VZ
484 if ( m_yScrollingEnabled )
485 {
486 dy = -m_yScrollPixelsPerLine * nScrollInc;
487 }
139adb6a 488 else
1e6feb95
VZ
489 {
490 needsRefresh = TRUE;
491 }
492 }
493
494 if ( needsRefresh )
495 {
496 m_targetWindow->Refresh(TRUE, GetRect());
497 }
498 else
499 {
500 m_targetWindow->ScrollWindow(dx, dy, GetRect());
3d2b9c20 501 }
1e6feb95 502
7c74e7fe 503#ifdef __WXMAC__
d80cd92a 504 m_targetWindow->MacUpdateImmediately() ;
7c74e7fe 505#endif
c801d85f
KB
506}
507
1e6feb95 508int wxScrollHelper::CalcScrollInc(wxScrollWinEvent& event)
c801d85f 509{
ecab4dba
RR
510 int pos = event.GetPosition();
511 int orient = event.GetOrientation();
c801d85f 512
ecab4dba 513 int nScrollInc = 0;
1a8caf94 514 if (event.GetEventType() == wxEVT_SCROLLWIN_TOP)
c801d85f 515 {
ecab4dba
RR
516 if (orient == wxHORIZONTAL)
517 nScrollInc = - m_xScrollPosition;
518 else
519 nScrollInc = - m_yScrollPosition;
1a8caf94
RR
520 } else
521 if (event.GetEventType() == wxEVT_SCROLLWIN_BOTTOM)
522 {
ecab4dba
RR
523 if (orient == wxHORIZONTAL)
524 nScrollInc = m_xScrollLines - m_xScrollPosition;
525 else
526 nScrollInc = m_yScrollLines - m_yScrollPosition;
1a8caf94
RR
527 } else
528 if (event.GetEventType() == wxEVT_SCROLLWIN_LINEUP)
529 {
ecab4dba 530 nScrollInc = -1;
1a8caf94
RR
531 } else
532 if (event.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN)
533 {
ecab4dba 534 nScrollInc = 1;
1a8caf94
RR
535 } else
536 if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEUP)
537 {
ecab4dba
RR
538 if (orient == wxHORIZONTAL)
539 nScrollInc = -GetScrollPageSize(wxHORIZONTAL);
540 else
541 nScrollInc = -GetScrollPageSize(wxVERTICAL);
1a8caf94
RR
542 } else
543 if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN)
544 {
ecab4dba
RR
545 if (orient == wxHORIZONTAL)
546 nScrollInc = GetScrollPageSize(wxHORIZONTAL);
547 else
548 nScrollInc = GetScrollPageSize(wxVERTICAL);
1a8caf94
RR
549 } else
550 if ((event.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK) ||
551 (event.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE))
552 {
ecab4dba
RR
553 if (orient == wxHORIZONTAL)
554 nScrollInc = pos - m_xScrollPosition;
555 else
556 nScrollInc = pos - m_yScrollPosition;
c801d85f 557 }
88150e60 558
ecab4dba
RR
559 if (orient == wxHORIZONTAL)
560 {
a58a12e9 561 if (m_xScrollPixelsPerLine > 0)
ecab4dba
RR
562 {
563 int w, h;
1e6feb95 564 GetTargetSize(&w, &h);
ecab4dba
RR
565
566 int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine;
567 int noPositions = (int) ( ((nMaxWidth - w)/(double)m_xScrollPixelsPerLine) + 0.5 );
568 if (noPositions < 0)
d80cd92a 569 noPositions = 0;
ecab4dba
RR
570
571 if ( (m_xScrollPosition + nScrollInc) < 0 )
d80cd92a 572 nScrollInc = -m_xScrollPosition; // As -ve as we can go
ecab4dba 573 else if ( (m_xScrollPosition + nScrollInc) > noPositions )
d80cd92a 574 nScrollInc = noPositions - m_xScrollPosition; // As +ve as we can go
ecab4dba
RR
575 }
576 else
1e6feb95 577 m_targetWindow->Refresh(TRUE, GetRect());
9d9355c6
VZ
578 }
579 else
ecab4dba 580 {
a58a12e9 581 if (m_yScrollPixelsPerLine > 0)
d80cd92a 582 {
ecab4dba 583 int w, h;
1e6feb95 584 GetTargetSize(&w, &h);
a58a12e9 585
ecab4dba
RR
586 int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine;
587 int noPositions = (int) ( ((nMaxHeight - h)/(double)m_yScrollPixelsPerLine) + 0.5 );
588 if (noPositions < 0)
d80cd92a 589 noPositions = 0;
a58a12e9 590
ecab4dba 591 if ( (m_yScrollPosition + nScrollInc) < 0 )
d80cd92a 592 nScrollInc = -m_yScrollPosition; // As -ve as we can go
ecab4dba 593 else if ( (m_yScrollPosition + nScrollInc) > noPositions )
d80cd92a 594 nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go
ecab4dba
RR
595 }
596 else
1e6feb95 597 m_targetWindow->Refresh(TRUE, GetRect());
9d9355c6 598 }
9d9355c6 599
ecab4dba 600 return nScrollInc;
c801d85f
KB
601}
602
603// Adjust the scrollbars - new version.
1e6feb95 604void wxScrollHelper::AdjustScrollbars()
c801d85f 605{
aeb313f3
SC
606#ifdef __WXMAC__
607 m_targetWindow->MacUpdateImmediately();
608#endif
609
566d84a7
RL
610 int w = 0, h = 0;
611 int oldw, oldh;
a58a12e9 612
27d029c7
RR
613 int oldXScroll = m_xScrollPosition;
614 int oldYScroll = m_yScrollPosition;
c801d85f 615
566d84a7
RL
616 do {
617 GetTargetSize(&w, 0);
c801d85f 618
566d84a7
RL
619 if (m_xScrollPixelsPerLine == 0)
620 {
621 m_xScrollLines = 0;
622 m_xScrollPosition = 0;
623 m_win->SetScrollbar (wxHORIZONTAL, 0, 0, 0, FALSE);
624 }
625 else
626 {
627 m_xScrollLines = m_targetWindow->GetVirtualSize().GetWidth() / m_xScrollPixelsPerLine;
628
629 // Calculate page size i.e. number of scroll units you get on the
630 // current client window
631 int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 );
632 if (noPagePositions < 1) noPagePositions = 1;
633 if ( noPagePositions > m_xScrollLines )
634 noPagePositions = m_xScrollLines;
635
636 // Correct position if greater than extent of canvas minus
637 // the visible portion of it or if below zero
638 m_xScrollPosition = wxMin( m_xScrollLines - noPagePositions, m_xScrollPosition);
639 m_xScrollPosition = wxMax( 0, m_xScrollPosition );
640
641 m_win->SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, m_xScrollLines);
642 // The amount by which we scroll when paging
643 SetScrollPageSize(wxHORIZONTAL, noPagePositions);
644 }
c801d85f 645
566d84a7 646 GetTargetSize(0, &h);
a58a12e9 647
566d84a7
RL
648 if (m_yScrollPixelsPerLine == 0)
649 {
650 m_yScrollLines = 0;
651 m_yScrollPosition = 0;
652 m_win->SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE);
653 }
654 else
655 {
656 m_yScrollLines = m_targetWindow->GetVirtualSize().GetHeight() / m_yScrollPixelsPerLine;
657
658 // Calculate page size i.e. number of scroll units you get on the
659 // current client window
660 int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 );
661 if (noPagePositions < 1) noPagePositions = 1;
662 if ( noPagePositions > m_yScrollLines )
663 noPagePositions = m_yScrollLines;
664
665 // Correct position if greater than extent of canvas minus
666 // the visible portion of it or if below zero
667 m_yScrollPosition = wxMin( m_yScrollLines - noPagePositions, m_yScrollPosition );
668 m_yScrollPosition = wxMax( 0, m_yScrollPosition );
669
670 m_win->SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, m_yScrollLines);
671 // The amount by which we scroll when paging
672 SetScrollPageSize(wxVERTICAL, noPagePositions);
673 }
c801d85f 674
566d84a7 675 // If a scrollbar (dis)appeared as a result of this, adjust them again.
139adb6a 676
566d84a7
RL
677 oldw = w;
678 oldh = h;
679
680 GetTargetSize( &w, &h );
681 } while ( w != oldw && h != oldh );
682
683#ifdef __WXMOTIF__
684 // Sorry, some Motif-specific code to implement a backing pixmap
685 // for the wxRETAINED style. Implementing a backing store can't
686 // be entirely generic because it relies on the wxWindowDC implementation
687 // to duplicate X drawing calls for the backing pixmap.
688
689 if ( m_targetWindow->GetWindowStyle() & wxRETAINED )
139adb6a 690 {
566d84a7
RL
691 Display* dpy = XtDisplay((Widget)m_targetWindow->GetMainWidget());
692
693 int totalPixelWidth = m_xScrollLines * m_xScrollPixelsPerLine;
694 int totalPixelHeight = m_yScrollLines * m_yScrollPixelsPerLine;
695 if (m_targetWindow->GetBackingPixmap() &&
696 !((m_targetWindow->GetPixmapWidth() == totalPixelWidth) &&
697 (m_targetWindow->GetPixmapHeight() == totalPixelHeight)))
698 {
699 XFreePixmap (dpy, (Pixmap) m_targetWindow->GetBackingPixmap());
700 m_targetWindow->SetBackingPixmap((WXPixmap) 0);
701 }
702
703 if (!m_targetWindow->GetBackingPixmap() &&
9b66c26a 704 (m_xScrollLines != 0) && (m_yScrollLines != 0))
566d84a7
RL
705 {
706 int depth = wxDisplayDepth();
707 m_targetWindow->SetPixmapWidth(totalPixelWidth);
708 m_targetWindow->SetPixmapHeight(totalPixelHeight);
709 m_targetWindow->SetBackingPixmap((WXPixmap) XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)),
710 m_targetWindow->GetPixmapWidth(), m_targetWindow->GetPixmapHeight(), depth));
711 }
712
139adb6a 713 }
566d84a7 714#endif // Motif
a58a12e9 715
27d029c7
RR
716 if (oldXScroll != m_xScrollPosition)
717 {
718 if (m_xScrollingEnabled)
566d84a7 719 m_targetWindow->ScrollWindow( m_xScrollPixelsPerLine * (oldXScroll - m_xScrollPosition), 0,
1e6feb95 720 GetRect() );
27d029c7 721 else
1e6feb95 722 m_targetWindow->Refresh(TRUE, GetRect());
27d029c7 723 }
a58a12e9 724
27d029c7
RR
725 if (oldYScroll != m_yScrollPosition)
726 {
727 if (m_yScrollingEnabled)
1e6feb95
VZ
728 m_targetWindow->ScrollWindow( 0, m_yScrollPixelsPerLine * (oldYScroll-m_yScrollPosition),
729 GetRect() );
27d029c7 730 else
1e6feb95 731 m_targetWindow->Refresh(TRUE, GetRect());
27d029c7 732 }
aeb313f3
SC
733
734#ifdef __WXMAC__
735 m_targetWindow->MacUpdateImmediately();
736#endif
c801d85f
KB
737}
738
1e6feb95 739void wxScrollHelper::DoPrepareDC(wxDC& dc)
c801d85f 740{
1e6feb95
VZ
741 wxPoint pt = dc.GetDeviceOrigin();
742 dc.SetDeviceOrigin( pt.x - m_xScrollPosition * m_xScrollPixelsPerLine,
743 pt.y - m_yScrollPosition * m_yScrollPixelsPerLine );
139adb6a 744 dc.SetUserScale( m_scaleX, m_scaleY );
c801d85f
KB
745}
746
566d84a7
RL
747void wxScrollHelper::SetScrollRate( int xstep, int ystep )
748{
749 int old_x = m_xScrollPixelsPerLine * m_xScrollPosition;
750 int old_y = m_yScrollPixelsPerLine * m_yScrollPosition;
751
752 m_xScrollPixelsPerLine = xstep;
753 m_yScrollPixelsPerLine = ystep;
754
755 int new_x = m_xScrollPixelsPerLine * m_xScrollPosition;
756 int new_y = m_yScrollPixelsPerLine * m_yScrollPosition;
757
758 m_win->SetScrollPos( wxHORIZONTAL, m_xScrollPosition );
759 m_win->SetScrollPos( wxVERTICAL, m_yScrollPosition );
760 m_targetWindow->ScrollWindow( old_x - new_x, old_y - new_y );
761
762 AdjustScrollbars();
763}
764
1e6feb95 765void wxScrollHelper::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const
c801d85f 766{
a0bc2c1d
VZ
767 if ( x_unit )
768 *x_unit = m_xScrollPixelsPerLine;
769 if ( y_unit )
770 *y_unit = m_yScrollPixelsPerLine;
c801d85f
KB
771}
772
1e6feb95 773int wxScrollHelper::GetScrollPageSize(int orient) const
c801d85f
KB
774{
775 if ( orient == wxHORIZONTAL )
776 return m_xScrollLinesPerPage;
777 else
778 return m_yScrollLinesPerPage;
779}
780
1e6feb95 781void wxScrollHelper::SetScrollPageSize(int orient, int pageSize)
c801d85f
KB
782{
783 if ( orient == wxHORIZONTAL )
784 m_xScrollLinesPerPage = pageSize;
785 else
786 m_yScrollLinesPerPage = pageSize;
787}
788
789/*
790 * Scroll to given position (scroll position, not pixel position)
791 */
1e6feb95 792void wxScrollHelper::Scroll( int x_pos, int y_pos )
c801d85f 793{
8b089c5e
JS
794 if (!m_targetWindow)
795 return;
796
a58a12e9 797 if (((x_pos == -1) || (x_pos == m_xScrollPosition)) &&
139adb6a 798 ((y_pos == -1) || (y_pos == m_yScrollPosition))) return;
a58a12e9 799
aeb313f3
SC
800#ifdef __WXMAC__
801 m_targetWindow->MacUpdateImmediately();
802#endif
803
139adb6a 804 int w, h;
1e6feb95 805 GetTargetSize(&w, &h);
c801d85f 806
8775b357 807 if ((x_pos != -1) && (m_xScrollPixelsPerLine))
c801d85f 808 {
ed673c6a 809 int old_x = m_xScrollPosition;
139adb6a 810 m_xScrollPosition = x_pos;
a58a12e9 811
3d2b9c20
RR
812 // Calculate page size i.e. number of scroll units you get on the
813 // current client window
ecab4dba 814 int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 );
139adb6a
RR
815 if (noPagePositions < 1) noPagePositions = 1;
816
817 // Correct position if greater than extent of canvas minus
3d2b9c20 818 // the visible portion of it or if below zero
139adb6a
RR
819 m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition );
820 m_xScrollPosition = wxMax( 0, m_xScrollPosition );
a58a12e9 821
f6bcfd97 822 if (old_x != m_xScrollPosition) {
5f3286d1 823 m_win->SetScrollPos( wxHORIZONTAL, m_xScrollPosition );
1e6feb95
VZ
824 m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0,
825 GetRect() );
f6bcfd97 826 }
c801d85f 827 }
8775b357 828 if ((y_pos != -1) && (m_yScrollPixelsPerLine))
c801d85f 829 {
ed673c6a 830 int old_y = m_yScrollPosition;
139adb6a 831 m_yScrollPosition = y_pos;
a58a12e9 832
3d2b9c20
RR
833 // Calculate page size i.e. number of scroll units you get on the
834 // current client window
ecab4dba 835 int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 );
139adb6a
RR
836 if (noPagePositions < 1) noPagePositions = 1;
837
838 // Correct position if greater than extent of canvas minus
3d2b9c20 839 // the visible portion of it or if below zero
139adb6a
RR
840 m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
841 m_yScrollPosition = wxMax( 0, m_yScrollPosition );
d2c52078 842
f6bcfd97 843 if (old_y != m_yScrollPosition) {
5f3286d1 844 m_win->SetScrollPos( wxVERTICAL, m_yScrollPosition );
1e6feb95
VZ
845 m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine,
846 GetRect() );
f6bcfd97 847 }
c801d85f 848 }
a58a12e9 849
7c74e7fe 850#ifdef __WXMAC__
3d2b9c20 851 m_targetWindow->MacUpdateImmediately();
7c74e7fe 852#endif
aeb313f3 853
c801d85f
KB
854}
855
1e6feb95 856void wxScrollHelper::EnableScrolling (bool x_scroll, bool y_scroll)
c801d85f 857{
139adb6a
RR
858 m_xScrollingEnabled = x_scroll;
859 m_yScrollingEnabled = y_scroll;
c801d85f
KB
860}
861
c801d85f 862// Where the current view starts from
1e6feb95 863void wxScrollHelper::GetViewStart (int *x, int *y) const
c801d85f 864{
a0bc2c1d
VZ
865 if ( x )
866 *x = m_xScrollPosition;
867 if ( y )
868 *y = m_yScrollPosition;
c801d85f
KB
869}
870
8c2f3797 871void wxScrollHelper::DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const
c801d85f 872{
a0bc2c1d
VZ
873 if ( xx )
874 *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine;
875 if ( yy )
876 *yy = y - m_yScrollPosition * m_yScrollPixelsPerLine;
c801d85f
KB
877}
878
8c2f3797 879void wxScrollHelper::DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
c801d85f 880{
a0bc2c1d
VZ
881 if ( xx )
882 *xx = x + m_xScrollPosition * m_xScrollPixelsPerLine;
883 if ( yy )
884 *yy = y + m_yScrollPosition * m_yScrollPixelsPerLine;
c801d85f 885}
d80cd92a
VZ
886
887// ----------------------------------------------------------------------------
888// event handlers
889// ----------------------------------------------------------------------------
890
891// Default OnSize resets scrollbars, if any
1e6feb95 892void wxScrollHelper::HandleOnSize(wxSizeEvent& WXUNUSED(event))
d80cd92a 893{
2b5f62a0
VZ
894 if( m_win->GetAutoLayout() )
895 {
896 if ( m_targetWindow != m_win )
897 m_targetWindow->FitInside();
566d84a7 898
2b5f62a0 899 m_win->FitInside();
dc429f89 900
566d84a7 901#if wxUSE_CONSTRAINTS
566d84a7
RL
902 m_win->Layout();
903#endif
2b5f62a0
VZ
904 }
905 else
906 AdjustScrollbars();
d80cd92a
VZ
907}
908
909// This calls OnDraw, having adjusted the origin according to the current
910// scroll position
1e6feb95 911void wxScrollHelper::HandleOnPaint(wxPaintEvent& WXUNUSED(event))
d80cd92a 912{
af4088f1
VZ
913 // don't use m_targetWindow here, this is always called for ourselves
914 wxPaintDC dc(m_win);
1e6feb95 915 DoPrepareDC(dc);
d80cd92a
VZ
916
917 OnDraw(dc);
918}
919
438e3558
VZ
920// kbd handling: notice that we use OnChar() and not OnKeyDown() for
921// compatibility here - if we used OnKeyDown(), the programs which process
922// arrows themselves in their OnChar() would never get the message and like
923// this they always have the priority
1e6feb95 924void wxScrollHelper::HandleOnChar(wxKeyEvent& event)
d80cd92a
VZ
925{
926 int stx, sty, // view origin
927 szx, szy, // view size (total)
928 clix, cliy; // view size (on screen)
929
1e6feb95
VZ
930 GetViewStart(&stx, &sty);
931 GetTargetSize(&clix, &cliy);
566d84a7 932 m_targetWindow->GetVirtualSize(&szx, &szy);
56dade3c
RL
933
934 if( m_xScrollPixelsPerLine )
935 {
936 clix /= m_xScrollPixelsPerLine;
d7da9756 937 szx /= m_xScrollPixelsPerLine;
56dade3c
RL
938 }
939 else
940 {
941 clix = 0;
d7da9756 942 szx = -1;
56dade3c
RL
943 }
944 if( m_yScrollPixelsPerLine )
945 {
946 cliy /= m_yScrollPixelsPerLine;
947 szy /= m_yScrollPixelsPerLine;
948 }
949 else
950 {
951 cliy = 0;
d7da9756 952 szy = -1;
56dade3c 953 }
d80cd92a 954
39c869a6
VZ
955 int xScrollOld = m_xScrollPosition,
956 yScrollOld = m_yScrollPosition;
957
ecb01792 958 int dsty;
4995ca80 959 switch ( event.GetKeyCode() )
d80cd92a
VZ
960 {
961 case WXK_PAGEUP:
962 case WXK_PRIOR:
ecb01792
RL
963 dsty = sty - (5 * cliy / 6);
964 Scroll(-1, (dsty == -1) ? 0 : dsty);
d80cd92a
VZ
965 break;
966
967 case WXK_PAGEDOWN:
968 case WXK_NEXT:
969 Scroll(-1, sty + (5 * cliy / 6));
970 break;
971
d80cd92a
VZ
972 case WXK_HOME:
973 Scroll(0, event.ControlDown() ? 0 : -1);
974 break;
975
976 case WXK_END:
4acd108c 977 Scroll(szx - clix, event.ControlDown() ? szy - cliy : -1);
d80cd92a
VZ
978 break;
979
980 case WXK_UP:
981 Scroll(-1, sty - 1);
982 break;
983
984 case WXK_DOWN:
985 Scroll(-1, sty + 1);
986 break;
987
988 case WXK_LEFT:
989 Scroll(stx - 1, -1);
990 break;
991
992 case WXK_RIGHT:
993 Scroll(stx + 1, -1);
994 break;
995
996 default:
997 // not for us
998 event.Skip();
999 }
39c869a6
VZ
1000
1001 if ( m_xScrollPosition != xScrollOld )
1002 {
1003 wxScrollWinEvent event(wxEVT_SCROLLWIN_THUMBTRACK, m_xScrollPosition,
1004 wxHORIZONTAL);
1005 event.SetEventObject(m_win);
1006 m_win->GetEventHandler()->ProcessEvent(event);
1007 }
1008
1009 if ( m_yScrollPosition != yScrollOld )
1010 {
1011 wxScrollWinEvent event(wxEVT_SCROLLWIN_THUMBTRACK, m_yScrollPosition,
1012 wxVERTICAL);
1013 event.SetEventObject(m_win);
1014 m_win->GetEventHandler()->ProcessEvent(event);
1015 }
d80cd92a 1016}
d2c52078 1017
1e6feb95
VZ
1018// ----------------------------------------------------------------------------
1019// autoscroll stuff: these functions deal with sending fake scroll events when
1020// a captured mouse is being held outside the window
1021// ----------------------------------------------------------------------------
1022
1023bool wxScrollHelper::SendAutoScrollEvents(wxScrollWinEvent& event) const
1024{
1025 // only send the event if the window is scrollable in this direction
1026 wxWindow *win = (wxWindow *)event.GetEventObject();
1027 return win->HasScrollbar(event.GetOrientation());
1028}
1029
1030void wxScrollHelper::StopAutoScrolling()
1031{
1032 if ( m_timerAutoScroll )
1033 {
1034 delete m_timerAutoScroll;
1035 m_timerAutoScroll = (wxTimer *)NULL;
1036 }
1037}
d2c52078 1038
1e6feb95 1039void wxScrollHelper::HandleOnMouseEnter(wxMouseEvent& event)
d2c52078 1040{
1e6feb95
VZ
1041 StopAutoScrolling();
1042
1043 event.Skip();
1044}
d2c52078 1045
1e6feb95
VZ
1046void wxScrollHelper::HandleOnMouseLeave(wxMouseEvent& event)
1047{
1048 // don't prevent the usual processing of the event from taking place
1049 event.Skip();
1050
1051 // when a captured mouse leave a scrolled window we start generate
1052 // scrolling events to allow, for example, extending selection beyond the
1053 // visible area in some controls
1054 if ( wxWindow::GetCapture() == m_targetWindow )
1055 {
1056 // where is the mouse leaving?
1057 int pos, orient;
1058 wxPoint pt = event.GetPosition();
1059 if ( pt.x < 0 )
1060 {
1061 orient = wxHORIZONTAL;
1062 pos = 0;
1063 }
1064 else if ( pt.y < 0 )
1065 {
1066 orient = wxVERTICAL;
1067 pos = 0;
1068 }
1069 else // we're lower or to the right of the window
1070 {
1071 wxSize size = m_targetWindow->GetClientSize();
1072 if ( pt.x > size.x )
1073 {
1074 orient = wxHORIZONTAL;
1075 pos = m_xScrollLines;
1076 }
1077 else if ( pt.y > size.y )
1078 {
1079 orient = wxVERTICAL;
1080 pos = m_yScrollLines;
1081 }
1082 else // this should be impossible
1083 {
1084 // but seems to happen sometimes under wxMSW - maybe it's a bug
1085 // there but for now just ignore it
1086
1087 //wxFAIL_MSG( _T("can't understand where has mouse gone") );
1088
1089 return;
1090 }
1091 }
1092
1093 // only start the auto scroll timer if the window can be scrolled in
1094 // this direction
1095 if ( !m_targetWindow->HasScrollbar(orient) )
1096 return;
1097
1098 delete m_timerAutoScroll;
1099 m_timerAutoScroll = new wxAutoScrollTimer
1100 (
1101 m_targetWindow, this,
1102 pos == 0 ? wxEVT_SCROLLWIN_LINEUP
1103 : wxEVT_SCROLLWIN_LINEDOWN,
1104 pos,
1105 orient
1106 );
1107 m_timerAutoScroll->Start(50); // FIXME: make configurable
1108 }
1109}
1110
e421922f
VZ
1111#if wxUSE_MOUSEWHEEL
1112
1e6feb95
VZ
1113void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent& event)
1114{
d2c52078 1115 m_wheelRotation += event.GetWheelRotation();
1e6feb95 1116 int lines = m_wheelRotation / event.GetWheelDelta();
d2c52078
RD
1117 m_wheelRotation -= lines * event.GetWheelDelta();
1118
1e6feb95
VZ
1119 if (lines != 0)
1120 {
1e6feb95 1121
b6b85bdc
JS
1122 wxScrollWinEvent newEvent;
1123
ac6f6ffc 1124 newEvent.SetPosition(0);
b6b85bdc
JS
1125 newEvent.SetOrientation(wxVERTICAL);
1126 newEvent.m_eventObject = m_win;
b6b85bdc 1127
9b9337da 1128 if (event.IsPageScroll())
4b056ef5
RD
1129 {
1130 if (lines > 0)
1131 newEvent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
1132 else
1133 newEvent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
1134
b6b85bdc 1135 m_win->GetEventHandler()->ProcessEvent(newEvent);
4b056ef5
RD
1136 }
1137 else
1138 {
1139 lines *= event.GetLinesPerAction();
1140 if (lines > 0)
1141 newEvent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
1142 else
1143 newEvent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
b6b85bdc 1144
4b056ef5
RD
1145 int times = abs(lines);
1146 for (; times > 0; times--)
1147 m_win->GetEventHandler()->ProcessEvent(newEvent);
1148 }
d2c52078
RD
1149 }
1150}
1151
e421922f
VZ
1152#endif // wxUSE_MOUSEWHEEL
1153
1e6feb95
VZ
1154// ----------------------------------------------------------------------------
1155// wxGenericScrolledWindow implementation
1156// ----------------------------------------------------------------------------
1157
1158IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow, wxPanel)
1159
349efbaa
VZ
1160BEGIN_EVENT_TABLE(wxGenericScrolledWindow, wxPanel)
1161 EVT_PAINT(wxGenericScrolledWindow::OnPaint)
1162END_EVENT_TABLE()
1163
1e6feb95
VZ
1164bool wxGenericScrolledWindow::Create(wxWindow *parent,
1165 wxWindowID id,
1166 const wxPoint& pos,
1167 const wxSize& size,
1168 long style,
1169 const wxString& name)
1170{
1171 m_targetWindow = this;
1172
1173 bool ok = wxPanel::Create(parent, id, pos, size, style, name);
1174
1e6feb95
VZ
1175 return ok;
1176}
1177
1178wxGenericScrolledWindow::~wxGenericScrolledWindow()
1179{
1180}
d2c52078 1181
30486297
RD
1182bool wxGenericScrolledWindow::Layout()
1183{
566d84a7 1184 if (GetSizer() && m_targetWindow == this)
30486297 1185 {
566d84a7
RL
1186 // If we're the scroll target, take into account the
1187 // virtual size and scrolled position of the window.
1188
30486297
RD
1189 int x, y, w, h;
1190 CalcScrolledPosition(0,0, &x,&y);
1191 GetVirtualSize(&w, &h);
1192 GetSizer()->SetDimension(x, y, w, h);
1193 return TRUE;
1194 }
7152f0c6
VZ
1195
1196 // fall back to default for LayoutConstraints
1197 return wxPanel::Layout();
30486297
RD
1198}
1199
2b5f62a0
VZ
1200void wxGenericScrolledWindow::DoSetVirtualSize(int x, int y)
1201{
1202 wxPanel::DoSetVirtualSize( x, y );
1203 AdjustScrollbars();
1204
1205#if wxUSE_CONSTRAINTS
1206 if (GetAutoLayout())
1207 Layout();
1208#endif
1209}
1210
349efbaa
VZ
1211void wxGenericScrolledWindow::OnPaint(wxPaintEvent& event)
1212{
1213 // the user code didn't really draw the window if we got here, so set this
1214 // flag to try to call OnDraw() later
1215 m_handler->ResetDrawnFlag();
1216
1217 event.Skip();
1218}
1219
0cf5b099
VZ
1220#ifdef __WXMSW__
1221long
1222wxGenericScrolledWindow::MSWWindowProc(WXUINT nMsg,
1223 WXWPARAM wParam,
1224 WXLPARAM lParam)
1225{
1226 long rc = wxPanel::MSWWindowProc(nMsg, wParam, lParam);
1227
1228 // we need to process arrows ourselves for scrolling
1229 if ( nMsg == WM_GETDLGCODE )
1230 {
1231 rc |= DLGC_WANTARROWS;
1232 }
1233
1234 return rc;
1235}
1236
1237#endif // __WXMSW__
1238
1e6feb95 1239#if WXWIN_COMPATIBILITY
349efbaa 1240
1e6feb95
VZ
1241void wxGenericScrolledWindow::GetScrollUnitsPerPage (int *x_page, int *y_page) const
1242{
1243 *x_page = GetScrollPageSize(wxHORIZONTAL);
1244 *y_page = GetScrollPageSize(wxVERTICAL);
1245}
d2c52078 1246
1e6feb95
VZ
1247void wxGenericScrolledWindow::CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const
1248{
1249 if ( xx )
1250 *xx = (float)(x + m_xScrollPosition * m_xScrollPixelsPerLine);
1251 if ( yy )
1252 *yy = (float)(y + m_yScrollPosition * m_yScrollPixelsPerLine);
1253}
349efbaa 1254
1e6feb95 1255#endif // WXWIN_COMPATIBILITY
d2c52078 1256
3a8c693a
VZ
1257#endif // !wxGTK
1258
566d84a7 1259// vi:sts=4:sw=4:et