]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/gauge.cpp
added support for gcc precompiled headers
[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
4a0f7f3f 7// Licence: wxWindows licence
1a56f55c
RR
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 18#include <gtk/gtk.h>
1a56f55c
RR
19
20//-----------------------------------------------------------------------------
21// wxGauge
22//-----------------------------------------------------------------------------
23
2b5f62a0 24IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
1a56f55c 25
2b5f62a0
VZ
26bool wxGauge::Create( wxWindow *parent,
27 wxWindowID id,
28 int range,
29 const wxPoint& pos,
30 const wxSize& size,
31 long style,
32 const wxValidator& validator,
33 const wxString& name )
1a56f55c 34{
4dcaf11a 35 m_needParent = TRUE;
4a0f7f3f 36
4dcaf11a
RR
37 if (!PreCreation( parent, pos, size ) ||
38 !CreateBase( parent, id, pos, size, style, validator, name ))
39 {
223d09f6 40 wxFAIL_MSG( wxT("wxGauge creation failed") );
4a0f7f3f 41 return FALSE;
4dcaf11a 42 }
6de97a3b 43
4dcaf11a 44 m_rangeMax = range;
4a0f7f3f 45
4dcaf11a 46 m_widget = gtk_progress_bar_new();
2b5f62a0
VZ
47 if ( style & wxGA_VERTICAL )
48 {
49 gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget),
50 GTK_PROGRESS_BOTTOM_TO_TOP );
51 }
4a0f7f3f 52
4dcaf11a 53 m_parent->DoAddChild( this );
4a0f7f3f 54
4dcaf11a 55 PostCreation();
4a0f7f3f 56
4dcaf11a 57 Show( TRUE );
4a0f7f3f 58
4dcaf11a 59 return TRUE;
6de97a3b 60}
1a56f55c 61
2b5f62a0
VZ
62void wxGauge::DoSetGauge()
63{
64 wxASSERT_MSG( 0 <= m_gaugePos && m_gaugePos <= m_rangeMax,
65 _T("invalid gauge position in DoSetGauge()") );
66
67 gtk_progress_bar_update( GTK_PROGRESS_BAR(m_widget),
68 m_rangeMax ? ((float)m_gaugePos)/m_rangeMax : 0.);
69}
70
71void wxGauge::SetRange( int range )
1a56f55c 72{
2b5f62a0
VZ
73 m_rangeMax = range;
74 if (m_gaugePos > m_rangeMax)
75 m_gaugePos = m_rangeMax;
4a0f7f3f 76
2b5f62a0 77 DoSetGauge();
6de97a3b 78}
1a56f55c 79
debe6624 80void wxGauge::SetValue( int pos )
1a56f55c 81{
2b5f62a0
VZ
82 wxCHECK_RET( pos <= m_rangeMax, _T("invalid value in wxGauge::SetValue()") );
83
4dcaf11a 84 m_gaugePos = pos;
4a0f7f3f 85
2b5f62a0 86 DoSetGauge();
6de97a3b 87}
1a56f55c 88
4dcaf11a 89int wxGauge::GetRange() const
1a56f55c 90{
4dcaf11a 91 return m_rangeMax;
6de97a3b 92}
1a56f55c 93
4dcaf11a 94int wxGauge::GetValue() const
1a56f55c 95{
4dcaf11a 96 return m_gaugePos;
6de97a3b 97}
1a56f55c 98
58614078
RR
99void wxGauge::ApplyWidgetStyle()
100{
4dcaf11a
RR
101 SetWidgetStyle();
102 gtk_widget_set_style( m_widget, m_widgetStyle );
58614078
RR
103}
104
4a0f7f3f
VZ
105#endif // wxUSE_GAUGE
106