]> git.saurik.com Git - wxWidgets.git/blob - src/msw/gauge95.cpp
Applied wxGauge:Pulse() patch.
[wxWidgets.git] / src / msw / gauge95.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/gauge95.cpp
3 // Purpose: wxGauge95 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/msw/wrapcctl.h" // include <commctrl.h> "properly"
33 #endif
34
35 #include "wx/msw/private.h"
36
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
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
66 // ----------------------------------------------------------------------------
67 // wxWin macros
68 // ----------------------------------------------------------------------------
69
70 #if wxUSE_EXTENDED_RTTI
71 WX_DEFINE_FLAGS( wxGaugeStyle )
72
73 wxBEGIN_FLAGS( wxGaugeStyle )
74 // new style border flags, we put them first to
75 // use them for streaming out
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)
82
83 // old style border flags
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)
89 wxFLAGS_MEMBER(wxBORDER)
90
91 // standard window styles
92 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
93 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
94 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
95 wxFLAGS_MEMBER(wxWANTS_CHARS)
96 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
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)
103 #if WXWIN_COMPATIBILITY_2_6
104 wxFLAGS_MEMBER(wxGA_PROGRESSBAR)
105 #endif // WXWIN_COMPATIBILITY_2_6
106 wxFLAGS_MEMBER(wxGA_SMOOTH)
107
108 wxEND_FLAGS( wxGaugeStyle )
109
110 IMPLEMENT_DYNAMIC_CLASS_XTI(wxGauge, wxControl,"wx/gauge.h")
111
112 wxBEGIN_PROPERTIES_TABLE(wxGauge95)
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"))
117 wxPROPERTY_FLAGS( WindowStyle , wxGaugeStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
118 wxEND_PROPERTIES_TABLE()
119
120 wxBEGIN_HANDLERS_TABLE(wxGauge95)
121 wxEND_HANDLERS_TABLE()
122
123 wxCONSTRUCTOR_6( wxGauge95 , wxWindow* , Parent , wxWindowID , Id , int , Range , wxPoint , Position , wxSize , Size , long , WindowStyle )
124 #else
125 IMPLEMENT_DYNAMIC_CLASS(wxGauge95, wxControl)
126 #endif
127
128 // ============================================================================
129 // wxGauge95 implementation
130 // ============================================================================
131
132 // ----------------------------------------------------------------------------
133 // wxGauge95 creation
134 // ----------------------------------------------------------------------------
135
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;
147
148 if ( !MSWCreateControl(PROGRESS_CLASS, wxEmptyString, pos, size) )
149 return false;
150
151 SetRange(range);
152
153 // in case we need to emulate indeterminate mode...
154 m_nDirection = wxRIGHT;
155
156 return true;
157 }
158
159 WXDWORD wxGauge95::MSWGetStyle(long style, WXDWORD *exstyle) const
160 {
161 WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
162
163 if ( style & wxGA_VERTICAL )
164 msStyle |= PBS_VERTICAL;
165
166 if ( style & wxGA_SMOOTH )
167 msStyle |= PBS_SMOOTH;
168
169 return msStyle;
170 }
171
172 // ----------------------------------------------------------------------------
173 // wxGauge95 geometry
174 // ----------------------------------------------------------------------------
175
176 wxSize wxGauge95::DoGetBestSize() const
177 {
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...
180 if (HasFlag(wxGA_VERTICAL))
181 return wxSize(28, 100);
182 else
183 return wxSize(100, 28);
184 }
185
186 // ----------------------------------------------------------------------------
187 // wxGauge95 setters
188 // ----------------------------------------------------------------------------
189
190 void wxGauge95::SetRange(int r)
191 {
192 // switch to determinate mode if required
193 SetDeterminateMode();
194
195 m_rangeMax = r;
196
197 #ifdef PBM_SETRANGE32
198 ::SendMessage(GetHwnd(), PBM_SETRANGE32, 0, r);
199 #else // !PBM_SETRANGE32
200 // fall back to PBM_SETRANGE (limited to 16 bits)
201 ::SendMessage(GetHwnd(), PBM_SETRANGE, 0, MAKELPARAM(0, r));
202 #endif // PBM_SETRANGE32/!PBM_SETRANGE32
203 }
204
205 void wxGauge95::SetValue(int pos)
206 {
207 // switch to determinate mode if required
208 SetDeterminateMode();
209
210 m_gaugePos = pos;
211
212 ::SendMessage(GetHwnd(), PBM_SETPOS, pos, 0);
213 }
214
215 bool wxGauge95::SetForegroundColour(const wxColour& col)
216 {
217 if ( !wxControl::SetForegroundColour(col) )
218 return false;
219
220 ::SendMessage(GetHwnd(), PBM_SETBARCOLOR, 0, (LPARAM)wxColourToRGB(col));
221
222 return true;
223 }
224
225 bool wxGauge95::SetBackgroundColour(const wxColour& col)
226 {
227 if ( !wxControl::SetBackgroundColour(col) )
228 return false;
229
230 ::SendMessage(GetHwnd(), PBM_SETBKCOLOR, 0, (LPARAM)wxColourToRGB(col));
231
232 return true;
233 }
234
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
274 #endif // wxUSE_GAUGE