]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/gauge.cpp
3 // Purpose: wxGauge class
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
33 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
36 #include "wx/msw/private.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 // old commctrl.h (< 4.71) don't have those
44 #define PBS_SMOOTH 0x01
48 #define PBS_VERTICAL 0x04
51 #ifndef PBM_SETBARCOLOR
52 #define PBM_SETBARCOLOR (WM_USER+9)
55 #ifndef PBM_SETBKCOLOR
56 #define PBM_SETBKCOLOR 0x2001
60 #define PBS_MARQUEE 0x08
63 #ifndef PBM_SETMARQUEE
64 #define PBM_SETMARQUEE (WM_USER+10)
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 // ============================================================================
72 // wxGauge implementation
73 // ============================================================================
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 bool wxGauge::Create(wxWindow
*parent
,
85 const wxValidator
& validator
,
88 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
91 if ( !MSWCreateControl(PROGRESS_CLASS
, wxEmptyString
, pos
, size
) )
96 // in case we need to emulate indeterminate mode...
97 m_nDirection
= wxRIGHT
;
102 WXDWORD
wxGauge::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
104 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
106 if ( style
& wxGA_VERTICAL
)
107 msStyle
|= PBS_VERTICAL
;
109 if ( style
& wxGA_SMOOTH
)
110 msStyle
|= PBS_SMOOTH
;
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
119 wxSize
wxGauge::DoGetBestSize() const
121 // Windows HIG (http://msdn.microsoft.com/en-us/library/aa511279.aspx)
122 // suggest progress bar size of "107 or 237 x 8 dialog units". Let's use
125 if (HasFlag(wxGA_VERTICAL
))
126 return ConvertDialogToPixels(wxSize(8, 107));
128 return ConvertDialogToPixels(wxSize(107, 8));
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
135 void wxGauge::SetRange(int r
)
137 // Changing range implicitly means we're using determinate mode.
138 if ( IsInIndeterminateMode() )
139 SetDeterminateMode();
143 #ifdef PBM_SETRANGE32
144 ::SendMessage(GetHwnd(), PBM_SETRANGE32
, 0, r
);
145 #else // !PBM_SETRANGE32
146 // fall back to PBM_SETRANGE (limited to 16 bits)
147 ::SendMessage(GetHwnd(), PBM_SETRANGE
, 0, MAKELPARAM(0, r
));
148 #endif // PBM_SETRANGE32/!PBM_SETRANGE32
151 void wxGauge::SetValue(int pos
)
153 // Setting the value implicitly means that we're using determinate mode.
154 if ( IsInIndeterminateMode() )
155 SetDeterminateMode();
157 if ( GetValue() != pos
)
161 ::SendMessage(GetHwnd(), PBM_SETPOS
, pos
, 0);
165 bool wxGauge::SetForegroundColour(const wxColour
& col
)
167 if ( !wxControl::SetForegroundColour(col
) )
170 ::SendMessage(GetHwnd(), PBM_SETBARCOLOR
, 0, (LPARAM
)wxColourToRGB(col
));
175 bool wxGauge::SetBackgroundColour(const wxColour
& col
)
177 if ( !wxControl::SetBackgroundColour(col
) )
180 ::SendMessage(GetHwnd(), PBM_SETBKCOLOR
, 0, (LPARAM
)wxColourToRGB(col
));
185 bool wxGauge::IsInIndeterminateMode() const
187 return (::GetWindowLong(GetHwnd(), GWL_STYLE
) & PBS_MARQUEE
) != 0;
190 void wxGauge::SetIndeterminateMode()
192 // Switch the control into indeterminate mode if necessary.
193 if ( !IsInIndeterminateMode() )
195 const long style
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
196 ::SetWindowLong(GetHwnd(), GWL_STYLE
, style
| PBS_MARQUEE
);
197 ::SendMessage(GetHwnd(), PBM_SETMARQUEE
, TRUE
, 0);
201 void wxGauge::SetDeterminateMode()
203 if ( IsInIndeterminateMode() )
205 const long style
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
206 ::SendMessage(GetHwnd(), PBM_SETMARQUEE
, FALSE
, 0);
207 ::SetWindowLong(GetHwnd(), GWL_STYLE
, style
& ~PBS_MARQUEE
);
211 void wxGauge::Pulse()
213 if (wxApp::GetComCtl32Version() >= 600)
215 // switch to indeterminate mode if required
216 SetIndeterminateMode();
218 SendMessage(GetHwnd(), PBM_STEPIT
, 0, 0);
222 // emulate indeterminate mode
223 wxGaugeBase::Pulse();
227 #endif // wxUSE_GAUGE