]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/scrolwin.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/scrolwin.cpp
3 // Purpose: wxScrolledWindow implementation
4 // Author: Robert Roebling
5 // Modified by: Ron Lee
6 // Vadim Zeitlin: removed 90% of duplicated common code
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/scrolwin.h"
28 #include "wx/gtk1/private.h"
30 // ============================================================================
32 // ============================================================================
34 // ----------------------------------------------------------------------------
35 // wxScrollHelper implementation
36 // ----------------------------------------------------------------------------
38 void wxScrollHelper::SetScrollbars(int pixelsPerUnitX
, int pixelsPerUnitY
,
39 int noUnitsX
, int noUnitsY
,
44 GetViewStart(& xs
, & ys
);
46 int old_x
= m_xScrollPixelsPerLine
* xs
;
47 int old_y
= m_yScrollPixelsPerLine
* ys
;
49 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
50 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
52 m_win
->m_hAdjust
->value
= m_xScrollPosition
= xPos
;
53 m_win
->m_vAdjust
->value
= m_yScrollPosition
= yPos
;
55 // Setting hints here should arguably be deprecated, but without it
56 // a sizer might override this manual scrollbar setting in old code.
57 // m_targetWindow->SetVirtualSizeHints( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY );
59 int w
= noUnitsX
* pixelsPerUnitX
;
60 int h
= noUnitsY
* pixelsPerUnitY
;
61 m_targetWindow
->SetVirtualSize( w
? w
: wxDefaultCoord
,
62 h
? h
: wxDefaultCoord
);
66 int new_x
= m_xScrollPixelsPerLine
* m_xScrollPosition
;
67 int new_y
= m_yScrollPixelsPerLine
* m_yScrollPosition
;
69 m_targetWindow
->ScrollWindow( old_x
- new_x
, old_y
- new_y
);
72 m_targetWindow
->m_hasScrolling
= pixelsPerUnitX
|| pixelsPerUnitY
;
75 void wxScrollHelper::DoAdjustScrollbar(GtkAdjustment
*adj
,
83 if ( pixelsPerLine
== 0 )
86 adj
->page_increment
= 1.0;
89 else // we do have scrollbar
91 adj
->upper
= (virtSize
+ pixelsPerLine
- 1) / pixelsPerLine
;
92 adj
->page_size
= winSize
/ pixelsPerLine
;
93 adj
->page_increment
= winSize
/ pixelsPerLine
;
95 // Special case. When client and virtual size are very close but
96 // the client is big enough, kill scrollbar.
98 if ((adj
->page_size
< adj
->upper
) && (winSize
>= virtSize
))
99 adj
->page_size
+= 1.0;
101 // If the scrollbar hits the right side, move the window
102 // right to keep it from over extending.
104 if ( !wxIsNullDouble(adj
->value
) &&
105 (adj
->value
+ adj
->page_size
> adj
->upper
) )
107 adj
->value
= adj
->upper
- adj
->page_size
;
108 if (adj
->value
< 0.0)
111 if ( m_win
->GetChildren().empty() )
113 // This is enough without child windows
114 *pos
= (int)adj
->value
;
118 // We need to actually scroll window
119 gtk_signal_emit_by_name( GTK_OBJECT(adj
), "value_changed" );
124 *lines
= (int)(adj
->upper
+ 0.5);
125 *linesPerPage
= (int)(adj
->page_increment
+ 0.5);
126 gtk_signal_emit_by_name( GTK_OBJECT(adj
), "changed" );
129 void wxScrollHelper::AdjustScrollbars()
134 m_targetWindow
->GetClientSize( &w
, &h
);
135 m_targetWindow
->GetVirtualSize( &vw
, &vh
);
137 DoAdjustScrollbar(m_win
->m_hAdjust
, m_xScrollPixelsPerLine
, w
, vw
,
138 &m_xScrollPosition
, &m_xScrollLines
, &m_xScrollLinesPerPage
);
139 DoAdjustScrollbar(m_win
->m_vAdjust
, m_yScrollPixelsPerLine
, h
, vh
,
140 &m_yScrollPosition
, &m_yScrollLines
, &m_yScrollLinesPerPage
);
143 void wxScrollHelper::DoScrollOneDir(int orient
,
149 if ( pos
!= -1 && pos
!= *posOld
&& pixelsPerLine
)
151 int max
= (int)(adj
->upper
- adj
->page_size
+ 0.5);
161 int diff
= (*posOld
- pos
)*pixelsPerLine
;
162 m_targetWindow
->ScrollWindow(orient
== wxHORIZONTAL
? diff
: 0,
163 orient
== wxHORIZONTAL
? 0 : diff
);
167 m_win
->GtkUpdateScrollbar(orient
);
171 void wxScrollHelper::DoScroll( int x_pos
, int y_pos
)
173 wxCHECK_RET( m_targetWindow
!= 0, wxT("No target window") );
175 DoScrollOneDir(wxHORIZONTAL
, m_win
->m_hAdjust
, x_pos
, m_xScrollPixelsPerLine
,
177 DoScrollOneDir(wxVERTICAL
, m_win
->m_vAdjust
, y_pos
, m_yScrollPixelsPerLine
,
181 bool wxScrollHelper::IsScrollbarShown(int WXUNUSED(orient
)) const
186 void wxScrollHelper::DoShowScrollbars(wxScrollbarVisibility
WXUNUSED(horz
),
187 wxScrollbarVisibility
WXUNUSED(vert
))
189 // TODO: not supported/implemented