support full 32bit range in wxGauge
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "gauge95.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/defs.h"
33 #endif
34
35 #if wxUSE_GAUGE && defined(__WIN95__)
36
37 #include "wx/msw/gauge95.h"
38 #include "wx/msw/private.h"
39
40 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
41 #include <commctrl.h>
42 #endif
43
44 // ----------------------------------------------------------------------------
45 // constants
46 // ----------------------------------------------------------------------------
47
48 // old commctrl.h (< 4.71) don't have those
49 #ifndef PBS_SMOOTH
50 #define PBS_SMOOTH 0x01
51 #endif
52
53 #ifndef PBS_VERTICAL
54 #define PBS_VERTICAL 0x04
55 #endif
56
57 #ifndef PBM_SETBARCOLOR
58 #define PBM_SETBARCOLOR (WM_USER+9)
59 #endif
60
61 #ifndef PBM_SETBKCOLOR
62 #define PBM_SETBKCOLOR 0x2001
63 #endif
64
65 // ----------------------------------------------------------------------------
66 // wxWin macros
67 // ----------------------------------------------------------------------------
68
69 #if wxUSE_EXTENDED_RTTI
70 WX_DEFINE_FLAGS( wxGaugeStyle )
71
72 wxBEGIN_FLAGS( wxGaugeStyle )
73 // new style border flags, we put them first to
74 // use them for streaming out
75 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
76 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
77 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
78 wxFLAGS_MEMBER(wxBORDER_RAISED)
79 wxFLAGS_MEMBER(wxBORDER_STATIC)
80 wxFLAGS_MEMBER(wxBORDER_NONE)
81
82 // old style border flags
83 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
84 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
85 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
86 wxFLAGS_MEMBER(wxRAISED_BORDER)
87 wxFLAGS_MEMBER(wxSTATIC_BORDER)
88 wxFLAGS_MEMBER(wxNO_BORDER)
89
90 // standard window styles
91 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
92 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
93 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
94 wxFLAGS_MEMBER(wxWANTS_CHARS)
95 wxFLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE)
96 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
97 wxFLAGS_MEMBER(wxVSCROLL)
98 wxFLAGS_MEMBER(wxHSCROLL)
99
100 wxFLAGS_MEMBER(wxGA_HORIZONTAL)
101 wxFLAGS_MEMBER(wxGA_VERTICAL)
102 wxFLAGS_MEMBER(wxGA_PROGRESSBAR)
103 wxFLAGS_MEMBER(wxGA_SMOOTH)
104
105 wxEND_FLAGS( wxGaugeStyle )
106
107 IMPLEMENT_DYNAMIC_CLASS_XTI(wxGauge, wxControl,"wx/gauge.h")
108
109 wxBEGIN_PROPERTIES_TABLE(wxGauge95)
110 wxPROPERTY( Value , int , SetValue, GetValue, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
111 wxPROPERTY( Range , int , SetRange, GetRange, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
112 wxPROPERTY( ShadowWidth , int , SetShadowWidth, GetShadowWidth, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
113 wxPROPERTY( BezelFace , int , SetBezelFace, GetBezelFace, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
114 wxPROPERTY_FLAGS( WindowStyle , wxGaugeStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
115 wxEND_PROPERTIES_TABLE()
116
117 wxBEGIN_HANDLERS_TABLE(wxGauge95)
118 wxEND_HANDLERS_TABLE()
119
120 wxCONSTRUCTOR_6( wxGauge95 , wxWindow* , Parent , wxWindowID , Id , int , Range , wxPoint , Position , wxSize , Size , long , WindowStyle )
121 #else
122 IMPLEMENT_DYNAMIC_CLASS(wxGauge95, wxControl)
123 #endif
124
125 // ============================================================================
126 // implementation
127 // ============================================================================
128
129 bool wxGauge95::Create(wxWindow *parent, wxWindowID id,
130 int range,
131 const wxPoint& pos,
132 const wxSize& size,
133 long style,
134 const wxValidator& wxVALIDATOR_PARAM(validator),
135 const wxString& name)
136 {
137 SetName(name);
138 #if wxUSE_VALIDATORS
139 SetValidator(validator);
140 #endif // wxUSE_VALIDATORS
141
142 if (parent) parent->AddChild(this);
143 m_gaugePos = 0;
144
145 m_windowStyle = style;
146
147 if ( id == -1 )
148 m_windowId = (int)NewControlId();
149 else
150 m_windowId = id;
151
152 int x = pos.x;
153 int y = pos.y;
154 int width = size.x;
155 int height = size.y;
156
157 WXDWORD exStyle = 0;
158 long msFlags = MSWGetStyle(style, & exStyle) ;
159
160 if (m_windowStyle & wxGA_VERTICAL)
161 msFlags |= PBS_VERTICAL;
162
163 if (m_windowStyle & wxGA_SMOOTH)
164 msFlags |= PBS_SMOOTH;
165
166 HWND wx_button =
167 CreateWindowEx(exStyle, PROGRESS_CLASS, NULL, msFlags,
168 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
169 wxGetInstance(), NULL);
170
171 m_hWnd = (WXHWND)wx_button;
172
173 SetBackgroundColour(parent->GetBackgroundColour());
174 SetForegroundColour(parent->GetForegroundColour());
175
176 // Subclass again for purposes of dialog editing mode
177 SubclassWin((WXHWND) wx_button);
178
179 SetRange(range);
180
181 SetFont(parent->GetFont());
182
183 if (width == -1)
184 width = 50;
185 if (height == -1)
186 height = 28;
187 SetSize(x, y, width, height);
188
189 ShowWindow(GetHwnd(), SW_SHOW);
190
191 return TRUE;
192 }
193
194 void wxGauge95::SetShadowWidth(int WXUNUSED(w))
195 {
196 }
197
198 void wxGauge95::SetBezelFace(int WXUNUSED(w))
199 {
200 }
201
202 void wxGauge95::SetRange(int r)
203 {
204 m_rangeMax = r;
205
206 #ifdef PBM_SETRANGE32
207 SendMessage(GetHwnd(), PBM_SETRANGE32, 0, r);
208 #else // !PBM_SETRANGE32
209 // fall back to PBM_SETRANGE (limited to 16 bits)
210 SendMessage(GetHwnd(), PBM_SETRANGE, 0, MAKELPARAM(0, r));
211 #endif // PBM_SETRANGE32/!PBM_SETRANGE32
212 }
213
214 void wxGauge95::SetValue(int pos)
215 {
216 m_gaugePos = pos;
217
218 SendMessage(GetHwnd(), PBM_SETPOS, pos, 0);
219 }
220
221 int wxGauge95::GetShadowWidth() const
222 {
223 return 0;
224 }
225
226 int wxGauge95::GetBezelFace() const
227 {
228 return 0;
229 }
230
231 int wxGauge95::GetRange() const
232 {
233 return m_rangeMax;
234 }
235
236 int wxGauge95::GetValue() const
237 {
238 return m_gaugePos;
239 }
240
241 bool wxGauge95::SetForegroundColour(const wxColour& col)
242 {
243 if ( !wxControl::SetForegroundColour(col) )
244 return FALSE;
245
246 SendMessage(GetHwnd(), PBM_SETBARCOLOR, 0, (LPARAM)wxColourToRGB(col));
247
248 return TRUE;
249 }
250
251 bool wxGauge95::SetBackgroundColour(const wxColour& col)
252 {
253 if ( !wxControl::SetBackgroundColour(col) )
254 return FALSE;
255
256 SendMessage(GetHwnd(), PBM_SETBKCOLOR, 0, (LPARAM)wxColourToRGB(col));
257
258 return TRUE;
259 }
260
261 #endif // wxUSE_GAUGE