1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/scrolwin.cpp
3 // Purpose: wxScrolledWindow implementation
4 // Author: Julian Smart
5 // Modified by: Ron Lee
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"
38 #include "wx/gtk/private.h"
39 #include "wx/gtk/win_gtk.h"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 BEGIN_EVENT_TABLE(wxScrolledWindow
, wxPanel
)
46 EVT_SCROLLWIN(wxScrolledWindow::OnScroll
)
47 EVT_SIZE(wxScrolledWindow::OnSize
)
48 EVT_PAINT(wxScrolledWindow::OnPaint
)
49 EVT_CHAR(wxScrolledWindow::OnChar
)
52 IMPLEMENT_DYNAMIC_CLASS(wxScrolledWindow
, wxPanel
)
54 // ============================================================================
56 // ============================================================================
58 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
62 extern bool g_blockEventsOnDrag
;
63 extern bool g_blockEventsOnScroll
;
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
69 extern void wxapp_install_idle_handler();
72 //-----------------------------------------------------------------------------
73 // "value_changed" from m_vAdjust
74 //-----------------------------------------------------------------------------
76 static void gtk_scrolled_window_vscroll_callback( GtkAdjustment
*adjust
,
78 wxScrolledWindow
*win
)
81 wxapp_install_idle_handler();
83 if (g_blockEventsOnDrag
) return;
85 if (!win
->m_hasVMT
) return;
87 win
->GtkVScroll( adjust
->value
,
88 GET_SCROLL_TYPE(GTK_SCROLLED_WINDOW(win
->m_widget
)->vscrollbar
) );
91 //-----------------------------------------------------------------------------
92 // "value_changed" from m_hAdjust
93 //-----------------------------------------------------------------------------
95 static void gtk_scrolled_window_hscroll_callback( GtkAdjustment
*adjust
,
97 wxScrolledWindow
*win
)
100 wxapp_install_idle_handler();
102 if (g_blockEventsOnDrag
) return;
103 if (!win
->m_hasVMT
) return;
105 win
->GtkHScroll( adjust
->value
,
106 GET_SCROLL_TYPE(GTK_SCROLLED_WINDOW(win
->m_widget
)->hscrollbar
) );
109 //-----------------------------------------------------------------------------
110 // "button_press_event" from scrollbar
111 //-----------------------------------------------------------------------------
113 static gint
gtk_scrollbar_button_press_callback( GtkRange
*widget
,
114 GdkEventButton
*gdk_event
,
118 wxapp_install_idle_handler();
120 g_blockEventsOnScroll
= TRUE
;
122 // FIXME: there is no slider field any more, what was meant here?
124 win
->m_isScrolling
= (gdk_event
->window
== widget
->slider
);
130 //-----------------------------------------------------------------------------
131 // "button_release_event" from scrollbar
132 //-----------------------------------------------------------------------------
134 static gint
gtk_scrollbar_button_release_callback( GtkRange
*widget
,
135 GdkEventButton
*WXUNUSED(gdk_event
),
138 // don't test here as we can release the mouse while being over
139 // a different window than the slider
141 // if (gdk_event->window != widget->slider) return FALSE;
143 g_blockEventsOnScroll
= FALSE
;
145 if (win
->m_isScrolling
)
147 wxEventType command
= wxEVT_SCROLLWIN_THUMBRELEASE
;
151 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(win
->m_widget
);
152 if (widget
== GTK_RANGE(scrolledWindow
->hscrollbar
))
154 value
= (int)(win
->m_hAdjust
->value
+0.5);
157 if (widget
== GTK_RANGE(scrolledWindow
->vscrollbar
))
159 value
= (int)(win
->m_vAdjust
->value
+0.5);
163 wxScrollWinEvent
event( command
, value
, dir
);
164 event
.SetEventObject( win
);
165 win
->GetEventHandler()->ProcessEvent( event
);
168 win
->m_isScrolling
= FALSE
;
173 //-----------------------------------------------------------------------------
174 // InsertChild for wxScrolledWindow
175 //-----------------------------------------------------------------------------
177 static void wxInsertChildInScrolledWindow( wxWindow
* parent
, wxWindow
* child
)
179 // The window might have been scrolled already, do we
180 // have to adapt the position.
181 GtkPizza
*pizza
= GTK_PIZZA(parent
->m_wxwindow
);
182 child
->m_x
+= pizza
->xoffset
;
183 child
->m_y
+= pizza
->yoffset
;
185 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
186 GTK_WIDGET(child
->m_widget
),
193 // ----------------------------------------------------------------------------
194 // wxScrolledWindow creation
195 // ----------------------------------------------------------------------------
197 void wxScrolledWindow::Init()
199 m_xScrollPixelsPerLine
= 0;
200 m_yScrollPixelsPerLine
= 0;
201 m_xScrollingEnabled
= TRUE
;
202 m_yScrollingEnabled
= TRUE
;
203 m_xScrollPosition
= 0;
204 m_yScrollPosition
= 0;
205 m_xScrollLinesPerPage
= 0;
206 m_yScrollLinesPerPage
= 0;
207 m_targetWindow
= (wxWindow
*) NULL
;
210 m_hasScrolling
= TRUE
;
213 bool wxScrolledWindow::Create(wxWindow
*parent
,
218 const wxString
& name
)
222 if (!PreCreation( parent
, pos
, size
) ||
223 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
225 wxFAIL_MSG( wxT("wxWindow creation failed") );
229 m_insertCallback
= wxInsertChildInScrolledWindow
;
231 m_targetWindow
= this;
233 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
234 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
236 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
238 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
239 scroll_class
->scrollbar_spacing
= 0;
241 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
243 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->hscrollbar
) );
244 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->vscrollbar
) );
246 m_wxwindow
= gtk_pizza_new();
248 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
250 GtkPizza
*pizza
= GTK_PIZZA(m_wxwindow
);
252 if (HasFlag(wxRAISED_BORDER
))
254 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_OUT
);
256 else if (HasFlag(wxSUNKEN_BORDER
))
258 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_IN
);
260 else if (HasFlag(wxSIMPLE_BORDER
))
262 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_THIN
);
266 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_NONE
);
269 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
270 m_acceptsFocus
= TRUE
;
272 // I _really_ don't want scrollbars in the beginning
273 m_vAdjust
->lower
= 0.0;
274 m_vAdjust
->upper
= 1.0;
275 m_vAdjust
->value
= 0.0;
276 m_vAdjust
->step_increment
= 1.0;
277 m_vAdjust
->page_increment
= 2.0;
278 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
279 m_hAdjust
->lower
= 0.0;
280 m_hAdjust
->upper
= 1.0;
281 m_hAdjust
->value
= 0.0;
282 m_hAdjust
->step_increment
= 1.0;
283 m_hAdjust
->page_increment
= 2.0;
284 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
286 // Handlers for new scrollbar values
290 // these handlers block mouse events to any window during scrolling such as
291 // motion events and prevent GTK and wxWindows from fighting over where the
294 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_press_event",
295 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
297 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_press_event",
298 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
300 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_release_event",
301 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
303 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_release_event",
304 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
306 gtk_widget_show( m_wxwindow
);
309 m_parent
->DoAddChild( this );
311 m_focusWidget
= m_wxwindow
;
320 // ----------------------------------------------------------------------------
321 // setting scrolling parameters
322 // ----------------------------------------------------------------------------
324 void wxScrolledWindow::DoSetVirtualSize( int x
, int y
)
326 wxPanel::DoSetVirtualSize( x
, y
);
331 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
332 * noUnitsX/noUnitsY: : no. units per scrollbar
334 void wxScrolledWindow::SetScrollbars( int pixelsPerUnitX
, int pixelsPerUnitY
,
335 int noUnitsX
, int noUnitsY
,
336 int xPos
, int yPos
, bool noRefresh
)
338 int old_x
= m_xScrollPixelsPerLine
* m_xScrollPosition
;
339 int old_y
= m_yScrollPixelsPerLine
* m_yScrollPosition
;
341 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
342 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
344 m_hAdjust
->value
= m_xScrollPosition
= xPos
;
345 m_vAdjust
->value
= m_yScrollPosition
= yPos
;
347 m_targetWindow
->SetVirtualSizeHints( noUnitsX
* pixelsPerUnitX
, noUnitsY
* pixelsPerUnitY
);
351 int new_x
= m_xScrollPixelsPerLine
* m_xScrollPosition
;
352 int new_y
= m_yScrollPixelsPerLine
* m_yScrollPosition
;
354 m_targetWindow
->ScrollWindow( old_x
- new_x
, old_y
- new_y
);
358 void wxScrolledWindow::AdjustScrollbars()
363 m_targetWindow
->GetClientSize( &w
, &h
);
364 m_targetWindow
->GetVirtualSize( &vw
, &vh
);
366 if (m_xScrollPixelsPerLine
== 0)
368 m_hAdjust
->upper
= 1.0;
369 m_hAdjust
->page_size
= 1.0;
373 m_hAdjust
->upper
= vw
/ m_xScrollPixelsPerLine
;
374 m_hAdjust
->page_size
= (w
/ m_xScrollPixelsPerLine
);
376 // If the scrollbar hits the right side, move the window
377 // right to keep it from over extending.
379 if( m_hAdjust
->value
+ m_hAdjust
->page_size
> m_hAdjust
->upper
)
381 m_hAdjust
->value
= m_hAdjust
->upper
- m_hAdjust
->page_size
;
382 m_targetWindow
->ScrollWindow( (m_xScrollPosition
- m_hAdjust
->value
) * m_xScrollPixelsPerLine
, 0 );
383 m_xScrollPosition
= (int)m_hAdjust
->value
;
387 if (m_yScrollPixelsPerLine
== 0)
389 m_vAdjust
->upper
= 1.0;
390 m_vAdjust
->page_size
= 1.0;
394 m_vAdjust
->upper
= vh
/ m_yScrollPixelsPerLine
;
395 m_vAdjust
->page_size
= (h
/ m_yScrollPixelsPerLine
);
397 if( m_vAdjust
->value
+ m_vAdjust
->page_size
> m_vAdjust
->upper
)
399 m_vAdjust
->value
= m_vAdjust
->upper
- m_vAdjust
->page_size
;
400 m_targetWindow
->ScrollWindow( 0, (m_yScrollPosition
- m_vAdjust
->value
) * m_yScrollPixelsPerLine
);
401 m_yScrollPosition
= (int)m_vAdjust
->value
;
405 m_xScrollLinesPerPage
= (int)(m_hAdjust
->page_size
+ 0.5);
406 m_yScrollLinesPerPage
= (int)(m_vAdjust
->page_size
+ 0.5);
408 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
409 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
413 // ----------------------------------------------------------------------------
414 // target window handling
415 // ----------------------------------------------------------------------------
417 void wxScrolledWindow::SetTargetWindow( wxWindow
*target
, bool WXUNUSED(pushEventHandler
) )
419 wxASSERT_MSG( target
, wxT("target window must not be NULL") );
420 m_targetWindow
= target
;
423 wxWindow
*wxScrolledWindow::GetTargetWindow()
425 return m_targetWindow
;
428 // Override this function if you don't want to have wxScrolledWindow
429 // automatically change the origin according to the scroll position.
430 void wxScrolledWindow::PrepareDC(wxDC
& dc
)
432 dc
.SetDeviceOrigin( -m_xScrollPosition
* m_xScrollPixelsPerLine
,
433 -m_yScrollPosition
* m_yScrollPixelsPerLine
);
436 void wxScrolledWindow::SetScrollRate( int xstep
, int ystep
)
438 int old_x
= m_xScrollPixelsPerLine
* m_xScrollPosition
;
439 int old_y
= m_yScrollPixelsPerLine
* m_yScrollPosition
;
441 m_xScrollPixelsPerLine
= xstep
;
442 m_yScrollPixelsPerLine
= ystep
;
444 int new_x
= m_xScrollPixelsPerLine
* m_xScrollPosition
;
445 int new_y
= m_yScrollPixelsPerLine
* m_yScrollPosition
;
447 m_targetWindow
->ScrollWindow( old_x
- new_x
, old_y
- new_y
);
452 void wxScrolledWindow::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
455 *x_unit
= m_xScrollPixelsPerLine
;
457 *y_unit
= m_yScrollPixelsPerLine
;
460 int wxScrolledWindow::GetScrollPageSize(int orient
) const
462 if ( orient
== wxHORIZONTAL
)
463 return m_xScrollLinesPerPage
;
465 return m_yScrollLinesPerPage
;
468 void wxScrolledWindow::SetScrollPageSize(int orient
, int pageSize
)
470 if ( orient
== wxHORIZONTAL
)
471 m_xScrollLinesPerPage
= pageSize
;
473 m_yScrollLinesPerPage
= pageSize
;
476 void wxScrolledWindow::OnScroll(wxScrollWinEvent
& event
)
478 int orient
= event
.GetOrientation();
480 int nScrollInc
= CalcScrollInc(event
);
481 if (nScrollInc
== 0) return;
483 if (orient
== wxHORIZONTAL
)
485 int newPos
= m_xScrollPosition
+ nScrollInc
;
486 SetScrollPos(wxHORIZONTAL
, newPos
, TRUE
);
490 int newPos
= m_yScrollPosition
+ nScrollInc
;
491 SetScrollPos(wxVERTICAL
, newPos
, TRUE
);
494 if (orient
== wxHORIZONTAL
)
496 m_xScrollPosition
+= nScrollInc
;
500 m_yScrollPosition
+= nScrollInc
;
503 if (orient
== wxHORIZONTAL
)
505 if (m_xScrollingEnabled
)
506 m_targetWindow
->ScrollWindow(-m_xScrollPixelsPerLine
* nScrollInc
, 0, (const wxRect
*) NULL
);
508 m_targetWindow
->Refresh();
512 if (m_yScrollingEnabled
)
513 m_targetWindow
->ScrollWindow(0, -m_yScrollPixelsPerLine
* nScrollInc
, (const wxRect
*) NULL
);
515 m_targetWindow
->Refresh();
519 void wxScrolledWindow::Scroll( int x_pos
, int y_pos
)
521 wxASSERT_MSG( m_targetWindow
!= 0, _T("No target window") );
523 if (((x_pos
== -1) || (x_pos
== m_xScrollPosition
)) &&
524 ((y_pos
== -1) || (y_pos
== m_yScrollPosition
))) return;
526 if ((x_pos
!= -1) && (m_xScrollPixelsPerLine
))
528 int max
= (int)(m_hAdjust
->upper
- m_hAdjust
->page_size
+ 0.5);
529 if (max
< 0) max
= 0;
530 if (x_pos
> max
) x_pos
= max
;
531 if (x_pos
< 0) x_pos
= 0;
533 int old_x
= m_xScrollPosition
;
534 m_xScrollPosition
= x_pos
;
535 m_hAdjust
->value
= x_pos
;
537 m_targetWindow
->ScrollWindow( (old_x
-m_xScrollPosition
)*m_xScrollPixelsPerLine
, 0 );
539 // Just update the scrollbar, don't send any wxWindows event
540 GtkHDisconnectEvent();
541 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
545 if ((y_pos
!= -1) && (m_yScrollPixelsPerLine
))
547 int max
= (int)(m_vAdjust
->upper
- m_vAdjust
->page_size
+ 0.5);
548 if (max
< 0) max
= 0;
549 if (y_pos
> max
) y_pos
= max
;
550 if (y_pos
< 0) y_pos
= 0;
552 int old_y
= m_yScrollPosition
;
553 m_yScrollPosition
= y_pos
;
554 m_vAdjust
->value
= y_pos
;
556 m_targetWindow
->ScrollWindow( 0, (old_y
-m_yScrollPosition
)*m_yScrollPixelsPerLine
);
558 // Just update the scrollbar, don't send any wxWindows event
559 GtkVDisconnectEvent();
560 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
565 // TODO: [VH]Scroll functions should be combined
567 void wxScrolledWindow::GtkVScroll( float value
, unsigned int scroll_type
)
569 wxASSERT_MSG( m_targetWindow
!= 0, _T("No target window") );
571 if (m_yScrollPixelsPerLine
== 0)
574 int y_pos
= (int)(value
+0.5);
576 if (y_pos
== m_yScrollPosition
)
579 wxEventType command
= GtkScrollWinTypeToWx(scroll_type
);
581 wxScrollWinEvent
event( command
, y_pos
, wxVERTICAL
);
582 event
.SetEventObject( this );
583 GetEventHandler()->ProcessEvent( event
);
586 void wxScrolledWindow::GtkHScroll( float value
, unsigned int scroll_type
)
588 wxASSERT_MSG( m_targetWindow
!= 0, _T("No target window") );
590 if (m_xScrollPixelsPerLine
== 0)
593 int x_pos
= (int)(value
+0.5);
595 if (x_pos
== m_xScrollPosition
)
598 wxEventType command
= GtkScrollWinTypeToWx(scroll_type
);
600 wxScrollWinEvent
event( command
, x_pos
, wxHORIZONTAL
);
601 event
.SetEventObject( this );
602 GetEventHandler()->ProcessEvent( event
);
605 void wxScrolledWindow::EnableScrolling (bool x_scroll
, bool y_scroll
)
607 m_xScrollingEnabled
= x_scroll
;
608 m_yScrollingEnabled
= y_scroll
;
611 // Where the current view starts from
612 void wxScrolledWindow::GetViewStart (int *x
, int *y
) const
615 *x
= m_xScrollPosition
;
617 *y
= m_yScrollPosition
;
620 void wxScrolledWindow::DoCalcScrolledPosition(int x
, int y
, int *xx
, int *yy
) const
623 *xx
= x
- m_xScrollPosition
* m_xScrollPixelsPerLine
;
625 *yy
= y
- m_yScrollPosition
* m_yScrollPixelsPerLine
;
628 void wxScrolledWindow::DoCalcUnscrolledPosition(int x
, int y
, int *xx
, int *yy
) const
631 *xx
= x
+ m_xScrollPosition
* m_xScrollPixelsPerLine
;
633 *yy
= y
+ m_yScrollPosition
* m_yScrollPixelsPerLine
;
636 int wxScrolledWindow::CalcScrollInc(wxScrollWinEvent
& event
)
638 int pos
= event
.GetPosition();
639 int orient
= event
.GetOrientation();
642 if (event
.GetEventType() == wxEVT_SCROLLWIN_TOP
)
644 if (orient
== wxHORIZONTAL
)
645 nScrollInc
= - m_xScrollPosition
;
647 nScrollInc
= - m_yScrollPosition
;
649 if (event
.GetEventType() == wxEVT_SCROLLWIN_BOTTOM
)
651 if (orient
== wxHORIZONTAL
)
652 nScrollInc
= GetVirtualSize().GetWidth() / m_xScrollPixelsPerLine
- m_xScrollPosition
;
654 nScrollInc
= GetVirtualSize().GetHeight() / m_yScrollPixelsPerLine
- m_yScrollPosition
;
656 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEUP
)
660 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN
)
664 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEUP
)
666 if (orient
== wxHORIZONTAL
)
667 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
669 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
671 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN
)
673 if (orient
== wxHORIZONTAL
)
674 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
676 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
678 if ((event
.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK
) ||
679 (event
.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE
))
681 if (orient
== wxHORIZONTAL
)
682 nScrollInc
= pos
- m_xScrollPosition
;
684 nScrollInc
= pos
- m_yScrollPosition
;
687 if (orient
== wxHORIZONTAL
)
689 if (m_xScrollPixelsPerLine
> 0)
691 int max
= (int)(m_hAdjust
->upper
- m_hAdjust
->page_size
+ 0.5);
692 if (max
< 0) max
= 0;
694 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
695 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
696 else if ( (m_xScrollPosition
+ nScrollInc
) > max
)
697 nScrollInc
= max
- m_xScrollPosition
; // As +ve as we can go
700 m_targetWindow
->Refresh();
704 if (m_yScrollPixelsPerLine
> 0)
706 int max
= (int)(m_vAdjust
->upper
- m_vAdjust
->page_size
+ 0.5);
707 if (max
< 0) max
= 0;
709 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
710 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
711 else if ( (m_yScrollPosition
+ nScrollInc
) > max
)
712 nScrollInc
= max
- m_yScrollPosition
; // As +ve as we can go
715 m_targetWindow
->Refresh();
721 void wxScrolledWindow::SetScrollPos( int orient
, int pos
, bool refresh
)
723 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
725 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
727 if (orient
== wxHORIZONTAL
)
729 int max
= (int)(m_hAdjust
->upper
- m_hAdjust
->page_size
+ 0.5);
730 if (max
< 0) max
= 0;
732 if (pos
> max
) pos
= 0;
733 if (pos
< 0) pos
= 0;
735 if (pos
== (int)(m_hAdjust
->value
+0.5)) return;
736 m_hAdjust
->value
= pos
;
740 int max
= (int)(m_vAdjust
->upper
- m_vAdjust
->page_size
+ 0.5);
741 if (max
< 0) max
= 0;
743 if (pos
> max
) pos
= 0;
744 if (pos
< 0) pos
= 0;
746 if (pos
== (int)(m_vAdjust
->value
+0.5)) return;
747 m_vAdjust
->value
= pos
;
750 if (m_wxwindow
->window
)
752 if (orient
== wxHORIZONTAL
)
754 // Just update the scrollbar, don't send any wxWindows event
755 GtkHDisconnectEvent();
756 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
761 // Just update the scrollbar, don't send any wxWindows event
762 GtkVDisconnectEvent();
763 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
769 void wxScrolledWindow::GtkVConnectEvent()
771 gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed",
772 (GtkSignalFunc
) gtk_scrolled_window_vscroll_callback
, (gpointer
) this );
775 void wxScrolledWindow::GtkHConnectEvent()
777 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed",
778 (GtkSignalFunc
) gtk_scrolled_window_hscroll_callback
, (gpointer
) this );
781 void wxScrolledWindow::GtkHDisconnectEvent()
783 gtk_signal_disconnect_by_func( GTK_OBJECT(m_hAdjust
),
784 (GtkSignalFunc
) gtk_scrolled_window_hscroll_callback
, (gpointer
) this );
787 void wxScrolledWindow::GtkVDisconnectEvent()
789 gtk_signal_disconnect_by_func( GTK_OBJECT(m_vAdjust
),
790 (GtkSignalFunc
) gtk_scrolled_window_vscroll_callback
, (gpointer
) this );
793 bool wxScrolledWindow::Layout()
795 if (GetSizer() && m_targetWindow
== this)
797 // If we're the scroll target, take into account the
798 // virtual size and scrolled position of the window.
801 CalcScrolledPosition(0,0, &x
,&y
);
802 GetVirtualSize(&w
, &h
);
803 GetSizer()->SetDimension(x
, y
, w
, h
);
807 return wxPanel::Layout(); // fall back to default for LayoutConstraints
810 // ----------------------------------------------------------------------------
812 // ----------------------------------------------------------------------------
814 // Default OnSize resets scrollbars, if any
815 void wxScrolledWindow::OnSize(wxSizeEvent
& WXUNUSED(event
))
817 if( m_targetWindow
!= this )
818 m_targetWindow
->SetVirtualSize( m_targetWindow
->GetClientSize() );
820 SetVirtualSize( GetClientSize() );
822 #if wxUSE_CONSTRAINTS
828 // This calls OnDraw, having adjusted the origin according to the current
830 void wxScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
838 // kbd handling: notice that we use OnChar() and not OnKeyDown() for
839 // compatibility here - if we used OnKeyDown(), the programs which process
840 // arrows themselves in their OnChar() would never get the message and like
841 // this they always have the priority
842 void wxScrolledWindow::OnChar(wxKeyEvent
& event
)
844 int stx
, sty
, // view origin
845 szx
, szy
, // view size (total)
846 clix
, cliy
; // view size (on screen)
848 ViewStart(&stx
, &sty
);
849 GetClientSize(&clix
, &cliy
);
850 GetVirtualSize(&szx
, &szy
);
852 if( m_xScrollPixelsPerLine
)
854 clix
/= m_xScrollPixelsPerLine
;
855 szx
/= m_xScrollPixelsPerLine
;
862 if( m_yScrollPixelsPerLine
)
864 cliy
/= m_yScrollPixelsPerLine
;
865 szy
/= m_yScrollPixelsPerLine
;
873 int xScrollOld
= GetScrollPos(wxHORIZONTAL
),
874 yScrollOld
= GetScrollPos(wxVERTICAL
);
877 switch ( event
.KeyCode() )
881 dsty
= sty
- (5 * cliy
/ 6);
882 Scroll(-1, (dsty
== -1) ? 0 : dsty
);
887 Scroll(-1, sty
+ (5 * cliy
/ 6));
891 Scroll(0, event
.ControlDown() ? 0 : -1);
895 Scroll(szx
- clix
, event
.ControlDown() ? szy
- cliy
: -1);
920 int xScroll
= GetScrollPos(wxHORIZONTAL
);
921 if ( xScroll
!= xScrollOld
)
923 wxScrollWinEvent
event(wxEVT_SCROLLWIN_THUMBTRACK
, xScroll
,
925 event
.SetEventObject(this);
926 GetEventHandler()->ProcessEvent(event
);
929 int yScroll
= GetScrollPos(wxVERTICAL
);
930 if ( yScroll
!= yScrollOld
)
932 wxScrollWinEvent
event(wxEVT_SCROLLWIN_THUMBTRACK
, yScroll
,
934 event
.SetEventObject(this);
935 GetEventHandler()->ProcessEvent(event
);