]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/gauge.cpp
gtk_signal_connect -> g_signal_connect in unix/mediactrl.cpp
[wxWidgets.git] / src / gtk / gauge.cpp
CommitLineData
1a56f55c
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: gauge.cpp
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
1a56f55c 13#include "wx/gauge.h"
dcf924a3
RR
14
15#if wxUSE_GAUGE
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 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") );
4a0f7f3f 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
4dcaf11a 52 m_parent->DoAddChild( this );
4a0f7f3f 53
abdeb9e7 54 PostCreation(size);
3a12cb0a 55 SetBestSize(size);
3d257b8d 56
4dcaf11a 57 return TRUE;
6de97a3b 58}
1a56f55c 59
2b5f62a0
VZ
60void wxGauge::DoSetGauge()
61{
62 wxASSERT_MSG( 0 <= m_gaugePos && m_gaugePos <= m_rangeMax,
63 _T("invalid gauge position in DoSetGauge()") );
64
1856b88f
MR
65 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (m_widget),
66 m_rangeMax ? ((float)m_gaugePos)/m_rangeMax : 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{
2b5f62a0
VZ
91 wxCHECK_RET( pos <= m_rangeMax, _T("invalid value in wxGauge::SetValue()") );
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
9d522606
RD
108wxVisualAttributes wxGauge::GetDefaultAttributes() const
109{
110 // Visible gauge colours use a different colour state
111 return GetDefaultAttributesFromGTKWidget(m_widget,
112 UseGTKStyleBase(),
113 GTK_STATE_ACTIVE);
114
115}
116
117// static
118wxVisualAttributes
119wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
120{
121 return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new,
122 false, GTK_STATE_ACTIVE);
123}
124
4a0f7f3f
VZ
125#endif // wxUSE_GAUGE
126