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