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
)
34 if (!PreCreation( parent
, pos
, size
) ||
35 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
37 wxFAIL_MSG( wxT("wxGauge creation failed") );
43 m_widget
= gtk_progress_bar_new();
44 g_object_ref(m_widget
);
45 if ( style
& wxGA_VERTICAL
)
47 gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget
),
48 GTK_PROGRESS_BOTTOM_TO_TOP
);
51 // when using the gauge in indeterminate mode, we need this:
52 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR (m_widget
), 0.05);
54 m_parent
->DoAddChild( this );
62 void wxGauge::DoSetGauge()
64 wxASSERT_MSG( 0 <= m_gaugePos
&& m_gaugePos
<= m_rangeMax
,
65 _T("invalid gauge position in DoSetGauge()") );
67 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (m_widget
),
68 m_rangeMax
? ((double)m_gaugePos
)/m_rangeMax
: 0.0);
71 wxSize
wxGauge::DoGetBestSize() const
74 if (HasFlag(wxGA_VERTICAL
))
75 best
= wxSize(28, 100);
77 best
= wxSize(100, 28);
82 void wxGauge::SetRange( int range
)
85 if (m_gaugePos
> m_rangeMax
)
86 m_gaugePos
= m_rangeMax
;
91 void wxGauge::SetValue( int pos
)
93 wxCHECK_RET( pos
<= m_rangeMax
, _T("invalid value in wxGauge::SetValue()") );
100 int wxGauge::GetRange() const
105 int wxGauge::GetValue() const
110 void wxGauge::Pulse()
112 gtk_progress_bar_pulse(GTK_PROGRESS_BAR (m_widget
));
115 wxVisualAttributes
wxGauge::GetDefaultAttributes() const
117 // Visible gauge colours use a different colour state
118 return GetDefaultAttributesFromGTKWidget(m_widget
,
126 wxGauge::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
128 return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new
,
129 false, GTK_STATE_ACTIVE
);
132 #endif // wxUSE_GAUGE