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