]>
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 #if wxUSE_EXTENDED_RTTI
73 WX_DEFINE_FLAGS( wxGaugeStyle
)
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
)
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
)
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
)
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
)
110 wxEND_FLAGS( wxGaugeStyle
)
112 IMPLEMENT_DYNAMIC_CLASS_XTI(wxGauge
, wxControl
,"wx/gauge.h")
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()
122 wxBEGIN_HANDLERS_TABLE(wxGauge
)
123 wxEND_HANDLERS_TABLE()
125 wxCONSTRUCTOR_6( wxGauge
, wxWindow
* , Parent
, wxWindowID
, Id
, int , Range
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
127 IMPLEMENT_DYNAMIC_CLASS(wxGauge
, wxControl
)
130 // ============================================================================
131 // wxGauge implementation
132 // ============================================================================
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 bool wxGauge::Create(wxWindow
*parent
,
144 const wxValidator
& validator
,
145 const wxString
& name
)
147 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
150 if ( !MSWCreateControl(PROGRESS_CLASS
, wxEmptyString
, pos
, size
) )
155 // in case we need to emulate indeterminate mode...
156 m_nDirection
= wxRIGHT
;
161 WXDWORD
wxGauge::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
163 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
165 if ( style
& wxGA_VERTICAL
)
166 msStyle
|= PBS_VERTICAL
;
168 if ( style
& wxGA_SMOOTH
)
169 msStyle
|= PBS_SMOOTH
;
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
178 wxSize
wxGauge::DoGetBestSize() const
180 // Windows HIG (http://msdn.microsoft.com/en-us/library/aa511279.aspx)
181 // suggest progress bar size of "107 or 237 x 8 dialog units". Let's use
184 if (HasFlag(wxGA_VERTICAL
))
185 return ConvertDialogToPixels(wxSize(8, 107));
187 return ConvertDialogToPixels(wxSize(107, 8));
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
194 void wxGauge::SetRange(int r
)
196 // Changing range implicitly means we're using determinate mode.
197 if ( IsInIndeterminateMode() )
198 SetDeterminateMode();
202 #ifdef PBM_SETRANGE32
203 ::SendMessage(GetHwnd(), PBM_SETRANGE32
, 0, r
);
204 #else // !PBM_SETRANGE32
205 // fall back to PBM_SETRANGE (limited to 16 bits)
206 ::SendMessage(GetHwnd(), PBM_SETRANGE
, 0, MAKELPARAM(0, r
));
207 #endif // PBM_SETRANGE32/!PBM_SETRANGE32
210 void wxGauge::SetValue(int pos
)
212 // Setting the value implicitly means that we're using determinate mode.
213 if ( IsInIndeterminateMode() )
214 SetDeterminateMode();
216 if ( GetValue() != pos
)
220 ::SendMessage(GetHwnd(), PBM_SETPOS
, pos
, 0);
224 bool wxGauge::SetForegroundColour(const wxColour
& col
)
226 if ( !wxControl::SetForegroundColour(col
) )
229 ::SendMessage(GetHwnd(), PBM_SETBARCOLOR
, 0, (LPARAM
)wxColourToRGB(col
));
234 bool wxGauge::SetBackgroundColour(const wxColour
& col
)
236 if ( !wxControl::SetBackgroundColour(col
) )
239 ::SendMessage(GetHwnd(), PBM_SETBKCOLOR
, 0, (LPARAM
)wxColourToRGB(col
));
244 bool wxGauge::IsInIndeterminateMode() const
246 return (::GetWindowLong(GetHwnd(), GWL_STYLE
) & PBS_MARQUEE
) != 0;
249 void wxGauge::SetIndeterminateMode()
251 // Switch the control into indeterminate mode if necessary.
252 if ( !IsInIndeterminateMode() )
254 const long style
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
255 ::SetWindowLong(GetHwnd(), GWL_STYLE
, style
| PBS_MARQUEE
);
256 ::SendMessage(GetHwnd(), PBM_SETMARQUEE
, TRUE
, 0);
260 void wxGauge::SetDeterminateMode()
262 if ( IsInIndeterminateMode() )
264 const long style
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
265 ::SendMessage(GetHwnd(), PBM_SETMARQUEE
, FALSE
, 0);
266 ::SetWindowLong(GetHwnd(), GWL_STYLE
, style
& ~PBS_MARQUEE
);
270 void wxGauge::Pulse()
272 if (wxApp::GetComCtl32Version() >= 600)
274 // switch to indeterminate mode if required
275 SetIndeterminateMode();
277 SendMessage(GetHwnd(), PBM_STEPIT
, 0, 0);
281 // emulate indeterminate mode
282 wxGaugeBase::Pulse();
286 #endif // wxUSE_GAUGE