]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/gauge.cpp
non-pch build fix, indentation and whitespace cleanup
[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 IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
24
25 bool wxGauge::Create( wxWindow *parent,
26 wxWindowID id,
27 int range,
28 const wxPoint& pos,
29 const wxSize& size,
30 long style,
31 const wxValidator& validator,
32 const wxString& name )
33 {
34 if (!PreCreation( parent, pos, size ) ||
35 !CreateBase( parent, id, pos, size, style, validator, name ))
36 {
37 wxFAIL_MSG( wxT("wxGauge creation failed") );
38 return false;
39 }
40
41 m_rangeMax = range;
42
43 m_widget = gtk_progress_bar_new();
44 if ( style & wxGA_VERTICAL )
45 {
46 gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget),
47 GTK_PROGRESS_BOTTOM_TO_TOP );
48 }
49
50 // when using the gauge in indeterminate mode, we need this:
51 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR (m_widget), 0.05);
52
53 m_parent->DoAddChild( this );
54
55 PostCreation(size);
56 SetInitialSize(size);
57
58 return true;
59 }
60
61 void wxGauge::DoSetGauge()
62 {
63 wxASSERT_MSG( 0 <= m_gaugePos && m_gaugePos <= m_rangeMax,
64 _T("invalid gauge position in DoSetGauge()") );
65
66 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (m_widget),
67 m_rangeMax ? ((double)m_gaugePos)/m_rangeMax : 0.0);
68 }
69
70 wxSize wxGauge::DoGetBestSize() const
71 {
72 wxSize best;
73 if (HasFlag(wxGA_VERTICAL))
74 best = wxSize(28, 100);
75 else
76 best = wxSize(100, 28);
77 CacheBestSize(best);
78 return best;
79 }
80
81 void wxGauge::SetRange( int range )
82 {
83 m_rangeMax = range;
84 if (m_gaugePos > m_rangeMax)
85 m_gaugePos = m_rangeMax;
86
87 DoSetGauge();
88 }
89
90 void wxGauge::SetValue( int pos )
91 {
92 wxCHECK_RET( pos <= m_rangeMax, _T("invalid value in wxGauge::SetValue()") );
93
94 m_gaugePos = pos;
95
96 DoSetGauge();
97 }
98
99 int wxGauge::GetRange() const
100 {
101 return m_rangeMax;
102 }
103
104 int wxGauge::GetValue() const
105 {
106 return m_gaugePos;
107 }
108
109 void wxGauge::Pulse()
110 {
111 gtk_progress_bar_pulse(GTK_PROGRESS_BAR (m_widget));
112 }
113
114 wxVisualAttributes wxGauge::GetDefaultAttributes() const
115 {
116 // Visible gauge colours use a different colour state
117 return GetDefaultAttributesFromGTKWidget(m_widget,
118 UseGTKStyleBase(),
119 GTK_STATE_ACTIVE);
120
121 }
122
123 // static
124 wxVisualAttributes
125 wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
126 {
127 return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new,
128 false, GTK_STATE_ACTIVE);
129 }
130
131 #endif // wxUSE_GAUGE