]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/scrolwin.cpp
Commited Bryan Petty's blind fix patch.
[wxWidgets.git] / src / gtk / scrolwin.cpp
CommitLineData
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
39void 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
add7cadd
PC
53 m_win->m_scrollBar[0]->adjustment->value =
54 m_xScrollPosition = xPos;
55 m_win->m_scrollBar[1]->adjustment->value =
56 m_yScrollPosition = yPos;
30954328 57
2b5f62a0
VZ
58 // Setting hints here should arguably be deprecated, but without it
59 // a sizer might override this manual scrollbar setting in old code.
878ddad5 60 // m_targetWindow->SetVirtualSizeHints( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY );
30486297 61
f18f464c
VZ
62 int w = noUnitsX * pixelsPerUnitX;
63 int h = noUnitsY * pixelsPerUnitY;
64 m_targetWindow->SetVirtualSize( w ? w : wxDefaultCoord,
65 h ? h : wxDefaultCoord);
2b5f62a0 66
add7cadd
PC
67 // If the target is not the same as the window with the scrollbars,
68 // then we need to update the scrollbars here, since they won't have
69 // been updated by SetVirtualSize().
70 if (m_targetWindow != m_win)
71 {
72 AdjustScrollbars();
73 }
74
ec7482df
RR
75 if (!noRefresh)
76 {
77 int new_x = m_xScrollPixelsPerLine * m_xScrollPosition;
78 int new_y = m_yScrollPixelsPerLine * m_yScrollPosition;
30486297 79
566d84a7 80 m_targetWindow->ScrollWindow( old_x - new_x, old_y - new_y );
ec7482df 81 }
30954328
RR
82}
83
add7cadd 84void wxScrollHelperNative::DoAdjustScrollbar(GtkRange* range,
d32e78bd
VZ
85 int pixelsPerLine,
86 int winSize,
87 int virtSize,
d32e78bd
VZ
88 int *lines,
89 int *linesPerPage)
30954328 90{
add7cadd
PC
91 // GtkRange won't allow upper == lower, so for disabled state use [0,1]
92 // with a page size of 1. This will also clamp position to 0.
93 int upper = 1;
94 int page_size = 1;
fb18afdd 95 if (pixelsPerLine > 0 && winSize > 0 && winSize < virtSize)
4ca24f18 96 {
add7cadd
PC
97 upper = (virtSize + pixelsPerLine - 1) / pixelsPerLine;
98 page_size = winSize / pixelsPerLine;
4ca24f18
RR
99 }
100
add7cadd
PC
101 *lines = upper;
102 *linesPerPage = page_size;
103
104 GtkAdjustment* adj = range->adjustment;
105 adj->step_increment = 1;
106 adj->page_increment =
107 adj->page_size = page_size;
108 gtk_range_set_range(range, 0, upper);
30954328
RR
109}
110
d32e78bd 111void wxScrollHelperNative::AdjustScrollbars()
566d84a7 112{
d32e78bd
VZ
113 int w, h;
114 int vw, vh;
830ed6d9 115
0f4f26bd
PC
116 m_targetWindow->m_hasScrolling = m_xScrollPixelsPerLine != 0 || m_yScrollPixelsPerLine != 0;
117
d32e78bd
VZ
118 m_targetWindow->GetClientSize( &w, &h );
119 m_targetWindow->GetVirtualSize( &vw, &vh );
830ed6d9 120
add7cadd
PC
121 DoAdjustScrollbar(m_win->m_scrollBar[0], m_xScrollPixelsPerLine, w, vw,
122 &m_xScrollLines, &m_xScrollLinesPerPage);
123 DoAdjustScrollbar(m_win->m_scrollBar[1], m_yScrollPixelsPerLine, h, vh,
124 &m_yScrollLines, &m_yScrollLinesPerPage);
830ed6d9
RR
125}
126
d32e78bd 127void wxScrollHelperNative::DoScroll(int orient,
d32e78bd
VZ
128 int pos,
129 int pixelsPerLine,
130 int *posOld)
30486297 131{
d32e78bd 132 if ( pos != -1 && pos != *posOld && pixelsPerLine )
30486297 133 {
add7cadd
PC
134 m_win->SetScrollPos(orient, pos);
135 pos = m_win->GetScrollPos(orient);
30486297 136
d32e78bd
VZ
137 int diff = (*posOld - pos)*pixelsPerLine;
138 m_targetWindow->ScrollWindow(orient == wxHORIZONTAL ? diff : 0,
139 orient == wxHORIZONTAL ? 0 : diff);
30954328 140
d32e78bd 141 *posOld = pos;
2b5f62a0 142 }
30954328
RR
143}
144
d32e78bd 145void wxScrollHelperNative::Scroll( int x_pos, int y_pos )
30954328 146{
d32e78bd 147 wxCHECK_RET( m_targetWindow != 0, _T("No target window") );
30954328 148
add7cadd
PC
149 DoScroll(wxHORIZONTAL, x_pos, m_xScrollPixelsPerLine, &m_xScrollPosition);
150 DoScroll(wxVERTICAL, y_pos, m_yScrollPixelsPerLine, &m_yScrollPosition);
30954328 151}