]>
Commit | Line | Data |
---|---|---|
1a56f55c | 1 | ///////////////////////////////////////////////////////////////////////////// |
9d2c19f1 | 2 | // Name: src/gtk/gauge.cpp |
1a56f55c RR |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
01111366 | 5 | // Copyright: (c) 1998 Robert Roebling |
65571936 | 6 | // Licence: wxWindows licence |
1a56f55c RR |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
14f355c2 VS |
9 | // For compilers that support precompilation, includes "wx.h". |
10 | #include "wx/wxprec.h" | |
11 | ||
dcf924a3 RR |
12 | #if wxUSE_GAUGE |
13 | ||
9d2c19f1 WS |
14 | #include "wx/gauge.h" |
15 | ||
55703c91 | 16 | #include <gtk/gtk.h> |
1a56f55c RR |
17 | |
18 | //----------------------------------------------------------------------------- | |
19 | // wxGauge | |
20 | //----------------------------------------------------------------------------- | |
21 | ||
2b5f62a0 VZ |
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 ) | |
1a56f55c | 30 | { |
4dcaf11a RR |
31 | if (!PreCreation( parent, pos, size ) || |
32 | !CreateBase( parent, id, pos, size, style, validator, name )) | |
33 | { | |
223d09f6 | 34 | wxFAIL_MSG( wxT("wxGauge creation failed") ); |
9d2c19f1 | 35 | return false; |
4dcaf11a | 36 | } |
6de97a3b | 37 | |
4dcaf11a | 38 | m_rangeMax = range; |
4a0f7f3f | 39 | |
4dcaf11a | 40 | m_widget = gtk_progress_bar_new(); |
9ff9d30c | 41 | g_object_ref(m_widget); |
2b5f62a0 VZ |
42 | if ( style & wxGA_VERTICAL ) |
43 | { | |
9dc44eff PC |
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 | |
2b5f62a0 VZ |
48 | gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget), |
49 | GTK_PROGRESS_BOTTOM_TO_TOP ); | |
9dc44eff | 50 | #endif |
2b5f62a0 | 51 | } |
4a0f7f3f | 52 | |
fe8635a7 RR |
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 | ||
4dcaf11a | 56 | m_parent->DoAddChild( this ); |
4a0f7f3f | 57 | |
abdeb9e7 | 58 | PostCreation(size); |
170acdc9 | 59 | SetInitialSize(size); |
3d257b8d | 60 | |
9d2c19f1 | 61 | return true; |
6de97a3b | 62 | } |
1a56f55c | 63 | |
2b5f62a0 VZ |
64 | void wxGauge::DoSetGauge() |
65 | { | |
66 | wxASSERT_MSG( 0 <= m_gaugePos && m_gaugePos <= m_rangeMax, | |
9a83f860 | 67 | wxT("invalid gauge position in DoSetGauge()") ); |
2b5f62a0 | 68 | |
1856b88f | 69 | gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (m_widget), |
3cb7a9ca | 70 | m_rangeMax ? ((double)m_gaugePos)/m_rangeMax : 0.0); |
2b5f62a0 VZ |
71 | } |
72 | ||
3a12cb0a RD |
73 | wxSize wxGauge::DoGetBestSize() const |
74 | { | |
9f884528 | 75 | wxSize best; |
ebbb22bd | 76 | if (HasFlag(wxGA_VERTICAL)) |
9f884528 | 77 | best = wxSize(28, 100); |
ebbb22bd | 78 | else |
9f884528 RD |
79 | best = wxSize(100, 28); |
80 | CacheBestSize(best); | |
81 | return best; | |
3a12cb0a RD |
82 | } |
83 | ||
2b5f62a0 | 84 | void wxGauge::SetRange( int range ) |
1a56f55c | 85 | { |
2b5f62a0 VZ |
86 | m_rangeMax = range; |
87 | if (m_gaugePos > m_rangeMax) | |
88 | m_gaugePos = m_rangeMax; | |
4a0f7f3f | 89 | |
2b5f62a0 | 90 | DoSetGauge(); |
6de97a3b | 91 | } |
1a56f55c | 92 | |
debe6624 | 93 | void wxGauge::SetValue( int pos ) |
1a56f55c | 94 | { |
9a83f860 | 95 | wxCHECK_RET( pos <= m_rangeMax, wxT("invalid value in wxGauge::SetValue()") ); |
2b5f62a0 | 96 | |
4dcaf11a | 97 | m_gaugePos = pos; |
4a0f7f3f | 98 | |
2b5f62a0 | 99 | DoSetGauge(); |
6de97a3b | 100 | } |
1a56f55c | 101 | |
4dcaf11a | 102 | int wxGauge::GetRange() const |
1a56f55c | 103 | { |
4dcaf11a | 104 | return m_rangeMax; |
6de97a3b | 105 | } |
1a56f55c | 106 | |
4dcaf11a | 107 | int wxGauge::GetValue() const |
1a56f55c | 108 | { |
4dcaf11a | 109 | return m_gaugePos; |
6de97a3b | 110 | } |
1a56f55c | 111 | |
fe8635a7 RR |
112 | void wxGauge::Pulse() |
113 | { | |
114 | gtk_progress_bar_pulse(GTK_PROGRESS_BAR (m_widget)); | |
115 | } | |
116 | ||
9d522606 RD |
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 | { | |
7fff16b8 | 130 | return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new(), |
9d522606 RD |
131 | false, GTK_STATE_ACTIVE); |
132 | } | |
133 | ||
4a0f7f3f | 134 | #endif // wxUSE_GAUGE |