]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/scrolwin.cpp
Fix Doxygen warnings due to documenting overloaded functions together.
[wxWidgets.git] / src / gtk1 / scrolwin.cpp
CommitLineData
30954328 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/gtk1/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 7// Created: 01/02/97
47a3ff38 8// Copyright: (c) Robert Roebling
65571936 9// Licence: wxWindows licence
30954328
RR
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
30954328
RR
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
e1bf3ad3 27#include "wx/scrolwin.h"
3cbab641 28#include "wx/gtk1/private.h"
30954328
RR
29
30// ============================================================================
31// implementation
32// ============================================================================
33
30954328 34// ----------------------------------------------------------------------------
d32e78bd 35// wxScrollHelper implementation
30954328
RR
36// ----------------------------------------------------------------------------
37
29e1398f 38void wxScrollHelper::SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
d32e78bd
VZ
39 int noUnitsX, int noUnitsY,
40 int xPos, int yPos,
41 bool noRefresh)
30954328 42{
1adff2f5 43 int xs, ys;
d32e78bd 44 GetViewStart(& xs, & ys);
4e115ed2 45
1adff2f5
JS
46 int old_x = m_xScrollPixelsPerLine * xs;
47 int old_y = m_yScrollPixelsPerLine * ys;
30486297 48
30954328
RR
49 m_xScrollPixelsPerLine = pixelsPerUnitX;
50 m_yScrollPixelsPerLine = pixelsPerUnitY;
39c869a6 51
d32e78bd
VZ
52 m_win->m_hAdjust->value = m_xScrollPosition = xPos;
53 m_win->m_vAdjust->value = m_yScrollPosition = yPos;
30954328 54
2b5f62a0
VZ
55 // Setting hints here should arguably be deprecated, but without it
56 // a sizer might override this manual scrollbar setting in old code.
878ddad5 57 // m_targetWindow->SetVirtualSizeHints( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY );
30486297 58
f18f464c
VZ
59 int w = noUnitsX * pixelsPerUnitX;
60 int h = noUnitsY * pixelsPerUnitY;
61 m_targetWindow->SetVirtualSize( w ? w : wxDefaultCoord,
62 h ? h : wxDefaultCoord);
2b5f62a0 63
ec7482df
RR
64 if (!noRefresh)
65 {
66 int new_x = m_xScrollPixelsPerLine * m_xScrollPosition;
67 int new_y = m_yScrollPixelsPerLine * m_yScrollPosition;
30486297 68
566d84a7 69 m_targetWindow->ScrollWindow( old_x - new_x, old_y - new_y );
ec7482df 70 }
d32e78bd
VZ
71
72 m_targetWindow->m_hasScrolling = pixelsPerUnitX || pixelsPerUnitY;
30954328
RR
73}
74
29e1398f 75void wxScrollHelper::DoAdjustScrollbar(GtkAdjustment *adj,
d32e78bd
VZ
76 int pixelsPerLine,
77 int winSize,
78 int virtSize,
79 int *pos,
80 int *lines,
81 int *linesPerPage)
30954328 82{
d32e78bd 83 if ( pixelsPerLine == 0 )
4ca24f18 84 {
d32e78bd
VZ
85 adj->upper = 1.0;
86 adj->page_increment = 1.0;
87 adj->page_size = 1.0;
4ca24f18 88 }
d32e78bd 89 else // we do have scrollbar
4ca24f18 90 {
d32e78bd
VZ
91 adj->upper = (virtSize + pixelsPerLine - 1) / pixelsPerLine;
92 adj->page_size = winSize / pixelsPerLine;
93 adj->page_increment = winSize / pixelsPerLine;
39c869a6 94
878ddad5
RR
95 // Special case. When client and virtual size are very close but
96 // the client is big enough, kill scrollbar.
4e115ed2 97
d32e78bd
VZ
98 if ((adj->page_size < adj->upper) && (winSize >= virtSize))
99 adj->page_size += 1.0;
4e115ed2 100
566d84a7
RL
101 // If the scrollbar hits the right side, move the window
102 // right to keep it from over extending.
4ca24f18 103
d32e78bd
VZ
104 if ( !wxIsNullDouble(adj->value) &&
105 (adj->value + adj->page_size > adj->upper) )
566d84a7 106 {
d32e78bd
VZ
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 }
2b5f62a0 116 else
d32e78bd
VZ
117 {
118 // We need to actually scroll window
119 gtk_signal_emit_by_name( GTK_OBJECT(adj), "value_changed" );
120 }
566d84a7 121 }
4ca24f18
RR
122 }
123
d32e78bd
VZ
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" );
30954328
RR
127}
128
29e1398f 129void wxScrollHelper::AdjustScrollbars()
566d84a7 130{
d32e78bd
VZ
131 int w, h;
132 int vw, vh;
830ed6d9 133
d32e78bd
VZ
134 m_targetWindow->GetClientSize( &w, &h );
135 m_targetWindow->GetVirtualSize( &vw, &vh );
830ed6d9 136
d32e78bd
VZ
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);
830ed6d9
RR
141}
142
29e1398f 143void wxScrollHelper::DoScrollOneDir(int orient,
d32e78bd
VZ
144 GtkAdjustment *adj,
145 int pos,
146 int pixelsPerLine,
147 int *posOld)
30486297 148{
d32e78bd 149 if ( pos != -1 && pos != *posOld && pixelsPerLine )
30486297 150 {
d32e78bd
VZ
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;
566d84a7 158
d32e78bd 159 adj->value = pos;
30486297 160
d32e78bd
VZ
161 int diff = (*posOld - pos)*pixelsPerLine;
162 m_targetWindow->ScrollWindow(orient == wxHORIZONTAL ? diff : 0,
163 orient == wxHORIZONTAL ? 0 : diff);
30954328 164
d32e78bd 165 *posOld = pos;
4e115ed2 166
d32e78bd 167 m_win->GtkUpdateScrollbar(orient);
2b5f62a0 168 }
30954328
RR
169}
170
29e1398f 171void wxScrollHelper::DoScroll( int x_pos, int y_pos )
30954328 172{
9a83f860 173 wxCHECK_RET( m_targetWindow != 0, wxT("No target window") );
30954328 174
29e1398f 175 DoScrollOneDir(wxHORIZONTAL, m_win->m_hAdjust, x_pos, m_xScrollPixelsPerLine,
d32e78bd 176 &m_xScrollPosition);
29e1398f 177 DoScrollOneDir(wxVERTICAL, m_win->m_vAdjust, y_pos, m_yScrollPixelsPerLine,
d32e78bd 178 &m_yScrollPosition);
30954328 179}
3379ed37 180
29e1398f
VZ
181void wxScrollHelper::DoShowScrollbars(wxScrollbarVisibility WXUNUSED(horz),
182 wxScrollbarVisibility WXUNUSED(vert))
183{
184 // TODO: not supported/implemented
185}
186