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