]>
Commit | Line | Data |
---|---|---|
30954328 | 1 | ///////////////////////////////////////////////////////////////////////////// |
e1437456 | 2 | // Name: gtk/scrolwin.cpp |
30954328 | 3 | // Purpose: wxScrolledWindow implementation |
47a3ff38 | 4 | // Author: Robert Roebling |
566d84a7 | 5 | // Modified by: Ron Lee |
d32e78bd | 6 | // Vadim Zeitlin: removed 90% of duplicated common code |
30954328 RR |
7 | // Created: 01/02/97 |
8 | // RCS-ID: $Id$ | |
47a3ff38 | 9 | // Copyright: (c) Robert Roebling |
65571936 | 10 | // Licence: wxWindows licence |
30954328 RR |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
13 | // ============================================================================ | |
14 | // declarations | |
15 | // ============================================================================ | |
16 | ||
17 | // ---------------------------------------------------------------------------- | |
18 | // headers | |
19 | // ---------------------------------------------------------------------------- | |
20 | ||
30954328 RR |
21 | // For compilers that support precompilation, includes "wx.h". |
22 | #include "wx/wxprec.h" | |
23 | ||
24 | #ifdef __BORLANDC__ | |
25 | #pragma hdrstop | |
26 | #endif | |
27 | ||
e1bf3ad3 | 28 | #include "wx/scrolwin.h" |
9e691f46 | 29 | #include "wx/gtk/private.h" |
30954328 RR |
30 | |
31 | // ============================================================================ | |
32 | // implementation | |
33 | // ============================================================================ | |
34 | ||
30954328 | 35 | // ---------------------------------------------------------------------------- |
d32e78bd | 36 | // wxScrollHelper implementation |
30954328 RR |
37 | // ---------------------------------------------------------------------------- |
38 | ||
d32e78bd VZ |
39 | void wxScrollHelperNative::SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY, |
40 | int noUnitsX, int noUnitsY, | |
41 | int xPos, int yPos, | |
42 | bool noRefresh) | |
30954328 | 43 | { |
1adff2f5 | 44 | int xs, ys; |
d32e78bd | 45 | GetViewStart(& xs, & ys); |
4e115ed2 | 46 | |
1adff2f5 JS |
47 | int old_x = m_xScrollPixelsPerLine * xs; |
48 | int old_y = m_yScrollPixelsPerLine * ys; | |
30486297 | 49 | |
30954328 RR |
50 | m_xScrollPixelsPerLine = pixelsPerUnitX; |
51 | m_yScrollPixelsPerLine = pixelsPerUnitY; | |
39c869a6 | 52 | |
d32e78bd VZ |
53 | m_win->m_hAdjust->value = m_xScrollPosition = xPos; |
54 | m_win->m_vAdjust->value = m_yScrollPosition = yPos; | |
30954328 | 55 | |
2b5f62a0 VZ |
56 | // Setting hints here should arguably be deprecated, but without it |
57 | // a sizer might override this manual scrollbar setting in old code. | |
878ddad5 | 58 | // m_targetWindow->SetVirtualSizeHints( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY ); |
30486297 | 59 | |
f18f464c VZ |
60 | int w = noUnitsX * pixelsPerUnitX; |
61 | int h = noUnitsY * pixelsPerUnitY; | |
62 | m_targetWindow->SetVirtualSize( w ? w : wxDefaultCoord, | |
63 | h ? h : wxDefaultCoord); | |
2b5f62a0 | 64 | |
ec7482df RR |
65 | if (!noRefresh) |
66 | { | |
67 | int new_x = m_xScrollPixelsPerLine * m_xScrollPosition; | |
68 | int new_y = m_yScrollPixelsPerLine * m_yScrollPosition; | |
30486297 | 69 | |
566d84a7 | 70 | m_targetWindow->ScrollWindow( old_x - new_x, old_y - new_y ); |
ec7482df | 71 | } |
d32e78bd VZ |
72 | |
73 | m_targetWindow->m_hasScrolling = pixelsPerUnitX || pixelsPerUnitY; | |
30954328 RR |
74 | } |
75 | ||
d32e78bd VZ |
76 | void wxScrollHelperNative::DoAdjustScrollbar(GtkAdjustment *adj, |
77 | int pixelsPerLine, | |
78 | int winSize, | |
79 | int virtSize, | |
80 | int *pos, | |
81 | int *lines, | |
82 | int *linesPerPage) | |
30954328 | 83 | { |
940f5ae8 | 84 | if ( pixelsPerLine == 0 || winSize >= virtSize) |
4ca24f18 | 85 | { |
940f5ae8 RR |
86 | if ( !wxIsNullDouble(adj->value) ) |
87 | { | |
88 | adj->value = 0.0; | |
89 | g_signal_emit_by_name (adj, "value_changed"); | |
90 | } | |
91 | ||
d32e78bd VZ |
92 | adj->upper = 1.0; |
93 | adj->page_increment = 1.0; | |
94 | adj->page_size = 1.0; | |
4ca24f18 | 95 | } |
d32e78bd | 96 | else // we do have scrollbar |
4ca24f18 | 97 | { |
760f0fc2 | 98 | // round because we need to show all the items |
d32e78bd | 99 | adj->upper = (virtSize + pixelsPerLine - 1) / pixelsPerLine; |
4e115ed2 | 100 | |
760f0fc2 VZ |
101 | // truncate here as we want to show visible lines entirely |
102 | adj->page_size = | |
103 | adj->page_increment = winSize / pixelsPerLine; | |
4e115ed2 | 104 | |
566d84a7 RL |
105 | // If the scrollbar hits the right side, move the window |
106 | // right to keep it from over extending. | |
d32e78bd VZ |
107 | if ( !wxIsNullDouble(adj->value) && |
108 | (adj->value + adj->page_size > adj->upper) ) | |
566d84a7 | 109 | { |
d32e78bd VZ |
110 | adj->value = adj->upper - adj->page_size; |
111 | if (adj->value < 0.0) | |
112 | adj->value = 0.0; | |
113 | ||
940f5ae8 | 114 | g_signal_emit_by_name (adj, "value_changed"); |
566d84a7 | 115 | } |
4ca24f18 RR |
116 | } |
117 | ||
d32e78bd VZ |
118 | *lines = (int)(adj->upper + 0.5); |
119 | *linesPerPage = (int)(adj->page_increment + 0.5); | |
9fa72bd2 | 120 | g_signal_emit_by_name (adj, "changed"); |
30954328 RR |
121 | } |
122 | ||
d32e78bd | 123 | void wxScrollHelperNative::AdjustScrollbars() |
566d84a7 | 124 | { |
d32e78bd VZ |
125 | int w, h; |
126 | int vw, vh; | |
830ed6d9 | 127 | |
0f4f26bd PC |
128 | m_targetWindow->m_hasScrolling = m_xScrollPixelsPerLine != 0 || m_yScrollPixelsPerLine != 0; |
129 | ||
d32e78bd VZ |
130 | m_targetWindow->GetClientSize( &w, &h ); |
131 | m_targetWindow->GetVirtualSize( &vw, &vh ); | |
830ed6d9 | 132 | |
d32e78bd VZ |
133 | DoAdjustScrollbar(m_win->m_hAdjust, m_xScrollPixelsPerLine, w, vw, |
134 | &m_xScrollPosition, &m_xScrollLines, &m_xScrollLinesPerPage); | |
135 | DoAdjustScrollbar(m_win->m_vAdjust, m_yScrollPixelsPerLine, h, vh, | |
136 | &m_yScrollPosition, &m_yScrollLines, &m_yScrollLinesPerPage); | |
830ed6d9 RR |
137 | } |
138 | ||
d32e78bd VZ |
139 | void wxScrollHelperNative::DoScroll(int orient, |
140 | GtkAdjustment *adj, | |
141 | int pos, | |
142 | int pixelsPerLine, | |
143 | int *posOld) | |
30486297 | 144 | { |
d32e78bd | 145 | if ( pos != -1 && pos != *posOld && pixelsPerLine ) |
30486297 | 146 | { |
d32e78bd VZ |
147 | int max = (int)(adj->upper - adj->page_size + 0.5); |
148 | if (max < 0) | |
149 | max = 0; | |
150 | if (pos > max) | |
151 | pos = max; | |
152 | if (pos < 0) | |
153 | pos = 0; | |
566d84a7 | 154 | |
d32e78bd | 155 | adj->value = pos; |
30486297 | 156 | |
d32e78bd VZ |
157 | int diff = (*posOld - pos)*pixelsPerLine; |
158 | m_targetWindow->ScrollWindow(orient == wxHORIZONTAL ? diff : 0, | |
159 | orient == wxHORIZONTAL ? 0 : diff); | |
30954328 | 160 | |
d32e78bd | 161 | *posOld = pos; |
4e115ed2 | 162 | |
d32e78bd | 163 | m_win->GtkUpdateScrollbar(orient); |
2b5f62a0 | 164 | } |
30954328 RR |
165 | } |
166 | ||
d32e78bd | 167 | void wxScrollHelperNative::Scroll( int x_pos, int y_pos ) |
30954328 | 168 | { |
d32e78bd | 169 | wxCHECK_RET( m_targetWindow != 0, _T("No target window") ); |
30954328 | 170 | |
d32e78bd VZ |
171 | DoScroll(wxHORIZONTAL, m_win->m_hAdjust, x_pos, m_xScrollPixelsPerLine, |
172 | &m_xScrollPosition); | |
173 | DoScroll(wxVERTICAL, m_win->m_vAdjust, y_pos, m_yScrollPixelsPerLine, | |
174 | &m_yScrollPosition); | |
30954328 | 175 | } |
3379ed37 | 176 |