]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/gauge95.cpp
3 // Purpose: wxGauge class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
34 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
37 #include "wx/msw/private.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 // old commctrl.h (< 4.71) don't have those
45 #define PBS_SMOOTH 0x01
49 #define PBS_VERTICAL 0x04
52 #ifndef PBM_SETBARCOLOR
53 #define PBM_SETBARCOLOR (WM_USER+9)
56 #ifndef PBM_SETBKCOLOR
57 #define PBM_SETBKCOLOR 0x2001
61 #define PBS_MARQUEE 0x08
64 #ifndef PBM_SETMARQUEE
65 #define PBM_SETMARQUEE (WM_USER+10)
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 // ============================================================================
73 // wxGauge implementation
74 // ============================================================================
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 bool wxGauge::Create(wxWindow
*parent
,
86 const wxValidator
& validator
,
89 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
92 if ( !MSWCreateControl(PROGRESS_CLASS
, wxEmptyString
, pos
, size
) )
97 // in case we need to emulate indeterminate mode...
98 m_nDirection
= wxRIGHT
;
103 WXDWORD
wxGauge::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
105 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
107 if ( style
& wxGA_VERTICAL
)
108 msStyle
|= PBS_VERTICAL
;
110 if ( style
& wxGA_SMOOTH
)
111 msStyle
|= PBS_SMOOTH
;
116 // ----------------------------------------------------------------------------
118 // ----------------------------------------------------------------------------
120 wxSize
wxGauge::DoGetBestSize() const
122 // Windows HIG (http://msdn.microsoft.com/en-us/library/aa511279.aspx)
123 // suggest progress bar size of "107 or 237 x 8 dialog units". Let's use
126 if (HasFlag(wxGA_VERTICAL
))
127 return ConvertDialogToPixels(wxSize(8, 107));
129 return ConvertDialogToPixels(wxSize(107, 8));
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
136 void wxGauge::SetRange(int r
)
138 // Changing range implicitly means we're using determinate mode.
139 if ( IsInIndeterminateMode() )
140 SetDeterminateMode();
144 #ifdef PBM_SETRANGE32
145 ::SendMessage(GetHwnd(), PBM_SETRANGE32
, 0, r
);
146 #else // !PBM_SETRANGE32
147 // fall back to PBM_SETRANGE (limited to 16 bits)
148 ::SendMessage(GetHwnd(), PBM_SETRANGE
, 0, MAKELPARAM(0, r
));
149 #endif // PBM_SETRANGE32/!PBM_SETRANGE32
152 void wxGauge::SetValue(int pos
)
154 // Setting the value implicitly means that we're using determinate mode.
155 if ( IsInIndeterminateMode() )
156 SetDeterminateMode();
158 if ( GetValue() != pos
)
162 ::SendMessage(GetHwnd(), PBM_SETPOS
, pos
, 0);
166 bool wxGauge::SetForegroundColour(const wxColour
& col
)
168 if ( !wxControl::SetForegroundColour(col
) )
171 ::SendMessage(GetHwnd(), PBM_SETBARCOLOR
, 0, (LPARAM
)wxColourToRGB(col
));
176 bool wxGauge::SetBackgroundColour(const wxColour
& col
)
178 if ( !wxControl::SetBackgroundColour(col
) )
181 ::SendMessage(GetHwnd(), PBM_SETBKCOLOR
, 0, (LPARAM
)wxColourToRGB(col
));
186 bool wxGauge::IsInIndeterminateMode() const
188 return (::GetWindowLong(GetHwnd(), GWL_STYLE
) & PBS_MARQUEE
) != 0;
191 void wxGauge::SetIndeterminateMode()
193 // Switch the control into indeterminate mode if necessary.
194 if ( !IsInIndeterminateMode() )
196 const long style
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
197 ::SetWindowLong(GetHwnd(), GWL_STYLE
, style
| PBS_MARQUEE
);
198 ::SendMessage(GetHwnd(), PBM_SETMARQUEE
, TRUE
, 0);
202 void wxGauge::SetDeterminateMode()
204 if ( IsInIndeterminateMode() )
206 const long style
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
207 ::SendMessage(GetHwnd(), PBM_SETMARQUEE
, FALSE
, 0);
208 ::SetWindowLong(GetHwnd(), GWL_STYLE
, style
& ~PBS_MARQUEE
);
212 void wxGauge::Pulse()
214 if (wxApp::GetComCtl32Version() >= 600)
216 // switch to indeterminate mode if required
217 SetIndeterminateMode();
219 SendMessage(GetHwnd(), PBM_STEPIT
, 0, 0);
223 // emulate indeterminate mode
224 wxGaugeBase::Pulse();
228 #endif // wxUSE_GAUGE