]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/gauge.cpp
remove always-true tests of unsigned >= 0
[wxWidgets.git] / src / gtk / gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/gauge.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #if wxUSE_GAUGE
14
15 #include "wx/gauge.h"
16
17 #include <gtk/gtk.h>
18
19 //-----------------------------------------------------------------------------
20 // wxGauge
21 //-----------------------------------------------------------------------------
22
23 bool wxGauge::Create( wxWindow *parent,
24 wxWindowID id,
25 int range,
26 const wxPoint& pos,
27 const wxSize& size,
28 long style,
29 const wxValidator& validator,
30 const wxString& name )
31 {
32 if (!PreCreation( parent, pos, size ) ||
33 !CreateBase( parent, id, pos, size, style, validator, name ))
34 {
35 wxFAIL_MSG( wxT("wxGauge creation failed") );
36 return false;
37 }
38
39 m_rangeMax = range;
40
41 m_widget = gtk_progress_bar_new();
42 g_object_ref(m_widget);
43 if ( style & wxGA_VERTICAL )
44 {
45 gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget),
46 GTK_PROGRESS_BOTTOM_TO_TOP );
47 }
48
49 // when using the gauge in indeterminate mode, we need this:
50 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR (m_widget), 0.05);
51
52 m_parent->DoAddChild( this );
53
54 PostCreation(size);
55 SetInitialSize(size);
56
57 return true;
58 }
59
60 void wxGauge::DoSetGauge()
61 {
62 wxASSERT_MSG( 0 <= m_gaugePos && m_gaugePos <= m_rangeMax,
63 wxT("invalid gauge position in DoSetGauge()") );
64
65 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (m_widget),
66 m_rangeMax ? ((double)m_gaugePos)/m_rangeMax : 0.0);
67 }
68
69 wxSize wxGauge::DoGetBestSize() const
70 {
71 wxSize best;
72 if (HasFlag(wxGA_VERTICAL))
73 best = wxSize(28, 100);
74 else
75 best = wxSize(100, 28);
76 CacheBestSize(best);
77 return best;
78 }
79
80 void wxGauge::SetRange( int range )
81 {
82 m_rangeMax = range;
83 if (m_gaugePos > m_rangeMax)
84 m_gaugePos = m_rangeMax;
85
86 DoSetGauge();
87 }
88
89 void wxGauge::SetValue( int pos )
90 {
91 wxCHECK_RET( pos <= m_rangeMax, wxT("invalid value in wxGauge::SetValue()") );
92
93 m_gaugePos = pos;
94
95 DoSetGauge();
96 }
97
98 int wxGauge::GetRange() const
99 {
100 return m_rangeMax;
101 }
102
103 int wxGauge::GetValue() const
104 {
105 return m_gaugePos;
106 }
107
108 void wxGauge::Pulse()
109 {
110 gtk_progress_bar_pulse(GTK_PROGRESS_BAR (m_widget));
111 }
112
113 wxVisualAttributes wxGauge::GetDefaultAttributes() const
114 {
115 // Visible gauge colours use a different colour state
116 return GetDefaultAttributesFromGTKWidget(m_widget,
117 UseGTKStyleBase(),
118 GTK_STATE_ACTIVE);
119
120 }
121
122 // static
123 wxVisualAttributes
124 wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
125 {
126 return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new,
127 false, GTK_STATE_ACTIVE);
128 }
129
130 #endif // wxUSE_GAUGE