]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/gauge.cpp
Enable variadic macros for VC9 and later.
[wxWidgets.git] / src / msw / gauge.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/gauge.cpp
3// Purpose: wxGauge class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#if wxUSE_GAUGE
28
29#include "wx/gauge.h"
30
31#ifndef WX_PRECOMP
32 #include "wx/app.h"
33
34 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
35#endif
36
37#include "wx/msw/private.h"
38
39// ----------------------------------------------------------------------------
40// constants
41// ----------------------------------------------------------------------------
42
43// old commctrl.h (< 4.71) don't have those
44#ifndef PBS_SMOOTH
45 #define PBS_SMOOTH 0x01
46#endif
47
48#ifndef PBS_VERTICAL
49 #define PBS_VERTICAL 0x04
50#endif
51
52#ifndef PBM_SETBARCOLOR
53 #define PBM_SETBARCOLOR (WM_USER+9)
54#endif
55
56#ifndef PBM_SETBKCOLOR
57 #define PBM_SETBKCOLOR 0x2001
58#endif
59
60#ifndef PBS_MARQUEE
61 #define PBS_MARQUEE 0x08
62#endif
63
64#ifndef PBM_SETMARQUEE
65 #define PBM_SETMARQUEE (WM_USER+10)
66#endif
67
68// ----------------------------------------------------------------------------
69// wxWin macros
70// ----------------------------------------------------------------------------
71
72// ============================================================================
73// wxGauge implementation
74// ============================================================================
75
76// ----------------------------------------------------------------------------
77// wxGauge creation
78// ----------------------------------------------------------------------------
79
80bool wxGauge::Create(wxWindow *parent,
81 wxWindowID id,
82 int range,
83 const wxPoint& pos,
84 const wxSize& size,
85 long style,
86 const wxValidator& validator,
87 const wxString& name)
88{
89 if ( !CreateControl(parent, id, pos, size, style, validator, name) )
90 return false;
91
92 if ( !MSWCreateControl(PROGRESS_CLASS, wxEmptyString, pos, size) )
93 return false;
94
95 SetRange(range);
96
97 // in case we need to emulate indeterminate mode...
98 m_nDirection = wxRIGHT;
99
100 return true;
101}
102
103WXDWORD wxGauge::MSWGetStyle(long style, WXDWORD *exstyle) const
104{
105 WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
106
107 if ( style & wxGA_VERTICAL )
108 msStyle |= PBS_VERTICAL;
109
110 if ( style & wxGA_SMOOTH )
111 msStyle |= PBS_SMOOTH;
112
113 return msStyle;
114}
115
116// ----------------------------------------------------------------------------
117// wxGauge geometry
118// ----------------------------------------------------------------------------
119
120wxSize wxGauge::DoGetBestSize() const
121{
122 // Windows HIG (http://msdn.microsoft.com/en-us/library/aa511279.aspx)
123 // suggest progress bar size of "107 or 237 x 8 dialog units". Let's use
124 // the smaller one.
125
126 if (HasFlag(wxGA_VERTICAL))
127 return ConvertDialogToPixels(wxSize(8, 107));
128 else
129 return ConvertDialogToPixels(wxSize(107, 8));
130}
131
132// ----------------------------------------------------------------------------
133// wxGauge setters
134// ----------------------------------------------------------------------------
135
136void wxGauge::SetRange(int r)
137{
138 // Changing range implicitly means we're using determinate mode.
139 if ( IsInIndeterminateMode() )
140 SetDeterminateMode();
141
142 m_rangeMax = r;
143
144#ifdef PBM_SETRANGE32
145 ::SendMessage(GetHwnd(), PBM_SETRANGE32, 0, r);
146#else // !PBM_SETRANGE32
147 // fall back to PBM_SETRANGE (limited to 16 bits)
148 ::SendMessage(GetHwnd(), PBM_SETRANGE, 0, MAKELPARAM(0, r));
149#endif // PBM_SETRANGE32/!PBM_SETRANGE32
150}
151
152void wxGauge::SetValue(int pos)
153{
154 // Setting the value implicitly means that we're using determinate mode.
155 if ( IsInIndeterminateMode() )
156 SetDeterminateMode();
157
158 if ( GetValue() != pos )
159 {
160 m_gaugePos = pos;
161
162 ::SendMessage(GetHwnd(), PBM_SETPOS, pos, 0);
163 }
164}
165
166bool wxGauge::SetForegroundColour(const wxColour& col)
167{
168 if ( !wxControl::SetForegroundColour(col) )
169 return false;
170
171 ::SendMessage(GetHwnd(), PBM_SETBARCOLOR, 0, (LPARAM)wxColourToRGB(col));
172
173 return true;
174}
175
176bool wxGauge::SetBackgroundColour(const wxColour& col)
177{
178 if ( !wxControl::SetBackgroundColour(col) )
179 return false;
180
181 ::SendMessage(GetHwnd(), PBM_SETBKCOLOR, 0, (LPARAM)wxColourToRGB(col));
182
183 return true;
184}
185
186bool wxGauge::IsInIndeterminateMode() const
187{
188 return (::GetWindowLong(GetHwnd(), GWL_STYLE) & PBS_MARQUEE) != 0;
189}
190
191void wxGauge::SetIndeterminateMode()
192{
193 // Switch the control into indeterminate mode if necessary.
194 if ( !IsInIndeterminateMode() )
195 {
196 const long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
197 ::SetWindowLong(GetHwnd(), GWL_STYLE, style | PBS_MARQUEE);
198 ::SendMessage(GetHwnd(), PBM_SETMARQUEE, TRUE, 0);
199 }
200}
201
202void wxGauge::SetDeterminateMode()
203{
204 if ( IsInIndeterminateMode() )
205 {
206 const long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
207 ::SendMessage(GetHwnd(), PBM_SETMARQUEE, FALSE, 0);
208 ::SetWindowLong(GetHwnd(), GWL_STYLE, style & ~PBS_MARQUEE);
209 }
210}
211
212void wxGauge::Pulse()
213{
214 if (wxApp::GetComCtl32Version() >= 600)
215 {
216 // switch to indeterminate mode if required
217 SetIndeterminateMode();
218
219 SendMessage(GetHwnd(), PBM_STEPIT, 0, 0);
220 }
221 else
222 {
223 // emulate indeterminate mode
224 wxGaugeBase::Pulse();
225 }
226}
227
228#endif // wxUSE_GAUGE