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