]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/gauge.cpp
Fix scrolling bug where client size was reported wrong
[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{
9d2c19f1 34 m_needParent = true;
4a0f7f3f 35
4dcaf11a
RR
36 if (!PreCreation( parent, pos, size ) ||
37 !CreateBase( parent, id, pos, size, style, validator, name ))
38 {
223d09f6 39 wxFAIL_MSG( wxT("wxGauge creation failed") );
9d2c19f1 40 return false;
4dcaf11a 41 }
6de97a3b 42
4dcaf11a 43 m_rangeMax = range;
4a0f7f3f 44
4dcaf11a 45 m_widget = gtk_progress_bar_new();
2b5f62a0
VZ
46 if ( style & wxGA_VERTICAL )
47 {
48 gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget),
49 GTK_PROGRESS_BOTTOM_TO_TOP );
50 }
4a0f7f3f 51
fe8635a7
RR
52 // when using the gauge in indeterminate mode, we need this:
53 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR (m_widget), 0.05);
54
4dcaf11a 55 m_parent->DoAddChild( this );
4a0f7f3f 56
abdeb9e7 57 PostCreation(size);
3a12cb0a 58 SetBestSize(size);
3d257b8d 59
9d2c19f1 60 return true;
6de97a3b 61}
1a56f55c 62
2b5f62a0
VZ
63void wxGauge::DoSetGauge()
64{
65 wxASSERT_MSG( 0 <= m_gaugePos && m_gaugePos <= m_rangeMax,
66 _T("invalid gauge position in DoSetGauge()") );
67
1856b88f 68 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (m_widget),
3cb7a9ca 69 m_rangeMax ? ((double)m_gaugePos)/m_rangeMax : 0.0);
2b5f62a0
VZ
70}
71
3a12cb0a
RD
72wxSize wxGauge::DoGetBestSize() const
73{
9f884528 74 wxSize best;
ebbb22bd 75 if (HasFlag(wxGA_VERTICAL))
9f884528 76 best = wxSize(28, 100);
ebbb22bd 77 else
9f884528
RD
78 best = wxSize(100, 28);
79 CacheBestSize(best);
80 return best;
3a12cb0a
RD
81}
82
2b5f62a0 83void wxGauge::SetRange( int range )
1a56f55c 84{
2b5f62a0
VZ
85 m_rangeMax = range;
86 if (m_gaugePos > m_rangeMax)
87 m_gaugePos = m_rangeMax;
4a0f7f3f 88
2b5f62a0 89 DoSetGauge();
6de97a3b 90}
1a56f55c 91
debe6624 92void wxGauge::SetValue( int pos )
1a56f55c 93{
2b5f62a0
VZ
94 wxCHECK_RET( pos <= m_rangeMax, _T("invalid value in wxGauge::SetValue()") );
95
4dcaf11a 96 m_gaugePos = pos;
4a0f7f3f 97
2b5f62a0 98 DoSetGauge();
6de97a3b 99}
1a56f55c 100
4dcaf11a 101int wxGauge::GetRange() const
1a56f55c 102{
4dcaf11a 103 return m_rangeMax;
6de97a3b 104}
1a56f55c 105
4dcaf11a 106int wxGauge::GetValue() const
1a56f55c 107{
4dcaf11a 108 return m_gaugePos;
6de97a3b 109}
1a56f55c 110
fe8635a7
RR
111void wxGauge::Pulse()
112{
113 gtk_progress_bar_pulse(GTK_PROGRESS_BAR (m_widget));
114}
115
9d522606
RD
116wxVisualAttributes wxGauge::GetDefaultAttributes() const
117{
118 // Visible gauge colours use a different colour state
119 return GetDefaultAttributesFromGTKWidget(m_widget,
120 UseGTKStyleBase(),
121 GTK_STATE_ACTIVE);
122
123}
124
125// static
126wxVisualAttributes
127wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
128{
129 return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new,
130 false, GTK_STATE_ACTIVE);
131}
132
4a0f7f3f 133#endif // wxUSE_GAUGE