]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/gauge95.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/gauge95.cpp
3 // Purpose: wxGauge95 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"
32 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
35 #include "wx/msw/private.h"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 // old commctrl.h (< 4.71) don't have those
43 #define PBS_SMOOTH 0x01
47 #define PBS_VERTICAL 0x04
50 #ifndef PBM_SETBARCOLOR
51 #define PBM_SETBARCOLOR (WM_USER+9)
54 #ifndef PBM_SETBKCOLOR
55 #define PBM_SETBKCOLOR 0x2001
59 #define PBS_MARQUEE 0x08
62 #ifndef PBM_SETMARQUEE
63 #define PBM_SETMARQUEE (WM_USER+10)
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 #if wxUSE_EXTENDED_RTTI
71 WX_DEFINE_FLAGS( wxGaugeStyle
)
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
)
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
)
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
)
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
)
108 wxEND_FLAGS( wxGaugeStyle
)
110 IMPLEMENT_DYNAMIC_CLASS_XTI(wxGauge
, wxControl
,"wx/gauge.h")
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()
120 wxBEGIN_HANDLERS_TABLE(wxGauge95
)
121 wxEND_HANDLERS_TABLE()
123 wxCONSTRUCTOR_6( wxGauge95
, wxWindow
* , Parent
, wxWindowID
, Id
, int , Range
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
125 IMPLEMENT_DYNAMIC_CLASS(wxGauge95
, wxControl
)
128 // ============================================================================
129 // wxGauge95 implementation
130 // ============================================================================
132 // ----------------------------------------------------------------------------
133 // wxGauge95 creation
134 // ----------------------------------------------------------------------------
136 bool wxGauge95::Create(wxWindow
*parent
,
142 const wxValidator
& validator
,
143 const wxString
& name
)
145 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
148 if ( !MSWCreateControl(PROGRESS_CLASS
, wxEmptyString
, pos
, size
) )
153 // in case we need to emulate indeterminate mode...
154 m_nDirection
= wxRIGHT
;
159 WXDWORD
wxGauge95::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
161 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
163 if ( style
& wxGA_VERTICAL
)
164 msStyle
|= PBS_VERTICAL
;
166 if ( style
& wxGA_SMOOTH
)
167 msStyle
|= PBS_SMOOTH
;
172 // ----------------------------------------------------------------------------
173 // wxGauge95 geometry
174 // ----------------------------------------------------------------------------
176 wxSize
wxGauge95::DoGetBestSize() const
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);
183 return wxSize(100, 28);
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
190 void wxGauge95::SetRange(int r
)
192 // switch to determinate mode if required
193 SetDeterminateMode();
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
205 void wxGauge95::SetValue(int pos
)
207 // switch to determinate mode if required
208 SetDeterminateMode();
212 ::SendMessage(GetHwnd(), PBM_SETPOS
, pos
, 0);
215 bool wxGauge95::SetForegroundColour(const wxColour
& col
)
217 if ( !wxControl::SetForegroundColour(col
) )
220 ::SendMessage(GetHwnd(), PBM_SETBARCOLOR
, 0, (LPARAM
)wxColourToRGB(col
));
225 bool wxGauge95::SetBackgroundColour(const wxColour
& col
)
227 if ( !wxControl::SetBackgroundColour(col
) )
230 ::SendMessage(GetHwnd(), PBM_SETBKCOLOR
, 0, (LPARAM
)wxColourToRGB(col
));
235 void wxGauge95::SetIndeterminateMode()
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
);
242 // now the control can only run in indeterminate mode
245 void wxGauge95::SetDeterminateMode()
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
);
252 // now the control can only run in determinate mode
255 void wxGauge95::Pulse()
257 if (wxApp::GetComCtl32Version() >= 600)
259 // switch to indeterminate mode if required
260 SetIndeterminateMode();
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);
269 // emulate indeterminate mode
270 wxGaugeBase::Pulse();
274 #endif // wxUSE_GAUGE