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