wxScrolledWindow now emits wxScrollWinEvents. Something
[wxWidgets.git] / src / gtk1 / scrolwin.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/scrolwin.cpp
3 // Purpose: wxScrolledWindow implementation
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "scrolwin.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #include "wx/utils.h"
32 #include "wx/dcclient.h"
33
34 #include "wx/gtk/scrolwin.h"
35 #include "wx/panel.h"
36
37 #include <gtk/gtk.h>
38 #include "wx/gtk/win_gtk.h"
39
40 // ----------------------------------------------------------------------------
41 // event tables
42 // ----------------------------------------------------------------------------
43
44 BEGIN_EVENT_TABLE(wxScrolledWindow, wxPanel)
45 EVT_SCROLLWIN(wxScrolledWindow::OnScroll)
46 EVT_SIZE(wxScrolledWindow::OnSize)
47 EVT_PAINT(wxScrolledWindow::OnPaint)
48 EVT_CHAR(wxScrolledWindow::OnChar)
49 END_EVENT_TABLE()
50
51 IMPLEMENT_DYNAMIC_CLASS(wxScrolledWindow, wxPanel)
52
53 // ============================================================================
54 // implementation
55 // ============================================================================
56
57 //-----------------------------------------------------------------------------
58 // data
59 //-----------------------------------------------------------------------------
60
61 extern bool g_blockEventsOnDrag;
62
63 //-----------------------------------------------------------------------------
64 // idle system
65 //-----------------------------------------------------------------------------
66
67 extern void wxapp_install_idle_handler();
68 extern bool g_isIdle;
69
70 //-----------------------------------------------------------------------------
71 // "value_changed" from m_vAdjust
72 //-----------------------------------------------------------------------------
73
74 static void gtk_scrolled_window_vscroll_callback( GtkAdjustment *adjust, wxScrolledWindow *win )
75 {
76 if (g_isIdle)
77 wxapp_install_idle_handler();
78
79 if (g_blockEventsOnDrag) return;
80
81 if (!win->m_hasVMT) return;
82
83 win->GtkVScroll( adjust->value );
84 }
85
86 //-----------------------------------------------------------------------------
87 // "value_changed" from m_hAdjust
88 //-----------------------------------------------------------------------------
89
90 static void gtk_scrolled_window_hscroll_callback( GtkAdjustment *adjust, wxScrolledWindow *win )
91 {
92 if (g_isIdle)
93 wxapp_install_idle_handler();
94
95 if (g_blockEventsOnDrag) return;
96 if (!win->m_hasVMT) return;
97
98 win->GtkHScroll( adjust->value );
99 }
100
101 //-----------------------------------------------------------------------------
102 // InsertChild for wxScrolledWindow
103 //-----------------------------------------------------------------------------
104
105 static void wxInsertChildInScrolledWindow( wxWindow* parent, wxWindow* child )
106 {
107 /* the window might have been scrolled already, do we
108 have to adapt the position */
109 GtkPizza *pizza = GTK_PIZZA(parent->m_wxwindow);
110 child->m_x += pizza->xoffset;
111 child->m_y += pizza->yoffset;
112
113 gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow),
114 GTK_WIDGET(child->m_widget),
115 child->m_x,
116 child->m_y,
117 child->m_width,
118 child->m_height );
119 }
120
121 // ----------------------------------------------------------------------------
122 // wxScrolledWindow creation
123 // ----------------------------------------------------------------------------
124
125 wxScrolledWindow::wxScrolledWindow()
126 {
127 m_xScrollPixelsPerLine = 0;
128 m_yScrollPixelsPerLine = 0;
129 m_xScrollingEnabled = TRUE;
130 m_yScrollingEnabled = TRUE;
131 m_xScrollPosition = 0;
132 m_yScrollPosition = 0;
133 m_xScrollLines = 0;
134 m_yScrollLines = 0;
135 m_xScrollLinesPerPage = 0;
136 m_yScrollLinesPerPage = 0;
137 m_targetWindow = (wxWindow*) NULL;
138 m_scaleX = 1.0;
139 m_scaleY = 1.0;
140 }
141
142 bool wxScrolledWindow::Create(wxWindow *parent,
143 wxWindowID id,
144 const wxPoint& pos,
145 const wxSize& size,
146 long style,
147 const wxString& name)
148 {
149 if (!PreCreation( parent, pos, size ) ||
150 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
151 {
152 wxFAIL_MSG( wxT("wxWindow creation failed") );
153 return FALSE;
154 }
155
156 m_insertCallback = wxInsertChildInScrolledWindow;
157
158 m_xScrollPixelsPerLine = 0;
159 m_yScrollPixelsPerLine = 0;
160 m_xScrollingEnabled = TRUE;
161 m_yScrollingEnabled = TRUE;
162 m_xScrollPosition = 0;
163 m_yScrollPosition = 0;
164 m_xScrollLines = 0;
165 m_yScrollLines = 0;
166 m_xScrollLinesPerPage = 0;
167 m_yScrollLinesPerPage = 0;
168
169 m_targetWindow = this;
170
171 m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
172 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
173
174 GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget);
175
176 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget) );
177 scroll_class->scrollbar_spacing = 0;
178
179 gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
180
181 m_hAdjust = gtk_range_get_adjustment( GTK_RANGE(scrolledWindow->hscrollbar) );
182 m_vAdjust = gtk_range_get_adjustment( GTK_RANGE(scrolledWindow->vscrollbar) );
183
184 m_wxwindow = gtk_pizza_new();
185
186 gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
187
188 GtkPizza *pizza = GTK_PIZZA(m_wxwindow);
189
190 if (HasFlag(wxRAISED_BORDER))
191 {
192 gtk_pizza_set_shadow_type( pizza, GTK_MYSHADOW_OUT );
193 }
194 else if (HasFlag(wxSUNKEN_BORDER))
195 {
196 gtk_pizza_set_shadow_type( pizza, GTK_MYSHADOW_IN );
197 }
198 else if (HasFlag(wxSIMPLE_BORDER))
199 {
200 gtk_pizza_set_shadow_type( pizza, GTK_MYSHADOW_THIN );
201 }
202 else
203 {
204 gtk_pizza_set_shadow_type( pizza, GTK_MYSHADOW_NONE );
205 }
206
207 GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
208 m_acceptsFocus = TRUE;
209
210 // I _really_ don't want scrollbars in the beginning
211 m_vAdjust->lower = 0.0;
212 m_vAdjust->upper = 1.0;
213 m_vAdjust->value = 0.0;
214 m_vAdjust->step_increment = 1.0;
215 m_vAdjust->page_increment = 1.0;
216 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
217 m_hAdjust->lower = 0.0;
218 m_hAdjust->upper = 1.0;
219 m_hAdjust->value = 0.0;
220 m_hAdjust->step_increment = 1.0;
221 m_hAdjust->page_increment = 1.0;
222 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
223
224 // these handlers get notified when screen updates are required either when
225 // scrolling or when the window size (and therefore scrollbar configuration)
226 // has changed
227 gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed",
228 (GtkSignalFunc) gtk_scrolled_window_hscroll_callback, (gpointer) this );
229 gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed",
230 (GtkSignalFunc) gtk_scrolled_window_vscroll_callback, (gpointer) this );
231
232 gtk_widget_show( m_wxwindow );
233
234 if (m_parent)
235 m_parent->DoAddChild( this );
236
237 PostCreation();
238
239 Show( TRUE );
240
241 return TRUE;
242 }
243
244 wxScrolledWindow::~wxScrolledWindow()
245 {
246 }
247
248 // ----------------------------------------------------------------------------
249 // setting scrolling parameters
250 // ----------------------------------------------------------------------------
251
252 /*
253 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
254 * noUnitsX/noUnitsY: : no. units per scrollbar
255 */
256 void wxScrolledWindow::SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY,
257 int noUnitsX, int noUnitsY,
258 int xPos, int yPos, bool noRefresh )
259 {
260 m_xScrollPixelsPerLine = pixelsPerUnitX;
261 m_yScrollPixelsPerLine = pixelsPerUnitY;
262 m_xScrollPosition = xPos;
263 m_yScrollPosition = yPos;
264 m_xScrollLines = noUnitsX;
265 m_yScrollLines = noUnitsY;
266
267 m_hAdjust->lower = 0.0;
268 m_hAdjust->upper = noUnitsX;
269 m_hAdjust->value = xPos;
270 m_hAdjust->step_increment = 1.0;
271 m_hAdjust->page_increment = 1.0;
272
273 m_vAdjust->lower = 0.0;
274 m_vAdjust->upper = noUnitsY;
275 m_vAdjust->value = yPos;
276 m_vAdjust->step_increment = 1.0;
277 m_vAdjust->page_increment = 1.0;
278
279 AdjustScrollbars();
280 }
281
282 void wxScrolledWindow::AdjustScrollbars()
283 {
284 int w, h;
285 m_targetWindow->GetClientSize( &w, &h );
286
287 if (m_xScrollPixelsPerLine == 0)
288 m_hAdjust->page_size = 1.0;
289 else
290 m_hAdjust->page_size = (w / m_xScrollPixelsPerLine);
291
292 if (m_yScrollPixelsPerLine == 0)
293 m_vAdjust->page_size = 1.0;
294 else
295 m_vAdjust->page_size = (h / m_yScrollPixelsPerLine);
296
297 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
298 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
299 }
300
301 // ----------------------------------------------------------------------------
302 // target window handling
303 // ----------------------------------------------------------------------------
304
305 void wxScrolledWindow::SetTargetWindow( wxWindow *target )
306 {
307 wxASSERT_MSG( target, wxT("target window must not be NULL") );
308 m_targetWindow = target;
309 }
310
311 wxWindow *wxScrolledWindow::GetTargetWindow()
312 {
313 return m_targetWindow;
314 }
315
316 // Override this function if you don't want to have wxScrolledWindow
317 // automatically change the origin according to the scroll position.
318 void wxScrolledWindow::PrepareDC(wxDC& dc)
319 {
320 dc.SetDeviceOrigin( -m_xScrollPosition * m_xScrollPixelsPerLine,
321 -m_yScrollPosition * m_yScrollPixelsPerLine );
322 }
323
324 void wxScrolledWindow::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const
325 {
326 if ( x_unit )
327 *x_unit = m_xScrollPixelsPerLine;
328 if ( y_unit )
329 *y_unit = m_yScrollPixelsPerLine;
330 }
331
332 int wxScrolledWindow::GetScrollPageSize(int orient) const
333 {
334 if ( orient == wxHORIZONTAL )
335 return m_xScrollLinesPerPage;
336 else
337 return m_yScrollLinesPerPage;
338 }
339
340 void wxScrolledWindow::SetScrollPageSize(int orient, int pageSize)
341 {
342 if ( orient == wxHORIZONTAL )
343 m_xScrollLinesPerPage = pageSize;
344 else
345 m_yScrollLinesPerPage = pageSize;
346 }
347
348 void wxScrolledWindow::OnScroll(wxScrollWinEvent& event)
349 {
350 int orient = event.GetOrientation();
351
352 int nScrollInc = CalcScrollInc(event);
353 if (nScrollInc == 0) return;
354
355 if (orient == wxHORIZONTAL)
356 {
357 int newPos = m_xScrollPosition + nScrollInc;
358 SetScrollPos(wxHORIZONTAL, newPos, TRUE );
359 }
360 else
361 {
362 int newPos = m_yScrollPosition + nScrollInc;
363 SetScrollPos(wxVERTICAL, newPos, TRUE );
364 }
365
366 if (orient == wxHORIZONTAL)
367 {
368 m_xScrollPosition += nScrollInc;
369 }
370 else
371 {
372 m_yScrollPosition += nScrollInc;
373 }
374
375 if (orient == wxHORIZONTAL)
376 {
377 if (m_xScrollingEnabled)
378 m_targetWindow->ScrollWindow(-m_xScrollPixelsPerLine * nScrollInc, 0, (const wxRect *) NULL);
379 else
380 m_targetWindow->Refresh();
381 }
382 else
383 {
384 if (m_yScrollingEnabled)
385 m_targetWindow->ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, (const wxRect *) NULL);
386 else
387 m_targetWindow->Refresh();
388 }
389 }
390
391 void wxScrolledWindow::Scroll( int x_pos, int y_pos )
392 {
393 if (!m_targetWindow)
394 return;
395
396 if (((x_pos == -1) || (x_pos == m_xScrollPosition)) &&
397 ((y_pos == -1) || (y_pos == m_yScrollPosition))) return;
398
399 if ((x_pos != -1) && (m_xScrollPixelsPerLine))
400 {
401 int old_x = m_xScrollPosition;
402 m_xScrollPosition = x_pos;
403 m_hAdjust->value = x_pos;
404
405 wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK;
406 wxScrollWinEvent event( command, m_xScrollPosition, wxHORIZONTAL );
407 event.SetEventObject( this );
408 GetEventHandler()->ProcessEvent( event );
409
410 m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 );
411
412 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" );
413 }
414
415 if ((y_pos != -1) && (m_yScrollPixelsPerLine))
416 {
417 int old_y = m_yScrollPosition;
418 m_yScrollPosition = y_pos;
419 m_vAdjust->value = y_pos;
420
421 wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK;
422 wxScrollWinEvent event( command, m_yScrollPosition, wxVERTICAL );
423 event.SetEventObject( this );
424 GetEventHandler()->ProcessEvent( event );
425
426 m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine );
427
428 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" );
429 }
430 }
431
432 void wxScrolledWindow::GtkVScroll( float value )
433 {
434 if (!m_targetWindow)
435 return;
436
437 if (m_yScrollPixelsPerLine == 0)
438 return;
439
440 int y_pos = (int)(value+0.5);
441
442 if (y_pos == m_yScrollPosition)
443 return;
444
445 int old_y = m_yScrollPosition;
446 m_yScrollPosition = y_pos;
447
448 GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget);
449 GtkRange *range = GTK_RANGE(scrolledWindow->hscrollbar);
450
451 wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK;
452 if (range->scroll_type == GTK_SCROLL_STEP_BACKWARD) command = wxEVT_SCROLLWIN_LINEUP;
453 else if (range->scroll_type == GTK_SCROLL_STEP_FORWARD) command = wxEVT_SCROLLWIN_LINEDOWN;
454 else if (range->scroll_type == GTK_SCROLL_PAGE_BACKWARD) command = wxEVT_SCROLLWIN_PAGEUP;
455 else if (range->scroll_type == GTK_SCROLL_PAGE_FORWARD) command = wxEVT_SCROLLWIN_PAGEDOWN;
456
457 wxScrollWinEvent event( command, m_yScrollPosition, wxVERTICAL );
458 event.SetEventObject( this );
459 GetEventHandler()->ProcessEvent( event );
460
461 m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine );
462 }
463
464 void wxScrolledWindow::GtkHScroll( float value )
465 {
466 if (!m_targetWindow)
467 return;
468
469 if (m_xScrollPixelsPerLine == 0)
470 return;
471
472 int x_pos = (int)(value+0.5);
473
474 if (x_pos == m_xScrollPosition)
475 return;
476
477 int old_x = m_xScrollPosition;
478 m_xScrollPosition = x_pos;
479
480 GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget);
481 GtkRange *range = GTK_RANGE(scrolledWindow->hscrollbar);
482
483 wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK;
484 if (range->scroll_type == GTK_SCROLL_STEP_BACKWARD) command = wxEVT_SCROLLWIN_LINEUP;
485 else if (range->scroll_type == GTK_SCROLL_STEP_FORWARD) command = wxEVT_SCROLLWIN_LINEDOWN;
486 else if (range->scroll_type == GTK_SCROLL_PAGE_BACKWARD) command = wxEVT_SCROLLWIN_PAGEUP;
487 else if (range->scroll_type == GTK_SCROLL_PAGE_FORWARD) command = wxEVT_SCROLLWIN_PAGEDOWN;
488
489 wxScrollWinEvent event( command, m_xScrollPosition, wxHORIZONTAL );
490 event.SetEventObject( this );
491 GetEventHandler()->ProcessEvent( event );
492
493 m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 );
494 }
495
496 void wxScrolledWindow::EnableScrolling (bool x_scroll, bool y_scroll)
497 {
498 m_xScrollingEnabled = x_scroll;
499 m_yScrollingEnabled = y_scroll;
500 }
501
502 void wxScrolledWindow::GetVirtualSize (int *x, int *y) const
503 {
504 if ( x )
505 *x = m_xScrollPixelsPerLine * m_xScrollLines;
506 if ( y )
507 *y = m_yScrollPixelsPerLine * m_yScrollLines;
508 }
509
510 // Where the current view starts from
511 void wxScrolledWindow::GetViewStart (int *x, int *y) const
512 {
513 if ( x )
514 *x = m_xScrollPosition;
515 if ( y )
516 *y = m_yScrollPosition;
517 }
518
519 void wxScrolledWindow::CalcScrolledPosition(int x, int y, int *xx, int *yy) const
520 {
521 if ( xx )
522 *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine;
523 if ( yy )
524 *yy = y - m_yScrollPosition * m_yScrollPixelsPerLine;
525 }
526
527 void wxScrolledWindow::CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
528 {
529 if ( xx )
530 *xx = x + m_xScrollPosition * m_xScrollPixelsPerLine;
531 if ( yy )
532 *yy = y + m_yScrollPosition * m_yScrollPixelsPerLine;
533 }
534
535 int wxScrolledWindow::CalcScrollInc(wxScrollWinEvent& event)
536 {
537 int pos = event.GetPosition();
538 int orient = event.GetOrientation();
539
540 int nScrollInc = 0;
541 if (event.GetEventType() == wxEVT_SCROLLWIN_TOP)
542 {
543 if (orient == wxHORIZONTAL)
544 nScrollInc = - m_xScrollPosition;
545 else
546 nScrollInc = - m_yScrollPosition;
547 } else
548 if (event.GetEventType() == wxEVT_SCROLLWIN_BOTTOM)
549 {
550 if (orient == wxHORIZONTAL)
551 nScrollInc = m_xScrollLines - m_xScrollPosition;
552 else
553 nScrollInc = m_yScrollLines - m_yScrollPosition;
554 } else
555 if (event.GetEventType() == wxEVT_SCROLLWIN_LINEUP)
556 {
557 nScrollInc = -1;
558 } else
559 if (event.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN)
560 {
561 nScrollInc = 1;
562 } else
563 if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEUP)
564 {
565 if (orient == wxHORIZONTAL)
566 nScrollInc = -GetScrollPageSize(wxHORIZONTAL);
567 else
568 nScrollInc = -GetScrollPageSize(wxVERTICAL);
569 } else
570 if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN)
571 {
572 if (orient == wxHORIZONTAL)
573 nScrollInc = GetScrollPageSize(wxHORIZONTAL);
574 else
575 nScrollInc = GetScrollPageSize(wxVERTICAL);
576 } else
577 if ((event.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK) ||
578 (event.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE))
579 {
580 if (orient == wxHORIZONTAL)
581 nScrollInc = pos - m_xScrollPosition;
582 else
583 nScrollInc = pos - m_yScrollPosition;
584 }
585
586 if (orient == wxHORIZONTAL)
587 {
588 if (m_xScrollPixelsPerLine > 0)
589 {
590 int w, h;
591 m_targetWindow->GetClientSize(&w, &h);
592
593 int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine;
594 int noPositions = (int) ( ((nMaxWidth - w)/(double)m_xScrollPixelsPerLine) + 0.5 );
595 if (noPositions < 0)
596 noPositions = 0;
597
598 if ( (m_xScrollPosition + nScrollInc) < 0 )
599 nScrollInc = -m_xScrollPosition; // As -ve as we can go
600 else if ( (m_xScrollPosition + nScrollInc) > noPositions )
601 nScrollInc = noPositions - m_xScrollPosition; // As +ve as we can go
602 }
603 else
604 m_targetWindow->Refresh();
605 }
606 else
607 {
608 if (m_yScrollPixelsPerLine > 0)
609 {
610 int w, h;
611 m_targetWindow->GetClientSize(&w, &h);
612
613 int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine;
614 int noPositions = (int) ( ((nMaxHeight - h)/(double)m_yScrollPixelsPerLine) + 0.5 );
615 if (noPositions < 0)
616 noPositions = 0;
617
618 if ( (m_yScrollPosition + nScrollInc) < 0 )
619 nScrollInc = -m_yScrollPosition; // As -ve as we can go
620 else if ( (m_yScrollPosition + nScrollInc) > noPositions )
621 nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go
622 }
623 else
624 m_targetWindow->Refresh();
625 }
626
627 return nScrollInc;
628 }
629
630 // ----------------------------------------------------------------------------
631 // event handlers
632 // ----------------------------------------------------------------------------
633
634 // Default OnSize resets scrollbars, if any
635 void wxScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event))
636 {
637 #if wxUSE_CONSTRAINTS
638 if (GetAutoLayout())
639 Layout();
640 #endif
641
642 AdjustScrollbars();
643 }
644
645 // This calls OnDraw, having adjusted the origin according to the current
646 // scroll position
647 void wxScrolledWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
648 {
649 wxPaintDC dc(this);
650 PrepareDC(dc);
651
652 OnDraw(dc);
653 }
654
655 // kbd handling: notice that we use OnChar() and not OnKeyDown() for
656 // compatibility here - if we used OnKeyDown(), the programs which process
657 // arrows themselves in their OnChar() would never get the message and like
658 // this they always have the priority
659 void wxScrolledWindow::OnChar(wxKeyEvent& event)
660 {
661 int stx, sty, // view origin
662 szx, szy, // view size (total)
663 clix, cliy; // view size (on screen)
664
665 ViewStart(&stx, &sty);
666 GetClientSize(&clix, &cliy);
667 GetVirtualSize(&szx, &szy);
668
669 if( m_xScrollPixelsPerLine )
670 {
671 clix /= m_xScrollPixelsPerLine;
672 szx /= m_xScrollPixelsPerLine;
673 }
674 else
675 {
676 clix = 0;
677 szx = -1;
678 }
679 if( m_yScrollPixelsPerLine )
680 {
681 cliy /= m_yScrollPixelsPerLine;
682 szy /= m_yScrollPixelsPerLine;
683 }
684 else
685 {
686 cliy = 0;
687 szy = -1;
688 }
689
690 int dsty;
691 switch ( event.KeyCode() )
692 {
693 case WXK_PAGEUP:
694 case WXK_PRIOR:
695 dsty = sty - (5 * cliy / 6);
696 Scroll(-1, (dsty == -1) ? 0 : dsty);
697 break;
698
699 case WXK_PAGEDOWN:
700 case WXK_NEXT:
701 Scroll(-1, sty + (5 * cliy / 6));
702 break;
703
704 case WXK_HOME:
705 Scroll(0, event.ControlDown() ? 0 : -1);
706 break;
707
708 case WXK_END:
709 Scroll(szx - clix, event.ControlDown() ? szy - cliy : -1);
710 break;
711
712 case WXK_UP:
713 Scroll(-1, sty - 1);
714 break;
715
716 case WXK_DOWN:
717 Scroll(-1, sty + 1);
718 break;
719
720 case WXK_LEFT:
721 Scroll(stx - 1, -1);
722 break;
723
724 case WXK_RIGHT:
725 Scroll(stx + 1, -1);
726 break;
727
728 default:
729 // not for us
730 event.Skip();
731 }
732 }