]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/scrolwin.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/scrolwin.cpp
3 // Purpose: wxScrolledWindow implementation
4 // Author: Robert Roebling
5 // Modified by: Ron Lee
6 // Vadim Zeitlin: removed 90% of duplicated common code
9 // Copyright: (c) Robert Roebling
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
15 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 // For compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
28 #include "wx/scrolwin.h"
29 #include "wx/gtk/private.h"
31 // ============================================================================
33 // ============================================================================
35 // ----------------------------------------------------------------------------
36 // wxScrollHelper implementation
37 // ----------------------------------------------------------------------------
39 void wxScrollHelperNative::SetScrollbars(int pixelsPerUnitX
, int pixelsPerUnitY
,
40 int noUnitsX
, int noUnitsY
,
45 GetViewStart(& xs
, & ys
);
47 int old_x
= m_xScrollPixelsPerLine
* xs
;
48 int old_y
= m_yScrollPixelsPerLine
* ys
;
50 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
51 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
53 m_win
->m_hAdjust
->value
= m_xScrollPosition
= xPos
;
54 m_win
->m_vAdjust
->value
= m_yScrollPosition
= yPos
;
56 // Setting hints here should arguably be deprecated, but without it
57 // a sizer might override this manual scrollbar setting in old code.
58 // m_targetWindow->SetVirtualSizeHints( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY );
60 int w
= noUnitsX
* pixelsPerUnitX
;
61 int h
= noUnitsY
* pixelsPerUnitY
;
62 m_targetWindow
->SetVirtualSize( w
? w
: wxDefaultCoord
,
63 h
? h
: wxDefaultCoord
);
67 int new_x
= m_xScrollPixelsPerLine
* m_xScrollPosition
;
68 int new_y
= m_yScrollPixelsPerLine
* m_yScrollPosition
;
70 m_targetWindow
->ScrollWindow( old_x
- new_x
, old_y
- new_y
);
73 m_targetWindow
->m_hasScrolling
= pixelsPerUnitX
|| pixelsPerUnitY
;
76 void wxScrollHelperNative::DoAdjustScrollbar(GtkAdjustment
*adj
,
84 if ( pixelsPerLine
== 0 || winSize
>= virtSize
)
86 if ( !wxIsNullDouble(adj
->value
) )
89 g_signal_emit_by_name (adj
, "value_changed");
93 adj
->page_increment
= 1.0;
96 else // we do have scrollbar
98 // round because we need to show all the items
99 adj
->upper
= (virtSize
+ pixelsPerLine
- 1) / pixelsPerLine
;
101 // truncate here as we want to show visible lines entirely
103 adj
->page_increment
= winSize
/ pixelsPerLine
;
105 // If the scrollbar hits the right side, move the window
106 // right to keep it from over extending.
107 if ( !wxIsNullDouble(adj
->value
) &&
108 (adj
->value
+ adj
->page_size
> adj
->upper
) )
110 adj
->value
= adj
->upper
- adj
->page_size
;
111 if (adj
->value
< 0.0)
114 g_signal_emit_by_name (adj
, "value_changed");
118 *lines
= (int)(adj
->upper
+ 0.5);
119 *linesPerPage
= (int)(adj
->page_increment
+ 0.5);
120 g_signal_emit_by_name (adj
, "changed");
123 void wxScrollHelperNative::AdjustScrollbars()
128 m_targetWindow
->GetClientSize( &w
, &h
);
129 m_targetWindow
->GetVirtualSize( &vw
, &vh
);
131 DoAdjustScrollbar(m_win
->m_hAdjust
, m_xScrollPixelsPerLine
, w
, vw
,
132 &m_xScrollPosition
, &m_xScrollLines
, &m_xScrollLinesPerPage
);
133 DoAdjustScrollbar(m_win
->m_vAdjust
, m_yScrollPixelsPerLine
, h
, vh
,
134 &m_yScrollPosition
, &m_yScrollLines
, &m_yScrollLinesPerPage
);
137 void wxScrollHelperNative::DoScroll(int orient
,
143 if ( pos
!= -1 && pos
!= *posOld
&& pixelsPerLine
)
145 int max
= (int)(adj
->upper
- adj
->page_size
+ 0.5);
155 int diff
= (*posOld
- pos
)*pixelsPerLine
;
156 m_targetWindow
->ScrollWindow(orient
== wxHORIZONTAL
? diff
: 0,
157 orient
== wxHORIZONTAL
? 0 : diff
);
161 m_win
->GtkUpdateScrollbar(orient
);
165 void wxScrollHelperNative::Scroll( int x_pos
, int y_pos
)
167 wxCHECK_RET( m_targetWindow
!= 0, _T("No target window") );
169 DoScroll(wxHORIZONTAL
, m_win
->m_hAdjust
, x_pos
, m_xScrollPixelsPerLine
,
171 DoScroll(wxVERTICAL
, m_win
->m_vAdjust
, y_pos
, m_yScrollPixelsPerLine
,