]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/gauge.cpp
Fix broken and missing DataView interface items for Phoenix
[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 #ifdef __WXGTK3__
46 gtk_orientable_set_orientation(GTK_ORIENTABLE(m_widget), GTK_ORIENTATION_VERTICAL);
47 gtk_progress_bar_set_inverted(GTK_PROGRESS_BAR(m_widget), true);
48 #else
49 gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget),
50 GTK_PROGRESS_BOTTOM_TO_TOP );
51 #endif
52 }
53
54 // when using the gauge in indeterminate mode, we need this:
55 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR (m_widget), 0.05);
56
57 m_parent->DoAddChild( this );
58
59 PostCreation(size);
60 SetInitialSize(size);
61
62 return true;
63 }
64
65 void wxGauge::DoSetGauge()
66 {
67 wxASSERT_MSG( 0 <= m_gaugePos && m_gaugePos <= m_rangeMax,
68 wxT("invalid gauge position in DoSetGauge()") );
69
70 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (m_widget),
71 m_rangeMax ? ((double)m_gaugePos)/m_rangeMax : 0.0);
72 }
73
74 wxSize wxGauge::DoGetBestSize() const
75 {
76 wxSize best;
77 if (HasFlag(wxGA_VERTICAL))
78 best = wxSize(28, 100);
79 else
80 best = wxSize(100, 28);
81 CacheBestSize(best);
82 return best;
83 }
84
85 void wxGauge::SetRange( int range )
86 {
87 m_rangeMax = range;
88 if (m_gaugePos > m_rangeMax)
89 m_gaugePos = m_rangeMax;
90
91 DoSetGauge();
92 }
93
94 void wxGauge::SetValue( int pos )
95 {
96 wxCHECK_RET( pos <= m_rangeMax, wxT("invalid value in wxGauge::SetValue()") );
97
98 m_gaugePos = pos;
99
100 DoSetGauge();
101 }
102
103 int wxGauge::GetRange() const
104 {
105 return m_rangeMax;
106 }
107
108 int wxGauge::GetValue() const
109 {
110 return m_gaugePos;
111 }
112
113 void wxGauge::Pulse()
114 {
115 gtk_progress_bar_pulse(GTK_PROGRESS_BAR (m_widget));
116 }
117
118 wxVisualAttributes wxGauge::GetDefaultAttributes() const
119 {
120 // Visible gauge colours use a different colour state
121 return GetDefaultAttributesFromGTKWidget(m_widget,
122 UseGTKStyleBase(),
123 GTK_STATE_ACTIVE);
124
125 }
126
127 // static
128 wxVisualAttributes
129 wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
130 {
131 return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new,
132 false, GTK_STATE_ACTIVE);
133 }
134
135 #endif // wxUSE_GAUGE