1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/gauge.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 IMPLEMENT_DYNAMIC_CLASS(wxGauge
, wxControl
)
25 bool wxGauge::Create( wxWindow
*parent
,
31 const wxValidator
& validator
,
32 const wxString
& name
)
36 if (!PreCreation( parent
, pos
, size
) ||
37 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
39 wxFAIL_MSG( wxT("wxGauge creation failed") );
45 m_widget
= gtk_progress_bar_new();
46 if ( style
& wxGA_VERTICAL
)
48 gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget
),
49 GTK_PROGRESS_BOTTOM_TO_TOP
);
52 // when using the gauge in indeterminate mode, we need this:
53 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR (m_widget
), 0.05);
55 m_parent
->DoAddChild( this );
63 void wxGauge::DoSetGauge()
65 wxASSERT_MSG( 0 <= m_gaugePos
&& m_gaugePos
<= m_rangeMax
,
66 _T("invalid gauge position in DoSetGauge()") );
68 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (m_widget
),
69 m_rangeMax
? ((double)m_gaugePos
)/m_rangeMax
: 0.0);
72 wxSize
wxGauge::DoGetBestSize() const
75 if (HasFlag(wxGA_VERTICAL
))
76 best
= wxSize(28, 100);
78 best
= wxSize(100, 28);
83 void wxGauge::SetRange( int range
)
86 if (m_gaugePos
> m_rangeMax
)
87 m_gaugePos
= m_rangeMax
;
92 void wxGauge::SetValue( int pos
)
94 wxCHECK_RET( pos
<= m_rangeMax
, _T("invalid value in wxGauge::SetValue()") );
101 int wxGauge::GetRange() const
106 int wxGauge::GetValue() const
111 void wxGauge::Pulse()
113 gtk_progress_bar_pulse(GTK_PROGRESS_BAR (m_widget
));
116 wxVisualAttributes
wxGauge::GetDefaultAttributes() const
118 // Visible gauge colours use a different colour state
119 return GetDefaultAttributesFromGTKWidget(m_widget
,
127 wxGauge::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
129 return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new
,
130 false, GTK_STATE_ACTIVE
);
133 #endif // wxUSE_GAUGE