]>
Commit | Line | Data |
---|---|---|
da87a1ca | 1 | ///////////////////////////////////////////////////////////////////////////// |
f6bcfd97 | 2 | // Name: src/msw/gauge95.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 | ||
51741307 | 72 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
73 | WX_DEFINE_FLAGS( wxGaugeStyle ) |
74 | ||
3ff066a4 | 75 | wxBEGIN_FLAGS( wxGaugeStyle ) |
bc9fb572 JS |
76 | // new style border flags, we put them first to |
77 | // use them for streaming out | |
3ff066a4 SC |
78 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
79 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
80 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
81 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
82 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
83 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
213ceb3f | 84 | |
bc9fb572 | 85 | // old style border flags |
3ff066a4 SC |
86 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
87 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
88 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
89 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
90 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 91 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
92 | |
93 | // standard window styles | |
3ff066a4 SC |
94 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
95 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
96 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
97 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 98 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
99 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
100 | wxFLAGS_MEMBER(wxVSCROLL) | |
101 | wxFLAGS_MEMBER(wxHSCROLL) | |
102 | ||
103 | wxFLAGS_MEMBER(wxGA_HORIZONTAL) | |
104 | wxFLAGS_MEMBER(wxGA_VERTICAL) | |
40ff126a | 105 | #if WXWIN_COMPATIBILITY_2_6 |
3ff066a4 | 106 | wxFLAGS_MEMBER(wxGA_PROGRESSBAR) |
40ff126a | 107 | #endif // WXWIN_COMPATIBILITY_2_6 |
3ff066a4 SC |
108 | wxFLAGS_MEMBER(wxGA_SMOOTH) |
109 | ||
110 | wxEND_FLAGS( wxGaugeStyle ) | |
bc9fb572 | 111 | |
f0a126fe | 112 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxGauge, wxControl,"wx/gauge.h") |
51741307 | 113 | |
936f6353 | 114 | wxBEGIN_PROPERTIES_TABLE(wxGauge) |
da0f19f8 VZ |
115 | wxPROPERTY( Value , int , SetValue, GetValue, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
116 | wxPROPERTY( Range , int , SetRange, GetRange, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
117 | wxPROPERTY( ShadowWidth , int , SetShadowWidth, GetShadowWidth, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
118 | wxPROPERTY( BezelFace , int , SetBezelFace, GetBezelFace, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
af498247 | 119 | wxPROPERTY_FLAGS( WindowStyle , wxGaugeStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
3ff066a4 | 120 | wxEND_PROPERTIES_TABLE() |
51741307 | 121 | |
936f6353 | 122 | wxBEGIN_HANDLERS_TABLE(wxGauge) |
3ff066a4 | 123 | wxEND_HANDLERS_TABLE() |
51741307 | 124 | |
936f6353 | 125 | wxCONSTRUCTOR_6( wxGauge , wxWindow* , Parent , wxWindowID , Id , int , Range , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
51741307 | 126 | #else |
936f6353 | 127 | IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) |
51741307 | 128 | #endif |
066f1b7a | 129 | |
f6bcfd97 | 130 | // ============================================================================ |
936f6353 | 131 | // wxGauge implementation |
f6bcfd97 BP |
132 | // ============================================================================ |
133 | ||
da0f19f8 | 134 | // ---------------------------------------------------------------------------- |
936f6353 | 135 | // wxGauge creation |
da0f19f8 | 136 | // ---------------------------------------------------------------------------- |
da87a1ca | 137 | |
936f6353 VZ |
138 | bool wxGauge::Create(wxWindow *parent, |
139 | wxWindowID id, | |
140 | int range, | |
141 | const wxPoint& pos, | |
142 | const wxSize& size, | |
143 | long style, | |
144 | const wxValidator& validator, | |
145 | const wxString& name) | |
da0f19f8 VZ |
146 | { |
147 | if ( !CreateControl(parent, id, pos, size, style, validator, name) ) | |
148 | return false; | |
da87a1ca | 149 | |
da0f19f8 VZ |
150 | if ( !MSWCreateControl(PROGRESS_CLASS, wxEmptyString, pos, size) ) |
151 | return false; | |
da87a1ca | 152 | |
da0f19f8 | 153 | SetRange(range); |
da87a1ca | 154 | |
fe8635a7 RR |
155 | // in case we need to emulate indeterminate mode... |
156 | m_nDirection = wxRIGHT; | |
157 | ||
da0f19f8 VZ |
158 | return true; |
159 | } | |
da87a1ca | 160 | |
936f6353 | 161 | WXDWORD wxGauge::MSWGetStyle(long style, WXDWORD *exstyle) const |
da0f19f8 VZ |
162 | { |
163 | WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle); | |
da87a1ca | 164 | |
da0f19f8 VZ |
165 | if ( style & wxGA_VERTICAL ) |
166 | msStyle |= PBS_VERTICAL; | |
da87a1ca | 167 | |
da0f19f8 VZ |
168 | if ( style & wxGA_SMOOTH ) |
169 | msStyle |= PBS_SMOOTH; | |
da87a1ca | 170 | |
da0f19f8 | 171 | return msStyle; |
da87a1ca JS |
172 | } |
173 | ||
da0f19f8 | 174 | // ---------------------------------------------------------------------------- |
936f6353 | 175 | // wxGauge geometry |
da0f19f8 | 176 | // ---------------------------------------------------------------------------- |
da87a1ca | 177 | |
936f6353 | 178 | wxSize wxGauge::DoGetBestSize() const |
da87a1ca | 179 | { |
a2837c3c VS |
180 | // Windows HIG (http://msdn.microsoft.com/en-us/library/aa511279.aspx) |
181 | // suggest progress bar size of "107 or 237 x 8 dialog units". Let's use | |
182 | // the smaller one. | |
183 | ||
a04f431b | 184 | if (HasFlag(wxGA_VERTICAL)) |
a2837c3c | 185 | return ConvertDialogToPixels(wxSize(8, 107)); |
7bdfb981 | 186 | else |
a2837c3c | 187 | return ConvertDialogToPixels(wxSize(107, 8)); |
da87a1ca JS |
188 | } |
189 | ||
da0f19f8 | 190 | // ---------------------------------------------------------------------------- |
936f6353 | 191 | // wxGauge setters |
da0f19f8 VZ |
192 | // ---------------------------------------------------------------------------- |
193 | ||
936f6353 | 194 | void wxGauge::SetRange(int r) |
da87a1ca | 195 | { |
aaaa6070 VZ |
196 | // Changing range implicitly means we're using determinate mode. |
197 | if ( IsInIndeterminateMode() ) | |
198 | SetDeterminateMode(); | |
fe8635a7 | 199 | |
da0f19f8 | 200 | m_rangeMax = r; |
da87a1ca | 201 | |
9a78988f | 202 | #ifdef PBM_SETRANGE32 |
da0f19f8 | 203 | ::SendMessage(GetHwnd(), PBM_SETRANGE32, 0, r); |
9a78988f | 204 | #else // !PBM_SETRANGE32 |
da0f19f8 VZ |
205 | // fall back to PBM_SETRANGE (limited to 16 bits) |
206 | ::SendMessage(GetHwnd(), PBM_SETRANGE, 0, MAKELPARAM(0, r)); | |
9a78988f | 207 | #endif // PBM_SETRANGE32/!PBM_SETRANGE32 |
da87a1ca JS |
208 | } |
209 | ||
936f6353 | 210 | void wxGauge::SetValue(int pos) |
da87a1ca | 211 | { |
aaaa6070 VZ |
212 | // Setting the value implicitly means that we're using determinate mode. |
213 | if ( IsInIndeterminateMode() ) | |
214 | SetDeterminateMode(); | |
09981ba7 | 215 | |
aaaa6070 VZ |
216 | if ( GetValue() != pos ) |
217 | { | |
218 | m_gaugePos = pos; | |
da87a1ca | 219 | |
aaaa6070 VZ |
220 | ::SendMessage(GetHwnd(), PBM_SETPOS, pos, 0); |
221 | } | |
da87a1ca JS |
222 | } |
223 | ||
936f6353 | 224 | bool wxGauge::SetForegroundColour(const wxColour& col) |
da87a1ca | 225 | { |
cc2b7472 | 226 | if ( !wxControl::SetForegroundColour(col) ) |
da0f19f8 | 227 | return false; |
cc2b7472 | 228 | |
da0f19f8 | 229 | ::SendMessage(GetHwnd(), PBM_SETBARCOLOR, 0, (LPARAM)wxColourToRGB(col)); |
cc2b7472 | 230 | |
da0f19f8 | 231 | return true; |
da87a1ca JS |
232 | } |
233 | ||
936f6353 | 234 | bool wxGauge::SetBackgroundColour(const wxColour& col) |
da87a1ca | 235 | { |
cc2b7472 | 236 | if ( !wxControl::SetBackgroundColour(col) ) |
da0f19f8 | 237 | return false; |
cc2b7472 | 238 | |
da0f19f8 | 239 | ::SendMessage(GetHwnd(), PBM_SETBKCOLOR, 0, (LPARAM)wxColourToRGB(col)); |
cc2b7472 | 240 | |
da0f19f8 | 241 | return true; |
da87a1ca JS |
242 | } |
243 | ||
aaaa6070 | 244 | bool wxGauge::IsInIndeterminateMode() const |
fe8635a7 | 245 | { |
aaaa6070 VZ |
246 | return (::GetWindowLong(GetHwnd(), GWL_STYLE) & PBS_MARQUEE) != 0; |
247 | } | |
fe8635a7 | 248 | |
aaaa6070 VZ |
249 | void wxGauge::SetIndeterminateMode() |
250 | { | |
251 | // Switch the control into indeterminate mode if necessary. | |
252 | if ( !IsInIndeterminateMode() ) | |
253 | { | |
254 | const long style = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
255 | ::SetWindowLong(GetHwnd(), GWL_STYLE, style | PBS_MARQUEE); | |
256 | ::SendMessage(GetHwnd(), PBM_SETMARQUEE, TRUE, 0); | |
257 | } | |
fe8635a7 RR |
258 | } |
259 | ||
936f6353 | 260 | void wxGauge::SetDeterminateMode() |
fe8635a7 | 261 | { |
aaaa6070 VZ |
262 | if ( IsInIndeterminateMode() ) |
263 | { | |
264 | const long style = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
265 | ::SendMessage(GetHwnd(), PBM_SETMARQUEE, FALSE, 0); | |
fe8635a7 | 266 | ::SetWindowLong(GetHwnd(), GWL_STYLE, style & ~PBS_MARQUEE); |
aaaa6070 | 267 | } |
fe8635a7 RR |
268 | } |
269 | ||
936f6353 | 270 | void wxGauge::Pulse() |
fe8635a7 RR |
271 | { |
272 | if (wxApp::GetComCtl32Version() >= 600) | |
273 | { | |
274 | // switch to indeterminate mode if required | |
275 | SetIndeterminateMode(); | |
276 | ||
aaaa6070 | 277 | SendMessage(GetHwnd(), PBM_STEPIT, 0, 0); |
fe8635a7 RR |
278 | } |
279 | else | |
280 | { | |
281 | // emulate indeterminate mode | |
282 | wxGaugeBase::Pulse(); | |
283 | } | |
284 | } | |
285 | ||
47d67540 | 286 | #endif // wxUSE_GAUGE |