1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/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/scrolwin.h"
37 #include "wx/gtk/private.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
;
62 extern bool g_blockEventsOnScroll
;
64 //-----------------------------------------------------------------------------
66 //-----------------------------------------------------------------------------
68 extern void wxapp_install_idle_handler();
71 //-----------------------------------------------------------------------------
72 // "value_changed" from m_vAdjust
73 //-----------------------------------------------------------------------------
75 static void gtk_scrolled_window_vscroll_callback( GtkAdjustment
*adjust
,
77 wxScrolledWindow
*win
)
80 wxapp_install_idle_handler();
82 if (g_blockEventsOnDrag
) return;
84 if (!win
->m_hasVMT
) return;
86 win
->GtkVScroll( adjust
->value
,
87 GET_SCROLL_TYPE(GTK_SCROLLED_WINDOW(win
->m_widget
)->vscrollbar
) );
90 //-----------------------------------------------------------------------------
91 // "value_changed" from m_hAdjust
92 //-----------------------------------------------------------------------------
94 static void gtk_scrolled_window_hscroll_callback( GtkAdjustment
*adjust
,
96 wxScrolledWindow
*win
)
99 wxapp_install_idle_handler();
101 if (g_blockEventsOnDrag
) return;
102 if (!win
->m_hasVMT
) return;
104 win
->GtkHScroll( adjust
->value
,
105 GET_SCROLL_TYPE(GTK_SCROLLED_WINDOW(win
->m_widget
)->hscrollbar
) );
108 //-----------------------------------------------------------------------------
109 // "button_press_event" from scrollbar
110 //-----------------------------------------------------------------------------
112 static gint
gtk_scrollbar_button_press_callback( GtkRange
*widget
,
113 GdkEventButton
*gdk_event
,
117 wxapp_install_idle_handler();
119 g_blockEventsOnScroll
= TRUE
;
121 // FIXME: there is no slider field any more, what was meant here?
123 win
->m_isScrolling
= (gdk_event
->window
== widget
->slider
);
129 //-----------------------------------------------------------------------------
130 // "button_release_event" from scrollbar
131 //-----------------------------------------------------------------------------
133 static gint
gtk_scrollbar_button_release_callback( GtkRange
*widget
,
134 GdkEventButton
*WXUNUSED(gdk_event
),
137 // don't test here as we can release the mouse while being over
138 // a different window than the slider
140 // if (gdk_event->window != widget->slider) return FALSE;
142 g_blockEventsOnScroll
= FALSE
;
144 if (win
->m_isScrolling
)
146 wxEventType command
= wxEVT_SCROLLWIN_THUMBRELEASE
;
150 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(win
->m_widget
);
151 if (widget
== GTK_RANGE(scrolledWindow
->hscrollbar
))
153 value
= (int)(win
->m_hAdjust
->value
+0.5);
156 if (widget
== GTK_RANGE(scrolledWindow
->vscrollbar
))
158 value
= (int)(win
->m_vAdjust
->value
+0.5);
162 wxScrollWinEvent
event( command
, value
, dir
);
163 event
.SetEventObject( win
);
164 win
->GetEventHandler()->ProcessEvent( event
);
167 win
->m_isScrolling
= FALSE
;
172 //-----------------------------------------------------------------------------
173 // InsertChild for wxScrolledWindow
174 //-----------------------------------------------------------------------------
176 static void wxInsertChildInScrolledWindow( wxWindow
* parent
, wxWindow
* child
)
178 // The window might have been scrolled already, do we
179 // have to adapt the position.
180 GtkPizza
*pizza
= GTK_PIZZA(parent
->m_wxwindow
);
181 child
->m_x
+= pizza
->xoffset
;
182 child
->m_y
+= pizza
->yoffset
;
184 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
185 GTK_WIDGET(child
->m_widget
),
192 // ----------------------------------------------------------------------------
193 // wxScrolledWindow creation
194 // ----------------------------------------------------------------------------
196 void wxScrolledWindow::Init()
198 m_xScrollPixelsPerLine
= 0;
199 m_yScrollPixelsPerLine
= 0;
200 m_xScrollingEnabled
= TRUE
;
201 m_yScrollingEnabled
= TRUE
;
202 m_xScrollPosition
= 0;
203 m_yScrollPosition
= 0;
206 m_xScrollLinesPerPage
= 0;
207 m_yScrollLinesPerPage
= 0;
208 m_targetWindow
= (wxWindow
*) NULL
;
211 m_hasScrolling
= TRUE
;
214 bool wxScrolledWindow::Create(wxWindow
*parent
,
219 const wxString
& name
)
223 if (!PreCreation( parent
, pos
, size
) ||
224 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
226 wxFAIL_MSG( wxT("wxWindow creation failed") );
230 m_insertCallback
= wxInsertChildInScrolledWindow
;
232 m_targetWindow
= this;
234 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
235 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
237 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
239 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
240 scroll_class
->scrollbar_spacing
= 0;
242 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
244 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->hscrollbar
) );
245 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->vscrollbar
) );
247 m_wxwindow
= gtk_pizza_new();
249 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
251 GtkPizza
*pizza
= GTK_PIZZA(m_wxwindow
);
253 if (HasFlag(wxRAISED_BORDER
))
255 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_OUT
);
257 else if (HasFlag(wxSUNKEN_BORDER
))
259 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_IN
);
261 else if (HasFlag(wxSIMPLE_BORDER
))
263 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_THIN
);
267 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_NONE
);
270 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
271 m_acceptsFocus
= TRUE
;
273 // I _really_ don't want scrollbars in the beginning
274 m_vAdjust
->lower
= 0.0;
275 m_vAdjust
->upper
= 1.0;
276 m_vAdjust
->value
= 0.0;
277 m_vAdjust
->step_increment
= 1.0;
278 m_vAdjust
->page_increment
= 1.0;
279 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
280 m_hAdjust
->lower
= 0.0;
281 m_hAdjust
->upper
= 1.0;
282 m_hAdjust
->value
= 0.0;
283 m_hAdjust
->step_increment
= 1.0;
284 m_hAdjust
->page_increment
= 1.0;
285 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
287 // Handlers for new scrollbar values
291 // these handlers block mouse events to any window during scrolling such as
292 // motion events and prevent GTK and wxWindows from fighting over where the
295 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_press_event",
296 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
298 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_press_event",
299 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
301 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_release_event",
302 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
304 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_release_event",
305 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
307 gtk_widget_show( m_wxwindow
);
310 m_parent
->DoAddChild( this );
312 m_focusWidget
= m_wxwindow
;
321 // ----------------------------------------------------------------------------
322 // setting scrolling parameters
323 // ----------------------------------------------------------------------------
326 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
327 * noUnitsX/noUnitsY: : no. units per scrollbar
329 void wxScrolledWindow::SetScrollbars (int pixelsPerUnitX
, int pixelsPerUnitY
,
330 int noUnitsX
, int noUnitsY
,
331 int xPos
, int yPos
, bool noRefresh
)
333 int old_x
= m_xScrollPixelsPerLine
* m_xScrollPosition
;
334 int old_y
= m_yScrollPixelsPerLine
* m_yScrollPosition
;
336 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
337 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
338 m_xScrollLines
= noUnitsX
;
339 m_yScrollLines
= noUnitsY
;
340 m_xScrollPosition
= xPos
;
341 m_yScrollPosition
= yPos
;
343 m_hAdjust
->lower
= 0.0;
344 m_hAdjust
->upper
= noUnitsX
;
345 m_hAdjust
->value
= xPos
;
346 m_hAdjust
->step_increment
= 1.0;
347 m_hAdjust
->page_increment
= 2.0;
349 m_vAdjust
->lower
= 0.0;
350 m_vAdjust
->upper
= noUnitsY
;
351 m_vAdjust
->value
= yPos
;
352 m_vAdjust
->step_increment
= 1.0;
353 m_vAdjust
->page_increment
= 2.0;
359 int new_x
= m_xScrollPixelsPerLine
* m_xScrollPosition
;
360 int new_y
= m_yScrollPixelsPerLine
* m_yScrollPosition
;
362 m_targetWindow
->ScrollWindow( old_x
-new_x
, old_y
-new_y
);
366 void wxScrolledWindow::AdjustScrollbars()
369 m_targetWindow
->GetClientSize( &w
, &h
);
371 if (m_xScrollPixelsPerLine
== 0)
372 m_hAdjust
->page_size
= 1.0;
374 m_hAdjust
->page_size
= (w
/ m_xScrollPixelsPerLine
);
376 if (m_yScrollPixelsPerLine
== 0)
377 m_vAdjust
->page_size
= 1.0;
379 m_vAdjust
->page_size
= (h
/ m_yScrollPixelsPerLine
);
381 m_xScrollLinesPerPage
= (int)(m_hAdjust
->page_size
+ 0.5);
382 m_yScrollLinesPerPage
= (int)(m_vAdjust
->page_size
+ 0.5);
384 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
385 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
388 // ----------------------------------------------------------------------------
389 // target window handling
390 // ----------------------------------------------------------------------------
392 void wxScrolledWindow::SetTargetWindow( wxWindow
*target
, bool WXUNUSED(pushEventHandler
) )
394 wxASSERT_MSG( target
, wxT("target window must not be NULL") );
395 m_targetWindow
= target
;
398 wxWindow
*wxScrolledWindow::GetTargetWindow()
400 return m_targetWindow
;
403 // Override this function if you don't want to have wxScrolledWindow
404 // automatically change the origin according to the scroll position.
405 void wxScrolledWindow::PrepareDC(wxDC
& dc
)
407 dc
.SetDeviceOrigin( -m_xScrollPosition
* m_xScrollPixelsPerLine
,
408 -m_yScrollPosition
* m_yScrollPixelsPerLine
);
411 void wxScrolledWindow::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
414 *x_unit
= m_xScrollPixelsPerLine
;
416 *y_unit
= m_yScrollPixelsPerLine
;
419 int wxScrolledWindow::GetScrollPageSize(int orient
) const
421 if ( orient
== wxHORIZONTAL
)
422 return m_xScrollLinesPerPage
;
424 return m_yScrollLinesPerPage
;
427 void wxScrolledWindow::SetScrollPageSize(int orient
, int pageSize
)
429 if ( orient
== wxHORIZONTAL
)
430 m_xScrollLinesPerPage
= pageSize
;
432 m_yScrollLinesPerPage
= pageSize
;
435 void wxScrolledWindow::OnScroll(wxScrollWinEvent
& event
)
437 int orient
= event
.GetOrientation();
439 int nScrollInc
= CalcScrollInc(event
);
440 if (nScrollInc
== 0) return;
442 if (orient
== wxHORIZONTAL
)
444 int newPos
= m_xScrollPosition
+ nScrollInc
;
445 SetScrollPos(wxHORIZONTAL
, newPos
, TRUE
);
449 int newPos
= m_yScrollPosition
+ nScrollInc
;
450 SetScrollPos(wxVERTICAL
, newPos
, TRUE
);
453 if (orient
== wxHORIZONTAL
)
455 m_xScrollPosition
+= nScrollInc
;
459 m_yScrollPosition
+= nScrollInc
;
462 if (orient
== wxHORIZONTAL
)
464 if (m_xScrollingEnabled
)
465 m_targetWindow
->ScrollWindow(-m_xScrollPixelsPerLine
* nScrollInc
, 0, (const wxRect
*) NULL
);
467 m_targetWindow
->Refresh();
471 if (m_yScrollingEnabled
)
472 m_targetWindow
->ScrollWindow(0, -m_yScrollPixelsPerLine
* nScrollInc
, (const wxRect
*) NULL
);
474 m_targetWindow
->Refresh();
478 void wxScrolledWindow::Scroll( int x_pos
, int y_pos
)
483 if (((x_pos
== -1) || (x_pos
== m_xScrollPosition
)) &&
484 ((y_pos
== -1) || (y_pos
== m_yScrollPosition
))) return;
486 if ((x_pos
!= -1) && (m_xScrollPixelsPerLine
))
488 int max
= (int)(m_hAdjust
->upper
- m_hAdjust
->page_size
+ 0.5);
489 if (max
< 0) max
= 0;
490 if (x_pos
> max
) x_pos
= max
;
491 if (x_pos
< 0) x_pos
= 0;
493 int old_x
= m_xScrollPosition
;
494 m_xScrollPosition
= x_pos
;
495 m_hAdjust
->value
= x_pos
;
497 m_targetWindow
->ScrollWindow( (old_x
-m_xScrollPosition
)*m_xScrollPixelsPerLine
, 0 );
499 // Just update the scrollbar, don't send any wxWindows event
500 GtkHDisconnectEvent();
501 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
505 if ((y_pos
!= -1) && (m_yScrollPixelsPerLine
))
507 int max
= (int)(m_vAdjust
->upper
- m_vAdjust
->page_size
+ 0.5);
508 if (max
< 0) max
= 0;
509 if (y_pos
> max
) y_pos
= max
;
510 if (y_pos
< 0) y_pos
= 0;
512 int old_y
= m_yScrollPosition
;
513 m_yScrollPosition
= y_pos
;
514 m_vAdjust
->value
= y_pos
;
516 m_targetWindow
->ScrollWindow( 0, (old_y
-m_yScrollPosition
)*m_yScrollPixelsPerLine
);
518 // Just update the scrollbar, don't send any wxWindows event
519 GtkVDisconnectEvent();
520 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
525 // TODO: [VH]Scroll functions should be combined
527 void wxScrolledWindow::GtkVScroll( float value
, unsigned int scroll_type
)
532 if (m_yScrollPixelsPerLine
== 0)
535 int y_pos
= (int)(value
+0.5);
537 if (y_pos
== m_yScrollPosition
)
540 wxEventType command
= GtkScrollWinTypeToWx(scroll_type
);
542 wxScrollWinEvent
event( command
, y_pos
, wxVERTICAL
);
543 event
.SetEventObject( this );
544 GetEventHandler()->ProcessEvent( event
);
547 void wxScrolledWindow::GtkHScroll( float value
, unsigned int scroll_type
)
552 if (m_xScrollPixelsPerLine
== 0)
555 int x_pos
= (int)(value
+0.5);
557 if (x_pos
== m_xScrollPosition
)
560 wxEventType command
= GtkScrollWinTypeToWx(scroll_type
);
562 wxScrollWinEvent
event( command
, x_pos
, wxHORIZONTAL
);
563 event
.SetEventObject( this );
564 GetEventHandler()->ProcessEvent( event
);
567 void wxScrolledWindow::EnableScrolling (bool x_scroll
, bool y_scroll
)
569 m_xScrollingEnabled
= x_scroll
;
570 m_yScrollingEnabled
= y_scroll
;
573 void wxScrolledWindow::GetVirtualSize (int *x
, int *y
) const
576 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
578 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
581 // Where the current view starts from
582 void wxScrolledWindow::GetViewStart (int *x
, int *y
) const
585 *x
= m_xScrollPosition
;
587 *y
= m_yScrollPosition
;
590 void wxScrolledWindow::CalcScrolledPosition(int x
, int y
, int *xx
, int *yy
) const
593 *xx
= x
- m_xScrollPosition
* m_xScrollPixelsPerLine
;
595 *yy
= y
- m_yScrollPosition
* m_yScrollPixelsPerLine
;
598 void wxScrolledWindow::CalcUnscrolledPosition(int x
, int y
, int *xx
, int *yy
) const
601 *xx
= x
+ m_xScrollPosition
* m_xScrollPixelsPerLine
;
603 *yy
= y
+ m_yScrollPosition
* m_yScrollPixelsPerLine
;
606 int wxScrolledWindow::CalcScrollInc(wxScrollWinEvent
& event
)
608 int pos
= event
.GetPosition();
609 int orient
= event
.GetOrientation();
612 if (event
.GetEventType() == wxEVT_SCROLLWIN_TOP
)
614 if (orient
== wxHORIZONTAL
)
615 nScrollInc
= - m_xScrollPosition
;
617 nScrollInc
= - m_yScrollPosition
;
619 if (event
.GetEventType() == wxEVT_SCROLLWIN_BOTTOM
)
621 if (orient
== wxHORIZONTAL
)
622 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
624 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
626 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEUP
)
630 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN
)
634 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEUP
)
636 if (orient
== wxHORIZONTAL
)
637 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
639 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
641 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN
)
643 if (orient
== wxHORIZONTAL
)
644 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
646 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
648 if ((event
.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK
) ||
649 (event
.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE
))
651 if (orient
== wxHORIZONTAL
)
652 nScrollInc
= pos
- m_xScrollPosition
;
654 nScrollInc
= pos
- m_yScrollPosition
;
657 if (orient
== wxHORIZONTAL
)
659 if (m_xScrollPixelsPerLine
> 0)
661 int max
= (int)(m_hAdjust
->upper
- m_hAdjust
->page_size
+ 0.5);
662 if (max
< 0) max
= 0;
664 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
665 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
666 else if ( (m_xScrollPosition
+ nScrollInc
) > max
)
667 nScrollInc
= max
- m_xScrollPosition
; // As +ve as we can go
670 m_targetWindow
->Refresh();
674 if (m_yScrollPixelsPerLine
> 0)
676 int max
= (int)(m_vAdjust
->upper
- m_vAdjust
->page_size
+ 0.5);
677 if (max
< 0) max
= 0;
679 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
680 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
681 else if ( (m_yScrollPosition
+ nScrollInc
) > max
)
682 nScrollInc
= max
- m_yScrollPosition
; // As +ve as we can go
685 m_targetWindow
->Refresh();
691 void wxScrolledWindow::SetScrollPos( int orient
, int pos
, bool refresh
)
693 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
695 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
697 if (orient
== wxHORIZONTAL
)
699 int max
= (int)(m_hAdjust
->upper
- m_hAdjust
->page_size
+ 0.5);
700 if (max
< 0) max
= 0;
702 if (pos
> max
) pos
= 0;
703 if (pos
< 0) pos
= 0;
705 if (pos
== (int)(m_hAdjust
->value
+0.5)) return;
706 m_hAdjust
->value
= pos
;
710 int max
= (int)(m_vAdjust
->upper
- m_vAdjust
->page_size
+ 0.5);
711 if (max
< 0) max
= 0;
713 if (pos
> max
) pos
= 0;
714 if (pos
< 0) pos
= 0;
716 if (pos
== (int)(m_vAdjust
->value
+0.5)) return;
717 m_vAdjust
->value
= pos
;
720 if (m_wxwindow
->window
)
722 if (orient
== wxHORIZONTAL
)
724 // Just update the scrollbar, don't send any wxWindows event
725 GtkHDisconnectEvent();
726 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
731 // Just update the scrollbar, don't send any wxWindows event
732 GtkVDisconnectEvent();
733 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
739 void wxScrolledWindow::GtkVConnectEvent()
741 gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed",
742 (GtkSignalFunc
) gtk_scrolled_window_vscroll_callback
, (gpointer
) this );
745 void wxScrolledWindow::GtkHConnectEvent()
747 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed",
748 (GtkSignalFunc
) gtk_scrolled_window_hscroll_callback
, (gpointer
) this );
751 void wxScrolledWindow::GtkHDisconnectEvent()
753 gtk_signal_disconnect_by_func( GTK_OBJECT(m_hAdjust
),
754 (GtkSignalFunc
) gtk_scrolled_window_hscroll_callback
, (gpointer
) this );
757 void wxScrolledWindow::GtkVDisconnectEvent()
759 gtk_signal_disconnect_by_func( GTK_OBJECT(m_vAdjust
),
760 (GtkSignalFunc
) gtk_scrolled_window_vscroll_callback
, (gpointer
) this );
763 // ----------------------------------------------------------------------------
765 // ----------------------------------------------------------------------------
767 // Default OnSize resets scrollbars, if any
768 void wxScrolledWindow::OnSize(wxSizeEvent
& WXUNUSED(event
))
770 #if wxUSE_CONSTRAINTS
778 // This calls OnDraw, having adjusted the origin according to the current
780 void wxScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
788 // kbd handling: notice that we use OnChar() and not OnKeyDown() for
789 // compatibility here - if we used OnKeyDown(), the programs which process
790 // arrows themselves in their OnChar() would never get the message and like
791 // this they always have the priority
792 void wxScrolledWindow::OnChar(wxKeyEvent
& event
)
794 int stx
, sty
, // view origin
795 szx
, szy
, // view size (total)
796 clix
, cliy
; // view size (on screen)
798 ViewStart(&stx
, &sty
);
799 GetClientSize(&clix
, &cliy
);
800 GetVirtualSize(&szx
, &szy
);
802 if( m_xScrollPixelsPerLine
)
804 clix
/= m_xScrollPixelsPerLine
;
805 szx
/= m_xScrollPixelsPerLine
;
812 if( m_yScrollPixelsPerLine
)
814 cliy
/= m_yScrollPixelsPerLine
;
815 szy
/= m_yScrollPixelsPerLine
;
823 int xScrollOld
= GetScrollPos(wxHORIZONTAL
),
824 yScrollOld
= GetScrollPos(wxVERTICAL
);
827 switch ( event
.KeyCode() )
831 dsty
= sty
- (5 * cliy
/ 6);
832 Scroll(-1, (dsty
== -1) ? 0 : dsty
);
837 Scroll(-1, sty
+ (5 * cliy
/ 6));
841 Scroll(0, event
.ControlDown() ? 0 : -1);
845 Scroll(szx
- clix
, event
.ControlDown() ? szy
- cliy
: -1);
870 int xScroll
= GetScrollPos(wxHORIZONTAL
);
871 if ( xScroll
!= xScrollOld
)
873 wxScrollWinEvent
event(wxEVT_SCROLLWIN_THUMBTRACK
, xScroll
,
875 event
.SetEventObject(this);
876 GetEventHandler()->ProcessEvent(event
);
879 int yScroll
= GetScrollPos(wxVERTICAL
);
880 if ( yScroll
!= yScrollOld
)
882 wxScrollWinEvent
event(wxEVT_SCROLLWIN_THUMBTRACK
, yScroll
,
884 event
.SetEventObject(this);
885 GetEventHandler()->ProcessEvent(event
);