]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/scrolbar.cpp
Added SetFont to most controls and controls sample
[wxWidgets.git] / src / gtk1 / scrolbar.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: scrolbar.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11
12#ifdef __GNUG__
13#pragma implementation "scrolbar.h"
14#endif
15
16#include "wx/scrolbar.h"
17#include "wx/utils.h"
18
66bd6b93
RR
19//-----------------------------------------------------------------------------
20// data
21//-----------------------------------------------------------------------------
22
23extern bool g_blockEventsOnDrag;
24
c801d85f
KB
25//-----------------------------------------------------------------------------
26// wxScrollBar
27//-----------------------------------------------------------------------------
28
66bd6b93 29static void gtk_scrollbar_callback( GtkWidget *WXUNUSED(widget), wxScrollBar *win )
c801d85f 30{
c801d85f 31 if (!win->HasVMT()) return;
66bd6b93 32 if (g_blockEventsOnDrag) return;
c801d85f
KB
33
34 float diff = win->m_adjust->value - win->m_oldPos;
35 if (fabs(diff) < 0.2) return;
36
7798a18e 37 wxEventType command = wxEVT_NULL;
c801d85f
KB
38
39 float line_step = win->m_adjust->step_increment;
40 float page_step = win->m_adjust->page_increment;
41
42 if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN;
43 else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP;
44 else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN;
45 else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP;
46 else command = wxEVT_SCROLL_THUMBTRACK;
47
48 int value = (int)(win->m_adjust->value+0.5);
49
50 int orient = wxHORIZONTAL;
51 if (win->GetWindowStyleFlag() & wxSB_VERTICAL == wxSB_VERTICAL) orient = wxHORIZONTAL;
52
53 wxScrollEvent event( command, win->GetId(), value, orient );
54 event.SetEventObject( win );
47908e25 55 win->GetEventHandler()->ProcessEvent( event );
c801d85f
KB
56
57/*
58 wxCommandEvent cevent( wxEVT_COMMAND_SCROLLBAR_UPDATED, win->GetId() );
59 cevent.SetEventObject( win );
60 win->ProcessEvent( cevent );
61*/
6de97a3b 62}
c801d85f
KB
63
64IMPLEMENT_DYNAMIC_CLASS(wxScrollBar,wxControl)
65
c801d85f
KB
66wxScrollBar::~wxScrollBar(void)
67{
6de97a3b 68}
c801d85f 69
debe6624 70bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
c801d85f 71 const wxPoint& pos, const wxSize& size,
6de97a3b 72 long style, const wxValidator& validator, const wxString& name )
c801d85f
KB
73{
74 m_needParent = TRUE;
75
76 PreCreation( parent, id, pos, size, style, name );
77
6de97a3b
RR
78 SetValidator( validator );
79
c801d85f
KB
80 m_oldPos = 0.0;
81
82 if (style & wxSB_VERTICAL == wxSB_VERTICAL)
c67daf87 83 m_widget = gtk_hscrollbar_new( (GtkAdjustment *) NULL );
c801d85f 84 else
c67daf87 85 m_widget = gtk_vscrollbar_new( (GtkAdjustment *) NULL );
c801d85f
KB
86
87 m_adjust = gtk_range_get_adjustment( GTK_RANGE(m_widget) );
88
89 gtk_signal_connect (GTK_OBJECT (m_adjust), "value_changed",
90 (GtkSignalFunc) gtk_scrollbar_callback, (gpointer) this );
91
92 PostCreation();
93
94 Show( TRUE );
95
96 return TRUE;
6de97a3b 97}
c801d85f
KB
98
99int wxScrollBar::GetPosition(void) const
100{
101 return (int)(m_adjust->value+0.5);
6de97a3b 102}
c801d85f
KB
103
104int wxScrollBar::GetThumbSize() const
105{
106 return (int)(m_adjust->page_size+0.5);
6de97a3b 107}
c801d85f
KB
108
109int wxScrollBar::GetPageSize() const
110{
111 return (int)(m_adjust->page_increment+0.5);
6de97a3b 112}
c801d85f
KB
113
114int wxScrollBar::GetRange() const
115{
116 return (int)(m_adjust->upper+0.5);
6de97a3b 117}
c801d85f 118
debe6624 119void wxScrollBar::SetPosition( int viewStart )
c801d85f
KB
120{
121 float fpos = (float)viewStart;
122 m_oldPos = fpos;
123 if (fabs(fpos-m_adjust->value) < 0.2) return;
124 m_adjust->value = fpos;
125
126 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "value_changed" );
6de97a3b 127}
c801d85f 128
debe6624
JS
129void wxScrollBar::SetScrollbar( int position, int thumbSize, int range, int pageSize,
130 bool WXUNUSED(refresh) )
c801d85f
KB
131{
132 float fpos = (float)position;
133 m_oldPos = fpos;
134 float frange = (float)range;
135 float fthumb = (float)thumbSize;
136 float fpage = (float)pageSize;
137
138 if ((fabs(fpos-m_adjust->value) < 0.2) &&
139 (fabs(frange-m_adjust->upper) < 0.2) &&
140 (fabs(fthumb-m_adjust->page_size) < 0.2) &&
141 (fabs(fpage-m_adjust->page_increment) < 0.2))
142 return;
143
144 m_adjust->lower = 0.0;
145 m_adjust->upper = frange;
146 m_adjust->value = fpos;
147 m_adjust->step_increment = 1.0;
148 m_adjust->page_increment = (float)(wxMax(fpage-2,0));
149 m_adjust->page_size = fthumb;
150
151 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
6de97a3b 152}
c801d85f
KB
153
154// Backward compatibility
155int wxScrollBar::GetValue(void) const
156{
157 return GetPosition();
6de97a3b 158}
c801d85f 159
debe6624 160void wxScrollBar::SetValue( int viewStart )
c801d85f
KB
161{
162 SetPosition( viewStart );
6de97a3b 163}
c801d85f
KB
164
165void wxScrollBar::GetValues( int *viewStart, int *viewLength, int *objectLength, int *pageLength ) const
166{
167 int pos = (int)(m_adjust->value+0.5);
168 int thumb = (int)(m_adjust->page_size+0.5);
169 int page = (int)(m_adjust->page_increment+0.5);
170 int range = (int)(m_adjust->upper+0.5);
171
172 *viewStart = pos;
173 *viewLength = range;
174 *objectLength = thumb;
175 *pageLength = page;
6de97a3b 176}
c801d85f
KB
177
178int wxScrollBar::GetViewLength() const
179{
180 return (int)(m_adjust->upper+0.5);
6de97a3b 181}
c801d85f
KB
182
183int wxScrollBar::GetObjectLength() const
184{
185 return (int)(m_adjust->page_size+0.5);
6de97a3b 186}
c801d85f 187
debe6624 188void wxScrollBar::SetPageSize( int pageLength )
c801d85f
KB
189{
190 int pos = (int)(m_adjust->value+0.5);
191 int thumb = (int)(m_adjust->page_size+0.5);
192 int range = (int)(m_adjust->upper+0.5);
193 SetScrollbar( pos, thumb, range, pageLength );
6de97a3b 194}
c801d85f 195
debe6624 196void wxScrollBar::SetObjectLength( int objectLength )
c801d85f
KB
197{
198 int pos = (int)(m_adjust->value+0.5);
199 int page = (int)(m_adjust->page_increment+0.5);
200 int range = (int)(m_adjust->upper+0.5);
201 SetScrollbar( pos, objectLength, range, page );
6de97a3b 202}
c801d85f 203
debe6624 204void wxScrollBar::SetViewLength( int viewLength )
c801d85f
KB
205{
206 int pos = (int)(m_adjust->value+0.5);
207 int thumb = (int)(m_adjust->page_size+0.5);
208 int page = (int)(m_adjust->page_increment+0.5);
209 SetScrollbar( pos, thumb, viewLength, page );
6de97a3b 210}
c801d85f 211