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