]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/msw/gauge95.cpp | |
3 | // Purpose: wxGauge class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // For compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #if wxUSE_GAUGE | |
28 | ||
29 | #include "wx/gauge.h" | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/app.h" | |
33 | ||
34 | #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly" | |
35 | #endif | |
36 | ||
37 | #include "wx/msw/private.h" | |
38 | ||
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 | ||
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 | ||
68 | // ---------------------------------------------------------------------------- | |
69 | // wxWin macros | |
70 | // ---------------------------------------------------------------------------- | |
71 | ||
72 | #if wxUSE_EXTENDED_RTTI | |
73 | WX_DEFINE_FLAGS( wxGaugeStyle ) | |
74 | ||
75 | wxBEGIN_FLAGS( wxGaugeStyle ) | |
76 | // new style border flags, we put them first to | |
77 | // use them for streaming out | |
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) | |
84 | ||
85 | // old style border flags | |
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) | |
91 | wxFLAGS_MEMBER(wxBORDER) | |
92 | ||
93 | // standard window styles | |
94 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) | |
95 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
96 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
97 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
98 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) | |
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) | |
105 | #if WXWIN_COMPATIBILITY_2_6 | |
106 | wxFLAGS_MEMBER(wxGA_PROGRESSBAR) | |
107 | #endif // WXWIN_COMPATIBILITY_2_6 | |
108 | wxFLAGS_MEMBER(wxGA_SMOOTH) | |
109 | ||
110 | wxEND_FLAGS( wxGaugeStyle ) | |
111 | ||
112 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxGauge, wxControl,"wx/gauge.h") | |
113 | ||
114 | wxBEGIN_PROPERTIES_TABLE(wxGauge) | |
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")) | |
119 | wxPROPERTY_FLAGS( WindowStyle , wxGaugeStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style | |
120 | wxEND_PROPERTIES_TABLE() | |
121 | ||
122 | wxBEGIN_HANDLERS_TABLE(wxGauge) | |
123 | wxEND_HANDLERS_TABLE() | |
124 | ||
125 | wxCONSTRUCTOR_6( wxGauge , wxWindow* , Parent , wxWindowID , Id , int , Range , wxPoint , Position , wxSize , Size , long , WindowStyle ) | |
126 | #else | |
127 | IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) | |
128 | #endif | |
129 | ||
130 | // ============================================================================ | |
131 | // wxGauge implementation | |
132 | // ============================================================================ | |
133 | ||
134 | // ---------------------------------------------------------------------------- | |
135 | // wxGauge creation | |
136 | // ---------------------------------------------------------------------------- | |
137 | ||
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) | |
146 | { | |
147 | if ( !CreateControl(parent, id, pos, size, style, validator, name) ) | |
148 | return false; | |
149 | ||
150 | if ( !MSWCreateControl(PROGRESS_CLASS, wxEmptyString, pos, size) ) | |
151 | return false; | |
152 | ||
153 | SetRange(range); | |
154 | ||
155 | // in case we need to emulate indeterminate mode... | |
156 | m_nDirection = wxRIGHT; | |
157 | ||
158 | return true; | |
159 | } | |
160 | ||
161 | WXDWORD wxGauge::MSWGetStyle(long style, WXDWORD *exstyle) const | |
162 | { | |
163 | WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle); | |
164 | ||
165 | if ( style & wxGA_VERTICAL ) | |
166 | msStyle |= PBS_VERTICAL; | |
167 | ||
168 | if ( style & wxGA_SMOOTH ) | |
169 | msStyle |= PBS_SMOOTH; | |
170 | ||
171 | return msStyle; | |
172 | } | |
173 | ||
174 | // ---------------------------------------------------------------------------- | |
175 | // wxGauge geometry | |
176 | // ---------------------------------------------------------------------------- | |
177 | ||
178 | wxSize wxGauge::DoGetBestSize() const | |
179 | { | |
180 | // VZ: no idea where does 28 come from, it was there before my changes and | |
181 | // as nobody ever complained I guess we can leave it... | |
182 | if (HasFlag(wxGA_VERTICAL)) | |
183 | return wxSize(28, 100); | |
184 | else | |
185 | return wxSize(100, 28); | |
186 | } | |
187 | ||
188 | // ---------------------------------------------------------------------------- | |
189 | // wxGauge setters | |
190 | // ---------------------------------------------------------------------------- | |
191 | ||
192 | void wxGauge::SetRange(int r) | |
193 | { | |
194 | // switch to determinate mode if required | |
195 | SetDeterminateMode(); | |
196 | ||
197 | m_rangeMax = r; | |
198 | ||
199 | #ifdef PBM_SETRANGE32 | |
200 | ::SendMessage(GetHwnd(), PBM_SETRANGE32, 0, r); | |
201 | #else // !PBM_SETRANGE32 | |
202 | // fall back to PBM_SETRANGE (limited to 16 bits) | |
203 | ::SendMessage(GetHwnd(), PBM_SETRANGE, 0, MAKELPARAM(0, r)); | |
204 | #endif // PBM_SETRANGE32/!PBM_SETRANGE32 | |
205 | } | |
206 | ||
207 | void wxGauge::SetValue(int pos) | |
208 | { | |
209 | // switch to determinate mode if required | |
210 | SetDeterminateMode(); | |
211 | ||
212 | m_gaugePos = pos; | |
213 | ||
214 | ::SendMessage(GetHwnd(), PBM_SETPOS, pos, 0); | |
215 | } | |
216 | ||
217 | bool wxGauge::SetForegroundColour(const wxColour& col) | |
218 | { | |
219 | if ( !wxControl::SetForegroundColour(col) ) | |
220 | return false; | |
221 | ||
222 | ::SendMessage(GetHwnd(), PBM_SETBARCOLOR, 0, (LPARAM)wxColourToRGB(col)); | |
223 | ||
224 | return true; | |
225 | } | |
226 | ||
227 | bool wxGauge::SetBackgroundColour(const wxColour& col) | |
228 | { | |
229 | if ( !wxControl::SetBackgroundColour(col) ) | |
230 | return false; | |
231 | ||
232 | ::SendMessage(GetHwnd(), PBM_SETBKCOLOR, 0, (LPARAM)wxColourToRGB(col)); | |
233 | ||
234 | return true; | |
235 | } | |
236 | ||
237 | void wxGauge::SetIndeterminateMode() | |
238 | { | |
239 | // add the PBS_MARQUEE style to the progress bar | |
240 | LONG style = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
241 | if ((style & PBS_MARQUEE) == 0) | |
242 | ::SetWindowLong(GetHwnd(), GWL_STYLE, style|PBS_MARQUEE); | |
243 | ||
244 | // now the control can only run in indeterminate mode | |
245 | } | |
246 | ||
247 | void wxGauge::SetDeterminateMode() | |
248 | { | |
249 | // remove the PBS_MARQUEE style to the progress bar | |
250 | LONG style = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
251 | if ((style & PBS_MARQUEE) != 0) | |
252 | ::SetWindowLong(GetHwnd(), GWL_STYLE, style & ~PBS_MARQUEE); | |
253 | ||
254 | // now the control can only run in determinate mode | |
255 | } | |
256 | ||
257 | void wxGauge::Pulse() | |
258 | { | |
259 | if (wxApp::GetComCtl32Version() >= 600) | |
260 | { | |
261 | // switch to indeterminate mode if required | |
262 | SetIndeterminateMode(); | |
263 | ||
264 | // NOTE: when in indeterminate mode, the PBM_SETPOS message will just make | |
265 | // the bar's blocks move a bit and the WPARAM value is just ignored | |
266 | // so that we can safely use zero | |
267 | SendMessage(GetHwnd(), (UINT) PBM_SETPOS, (WPARAM)0, (LPARAM)0); | |
268 | } | |
269 | else | |
270 | { | |
271 | // emulate indeterminate mode | |
272 | wxGaugeBase::Pulse(); | |
273 | } | |
274 | } | |
275 | ||
276 | #endif // wxUSE_GAUGE |