]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/gauge.cpp
fixed a printf() format warning
[wxWidgets.git] / src / gtk / gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gauge.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation "gauge.h"
12 #endif
13
14 #include "wx/gauge.h"
15
16 #if wxUSE_GAUGE
17
18 #include <gtk/gtk.h>
19
20 //-----------------------------------------------------------------------------
21 // wxGauge
22 //-----------------------------------------------------------------------------
23
24 IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
25
26 bool 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 )
34 {
35 m_needParent = TRUE;
36
37 if (!PreCreation( parent, pos, size ) ||
38 !CreateBase( parent, id, pos, size, style, validator, name ))
39 {
40 wxFAIL_MSG( wxT("wxGauge creation failed") );
41 return FALSE;
42 }
43
44 m_rangeMax = range;
45
46 m_widget = gtk_progress_bar_new();
47 if ( style & wxGA_VERTICAL )
48 {
49 gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget),
50 GTK_PROGRESS_BOTTOM_TO_TOP );
51 }
52
53 m_parent->DoAddChild( this );
54
55 PostCreation();
56
57 Show( TRUE );
58
59 return TRUE;
60 }
61
62 void 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
71 void wxGauge::SetRange( int range )
72 {
73 m_rangeMax = range;
74 if (m_gaugePos > m_rangeMax)
75 m_gaugePos = m_rangeMax;
76
77 DoSetGauge();
78 }
79
80 void wxGauge::SetValue( int pos )
81 {
82 wxCHECK_RET( pos <= m_rangeMax, _T("invalid value in wxGauge::SetValue()") );
83
84 m_gaugePos = pos;
85
86 DoSetGauge();
87 }
88
89 int wxGauge::GetRange() const
90 {
91 return m_rangeMax;
92 }
93
94 int wxGauge::GetValue() const
95 {
96 return m_gaugePos;
97 }
98
99 void wxGauge::ApplyWidgetStyle()
100 {
101 SetWidgetStyle();
102 gtk_widget_set_style( m_widget, m_widgetStyle );
103 }
104
105 #endif // wxUSE_GAUGE
106