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/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
;
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
, wxScrolledWindow
*win
)
78 wxapp_install_idle_handler();
80 if (g_blockEventsOnDrag
) return;
82 if (!win
->m_hasVMT
) return;
84 win
->GtkVScroll( adjust
->value
);
87 //-----------------------------------------------------------------------------
88 // "value_changed" from m_hAdjust
89 //-----------------------------------------------------------------------------
91 static void gtk_scrolled_window_hscroll_callback( GtkAdjustment
*adjust
, wxScrolledWindow
*win
)
94 wxapp_install_idle_handler();
96 if (g_blockEventsOnDrag
) return;
97 if (!win
->m_hasVMT
) return;
99 win
->GtkHScroll( adjust
->value
);
102 //-----------------------------------------------------------------------------
103 // "button_press_event" from scrollbar
104 //-----------------------------------------------------------------------------
106 static gint
gtk_scrollbar_button_press_callback( GtkRange
*widget
,
107 GdkEventButton
*gdk_event
,
111 wxapp_install_idle_handler();
113 g_blockEventsOnScroll
= TRUE
;
114 win
->m_isScrolling
= (gdk_event
->window
== widget
->slider
);
119 //-----------------------------------------------------------------------------
120 // "button_release_event" from scrollbar
121 //-----------------------------------------------------------------------------
123 static gint
gtk_scrollbar_button_release_callback( GtkRange
*widget
,
124 GdkEventButton
*WXUNUSED(gdk_event
),
127 // don't test here as we can release the mouse while being over
128 // a different window than the slider
130 // if (gdk_event->window != widget->slider) return FALSE;
132 g_blockEventsOnScroll
= FALSE
;
134 if (win
->m_isScrolling
)
136 wxEventType command
= wxEVT_SCROLLWIN_THUMBRELEASE
;
140 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(win
->m_widget
);
141 if (widget
== GTK_RANGE(scrolledWindow
->hscrollbar
))
143 value
= (int)(win
->m_hAdjust
->value
+0.5);
146 if (widget
== GTK_RANGE(scrolledWindow
->vscrollbar
))
148 value
= (int)(win
->m_vAdjust
->value
+0.5);
152 wxScrollWinEvent
event( command
, value
, dir
);
153 event
.SetEventObject( win
);
154 win
->GetEventHandler()->ProcessEvent( event
);
157 win
->m_isScrolling
= FALSE
;
162 //-----------------------------------------------------------------------------
163 // InsertChild for wxScrolledWindow
164 //-----------------------------------------------------------------------------
166 static void wxInsertChildInScrolledWindow( wxWindow
* parent
, wxWindow
* child
)
168 // The window might have been scrolled already, do we
169 // have to adapt the position.
170 GtkPizza
*pizza
= GTK_PIZZA(parent
->m_wxwindow
);
171 child
->m_x
+= pizza
->xoffset
;
172 child
->m_y
+= pizza
->yoffset
;
174 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
175 GTK_WIDGET(child
->m_widget
),
182 // ----------------------------------------------------------------------------
183 // wxScrolledWindow creation
184 // ----------------------------------------------------------------------------
186 void wxScrolledWindow::Init()
188 m_xScrollPixelsPerLine
= 0;
189 m_yScrollPixelsPerLine
= 0;
190 m_xScrollingEnabled
= TRUE
;
191 m_yScrollingEnabled
= TRUE
;
192 m_xScrollPosition
= 0;
193 m_yScrollPosition
= 0;
196 m_xScrollLinesPerPage
= 0;
197 m_yScrollLinesPerPage
= 0;
198 m_targetWindow
= (wxWindow
*) NULL
;
201 m_hasScrolling
= TRUE
;
204 bool wxScrolledWindow::Create(wxWindow
*parent
,
209 const wxString
& name
)
213 if (!PreCreation( parent
, pos
, size
) ||
214 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
216 wxFAIL_MSG( wxT("wxWindow creation failed") );
220 m_insertCallback
= wxInsertChildInScrolledWindow
;
222 m_targetWindow
= this;
224 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
225 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
227 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
229 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
230 scroll_class
->scrollbar_spacing
= 0;
232 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
234 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->hscrollbar
) );
235 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->vscrollbar
) );
237 m_wxwindow
= gtk_pizza_new();
239 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
241 GtkPizza
*pizza
= GTK_PIZZA(m_wxwindow
);
243 if (HasFlag(wxRAISED_BORDER
))
245 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_OUT
);
247 else if (HasFlag(wxSUNKEN_BORDER
))
249 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_IN
);
251 else if (HasFlag(wxSIMPLE_BORDER
))
253 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_THIN
);
257 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_NONE
);
260 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
261 m_acceptsFocus
= TRUE
;
263 // I _really_ don't want scrollbars in the beginning
264 m_vAdjust
->lower
= 0.0;
265 m_vAdjust
->upper
= 1.0;
266 m_vAdjust
->value
= 0.0;
267 m_vAdjust
->step_increment
= 1.0;
268 m_vAdjust
->page_increment
= 1.0;
269 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
270 m_hAdjust
->lower
= 0.0;
271 m_hAdjust
->upper
= 1.0;
272 m_hAdjust
->value
= 0.0;
273 m_hAdjust
->step_increment
= 1.0;
274 m_hAdjust
->page_increment
= 1.0;
275 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
277 // Handlers for new scrollbar values
281 // these handlers block mouse events to any window during scrolling such as
282 // motion events and prevent GTK and wxWindows from fighting over where the
285 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_press_event",
286 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
288 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_press_event",
289 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
291 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_release_event",
292 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
294 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_release_event",
295 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
297 gtk_widget_show( m_wxwindow
);
300 m_parent
->DoAddChild( this );
302 m_focusWidget
= m_wxwindow
;
311 // ----------------------------------------------------------------------------
312 // setting scrolling parameters
313 // ----------------------------------------------------------------------------
316 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
317 * noUnitsX/noUnitsY: : no. units per scrollbar
319 void wxScrolledWindow::SetScrollbars (int pixelsPerUnitX
, int pixelsPerUnitY
,
320 int noUnitsX
, int noUnitsY
,
321 int xPos
, int yPos
, bool noRefresh
)
323 int old_x
= m_xScrollPixelsPerLine
* m_xScrollPosition
;
324 int old_y
= m_yScrollPixelsPerLine
* m_yScrollPosition
;
326 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
327 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
328 m_xScrollLines
= noUnitsX
;
329 m_yScrollLines
= noUnitsY
;
330 m_xScrollPosition
= xPos
;
331 m_yScrollPosition
= yPos
;
333 m_hAdjust
->lower
= 0.0;
334 m_hAdjust
->upper
= noUnitsX
;
335 m_hAdjust
->value
= xPos
;
336 m_hAdjust
->step_increment
= 1.0;
337 m_hAdjust
->page_increment
= 2.0;
339 m_vAdjust
->lower
= 0.0;
340 m_vAdjust
->upper
= noUnitsY
;
341 m_vAdjust
->value
= yPos
;
342 m_vAdjust
->step_increment
= 1.0;
343 m_vAdjust
->page_increment
= 2.0;
349 int new_x
= m_xScrollPixelsPerLine
* m_xScrollPosition
;
350 int new_y
= m_yScrollPixelsPerLine
* m_yScrollPosition
;
352 m_targetWindow
->ScrollWindow( old_x
-new_x
, old_y
-new_y
);
356 void wxScrolledWindow::AdjustScrollbars()
359 m_targetWindow
->GetClientSize( &w
, &h
);
361 if (m_xScrollPixelsPerLine
== 0)
362 m_hAdjust
->page_size
= 1.0;
364 m_hAdjust
->page_size
= (w
/ m_xScrollPixelsPerLine
);
366 if (m_yScrollPixelsPerLine
== 0)
367 m_vAdjust
->page_size
= 1.0;
369 m_vAdjust
->page_size
= (h
/ m_yScrollPixelsPerLine
);
371 m_xScrollLinesPerPage
= (int)(m_hAdjust
->page_size
+ 0.5);
372 m_yScrollLinesPerPage
= (int)(m_vAdjust
->page_size
+ 0.5);
374 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
375 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
378 // ----------------------------------------------------------------------------
379 // target window handling
380 // ----------------------------------------------------------------------------
382 void wxScrolledWindow::SetTargetWindow( wxWindow
*target
, bool WXUNUSED(pushEventHandler
) )
384 wxASSERT_MSG( target
, wxT("target window must not be NULL") );
385 m_targetWindow
= target
;
388 wxWindow
*wxScrolledWindow::GetTargetWindow()
390 return m_targetWindow
;
393 // Override this function if you don't want to have wxScrolledWindow
394 // automatically change the origin according to the scroll position.
395 void wxScrolledWindow::PrepareDC(wxDC
& dc
)
397 dc
.SetDeviceOrigin( -m_xScrollPosition
* m_xScrollPixelsPerLine
,
398 -m_yScrollPosition
* m_yScrollPixelsPerLine
);
401 void wxScrolledWindow::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
404 *x_unit
= m_xScrollPixelsPerLine
;
406 *y_unit
= m_yScrollPixelsPerLine
;
409 int wxScrolledWindow::GetScrollPageSize(int orient
) const
411 if ( orient
== wxHORIZONTAL
)
412 return m_xScrollLinesPerPage
;
414 return m_yScrollLinesPerPage
;
417 void wxScrolledWindow::SetScrollPageSize(int orient
, int pageSize
)
419 if ( orient
== wxHORIZONTAL
)
420 m_xScrollLinesPerPage
= pageSize
;
422 m_yScrollLinesPerPage
= pageSize
;
425 void wxScrolledWindow::OnScroll(wxScrollWinEvent
& event
)
427 int orient
= event
.GetOrientation();
429 int nScrollInc
= CalcScrollInc(event
);
430 if (nScrollInc
== 0) return;
432 if (orient
== wxHORIZONTAL
)
434 int newPos
= m_xScrollPosition
+ nScrollInc
;
435 SetScrollPos(wxHORIZONTAL
, newPos
, TRUE
);
439 int newPos
= m_yScrollPosition
+ nScrollInc
;
440 SetScrollPos(wxVERTICAL
, newPos
, TRUE
);
443 if (orient
== wxHORIZONTAL
)
445 m_xScrollPosition
+= nScrollInc
;
449 m_yScrollPosition
+= nScrollInc
;
452 if (orient
== wxHORIZONTAL
)
454 if (m_xScrollingEnabled
)
455 m_targetWindow
->ScrollWindow(-m_xScrollPixelsPerLine
* nScrollInc
, 0, (const wxRect
*) NULL
);
457 m_targetWindow
->Refresh();
461 if (m_yScrollingEnabled
)
462 m_targetWindow
->ScrollWindow(0, -m_yScrollPixelsPerLine
* nScrollInc
, (const wxRect
*) NULL
);
464 m_targetWindow
->Refresh();
468 void wxScrolledWindow::Scroll( int x_pos
, int y_pos
)
473 if (((x_pos
== -1) || (x_pos
== m_xScrollPosition
)) &&
474 ((y_pos
== -1) || (y_pos
== m_yScrollPosition
))) return;
476 if ((x_pos
!= -1) && (m_xScrollPixelsPerLine
))
478 int max
= (int)(m_hAdjust
->upper
- m_hAdjust
->page_size
+ 0.5);
479 if (max
< 0) max
= 0;
480 if (x_pos
> max
) x_pos
= max
;
481 if (x_pos
< 0) x_pos
= 0;
483 int old_x
= m_xScrollPosition
;
484 m_xScrollPosition
= x_pos
;
485 m_hAdjust
->value
= x_pos
;
487 m_targetWindow
->ScrollWindow( (old_x
-m_xScrollPosition
)*m_xScrollPixelsPerLine
, 0 );
489 // Just update the scrollbar, don't send any wxWindows event
490 GtkHDisconnectEvent();
491 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
495 if ((y_pos
!= -1) && (m_yScrollPixelsPerLine
))
497 int max
= (int)(m_vAdjust
->upper
- m_vAdjust
->page_size
+ 0.5);
498 if (max
< 0) max
= 0;
499 if (y_pos
> max
) y_pos
= max
;
500 if (y_pos
< 0) y_pos
= 0;
502 int old_y
= m_yScrollPosition
;
503 m_yScrollPosition
= y_pos
;
504 m_vAdjust
->value
= y_pos
;
506 m_targetWindow
->ScrollWindow( 0, (old_y
-m_yScrollPosition
)*m_yScrollPixelsPerLine
);
508 // Just update the scrollbar, don't send any wxWindows event
509 GtkVDisconnectEvent();
510 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
515 void wxScrolledWindow::GtkVScroll( float value
)
520 if (m_yScrollPixelsPerLine
== 0)
523 int y_pos
= (int)(value
+0.5);
525 if (y_pos
== m_yScrollPosition
)
528 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
529 GtkRange
*range
= GTK_RANGE(scrolledWindow
->vscrollbar
);
531 wxEventType command
= wxEVT_SCROLLWIN_THUMBTRACK
;
532 if (range
->scroll_type
== GTK_SCROLL_STEP_BACKWARD
) command
= wxEVT_SCROLLWIN_LINEUP
;
533 else if (range
->scroll_type
== GTK_SCROLL_STEP_FORWARD
) command
= wxEVT_SCROLLWIN_LINEDOWN
;
534 else if (range
->scroll_type
== GTK_SCROLL_PAGE_BACKWARD
) command
= wxEVT_SCROLLWIN_PAGEUP
;
535 else if (range
->scroll_type
== GTK_SCROLL_PAGE_FORWARD
) command
= wxEVT_SCROLLWIN_PAGEDOWN
;
537 wxScrollWinEvent
event( command
, y_pos
, wxVERTICAL
);
538 event
.SetEventObject( this );
539 GetEventHandler()->ProcessEvent( event
);
542 void wxScrolledWindow::GtkHScroll( float value
)
547 if (m_xScrollPixelsPerLine
== 0)
550 int x_pos
= (int)(value
+0.5);
552 if (x_pos
== m_xScrollPosition
)
555 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
556 GtkRange
*range
= GTK_RANGE(scrolledWindow
->hscrollbar
);
558 wxEventType command
= wxEVT_SCROLLWIN_THUMBTRACK
;
559 if (range
->scroll_type
== GTK_SCROLL_STEP_BACKWARD
) command
= wxEVT_SCROLLWIN_LINEUP
;
560 else if (range
->scroll_type
== GTK_SCROLL_STEP_FORWARD
) command
= wxEVT_SCROLLWIN_LINEDOWN
;
561 else if (range
->scroll_type
== GTK_SCROLL_PAGE_BACKWARD
) command
= wxEVT_SCROLLWIN_PAGEUP
;
562 else if (range
->scroll_type
== GTK_SCROLL_PAGE_FORWARD
) command
= wxEVT_SCROLLWIN_PAGEDOWN
;
564 wxScrollWinEvent
event( command
, x_pos
, wxHORIZONTAL
);
565 event
.SetEventObject( this );
566 GetEventHandler()->ProcessEvent( event
);
569 void wxScrolledWindow::EnableScrolling (bool x_scroll
, bool y_scroll
)
571 m_xScrollingEnabled
= x_scroll
;
572 m_yScrollingEnabled
= y_scroll
;
575 void wxScrolledWindow::GetVirtualSize (int *x
, int *y
) const
578 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
580 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
583 // Where the current view starts from
584 void wxScrolledWindow::GetViewStart (int *x
, int *y
) const
587 *x
= m_xScrollPosition
;
589 *y
= m_yScrollPosition
;
592 void wxScrolledWindow::CalcScrolledPosition(int x
, int y
, int *xx
, int *yy
) const
595 *xx
= x
- m_xScrollPosition
* m_xScrollPixelsPerLine
;
597 *yy
= y
- m_yScrollPosition
* m_yScrollPixelsPerLine
;
600 void wxScrolledWindow::CalcUnscrolledPosition(int x
, int y
, int *xx
, int *yy
) const
603 *xx
= x
+ m_xScrollPosition
* m_xScrollPixelsPerLine
;
605 *yy
= y
+ m_yScrollPosition
* m_yScrollPixelsPerLine
;
608 int wxScrolledWindow::CalcScrollInc(wxScrollWinEvent
& event
)
610 int pos
= event
.GetPosition();
611 int orient
= event
.GetOrientation();
614 if (event
.GetEventType() == wxEVT_SCROLLWIN_TOP
)
616 if (orient
== wxHORIZONTAL
)
617 nScrollInc
= - m_xScrollPosition
;
619 nScrollInc
= - m_yScrollPosition
;
621 if (event
.GetEventType() == wxEVT_SCROLLWIN_BOTTOM
)
623 if (orient
== wxHORIZONTAL
)
624 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
626 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
628 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEUP
)
632 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN
)
636 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEUP
)
638 if (orient
== wxHORIZONTAL
)
639 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
641 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
643 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN
)
645 if (orient
== wxHORIZONTAL
)
646 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
648 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
650 if ((event
.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK
) ||
651 (event
.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE
))
653 if (orient
== wxHORIZONTAL
)
654 nScrollInc
= pos
- m_xScrollPosition
;
656 nScrollInc
= pos
- m_yScrollPosition
;
659 if (orient
== wxHORIZONTAL
)
661 if (m_xScrollPixelsPerLine
> 0)
663 int max
= (int)(m_hAdjust
->upper
- m_hAdjust
->page_size
+ 0.5);
664 if (max
< 0) max
= 0;
666 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
667 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
668 else if ( (m_xScrollPosition
+ nScrollInc
) > max
)
669 nScrollInc
= max
- m_xScrollPosition
; // As +ve as we can go
672 m_targetWindow
->Refresh();
676 if (m_yScrollPixelsPerLine
> 0)
678 int max
= (int)(m_vAdjust
->upper
- m_vAdjust
->page_size
+ 0.5);
679 if (max
< 0) max
= 0;
681 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
682 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
683 else if ( (m_yScrollPosition
+ nScrollInc
) > max
)
684 nScrollInc
= max
- m_yScrollPosition
; // As +ve as we can go
687 m_targetWindow
->Refresh();
693 void wxScrolledWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
695 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
697 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
699 if (orient
== wxHORIZONTAL
)
701 int max
= (int)(m_hAdjust
->upper
- m_hAdjust
->page_size
+ 0.5);
702 if (max
< 0) max
= 0;
704 if (pos
> max
) pos
= 0;
705 if (pos
< 0) pos
= 0;
707 if (pos
== (int)(m_hAdjust
->value
+0.5)) return;
708 m_hAdjust
->value
= pos
;
712 int max
= (int)(m_vAdjust
->upper
- m_vAdjust
->page_size
+ 0.5);
713 if (max
< 0) max
= 0;
715 if (pos
> max
) pos
= 0;
716 if (pos
< 0) pos
= 0;
718 if (pos
== (int)(m_vAdjust
->value
+0.5)) return;
719 m_vAdjust
->value
= pos
;
722 if (m_wxwindow
->window
)
724 if (orient
== wxHORIZONTAL
)
726 // Just update the scrollbar, don't send any wxWindows event
727 GtkHDisconnectEvent();
728 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
733 // Just update the scrollbar, don't send any wxWindows event
734 GtkVDisconnectEvent();
735 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
741 void wxScrolledWindow::GtkVConnectEvent()
743 gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed",
744 (GtkSignalFunc
) gtk_scrolled_window_vscroll_callback
, (gpointer
) this );
747 void wxScrolledWindow::GtkHConnectEvent()
749 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed",
750 (GtkSignalFunc
) gtk_scrolled_window_hscroll_callback
, (gpointer
) this );
753 void wxScrolledWindow::GtkHDisconnectEvent()
755 gtk_signal_disconnect_by_func( GTK_OBJECT(m_hAdjust
),
756 (GtkSignalFunc
) gtk_scrolled_window_hscroll_callback
, (gpointer
) this );
759 void wxScrolledWindow::GtkVDisconnectEvent()
761 gtk_signal_disconnect_by_func( GTK_OBJECT(m_vAdjust
),
762 (GtkSignalFunc
) gtk_scrolled_window_vscroll_callback
, (gpointer
) this );
765 // ----------------------------------------------------------------------------
767 // ----------------------------------------------------------------------------
769 // Default OnSize resets scrollbars, if any
770 void wxScrolledWindow::OnSize(wxSizeEvent
& WXUNUSED(event
))
772 #if wxUSE_CONSTRAINTS
780 // This calls OnDraw, having adjusted the origin according to the current
782 void wxScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
790 // kbd handling: notice that we use OnChar() and not OnKeyDown() for
791 // compatibility here - if we used OnKeyDown(), the programs which process
792 // arrows themselves in their OnChar() would never get the message and like
793 // this they always have the priority
794 void wxScrolledWindow::OnChar(wxKeyEvent
& event
)
796 int stx
, sty
, // view origin
797 szx
, szy
, // view size (total)
798 clix
, cliy
; // view size (on screen)
800 ViewStart(&stx
, &sty
);
801 GetClientSize(&clix
, &cliy
);
802 GetVirtualSize(&szx
, &szy
);
804 if( m_xScrollPixelsPerLine
)
806 clix
/= m_xScrollPixelsPerLine
;
807 szx
/= m_xScrollPixelsPerLine
;
814 if( m_yScrollPixelsPerLine
)
816 cliy
/= m_yScrollPixelsPerLine
;
817 szy
/= m_yScrollPixelsPerLine
;
825 int xScrollOld
= GetScrollPos(wxHORIZONTAL
),
826 yScrollOld
= GetScrollPos(wxVERTICAL
);
829 switch ( event
.KeyCode() )
833 dsty
= sty
- (5 * cliy
/ 6);
834 Scroll(-1, (dsty
== -1) ? 0 : dsty
);
839 Scroll(-1, sty
+ (5 * cliy
/ 6));
843 Scroll(0, event
.ControlDown() ? 0 : -1);
847 Scroll(szx
- clix
, event
.ControlDown() ? szy
- cliy
: -1);
872 int xScroll
= GetScrollPos(wxHORIZONTAL
);
873 if ( xScroll
!= xScrollOld
)
875 wxScrollWinEvent
event(wxEVT_SCROLLWIN_THUMBTRACK
, xScroll
,
877 event
.SetEventObject(this);
878 GetEventHandler()->ProcessEvent(event
);
881 int yScroll
= GetScrollPos(wxVERTICAL
);
882 if ( yScroll
!= yScrollOld
)
884 wxScrollWinEvent
event(wxEVT_SCROLLWIN_THUMBTRACK
, yScroll
,
886 event
.SetEventObject(this);
887 GetEventHandler()->ProcessEvent(event
);