1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/scrolwin.cpp
3 // Purpose: wxScrolledWindow implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "scrolwin.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/dcclient.h"
34 #include "wx/gtk/scrolwin.h"
38 #include "wx/gtk/win_gtk.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
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
)
51 IMPLEMENT_DYNAMIC_CLASS(wxScrolledWindow
, wxPanel
)
53 // ============================================================================
55 // ============================================================================
57 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
61 extern bool g_blockEventsOnDrag
;
63 //-----------------------------------------------------------------------------
65 //-----------------------------------------------------------------------------
67 extern void wxapp_install_idle_handler();
70 //-----------------------------------------------------------------------------
71 // "value_changed" from m_vAdjust
72 //-----------------------------------------------------------------------------
74 static void gtk_scrolled_window_vscroll_callback( GtkAdjustment
*adjust
, wxScrolledWindow
*win
)
77 wxapp_install_idle_handler();
79 if (g_blockEventsOnDrag
) return;
81 if (!win
->m_hasVMT
) return;
83 win
->GtkVScroll( adjust
->value
);
86 //-----------------------------------------------------------------------------
87 // "value_changed" from m_hAdjust
88 //-----------------------------------------------------------------------------
90 static void gtk_scrolled_window_hscroll_callback( GtkAdjustment
*adjust
, wxScrolledWindow
*win
)
93 wxapp_install_idle_handler();
95 if (g_blockEventsOnDrag
) return;
96 if (!win
->m_hasVMT
) return;
98 win
->GtkHScroll( adjust
->value
);
101 //-----------------------------------------------------------------------------
102 // InsertChild for wxScrolledWindow
103 //-----------------------------------------------------------------------------
105 static void wxInsertChildInScrolledWindow( wxWindow
* parent
, wxWindow
* child
)
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
;
113 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
114 GTK_WIDGET(child
->m_widget
),
121 // ----------------------------------------------------------------------------
122 // wxScrolledWindow creation
123 // ----------------------------------------------------------------------------
125 wxScrolledWindow::wxScrolledWindow()
127 m_xScrollPixelsPerLine
= 0;
128 m_yScrollPixelsPerLine
= 0;
129 m_xScrollingEnabled
= TRUE
;
130 m_yScrollingEnabled
= TRUE
;
131 m_xScrollPosition
= 0;
132 m_yScrollPosition
= 0;
135 m_xScrollLinesPerPage
= 0;
136 m_yScrollLinesPerPage
= 0;
137 m_targetWindow
= (wxWindow
*) NULL
;
142 bool wxScrolledWindow::Create(wxWindow
*parent
,
147 const wxString
& name
)
149 if (!PreCreation( parent
, pos
, size
) ||
150 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
152 wxFAIL_MSG( wxT("wxWindow creation failed") );
156 m_insertCallback
= wxInsertChildInScrolledWindow
;
158 m_xScrollPixelsPerLine
= 0;
159 m_yScrollPixelsPerLine
= 0;
160 m_xScrollingEnabled
= TRUE
;
161 m_yScrollingEnabled
= TRUE
;
162 m_xScrollPosition
= 0;
163 m_yScrollPosition
= 0;
166 m_xScrollLinesPerPage
= 0;
167 m_yScrollLinesPerPage
= 0;
169 m_targetWindow
= this;
171 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
172 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
174 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
176 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
177 scroll_class
->scrollbar_spacing
= 0;
179 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
181 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->hscrollbar
) );
182 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->vscrollbar
) );
184 m_wxwindow
= gtk_pizza_new();
186 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
188 GtkPizza
*pizza
= GTK_PIZZA(m_wxwindow
);
190 if (HasFlag(wxRAISED_BORDER
))
192 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_OUT
);
194 else if (HasFlag(wxSUNKEN_BORDER
))
196 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_IN
);
198 else if (HasFlag(wxSIMPLE_BORDER
))
200 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_THIN
);
204 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_NONE
);
207 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
208 m_acceptsFocus
= TRUE
;
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" );
224 // these handlers get notified when screen updates are required either when
225 // scrolling or when the window size (and therefore scrollbar configuration)
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 );
232 gtk_widget_show( m_wxwindow
);
235 m_parent
->DoAddChild( this );
244 wxScrolledWindow::~wxScrolledWindow()
248 // ----------------------------------------------------------------------------
249 // setting scrolling parameters
250 // ----------------------------------------------------------------------------
253 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
254 * noUnitsX/noUnitsY: : no. units per scrollbar
256 void wxScrolledWindow::SetScrollbars (int pixelsPerUnitX
, int pixelsPerUnitY
,
257 int noUnitsX
, int noUnitsY
,
258 int xPos
, int yPos
, bool noRefresh
)
260 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
261 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
262 m_xScrollPosition
= xPos
;
263 m_yScrollPosition
= yPos
;
264 m_xScrollLines
= noUnitsX
;
265 m_yScrollLines
= noUnitsY
;
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
= 2.0;
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
= 2.0;
282 void wxScrolledWindow::AdjustScrollbars()
285 m_targetWindow
->GetClientSize( &w
, &h
);
287 if (m_xScrollPixelsPerLine
== 0)
288 m_hAdjust
->page_size
= 1.0;
290 m_hAdjust
->page_size
= (w
/ m_xScrollPixelsPerLine
);
292 if (m_yScrollPixelsPerLine
== 0)
293 m_vAdjust
->page_size
= 1.0;
295 m_vAdjust
->page_size
= (h
/ m_yScrollPixelsPerLine
);
297 m_xScrollLinesPerPage
= (int)(m_hAdjust
->page_size
+ 0.5);
298 m_yScrollLinesPerPage
= (int)(m_vAdjust
->page_size
+ 0.5);
300 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
301 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
304 // ----------------------------------------------------------------------------
305 // target window handling
306 // ----------------------------------------------------------------------------
308 void wxScrolledWindow::SetTargetWindow( wxWindow
*target
)
310 wxASSERT_MSG( target
, wxT("target window must not be NULL") );
311 m_targetWindow
= target
;
314 wxWindow
*wxScrolledWindow::GetTargetWindow()
316 return m_targetWindow
;
319 // Override this function if you don't want to have wxScrolledWindow
320 // automatically change the origin according to the scroll position.
321 void wxScrolledWindow::PrepareDC(wxDC
& dc
)
323 dc
.SetDeviceOrigin( -m_xScrollPosition
* m_xScrollPixelsPerLine
,
324 -m_yScrollPosition
* m_yScrollPixelsPerLine
);
327 void wxScrolledWindow::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
330 *x_unit
= m_xScrollPixelsPerLine
;
332 *y_unit
= m_yScrollPixelsPerLine
;
335 int wxScrolledWindow::GetScrollPageSize(int orient
) const
337 if ( orient
== wxHORIZONTAL
)
338 return m_xScrollLinesPerPage
;
340 return m_yScrollLinesPerPage
;
343 void wxScrolledWindow::SetScrollPageSize(int orient
, int pageSize
)
345 if ( orient
== wxHORIZONTAL
)
346 m_xScrollLinesPerPage
= pageSize
;
348 m_yScrollLinesPerPage
= pageSize
;
351 void wxScrolledWindow::OnScroll(wxScrollWinEvent
& event
)
353 int orient
= event
.GetOrientation();
355 int nScrollInc
= CalcScrollInc(event
);
356 if (nScrollInc
== 0) return;
358 if (orient
== wxHORIZONTAL
)
360 int newPos
= m_xScrollPosition
+ nScrollInc
;
361 SetScrollPos(wxHORIZONTAL
, newPos
, TRUE
);
365 int newPos
= m_yScrollPosition
+ nScrollInc
;
366 SetScrollPos(wxVERTICAL
, newPos
, TRUE
);
369 if (orient
== wxHORIZONTAL
)
371 m_xScrollPosition
+= nScrollInc
;
375 m_yScrollPosition
+= nScrollInc
;
378 if (orient
== wxHORIZONTAL
)
380 if (m_xScrollingEnabled
)
381 m_targetWindow
->ScrollWindow(-m_xScrollPixelsPerLine
* nScrollInc
, 0, (const wxRect
*) NULL
);
383 m_targetWindow
->Refresh();
387 if (m_yScrollingEnabled
)
388 m_targetWindow
->ScrollWindow(0, -m_yScrollPixelsPerLine
* nScrollInc
, (const wxRect
*) NULL
);
390 m_targetWindow
->Refresh();
394 void wxScrolledWindow::Scroll( int x_pos
, int y_pos
)
399 if (((x_pos
== -1) || (x_pos
== m_xScrollPosition
)) &&
400 ((y_pos
== -1) || (y_pos
== m_yScrollPosition
))) return;
402 if ((x_pos
!= -1) && (m_xScrollPixelsPerLine
))
404 int old_x
= m_xScrollPosition
;
405 m_xScrollPosition
= x_pos
;
406 m_hAdjust
->value
= x_pos
;
408 wxEventType command
= wxEVT_SCROLLWIN_THUMBTRACK
;
409 wxScrollWinEvent
event( command
, m_xScrollPosition
, wxHORIZONTAL
);
410 event
.SetEventObject( this );
411 GetEventHandler()->ProcessEvent( event
);
413 m_targetWindow
->ScrollWindow( (old_x
-m_xScrollPosition
)*m_xScrollPixelsPerLine
, 0 );
415 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
418 if ((y_pos
!= -1) && (m_yScrollPixelsPerLine
))
420 int old_y
= m_yScrollPosition
;
421 m_yScrollPosition
= y_pos
;
422 m_vAdjust
->value
= y_pos
;
424 wxEventType command
= wxEVT_SCROLLWIN_THUMBTRACK
;
425 wxScrollWinEvent
event( command
, m_yScrollPosition
, wxVERTICAL
);
426 event
.SetEventObject( this );
427 GetEventHandler()->ProcessEvent( event
);
429 m_targetWindow
->ScrollWindow( 0, (old_y
-m_yScrollPosition
)*m_yScrollPixelsPerLine
);
431 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
435 void wxScrolledWindow::GtkVScroll( float value
)
440 if (m_yScrollPixelsPerLine
== 0)
443 int y_pos
= (int)(value
+0.5);
445 if (y_pos
== m_yScrollPosition
)
448 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
449 GtkRange
*range
= GTK_RANGE(scrolledWindow
->vscrollbar
);
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
;
457 wxScrollWinEvent
event( command
, y_pos
, wxVERTICAL
);
458 event
.SetEventObject( this );
459 GetEventHandler()->ProcessEvent( event
);
462 int old_y = m_yScrollPosition;
463 m_yScrollPosition = y_pos;
465 m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine );
469 void wxScrolledWindow::GtkHScroll( float value
)
474 if (m_xScrollPixelsPerLine
== 0)
477 int x_pos
= (int)(value
+0.5);
479 if (x_pos
== m_xScrollPosition
)
482 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
483 GtkRange
*range
= GTK_RANGE(scrolledWindow
->hscrollbar
);
485 wxEventType command
= wxEVT_SCROLLWIN_THUMBTRACK
;
486 if (range
->scroll_type
== GTK_SCROLL_STEP_BACKWARD
) command
= wxEVT_SCROLLWIN_LINEUP
;
487 else if (range
->scroll_type
== GTK_SCROLL_STEP_FORWARD
) command
= wxEVT_SCROLLWIN_LINEDOWN
;
488 else if (range
->scroll_type
== GTK_SCROLL_PAGE_BACKWARD
) command
= wxEVT_SCROLLWIN_PAGEUP
;
489 else if (range
->scroll_type
== GTK_SCROLL_PAGE_FORWARD
) command
= wxEVT_SCROLLWIN_PAGEDOWN
;
491 wxScrollWinEvent
event( command
, x_pos
, wxHORIZONTAL
);
492 event
.SetEventObject( this );
493 GetEventHandler()->ProcessEvent( event
);
496 int old_x = m_xScrollPosition;
497 m_xScrollPosition = x_pos;
499 m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 );
503 void wxScrolledWindow::EnableScrolling (bool x_scroll
, bool y_scroll
)
505 m_xScrollingEnabled
= x_scroll
;
506 m_yScrollingEnabled
= y_scroll
;
509 void wxScrolledWindow::GetVirtualSize (int *x
, int *y
) const
512 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
514 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
517 // Where the current view starts from
518 void wxScrolledWindow::GetViewStart (int *x
, int *y
) const
521 *x
= m_xScrollPosition
;
523 *y
= m_yScrollPosition
;
526 void wxScrolledWindow::CalcScrolledPosition(int x
, int y
, int *xx
, int *yy
) const
529 *xx
= x
- m_xScrollPosition
* m_xScrollPixelsPerLine
;
531 *yy
= y
- m_yScrollPosition
* m_yScrollPixelsPerLine
;
534 void wxScrolledWindow::CalcUnscrolledPosition(int x
, int y
, int *xx
, int *yy
) const
537 *xx
= x
+ m_xScrollPosition
* m_xScrollPixelsPerLine
;
539 *yy
= y
+ m_yScrollPosition
* m_yScrollPixelsPerLine
;
542 int wxScrolledWindow::CalcScrollInc(wxScrollWinEvent
& event
)
544 int pos
= event
.GetPosition();
545 int orient
= event
.GetOrientation();
548 if (event
.GetEventType() == wxEVT_SCROLLWIN_TOP
)
550 if (orient
== wxHORIZONTAL
)
551 nScrollInc
= - m_xScrollPosition
;
553 nScrollInc
= - m_yScrollPosition
;
555 if (event
.GetEventType() == wxEVT_SCROLLWIN_BOTTOM
)
557 if (orient
== wxHORIZONTAL
)
558 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
560 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
562 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEUP
)
566 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN
)
570 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEUP
)
572 if (orient
== wxHORIZONTAL
)
573 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
575 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
577 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN
)
579 if (orient
== wxHORIZONTAL
)
580 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
582 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
584 if ((event
.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK
) ||
585 (event
.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE
))
587 if (orient
== wxHORIZONTAL
)
588 nScrollInc
= pos
- m_xScrollPosition
;
590 nScrollInc
= pos
- m_yScrollPosition
;
593 if (orient
== wxHORIZONTAL
)
595 if (m_xScrollPixelsPerLine
> 0)
598 m_targetWindow
->GetClientSize(&w
, &h
);
600 int noPositions
= (int)(m_hAdjust
->upper
- m_hAdjust
->page_size
+ 0.5);
601 if (noPositions
< 0) noPositions
= 0;
603 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
604 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
605 else if ( (m_xScrollPosition
+ nScrollInc
) > noPositions
)
606 nScrollInc
= noPositions
- m_xScrollPosition
; // As +ve as we can go
609 m_targetWindow
->Refresh();
613 if (m_yScrollPixelsPerLine
> 0)
616 m_targetWindow
->GetClientSize(&w
, &h
);
618 int noPositions
= (int)(m_vAdjust
->upper
- m_vAdjust
->page_size
+ 0.5);
619 if (noPositions
< 0) noPositions
= 0;
621 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
622 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
623 else if ( (m_yScrollPosition
+ nScrollInc
) > noPositions
)
624 nScrollInc
= noPositions
- m_yScrollPosition
; // As +ve as we can go
627 m_targetWindow
->Refresh();
633 void wxScrolledWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
635 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
637 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
639 if (orient
== wxHORIZONTAL
)
641 float fpos
= (float)pos
;
642 if (fpos
> m_hAdjust
->upper
- m_hAdjust
->page_size
) fpos
= m_hAdjust
->upper
- m_hAdjust
->page_size
;
643 if (fpos
< 0.0) fpos
= 0.0;
645 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
646 m_hAdjust
->value
= fpos
;
650 float fpos
= (float)pos
;
651 if (fpos
> m_vAdjust
->upper
- m_vAdjust
->page_size
) fpos
= m_vAdjust
->upper
- m_vAdjust
->page_size
;
652 if (fpos
< 0.0) fpos
= 0.0;
654 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
655 m_vAdjust
->value
= fpos
;
658 if (m_wxwindow
->window
)
660 if (orient
== wxHORIZONTAL
)
662 gtk_signal_disconnect_by_func( GTK_OBJECT(m_hAdjust
),
663 (GtkSignalFunc
) gtk_scrolled_window_hscroll_callback
, (gpointer
) this );
665 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
667 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed",
668 (GtkSignalFunc
) gtk_scrolled_window_hscroll_callback
, (gpointer
) this );
672 gtk_signal_disconnect_by_func( GTK_OBJECT(m_vAdjust
),
673 (GtkSignalFunc
) gtk_scrolled_window_vscroll_callback
, (gpointer
) this );
675 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
677 gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed",
678 (GtkSignalFunc
) gtk_scrolled_window_vscroll_callback
, (gpointer
) this );
683 // ----------------------------------------------------------------------------
685 // ----------------------------------------------------------------------------
687 // Default OnSize resets scrollbars, if any
688 void wxScrolledWindow::OnSize(wxSizeEvent
& WXUNUSED(event
))
690 #if wxUSE_CONSTRAINTS
698 // This calls OnDraw, having adjusted the origin according to the current
700 void wxScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
708 // kbd handling: notice that we use OnChar() and not OnKeyDown() for
709 // compatibility here - if we used OnKeyDown(), the programs which process
710 // arrows themselves in their OnChar() would never get the message and like
711 // this they always have the priority
712 void wxScrolledWindow::OnChar(wxKeyEvent
& event
)
714 int stx
, sty
, // view origin
715 szx
, szy
, // view size (total)
716 clix
, cliy
; // view size (on screen)
718 ViewStart(&stx
, &sty
);
719 GetClientSize(&clix
, &cliy
);
720 GetVirtualSize(&szx
, &szy
);
722 if( m_xScrollPixelsPerLine
)
724 clix
/= m_xScrollPixelsPerLine
;
725 szx
/= m_xScrollPixelsPerLine
;
732 if( m_yScrollPixelsPerLine
)
734 cliy
/= m_yScrollPixelsPerLine
;
735 szy
/= m_yScrollPixelsPerLine
;
744 switch ( event
.KeyCode() )
748 dsty
= sty
- (5 * cliy
/ 6);
749 Scroll(-1, (dsty
== -1) ? 0 : dsty
);
754 Scroll(-1, sty
+ (5 * cliy
/ 6));
758 Scroll(0, event
.ControlDown() ? 0 : -1);
762 Scroll(szx
- clix
, event
.ControlDown() ? szy
- cliy
: -1);