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