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