]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/gauge.cpp
Applied #15375 to stop event-sending in generic wxSpinCtrl ctor (eco)
[wxWidgets.git] / src / gtk1 / gauge.cpp
CommitLineData
1a56f55c 1/////////////////////////////////////////////////////////////////////////////
9d2c19f1 2// Name: src/gtk1/gauge.cpp
1a56f55c
RR
3// Purpose:
4// Author: Robert Roebling
01111366 5// Copyright: (c) 1998 Robert Roebling
65571936 6// Licence: wxWindows licence
1a56f55c
RR
7/////////////////////////////////////////////////////////////////////////////
8
14f355c2
VS
9// For compilers that support precompilation, includes "wx.h".
10#include "wx/wxprec.h"
11
dcf924a3
RR
12#if wxUSE_GAUGE
13
9d2c19f1
WS
14#include "wx/gauge.h"
15
55703c91 16#include <gtk/gtk.h>
1a56f55c
RR
17
18//-----------------------------------------------------------------------------
19// wxGauge
20//-----------------------------------------------------------------------------
21
2b5f62a0
VZ
22bool wxGauge::Create( wxWindow *parent,
23 wxWindowID id,
24 int range,
25 const wxPoint& pos,
26 const wxSize& size,
27 long style,
28 const wxValidator& validator,
29 const wxString& name )
1a56f55c 30{
9d2c19f1 31 m_needParent = true;
4a0f7f3f 32
4dcaf11a
RR
33 if (!PreCreation( parent, pos, size ) ||
34 !CreateBase( parent, id, pos, size, style, validator, name ))
35 {
223d09f6 36 wxFAIL_MSG( wxT("wxGauge creation failed") );
9d2c19f1 37 return false;
4dcaf11a 38 }
6de97a3b 39
4dcaf11a 40 m_rangeMax = range;
4a0f7f3f 41
4dcaf11a 42 m_widget = gtk_progress_bar_new();
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
4dcaf11a 49 m_parent->DoAddChild( this );
4a0f7f3f 50
abdeb9e7 51 PostCreation(size);
170acdc9 52 SetInitialSize(size);
3d257b8d 53
9d2c19f1 54 return true;
6de97a3b 55}
1a56f55c 56
2b5f62a0
VZ
57void wxGauge::DoSetGauge()
58{
59 wxASSERT_MSG( 0 <= m_gaugePos && m_gaugePos <= m_rangeMax,
9a83f860 60 wxT("invalid gauge position in DoSetGauge()") );
2b5f62a0
VZ
61
62 gtk_progress_bar_update( GTK_PROGRESS_BAR(m_widget),
63 m_rangeMax ? ((float)m_gaugePos)/m_rangeMax : 0.);
64}
65
3a12cb0a
RD
66wxSize wxGauge::DoGetBestSize() const
67{
9f884528 68 wxSize best;
ebbb22bd 69 if (HasFlag(wxGA_VERTICAL))
9f884528 70 best = wxSize(28, 100);
ebbb22bd 71 else
9f884528
RD
72 best = wxSize(100, 28);
73 CacheBestSize(best);
74 return best;
3a12cb0a
RD
75}
76
2b5f62a0 77void wxGauge::SetRange( int range )
1a56f55c 78{
2b5f62a0
VZ
79 m_rangeMax = range;
80 if (m_gaugePos > m_rangeMax)
81 m_gaugePos = m_rangeMax;
4a0f7f3f 82
2b5f62a0 83 DoSetGauge();
6de97a3b 84}
1a56f55c 85
debe6624 86void wxGauge::SetValue( int pos )
1a56f55c 87{
9a83f860 88 wxCHECK_RET( pos <= m_rangeMax, wxT("invalid value in wxGauge::SetValue()") );
2b5f62a0 89
4dcaf11a 90 m_gaugePos = pos;
4a0f7f3f 91
2b5f62a0 92 DoSetGauge();
6de97a3b 93}
1a56f55c 94
4dcaf11a 95int wxGauge::GetRange() const
1a56f55c 96{
4dcaf11a 97 return m_rangeMax;
6de97a3b 98}
1a56f55c 99
4dcaf11a 100int wxGauge::GetValue() const
1a56f55c 101{
4dcaf11a 102 return m_gaugePos;
6de97a3b 103}
1a56f55c 104
9d522606
RD
105wxVisualAttributes wxGauge::GetDefaultAttributes() const
106{
107 // Visible gauge colours use a different colour state
108 return GetDefaultAttributesFromGTKWidget(m_widget,
109 UseGTKStyleBase(),
110 GTK_STATE_ACTIVE);
111
112}
113
114// static
115wxVisualAttributes
116wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
117{
118 return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new,
119 false, GTK_STATE_ACTIVE);
120}
121
4a0f7f3f 122#endif // wxUSE_GAUGE