]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/gauge.cpp
Fixed some off-by-one errors that were visible on wxGTK but actually
[wxWidgets.git] / src / gtk1 / gauge.cpp
CommitLineData
1a56f55c
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: gauge.cpp
3// Purpose:
4// Author: Robert Roebling
a81258be 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
1a56f55c
RR
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "gauge.h"
12#endif
13
14#include "wx/gauge.h"
dcf924a3
RR
15
16#if wxUSE_GAUGE
17
55703c91
RR
18#include <gdk/gdk.h>
19#include <gtk/gtk.h>
1a56f55c
RR
20
21//-----------------------------------------------------------------------------
22// wxGauge
23//-----------------------------------------------------------------------------
24
25IMPLEMENT_DYNAMIC_CLASS(wxGauge,wxControl)
26
debe6624 27bool wxGauge::Create( wxWindow *parent, wxWindowID id, int range,
1a56f55c 28 const wxPoint& pos, const wxSize& size,
6de97a3b 29 long style, const wxValidator& validator, const wxString& name )
1a56f55c 30{
4dcaf11a 31 m_needParent = TRUE;
1a56f55c 32
4dcaf11a
RR
33 if (!PreCreation( parent, pos, size ) ||
34 !CreateBase( parent, id, pos, size, style, validator, name ))
35 {
223d09f6 36 wxFAIL_MSG( wxT("wxGauge creation failed") );
4dcaf11a
RR
37 return FALSE;
38 }
6de97a3b 39
4dcaf11a
RR
40 m_rangeMax = range;
41 m_gaugePos = 0;
42 m_useProgressBar = TRUE;
1a56f55c 43
4dcaf11a 44 m_widget = gtk_progress_bar_new();
1a56f55c 45
4dcaf11a 46 m_parent->DoAddChild( this );
6ca41e57 47
4dcaf11a 48 PostCreation();
1a56f55c 49
4dcaf11a 50 Show( TRUE );
1a56f55c 51
4dcaf11a 52 return TRUE;
6de97a3b 53}
1a56f55c 54
debe6624 55void wxGauge::SetRange( int r )
1a56f55c 56{
4dcaf11a
RR
57 m_rangeMax = r;
58 if (m_gaugePos > m_rangeMax) m_gaugePos = m_rangeMax;
1a56f55c 59
4dcaf11a 60 gtk_progress_bar_update( GTK_PROGRESS_BAR(m_widget), ((float)m_gaugePos)/m_rangeMax );
6de97a3b 61}
1a56f55c 62
debe6624 63void wxGauge::SetValue( int pos )
1a56f55c 64{
4dcaf11a
RR
65 m_gaugePos = pos;
66 if (m_gaugePos > m_rangeMax) m_gaugePos = m_rangeMax;
1a56f55c 67
4dcaf11a 68 gtk_progress_bar_update( GTK_PROGRESS_BAR(m_widget), ((float)m_gaugePos)/m_rangeMax );
6de97a3b 69}
1a56f55c 70
4dcaf11a 71int wxGauge::GetRange() const
1a56f55c 72{
4dcaf11a 73 return m_rangeMax;
6de97a3b 74}
1a56f55c 75
4dcaf11a 76int wxGauge::GetValue() const
1a56f55c 77{
4dcaf11a 78 return m_gaugePos;
6de97a3b 79}
1a56f55c 80
58614078
RR
81void wxGauge::ApplyWidgetStyle()
82{
4dcaf11a
RR
83 SetWidgetStyle();
84 gtk_widget_set_style( m_widget, m_widgetStyle );
58614078
RR
85}
86
dcf924a3 87#endif