]>
Commit | Line | Data |
---|---|---|
da87a1ca | 1 | ///////////////////////////////////////////////////////////////////////////// |
f6bcfd97 | 2 | // Name: src/msw/gauge95.cpp |
da87a1ca JS |
3 | // Purpose: wxGauge95 class |
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 |
57bd4c60 | 32 | #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly" |
da87a1ca JS |
33 | #endif |
34 | ||
da87a1ca JS |
35 | #include "wx/msw/private.h" |
36 | ||
f6bcfd97 BP |
37 | // ---------------------------------------------------------------------------- |
38 | // constants | |
39 | // ---------------------------------------------------------------------------- | |
40 | ||
41 | // old commctrl.h (< 4.71) don't have those | |
42 | #ifndef PBS_SMOOTH | |
43 | #define PBS_SMOOTH 0x01 | |
44 | #endif | |
45 | ||
46 | #ifndef PBS_VERTICAL | |
47 | #define PBS_VERTICAL 0x04 | |
48 | #endif | |
49 | ||
50 | #ifndef PBM_SETBARCOLOR | |
51 | #define PBM_SETBARCOLOR (WM_USER+9) | |
52 | #endif | |
53 | ||
54 | #ifndef PBM_SETBKCOLOR | |
55 | #define PBM_SETBKCOLOR 0x2001 | |
56 | #endif | |
57 | ||
fe8635a7 RR |
58 | #ifndef PBS_MARQUEE |
59 | #define PBS_MARQUEE 0x08 | |
60 | #endif | |
61 | ||
62 | #ifndef PBM_SETMARQUEE | |
63 | #define PBM_SETMARQUEE (WM_USER+10) | |
64 | #endif | |
65 | ||
f6bcfd97 BP |
66 | // ---------------------------------------------------------------------------- |
67 | // wxWin macros | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
51741307 | 70 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
71 | WX_DEFINE_FLAGS( wxGaugeStyle ) |
72 | ||
3ff066a4 | 73 | wxBEGIN_FLAGS( wxGaugeStyle ) |
bc9fb572 JS |
74 | // new style border flags, we put them first to |
75 | // use them for streaming out | |
3ff066a4 SC |
76 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
77 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
78 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
79 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
80 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
81 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
213ceb3f | 82 | |
bc9fb572 | 83 | // old style border flags |
3ff066a4 SC |
84 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
85 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
86 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
87 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
88 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 89 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
90 | |
91 | // standard window styles | |
3ff066a4 SC |
92 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
93 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
94 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
95 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 96 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
97 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
98 | wxFLAGS_MEMBER(wxVSCROLL) | |
99 | wxFLAGS_MEMBER(wxHSCROLL) | |
100 | ||
101 | wxFLAGS_MEMBER(wxGA_HORIZONTAL) | |
102 | wxFLAGS_MEMBER(wxGA_VERTICAL) | |
40ff126a | 103 | #if WXWIN_COMPATIBILITY_2_6 |
3ff066a4 | 104 | wxFLAGS_MEMBER(wxGA_PROGRESSBAR) |
40ff126a | 105 | #endif // WXWIN_COMPATIBILITY_2_6 |
3ff066a4 SC |
106 | wxFLAGS_MEMBER(wxGA_SMOOTH) |
107 | ||
108 | wxEND_FLAGS( wxGaugeStyle ) | |
bc9fb572 | 109 | |
f0a126fe | 110 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxGauge, wxControl,"wx/gauge.h") |
51741307 | 111 | |
3ff066a4 | 112 | wxBEGIN_PROPERTIES_TABLE(wxGauge95) |
da0f19f8 VZ |
113 | wxPROPERTY( Value , int , SetValue, GetValue, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
114 | wxPROPERTY( Range , int , SetRange, GetRange, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
115 | wxPROPERTY( ShadowWidth , int , SetShadowWidth, GetShadowWidth, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
116 | wxPROPERTY( BezelFace , int , SetBezelFace, GetBezelFace, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
af498247 | 117 | wxPROPERTY_FLAGS( WindowStyle , wxGaugeStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
3ff066a4 | 118 | wxEND_PROPERTIES_TABLE() |
51741307 | 119 | |
3ff066a4 SC |
120 | wxBEGIN_HANDLERS_TABLE(wxGauge95) |
121 | wxEND_HANDLERS_TABLE() | |
51741307 | 122 | |
213ceb3f | 123 | wxCONSTRUCTOR_6( wxGauge95 , wxWindow* , Parent , wxWindowID , Id , int , Range , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
51741307 SC |
124 | #else |
125 | IMPLEMENT_DYNAMIC_CLASS(wxGauge95, wxControl) | |
126 | #endif | |
066f1b7a | 127 | |
f6bcfd97 | 128 | // ============================================================================ |
da0f19f8 | 129 | // wxGauge95 implementation |
f6bcfd97 BP |
130 | // ============================================================================ |
131 | ||
da0f19f8 VZ |
132 | // ---------------------------------------------------------------------------- |
133 | // wxGauge95 creation | |
134 | // ---------------------------------------------------------------------------- | |
da87a1ca | 135 | |
da0f19f8 VZ |
136 | bool wxGauge95::Create(wxWindow *parent, |
137 | wxWindowID id, | |
138 | int range, | |
139 | const wxPoint& pos, | |
140 | const wxSize& size, | |
141 | long style, | |
142 | const wxValidator& validator, | |
143 | const wxString& name) | |
144 | { | |
145 | if ( !CreateControl(parent, id, pos, size, style, validator, name) ) | |
146 | return false; | |
da87a1ca | 147 | |
da0f19f8 VZ |
148 | if ( !MSWCreateControl(PROGRESS_CLASS, wxEmptyString, pos, size) ) |
149 | return false; | |
da87a1ca | 150 | |
da0f19f8 | 151 | SetRange(range); |
da87a1ca | 152 | |
fe8635a7 RR |
153 | // in case we need to emulate indeterminate mode... |
154 | m_nDirection = wxRIGHT; | |
155 | ||
da0f19f8 VZ |
156 | return true; |
157 | } | |
da87a1ca | 158 | |
da0f19f8 VZ |
159 | WXDWORD wxGauge95::MSWGetStyle(long style, WXDWORD *exstyle) const |
160 | { | |
161 | WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle); | |
da87a1ca | 162 | |
da0f19f8 VZ |
163 | if ( style & wxGA_VERTICAL ) |
164 | msStyle |= PBS_VERTICAL; | |
da87a1ca | 165 | |
da0f19f8 VZ |
166 | if ( style & wxGA_SMOOTH ) |
167 | msStyle |= PBS_SMOOTH; | |
da87a1ca | 168 | |
da0f19f8 | 169 | return msStyle; |
da87a1ca JS |
170 | } |
171 | ||
da0f19f8 VZ |
172 | // ---------------------------------------------------------------------------- |
173 | // wxGauge95 geometry | |
174 | // ---------------------------------------------------------------------------- | |
da87a1ca | 175 | |
da0f19f8 | 176 | wxSize wxGauge95::DoGetBestSize() const |
da87a1ca | 177 | { |
da0f19f8 VZ |
178 | // VZ: no idea where does 28 come from, it was there before my changes and |
179 | // as nobody ever complained I guess we can leave it... | |
a04f431b DS |
180 | if (HasFlag(wxGA_VERTICAL)) |
181 | return wxSize(28, 100); | |
7bdfb981 | 182 | else |
a04f431b | 183 | return wxSize(100, 28); |
da87a1ca JS |
184 | } |
185 | ||
da0f19f8 VZ |
186 | // ---------------------------------------------------------------------------- |
187 | // wxGauge95 setters | |
188 | // ---------------------------------------------------------------------------- | |
189 | ||
debe6624 | 190 | void wxGauge95::SetRange(int r) |
da87a1ca | 191 | { |
fe8635a7 RR |
192 | // switch to determinate mode if required |
193 | SetDeterminateMode(); | |
194 | ||
da0f19f8 | 195 | m_rangeMax = r; |
da87a1ca | 196 | |
9a78988f | 197 | #ifdef PBM_SETRANGE32 |
da0f19f8 | 198 | ::SendMessage(GetHwnd(), PBM_SETRANGE32, 0, r); |
9a78988f | 199 | #else // !PBM_SETRANGE32 |
da0f19f8 VZ |
200 | // fall back to PBM_SETRANGE (limited to 16 bits) |
201 | ::SendMessage(GetHwnd(), PBM_SETRANGE, 0, MAKELPARAM(0, r)); | |
9a78988f | 202 | #endif // PBM_SETRANGE32/!PBM_SETRANGE32 |
da87a1ca JS |
203 | } |
204 | ||
debe6624 | 205 | void wxGauge95::SetValue(int pos) |
da87a1ca | 206 | { |
fe8635a7 RR |
207 | // switch to determinate mode if required |
208 | SetDeterminateMode(); | |
209 | ||
da0f19f8 | 210 | m_gaugePos = pos; |
da87a1ca | 211 | |
da0f19f8 | 212 | ::SendMessage(GetHwnd(), PBM_SETPOS, pos, 0); |
da87a1ca JS |
213 | } |
214 | ||
cc2b7472 | 215 | bool wxGauge95::SetForegroundColour(const wxColour& col) |
da87a1ca | 216 | { |
cc2b7472 | 217 | if ( !wxControl::SetForegroundColour(col) ) |
da0f19f8 | 218 | return false; |
cc2b7472 | 219 | |
da0f19f8 | 220 | ::SendMessage(GetHwnd(), PBM_SETBARCOLOR, 0, (LPARAM)wxColourToRGB(col)); |
cc2b7472 | 221 | |
da0f19f8 | 222 | return true; |
da87a1ca JS |
223 | } |
224 | ||
cc2b7472 | 225 | bool wxGauge95::SetBackgroundColour(const wxColour& col) |
da87a1ca | 226 | { |
cc2b7472 | 227 | if ( !wxControl::SetBackgroundColour(col) ) |
da0f19f8 | 228 | return false; |
cc2b7472 | 229 | |
da0f19f8 | 230 | ::SendMessage(GetHwnd(), PBM_SETBKCOLOR, 0, (LPARAM)wxColourToRGB(col)); |
cc2b7472 | 231 | |
da0f19f8 | 232 | return true; |
da87a1ca JS |
233 | } |
234 | ||
fe8635a7 RR |
235 | void wxGauge95::SetIndeterminateMode() |
236 | { | |
237 | // add the PBS_MARQUEE style to the progress bar | |
238 | LONG style = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
239 | if ((style & PBS_MARQUEE) == 0) | |
240 | ::SetWindowLong(GetHwnd(), GWL_STYLE, style|PBS_MARQUEE); | |
241 | ||
242 | // now the control can only run in indeterminate mode | |
243 | } | |
244 | ||
245 | void wxGauge95::SetDeterminateMode() | |
246 | { | |
247 | // remove the PBS_MARQUEE style to the progress bar | |
248 | LONG style = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
249 | if ((style & PBS_MARQUEE) != 0) | |
250 | ::SetWindowLong(GetHwnd(), GWL_STYLE, style & ~PBS_MARQUEE); | |
251 | ||
252 | // now the control can only run in determinate mode | |
253 | } | |
254 | ||
255 | void wxGauge95::Pulse() | |
256 | { | |
257 | if (wxApp::GetComCtl32Version() >= 600) | |
258 | { | |
259 | // switch to indeterminate mode if required | |
260 | SetIndeterminateMode(); | |
261 | ||
262 | // NOTE: when in indeterminate mode, the PBM_SETPOS message will just make | |
263 | // the bar's blocks move a bit and the WPARAM value is just ignored | |
264 | // so that we can safely use zero | |
265 | SendMessage(GetHwnd(), (UINT) PBM_SETPOS, (WPARAM)0, (LPARAM)0); | |
266 | } | |
267 | else | |
268 | { | |
269 | // emulate indeterminate mode | |
270 | wxGaugeBase::Pulse(); | |
271 | } | |
272 | } | |
273 | ||
47d67540 | 274 | #endif // wxUSE_GAUGE |