]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/scrolwin.cpp
Pressing build-in joystick on WinCE phones fires wxEVT_JOY_BUTTON_DOWN event.
[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
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
76void wxScrollHelperNative::DoAdjustScrollbar(GtkAdjustment *adj,
77 int pixelsPerLine,
78 int winSize,
79 int virtSize,
80 int *pos,
81 int *lines,
82 int *linesPerPage)
30954328 83{
d32e78bd 84 if ( pixelsPerLine == 0 )
4ca24f18 85 {
d32e78bd
VZ
86 adj->upper = 1.0;
87 adj->page_increment = 1.0;
88 adj->page_size = 1.0;
4ca24f18 89 }
d32e78bd 90 else // we do have scrollbar
4ca24f18 91 {
d32e78bd
VZ
92 adj->upper = (virtSize + pixelsPerLine - 1) / pixelsPerLine;
93 adj->page_size = winSize / pixelsPerLine;
94 adj->page_increment = winSize / pixelsPerLine;
39c869a6 95
878ddad5
RR
96 // Special case. When client and virtual size are very close but
97 // the client is big enough, kill scrollbar.
4e115ed2 98
d32e78bd
VZ
99 if ((adj->page_size < adj->upper) && (winSize >= virtSize))
100 adj->page_size += 1.0;
4e115ed2 101
566d84a7
RL
102 // If the scrollbar hits the right side, move the window
103 // right to keep it from over extending.
4ca24f18 104
d32e78bd
VZ
105 if ( !wxIsNullDouble(adj->value) &&
106 (adj->value + adj->page_size > adj->upper) )
566d84a7 107 {
d32e78bd
VZ
108 adj->value = adj->upper - adj->page_size;
109 if (adj->value < 0.0)
110 adj->value = 0.0;
111
112 if ( m_win->GetChildren().empty() )
113 {
114 // This is enough without child windows
115 *pos = (int)adj->value;
116 }
2b5f62a0 117 else
d32e78bd
VZ
118 {
119 // We need to actually scroll window
120 gtk_signal_emit_by_name( GTK_OBJECT(adj), "value_changed" );
121 }
566d84a7 122 }
4ca24f18
RR
123 }
124
d32e78bd
VZ
125 *lines = (int)(adj->upper + 0.5);
126 *linesPerPage = (int)(adj->page_increment + 0.5);
127 gtk_signal_emit_by_name( GTK_OBJECT(adj), "changed" );
30954328
RR
128}
129
d32e78bd 130void wxScrollHelperNative::AdjustScrollbars()
566d84a7 131{
d32e78bd
VZ
132 int w, h;
133 int vw, vh;
830ed6d9 134
d32e78bd
VZ
135 m_targetWindow->GetClientSize( &w, &h );
136 m_targetWindow->GetVirtualSize( &vw, &vh );
830ed6d9 137
d32e78bd
VZ
138 DoAdjustScrollbar(m_win->m_hAdjust, m_xScrollPixelsPerLine, w, vw,
139 &m_xScrollPosition, &m_xScrollLines, &m_xScrollLinesPerPage);
140 DoAdjustScrollbar(m_win->m_vAdjust, m_yScrollPixelsPerLine, h, vh,
141 &m_yScrollPosition, &m_yScrollLines, &m_yScrollLinesPerPage);
830ed6d9
RR
142}
143
d32e78bd
VZ
144void wxScrollHelperNative::DoScroll(int orient,
145 GtkAdjustment *adj,
146 int pos,
147 int pixelsPerLine,
148 int *posOld)
30486297 149{
d32e78bd 150 if ( pos != -1 && pos != *posOld && pixelsPerLine )
30486297 151 {
d32e78bd
VZ
152 int max = (int)(adj->upper - adj->page_size + 0.5);
153 if (max < 0)
154 max = 0;
155 if (pos > max)
156 pos = max;
157 if (pos < 0)
158 pos = 0;
566d84a7 159
d32e78bd 160 adj->value = pos;
30486297 161
d32e78bd
VZ
162 int diff = (*posOld - pos)*pixelsPerLine;
163 m_targetWindow->ScrollWindow(orient == wxHORIZONTAL ? diff : 0,
164 orient == wxHORIZONTAL ? 0 : diff);
30954328 165
d32e78bd 166 *posOld = pos;
4e115ed2 167
d32e78bd 168 m_win->GtkUpdateScrollbar(orient);
2b5f62a0 169 }
30954328
RR
170}
171
d32e78bd 172void wxScrollHelperNative::Scroll( int x_pos, int y_pos )
30954328 173{
d32e78bd 174 wxCHECK_RET( m_targetWindow != 0, _T("No target window") );
30954328 175
d32e78bd
VZ
176 DoScroll(wxHORIZONTAL, m_win->m_hAdjust, x_pos, m_xScrollPixelsPerLine,
177 &m_xScrollPosition);
178 DoScroll(wxVERTICAL, m_win->m_vAdjust, y_pos, m_yScrollPixelsPerLine,
179 &m_yScrollPosition);
30954328 180}
3379ed37 181