]>
Commit | Line | Data |
---|---|---|
1a56f55c RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: gauge.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
a81258be | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
4a0f7f3f | 7 | // Licence: wxWindows licence |
1a56f55c RR |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 | 10 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
1a56f55c RR |
11 | #pragma implementation "gauge.h" |
12 | #endif | |
13 | ||
14f355c2 VS |
14 | // For compilers that support precompilation, includes "wx.h". |
15 | #include "wx/wxprec.h" | |
16 | ||
1a56f55c | 17 | #include "wx/gauge.h" |
dcf924a3 RR |
18 | |
19 | #if wxUSE_GAUGE | |
20 | ||
55703c91 | 21 | #include <gtk/gtk.h> |
1a56f55c RR |
22 | |
23 | //----------------------------------------------------------------------------- | |
24 | // wxGauge | |
25 | //----------------------------------------------------------------------------- | |
26 | ||
2b5f62a0 | 27 | IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) |
1a56f55c | 28 | |
2b5f62a0 VZ |
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 ) | |
1a56f55c | 37 | { |
4dcaf11a | 38 | m_needParent = TRUE; |
4a0f7f3f | 39 | |
4dcaf11a RR |
40 | if (!PreCreation( parent, pos, size ) || |
41 | !CreateBase( parent, id, pos, size, style, validator, name )) | |
42 | { | |
223d09f6 | 43 | wxFAIL_MSG( wxT("wxGauge creation failed") ); |
4a0f7f3f | 44 | return FALSE; |
4dcaf11a | 45 | } |
6de97a3b | 46 | |
4dcaf11a | 47 | m_rangeMax = range; |
4a0f7f3f | 48 | |
4dcaf11a | 49 | m_widget = gtk_progress_bar_new(); |
2b5f62a0 VZ |
50 | if ( style & wxGA_VERTICAL ) |
51 | { | |
52 | gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget), | |
53 | GTK_PROGRESS_BOTTOM_TO_TOP ); | |
54 | } | |
4a0f7f3f | 55 | |
4dcaf11a | 56 | m_parent->DoAddChild( this ); |
4a0f7f3f | 57 | |
abdeb9e7 | 58 | PostCreation(size); |
3a12cb0a RD |
59 | SetBestSize(size); |
60 | ||
4dcaf11a | 61 | return TRUE; |
6de97a3b | 62 | } |
1a56f55c | 63 | |
2b5f62a0 VZ |
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 | ||
3a12cb0a RD |
73 | wxSize wxGauge::DoGetBestSize() const |
74 | { | |
ebbb22bd | 75 | if (HasFlag(wxGA_VERTICAL)) |
7bdfb981 | 76 | return wxSize(28, 100); |
ebbb22bd RR |
77 | else |
78 | return wxSize(100, 28); | |
3a12cb0a RD |
79 | } |
80 | ||
2b5f62a0 | 81 | void wxGauge::SetRange( int range ) |
1a56f55c | 82 | { |
2b5f62a0 VZ |
83 | m_rangeMax = range; |
84 | if (m_gaugePos > m_rangeMax) | |
85 | m_gaugePos = m_rangeMax; | |
4a0f7f3f | 86 | |
2b5f62a0 | 87 | DoSetGauge(); |
6de97a3b | 88 | } |
1a56f55c | 89 | |
debe6624 | 90 | void wxGauge::SetValue( int pos ) |
1a56f55c | 91 | { |
2b5f62a0 VZ |
92 | wxCHECK_RET( pos <= m_rangeMax, _T("invalid value in wxGauge::SetValue()") ); |
93 | ||
4dcaf11a | 94 | m_gaugePos = pos; |
4a0f7f3f | 95 | |
2b5f62a0 | 96 | DoSetGauge(); |
6de97a3b | 97 | } |
1a56f55c | 98 | |
4dcaf11a | 99 | int wxGauge::GetRange() const |
1a56f55c | 100 | { |
4dcaf11a | 101 | return m_rangeMax; |
6de97a3b | 102 | } |
1a56f55c | 103 | |
4dcaf11a | 104 | int wxGauge::GetValue() const |
1a56f55c | 105 | { |
4dcaf11a | 106 | return m_gaugePos; |
6de97a3b | 107 | } |
1a56f55c | 108 | |
58614078 RR |
109 | void wxGauge::ApplyWidgetStyle() |
110 | { | |
4dcaf11a RR |
111 | SetWidgetStyle(); |
112 | gtk_widget_set_style( m_widget, m_widgetStyle ); | |
58614078 RR |
113 | } |
114 | ||
9d522606 RD |
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 | ||
4a0f7f3f VZ |
132 | #endif // wxUSE_GAUGE |
133 |