]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/scrolbar.cpp
Added wxFrame::OnCreateStatusBar and ToolBar
[wxWidgets.git] / src / gtk / 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*/
62};
63
64IMPLEMENT_DYNAMIC_CLASS(wxScrollBar,wxControl)
65
debe6624 66wxScrollBar::wxScrollBar(wxWindow *parent, wxWindowID id,
c801d85f 67 const wxPoint& pos, const wxSize& size,
debe6624 68 long style, const wxString& name )
c801d85f
KB
69{
70 Create( parent, id, pos, size, style, name );
71};
72
73wxScrollBar::~wxScrollBar(void)
74{
75};
76
debe6624 77bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
c801d85f 78 const wxPoint& pos, const wxSize& size,
debe6624 79 long style, const wxString& name )
c801d85f
KB
80{
81 m_needParent = TRUE;
82
83 PreCreation( parent, id, pos, size, style, name );
84
85 m_oldPos = 0.0;
86
87 if (style & wxSB_VERTICAL == wxSB_VERTICAL)
88 m_widget = gtk_hscrollbar_new( NULL );
89 else
90 m_widget = gtk_vscrollbar_new( NULL );
91
92 m_adjust = gtk_range_get_adjustment( GTK_RANGE(m_widget) );
93
94 gtk_signal_connect (GTK_OBJECT (m_adjust), "value_changed",
95 (GtkSignalFunc) gtk_scrollbar_callback, (gpointer) this );
96
97 PostCreation();
98
99 Show( TRUE );
100
101 return TRUE;
102};
103
104int wxScrollBar::GetPosition(void) const
105{
106 return (int)(m_adjust->value+0.5);
107};
108
109int wxScrollBar::GetThumbSize() const
110{
111 return (int)(m_adjust->page_size+0.5);
112};
113
114int wxScrollBar::GetPageSize() const
115{
116 return (int)(m_adjust->page_increment+0.5);
117};
118
119int wxScrollBar::GetRange() const
120{
121 return (int)(m_adjust->upper+0.5);
122};
123
debe6624 124void wxScrollBar::SetPosition( int viewStart )
c801d85f
KB
125{
126 float fpos = (float)viewStart;
127 m_oldPos = fpos;
128 if (fabs(fpos-m_adjust->value) < 0.2) return;
129 m_adjust->value = fpos;
130
131 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "value_changed" );
132};
133
debe6624
JS
134void wxScrollBar::SetScrollbar( int position, int thumbSize, int range, int pageSize,
135 bool WXUNUSED(refresh) )
c801d85f
KB
136{
137 float fpos = (float)position;
138 m_oldPos = fpos;
139 float frange = (float)range;
140 float fthumb = (float)thumbSize;
141 float fpage = (float)pageSize;
142
143 if ((fabs(fpos-m_adjust->value) < 0.2) &&
144 (fabs(frange-m_adjust->upper) < 0.2) &&
145 (fabs(fthumb-m_adjust->page_size) < 0.2) &&
146 (fabs(fpage-m_adjust->page_increment) < 0.2))
147 return;
148
149 m_adjust->lower = 0.0;
150 m_adjust->upper = frange;
151 m_adjust->value = fpos;
152 m_adjust->step_increment = 1.0;
153 m_adjust->page_increment = (float)(wxMax(fpage-2,0));
154 m_adjust->page_size = fthumb;
155
156 gtk_signal_emit_by_name( GTK_OBJECT(m_adjust), "changed" );
157};
158
159// Backward compatibility
160int wxScrollBar::GetValue(void) const
161{
162 return GetPosition();
163};
164
debe6624 165void wxScrollBar::SetValue( int viewStart )
c801d85f
KB
166{
167 SetPosition( viewStart );
168};
169
170void wxScrollBar::GetValues( int *viewStart, int *viewLength, int *objectLength, int *pageLength ) const
171{
172 int pos = (int)(m_adjust->value+0.5);
173 int thumb = (int)(m_adjust->page_size+0.5);
174 int page = (int)(m_adjust->page_increment+0.5);
175 int range = (int)(m_adjust->upper+0.5);
176
177 *viewStart = pos;
178 *viewLength = range;
179 *objectLength = thumb;
180 *pageLength = page;
181};
182
183int wxScrollBar::GetViewLength() const
184{
185 return (int)(m_adjust->upper+0.5);
186};
187
188int wxScrollBar::GetObjectLength() const
189{
190 return (int)(m_adjust->page_size+0.5);
191};
192
debe6624 193void wxScrollBar::SetPageSize( int pageLength )
c801d85f
KB
194{
195 int pos = (int)(m_adjust->value+0.5);
196 int thumb = (int)(m_adjust->page_size+0.5);
197 int range = (int)(m_adjust->upper+0.5);
198 SetScrollbar( pos, thumb, range, pageLength );
199};
200
debe6624 201void wxScrollBar::SetObjectLength( int objectLength )
c801d85f
KB
202{
203 int pos = (int)(m_adjust->value+0.5);
204 int page = (int)(m_adjust->page_increment+0.5);
205 int range = (int)(m_adjust->upper+0.5);
206 SetScrollbar( pos, objectLength, range, page );
207};
208
debe6624 209void wxScrollBar::SetViewLength( int viewLength )
c801d85f
KB
210{
211 int pos = (int)(m_adjust->value+0.5);
212 int thumb = (int)(m_adjust->page_size+0.5);
213 int page = (int)(m_adjust->page_increment+0.5);
214 SetScrollbar( pos, thumb, viewLength, page );
215};
216