]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/gauge.cpp
Performance optimization
[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();
2b5f62a0
VZ
44 if ( style & wxGA_VERTICAL )
45 {
46 gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget),
47 GTK_PROGRESS_BOTTOM_TO_TOP );
48 }
4a0f7f3f 49
fe8635a7
RR
50 // when using the gauge in indeterminate mode, we need this:
51 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR (m_widget), 0.05);
52
4dcaf11a 53 m_parent->DoAddChild( this );
4a0f7f3f 54
abdeb9e7 55 PostCreation(size);
170acdc9 56 SetInitialSize(size);
3d257b8d 57
9d2c19f1 58 return true;
6de97a3b 59}
1a56f55c 60
2b5f62a0
VZ
61void wxGauge::DoSetGauge()
62{
63 wxASSERT_MSG( 0 <= m_gaugePos && m_gaugePos <= m_rangeMax,
64 _T("invalid gauge position in DoSetGauge()") );
65
1856b88f 66 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (m_widget),
3cb7a9ca 67 m_rangeMax ? ((double)m_gaugePos)/m_rangeMax : 0.0);
2b5f62a0
VZ
68}
69
3a12cb0a
RD
70wxSize wxGauge::DoGetBestSize() const
71{
9f884528 72 wxSize best;
ebbb22bd 73 if (HasFlag(wxGA_VERTICAL))
9f884528 74 best = wxSize(28, 100);
ebbb22bd 75 else
9f884528
RD
76 best = wxSize(100, 28);
77 CacheBestSize(best);
78 return best;
3a12cb0a
RD
79}
80
2b5f62a0 81void 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 90void 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 99int wxGauge::GetRange() const
1a56f55c 100{
4dcaf11a 101 return m_rangeMax;
6de97a3b 102}
1a56f55c 103
4dcaf11a 104int wxGauge::GetValue() const
1a56f55c 105{
4dcaf11a 106 return m_gaugePos;
6de97a3b 107}
1a56f55c 108
fe8635a7
RR
109void wxGauge::Pulse()
110{
111 gtk_progress_bar_pulse(GTK_PROGRESS_BAR (m_widget));
112}
113
9d522606
RD
114wxVisualAttributes wxGauge::GetDefaultAttributes() const
115{
116 // Visible gauge colours use a different colour state
117 return GetDefaultAttributesFromGTKWidget(m_widget,
118 UseGTKStyleBase(),
119 GTK_STATE_ACTIVE);
120
121}
122
123// static
124wxVisualAttributes
125wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
126{
127 return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new,
128 false, GTK_STATE_ACTIVE);
129}
130
4a0f7f3f 131#endif // wxUSE_GAUGE