]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/gauge.cpp
key/char event changes for inline editing (japanese/hirgana etc)
[wxWidgets.git] / src / gtk1 / gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #include "wx/gauge.h"
14
15 #if wxUSE_GAUGE
16
17 #include <gtk/gtk.h>
18
19 //-----------------------------------------------------------------------------
20 // wxGauge
21 //-----------------------------------------------------------------------------
22
23 IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
24
25 bool 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 )
33 {
34 m_needParent = TRUE;
35
36 if (!PreCreation( parent, pos, size ) ||
37 !CreateBase( parent, id, pos, size, style, validator, name ))
38 {
39 wxFAIL_MSG( wxT("wxGauge creation failed") );
40 return FALSE;
41 }
42
43 m_rangeMax = range;
44
45 m_widget = gtk_progress_bar_new();
46 if ( style & wxGA_VERTICAL )
47 {
48 gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(m_widget),
49 GTK_PROGRESS_BOTTOM_TO_TOP );
50 }
51
52 m_parent->DoAddChild( this );
53
54 PostCreation(size);
55 SetBestSize(size);
56
57 return TRUE;
58 }
59
60 void wxGauge::DoSetGauge()
61 {
62 wxASSERT_MSG( 0 <= m_gaugePos && m_gaugePos <= m_rangeMax,
63 _T("invalid gauge position in DoSetGauge()") );
64
65 gtk_progress_bar_update( GTK_PROGRESS_BAR(m_widget),
66 m_rangeMax ? ((float)m_gaugePos)/m_rangeMax : 0.);
67 }
68
69 wxSize wxGauge::DoGetBestSize() const
70 {
71 wxSize best;
72 if (HasFlag(wxGA_VERTICAL))
73 best = wxSize(28, 100);
74 else
75 best = wxSize(100, 28);
76 CacheBestSize(best);
77 return best;
78 }
79
80 void wxGauge::SetRange( int range )
81 {
82 m_rangeMax = range;
83 if (m_gaugePos > m_rangeMax)
84 m_gaugePos = m_rangeMax;
85
86 DoSetGauge();
87 }
88
89 void wxGauge::SetValue( int pos )
90 {
91 wxCHECK_RET( pos <= m_rangeMax, _T("invalid value in wxGauge::SetValue()") );
92
93 m_gaugePos = pos;
94
95 DoSetGauge();
96 }
97
98 int wxGauge::GetRange() const
99 {
100 return m_rangeMax;
101 }
102
103 int wxGauge::GetValue() const
104 {
105 return m_gaugePos;
106 }
107
108 wxVisualAttributes 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
118 wxVisualAttributes
119 wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
120 {
121 return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new,
122 false, GTK_STATE_ACTIVE);
123 }
124
125 #endif // wxUSE_GAUGE
126