]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/gauge.cpp
Wrappers for *ToText
[wxWidgets.git] / src / gtk / gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gauge.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "gauge.h"
12 #endif
13
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
16
17 #include "wx/gauge.h"
18
19 #if wxUSE_GAUGE
20
21 #include <gtk/gtk.h>
22
23 //-----------------------------------------------------------------------------
24 // wxGauge
25 //-----------------------------------------------------------------------------
26
27 IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
28
29 bool wxGauge::Create( wxWindow *parent,
30 wxWindowID id,
31 int range,
32 const wxPoint& pos,
33 const wxSize& size,
34 long style,
35 const wxValidator& validator,
36 const wxString& name )
37 {
38 m_needParent = TRUE;
39
40 if (!PreCreation( parent, pos, size ) ||
41 !CreateBase( parent, id, pos, size, style, validator, name ))
42 {
43 wxFAIL_MSG( wxT("wxGauge creation failed") );
44 return FALSE;
45 }
46
47 m_rangeMax = range;
48
49 m_widget = gtk_progress_bar_new();
50 if ( style & wxGA_VERTICAL )
51 {
52 gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget),
53 GTK_PROGRESS_BOTTOM_TO_TOP );
54 }
55
56 m_parent->DoAddChild( this );
57
58 PostCreation(size);
59 SetBestSize(size);
60
61 return TRUE;
62 }
63
64 void wxGauge::DoSetGauge()
65 {
66 wxASSERT_MSG( 0 <= m_gaugePos && m_gaugePos <= m_rangeMax,
67 _T("invalid gauge position in DoSetGauge()") );
68
69 gtk_progress_bar_update( GTK_PROGRESS_BAR(m_widget),
70 m_rangeMax ? ((float)m_gaugePos)/m_rangeMax : 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, _T("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 wxVisualAttributes wxGauge::GetDefaultAttributes() const
113 {
114 // Visible gauge colours use a different colour state
115 return GetDefaultAttributesFromGTKWidget(m_widget,
116 UseGTKStyleBase(),
117 GTK_STATE_ACTIVE);
118
119 }
120
121 // static
122 wxVisualAttributes
123 wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
124 {
125 return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new,
126 false, GTK_STATE_ACTIVE);
127 }
128
129 #endif // wxUSE_GAUGE
130