]> git.saurik.com Git - wxWidgets.git/blame - src/msw/gauge.cpp
fixing mem leak
[wxWidgets.git] / src / msw / gauge.cpp
CommitLineData
da87a1ca 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/msw/gauge.cpp
936f6353 3// Purpose: wxGauge class
da87a1ca
JS
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
da87a1ca
JS
10/////////////////////////////////////////////////////////////////////////////
11
f6bcfd97
BP
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
da87a1ca
JS
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
da0f19f8 24 #pragma hdrstop
da87a1ca
JS
25#endif
26
7520f3da
WS
27#if wxUSE_GAUGE
28
9d2c19f1
WS
29#include "wx/gauge.h"
30
da87a1ca 31#ifndef WX_PRECOMP
da162534
VZ
32 #include "wx/app.h"
33
57bd4c60 34 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
da87a1ca
JS
35#endif
36
da87a1ca
JS
37#include "wx/msw/private.h"
38
f6bcfd97
BP
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
fe8635a7
RR
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
f6bcfd97
BP
68// ----------------------------------------------------------------------------
69// wxWin macros
70// ----------------------------------------------------------------------------
71
f6bcfd97 72// ============================================================================
936f6353 73// wxGauge implementation
f6bcfd97
BP
74// ============================================================================
75
da0f19f8 76// ----------------------------------------------------------------------------
936f6353 77// wxGauge creation
da0f19f8 78// ----------------------------------------------------------------------------
da87a1ca 79
936f6353
VZ
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)
da0f19f8
VZ
88{
89 if ( !CreateControl(parent, id, pos, size, style, validator, name) )
90 return false;
da87a1ca 91
da0f19f8
VZ
92 if ( !MSWCreateControl(PROGRESS_CLASS, wxEmptyString, pos, size) )
93 return false;
da87a1ca 94
da0f19f8 95 SetRange(range);
da87a1ca 96
fe8635a7
RR
97 // in case we need to emulate indeterminate mode...
98 m_nDirection = wxRIGHT;
99
da0f19f8
VZ
100 return true;
101}
da87a1ca 102
936f6353 103WXDWORD wxGauge::MSWGetStyle(long style, WXDWORD *exstyle) const
da0f19f8
VZ
104{
105 WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
da87a1ca 106
da0f19f8
VZ
107 if ( style & wxGA_VERTICAL )
108 msStyle |= PBS_VERTICAL;
da87a1ca 109
da0f19f8
VZ
110 if ( style & wxGA_SMOOTH )
111 msStyle |= PBS_SMOOTH;
da87a1ca 112
da0f19f8 113 return msStyle;
da87a1ca
JS
114}
115
da0f19f8 116// ----------------------------------------------------------------------------
936f6353 117// wxGauge geometry
da0f19f8 118// ----------------------------------------------------------------------------
da87a1ca 119
936f6353 120wxSize wxGauge::DoGetBestSize() const
da87a1ca 121{
a2837c3c
VS
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
a04f431b 126 if (HasFlag(wxGA_VERTICAL))
a2837c3c 127 return ConvertDialogToPixels(wxSize(8, 107));
7bdfb981 128 else
a2837c3c 129 return ConvertDialogToPixels(wxSize(107, 8));
da87a1ca
JS
130}
131
da0f19f8 132// ----------------------------------------------------------------------------
936f6353 133// wxGauge setters
da0f19f8
VZ
134// ----------------------------------------------------------------------------
135
936f6353 136void wxGauge::SetRange(int r)
da87a1ca 137{
aaaa6070
VZ
138 // Changing range implicitly means we're using determinate mode.
139 if ( IsInIndeterminateMode() )
140 SetDeterminateMode();
fe8635a7 141
da0f19f8 142 m_rangeMax = r;
da87a1ca 143
9a78988f 144#ifdef PBM_SETRANGE32
da0f19f8 145 ::SendMessage(GetHwnd(), PBM_SETRANGE32, 0, r);
9a78988f 146#else // !PBM_SETRANGE32
da0f19f8
VZ
147 // fall back to PBM_SETRANGE (limited to 16 bits)
148 ::SendMessage(GetHwnd(), PBM_SETRANGE, 0, MAKELPARAM(0, r));
9a78988f 149#endif // PBM_SETRANGE32/!PBM_SETRANGE32
da87a1ca
JS
150}
151
936f6353 152void wxGauge::SetValue(int pos)
da87a1ca 153{
aaaa6070
VZ
154 // Setting the value implicitly means that we're using determinate mode.
155 if ( IsInIndeterminateMode() )
156 SetDeterminateMode();
09981ba7 157
aaaa6070
VZ
158 if ( GetValue() != pos )
159 {
160 m_gaugePos = pos;
da87a1ca 161
aaaa6070
VZ
162 ::SendMessage(GetHwnd(), PBM_SETPOS, pos, 0);
163 }
da87a1ca
JS
164}
165
936f6353 166bool wxGauge::SetForegroundColour(const wxColour& col)
da87a1ca 167{
cc2b7472 168 if ( !wxControl::SetForegroundColour(col) )
da0f19f8 169 return false;
cc2b7472 170
da0f19f8 171 ::SendMessage(GetHwnd(), PBM_SETBARCOLOR, 0, (LPARAM)wxColourToRGB(col));
cc2b7472 172
da0f19f8 173 return true;
da87a1ca
JS
174}
175
936f6353 176bool wxGauge::SetBackgroundColour(const wxColour& col)
da87a1ca 177{
cc2b7472 178 if ( !wxControl::SetBackgroundColour(col) )
da0f19f8 179 return false;
cc2b7472 180
da0f19f8 181 ::SendMessage(GetHwnd(), PBM_SETBKCOLOR, 0, (LPARAM)wxColourToRGB(col));
cc2b7472 182
da0f19f8 183 return true;
da87a1ca
JS
184}
185
aaaa6070 186bool wxGauge::IsInIndeterminateMode() const
fe8635a7 187{
aaaa6070
VZ
188 return (::GetWindowLong(GetHwnd(), GWL_STYLE) & PBS_MARQUEE) != 0;
189}
fe8635a7 190
aaaa6070
VZ
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 }
fe8635a7
RR
200}
201
936f6353 202void wxGauge::SetDeterminateMode()
fe8635a7 203{
aaaa6070
VZ
204 if ( IsInIndeterminateMode() )
205 {
206 const long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
207 ::SendMessage(GetHwnd(), PBM_SETMARQUEE, FALSE, 0);
fe8635a7 208 ::SetWindowLong(GetHwnd(), GWL_STYLE, style & ~PBS_MARQUEE);
aaaa6070 209 }
fe8635a7
RR
210}
211
936f6353 212void wxGauge::Pulse()
fe8635a7
RR
213{
214 if (wxApp::GetComCtl32Version() >= 600)
215 {
216 // switch to indeterminate mode if required
217 SetIndeterminateMode();
218
aaaa6070 219 SendMessage(GetHwnd(), PBM_STEPIT, 0, 0);
fe8635a7
RR
220 }
221 else
222 {
223 // emulate indeterminate mode
224 wxGaugeBase::Pulse();
225 }
226}
227
47d67540 228#endif // wxUSE_GAUGE