1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/gauge.cpp
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 bool wxGauge::Create( wxWindow
*parent
,
28 const wxValidator
& validator
,
29 const wxString
& name
)
31 if (!PreCreation( parent
, pos
, size
) ||
32 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
34 wxFAIL_MSG( wxT("wxGauge creation failed") );
40 m_widget
= gtk_progress_bar_new();
41 g_object_ref(m_widget
);
42 if ( style
& wxGA_VERTICAL
)
45 gtk_orientable_set_orientation(GTK_ORIENTABLE(m_widget
), GTK_ORIENTATION_VERTICAL
);
46 gtk_progress_bar_set_inverted(GTK_PROGRESS_BAR(m_widget
), true);
48 gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget
),
49 GTK_PROGRESS_BOTTOM_TO_TOP
);
53 // when using the gauge in indeterminate mode, we need this:
54 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR (m_widget
), 0.05);
56 m_parent
->DoAddChild( this );
64 void wxGauge::DoSetGauge()
66 wxASSERT_MSG( 0 <= m_gaugePos
&& m_gaugePos
<= m_rangeMax
,
67 wxT("invalid gauge position in DoSetGauge()") );
69 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (m_widget
),
70 m_rangeMax
? ((double)m_gaugePos
)/m_rangeMax
: 0.0);
73 wxSize
wxGauge::DoGetBestSize() const
76 if (HasFlag(wxGA_VERTICAL
))
77 best
= wxSize(28, 100);
79 best
= wxSize(100, 28);
84 void wxGauge::SetRange( int range
)
87 if (m_gaugePos
> m_rangeMax
)
88 m_gaugePos
= m_rangeMax
;
93 void wxGauge::SetValue( int pos
)
95 wxCHECK_RET( pos
<= m_rangeMax
, wxT("invalid value in wxGauge::SetValue()") );
102 int wxGauge::GetRange() const
107 int wxGauge::GetValue() const
112 void wxGauge::Pulse()
114 gtk_progress_bar_pulse(GTK_PROGRESS_BAR (m_widget
));
117 wxVisualAttributes
wxGauge::GetDefaultAttributes() const
119 // Visible gauge colours use a different colour state
120 return GetDefaultAttributesFromGTKWidget(m_widget
,
128 wxGauge::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
130 return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new(),
131 false, GTK_STATE_ACTIVE
);
134 #endif // wxUSE_GAUGE