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