]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/gauge.cpp
Fixed wxRichTextCtrl caret test case
[wxWidgets.git] / src / gtk1 / gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/gauge.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #if wxUSE_GAUGE
14
15 #include "wx/gauge.h"
16
17 #include <gtk/gtk.h>
18
19 //-----------------------------------------------------------------------------
20 // wxGauge
21 //-----------------------------------------------------------------------------
22
23 bool 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 )
31 {
32 m_needParent = true;
33
34 if (!PreCreation( parent, pos, size ) ||
35 !CreateBase( parent, id, pos, size, style, validator, name ))
36 {
37 wxFAIL_MSG( wxT("wxGauge creation failed") );
38 return false;
39 }
40
41 m_rangeMax = range;
42
43 m_widget = gtk_progress_bar_new();
44 if ( style & wxGA_VERTICAL )
45 {
46 gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget),
47 GTK_PROGRESS_BOTTOM_TO_TOP );
48 }
49
50 m_parent->DoAddChild( this );
51
52 PostCreation(size);
53 SetInitialSize(size);
54
55 return true;
56 }
57
58 void wxGauge::DoSetGauge()
59 {
60 wxASSERT_MSG( 0 <= m_gaugePos && m_gaugePos <= m_rangeMax,
61 wxT("invalid gauge position in DoSetGauge()") );
62
63 gtk_progress_bar_update( GTK_PROGRESS_BAR(m_widget),
64 m_rangeMax ? ((float)m_gaugePos)/m_rangeMax : 0.);
65 }
66
67 wxSize wxGauge::DoGetBestSize() const
68 {
69 wxSize best;
70 if (HasFlag(wxGA_VERTICAL))
71 best = wxSize(28, 100);
72 else
73 best = wxSize(100, 28);
74 CacheBestSize(best);
75 return best;
76 }
77
78 void wxGauge::SetRange( int range )
79 {
80 m_rangeMax = range;
81 if (m_gaugePos > m_rangeMax)
82 m_gaugePos = m_rangeMax;
83
84 DoSetGauge();
85 }
86
87 void wxGauge::SetValue( int pos )
88 {
89 wxCHECK_RET( pos <= m_rangeMax, wxT("invalid value in wxGauge::SetValue()") );
90
91 m_gaugePos = pos;
92
93 DoSetGauge();
94 }
95
96 int wxGauge::GetRange() const
97 {
98 return m_rangeMax;
99 }
100
101 int wxGauge::GetValue() const
102 {
103 return m_gaugePos;
104 }
105
106 wxVisualAttributes wxGauge::GetDefaultAttributes() const
107 {
108 // Visible gauge colours use a different colour state
109 return GetDefaultAttributesFromGTKWidget(m_widget,
110 UseGTKStyleBase(),
111 GTK_STATE_ACTIVE);
112
113 }
114
115 // static
116 wxVisualAttributes
117 wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
118 {
119 return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new,
120 false, GTK_STATE_ACTIVE);
121 }
122
123 #endif // wxUSE_GAUGE