]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/scrolwin.cpp
Deallocate wxThreadSpecificInfo when wxThread ends.
[wxWidgets.git] / 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
7 // Created: 01/02/97
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/scrolwin.h"
28 #include "wx/gtk1/private.h"
29
30 // ============================================================================
31 // implementation
32 // ============================================================================
33
34 // ----------------------------------------------------------------------------
35 // wxScrollHelper implementation
36 // ----------------------------------------------------------------------------
37
38 void wxScrollHelper::SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
39 int noUnitsX, int noUnitsY,
40 int xPos, int yPos,
41 bool noRefresh)
42 {
43 int xs, ys;
44 GetViewStart(& xs, & ys);
45
46 int old_x = m_xScrollPixelsPerLine * xs;
47 int old_y = m_yScrollPixelsPerLine * ys;
48
49 m_xScrollPixelsPerLine = pixelsPerUnitX;
50 m_yScrollPixelsPerLine = pixelsPerUnitY;
51
52 m_win->m_hAdjust->value = m_xScrollPosition = xPos;
53 m_win->m_vAdjust->value = m_yScrollPosition = yPos;
54
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 );
58
59 int w = noUnitsX * pixelsPerUnitX;
60 int h = noUnitsY * pixelsPerUnitY;
61 m_targetWindow->SetVirtualSize( w ? w : wxDefaultCoord,
62 h ? h : wxDefaultCoord);
63
64 if (!noRefresh)
65 {
66 int new_x = m_xScrollPixelsPerLine * m_xScrollPosition;
67 int new_y = m_yScrollPixelsPerLine * m_yScrollPosition;
68
69 m_targetWindow->ScrollWindow( old_x - new_x, old_y - new_y );
70 }
71
72 m_targetWindow->m_hasScrolling = pixelsPerUnitX || pixelsPerUnitY;
73 }
74
75 void wxScrollHelper::DoAdjustScrollbar(GtkAdjustment *adj,
76 int pixelsPerLine,
77 int winSize,
78 int virtSize,
79 int *pos,
80 int *lines,
81 int *linesPerPage)
82 {
83 if ( pixelsPerLine == 0 )
84 {
85 adj->upper = 1.0;
86 adj->page_increment = 1.0;
87 adj->page_size = 1.0;
88 }
89 else // we do have scrollbar
90 {
91 adj->upper = (virtSize + pixelsPerLine - 1) / pixelsPerLine;
92 adj->page_size = winSize / pixelsPerLine;
93 adj->page_increment = winSize / pixelsPerLine;
94
95 // Special case. When client and virtual size are very close but
96 // the client is big enough, kill scrollbar.
97
98 if ((adj->page_size < adj->upper) && (winSize >= virtSize))
99 adj->page_size += 1.0;
100
101 // If the scrollbar hits the right side, move the window
102 // right to keep it from over extending.
103
104 if ( !wxIsNullDouble(adj->value) &&
105 (adj->value + adj->page_size > adj->upper) )
106 {
107 adj->value = adj->upper - adj->page_size;
108 if (adj->value < 0.0)
109 adj->value = 0.0;
110
111 if ( m_win->GetChildren().empty() )
112 {
113 // This is enough without child windows
114 *pos = (int)adj->value;
115 }
116 else
117 {
118 // We need to actually scroll window
119 gtk_signal_emit_by_name( GTK_OBJECT(adj), "value_changed" );
120 }
121 }
122 }
123
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" );
127 }
128
129 void wxScrollHelper::AdjustScrollbars()
130 {
131 int w, h;
132 int vw, vh;
133
134 m_targetWindow->GetClientSize( &w, &h );
135 m_targetWindow->GetVirtualSize( &vw, &vh );
136
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);
141 }
142
143 void wxScrollHelper::DoScrollOneDir(int orient,
144 GtkAdjustment *adj,
145 int pos,
146 int pixelsPerLine,
147 int *posOld)
148 {
149 if ( pos != -1 && pos != *posOld && pixelsPerLine )
150 {
151 int max = (int)(adj->upper - adj->page_size + 0.5);
152 if (max < 0)
153 max = 0;
154 if (pos > max)
155 pos = max;
156 if (pos < 0)
157 pos = 0;
158
159 adj->value = pos;
160
161 int diff = (*posOld - pos)*pixelsPerLine;
162 m_targetWindow->ScrollWindow(orient == wxHORIZONTAL ? diff : 0,
163 orient == wxHORIZONTAL ? 0 : diff);
164
165 *posOld = pos;
166
167 m_win->GtkUpdateScrollbar(orient);
168 }
169 }
170
171 void wxScrollHelper::DoScroll( int x_pos, int y_pos )
172 {
173 wxCHECK_RET( m_targetWindow != 0, wxT("No target window") );
174
175 DoScrollOneDir(wxHORIZONTAL, m_win->m_hAdjust, x_pos, m_xScrollPixelsPerLine,
176 &m_xScrollPosition);
177 DoScrollOneDir(wxVERTICAL, m_win->m_vAdjust, y_pos, m_yScrollPixelsPerLine,
178 &m_yScrollPosition);
179 }
180
181 bool wxScrollHelper::IsScrollbarShown(int WXUNUSED(orient)) const
182 {
183 return true;
184 }
185
186 void wxScrollHelper::DoShowScrollbars(wxScrollbarVisibility WXUNUSED(horz),
187 wxScrollbarVisibility WXUNUSED(vert))
188 {
189 // TODO: not supported/implemented
190 }
191