]> git.saurik.com Git - wxWidgets.git/blob - src/msw/gauge95.cpp
two fixes from Justin Bradford
[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 IMPLEMENT_DYNAMIC_CLASS(wxGauge95, wxControl)
70
71 /*
72 TODO PROPERTIES
73 range (long)
74 value (long)
75 shadow (ShadowWidth)
76 bezel (BezelFace)
77 */
78
79 // ============================================================================
80 // implementation
81 // ============================================================================
82
83 bool wxGauge95::Create(wxWindow *parent, wxWindowID id,
84 int range,
85 const wxPoint& pos,
86 const wxSize& size,
87 long style,
88 const wxValidator& validator,
89 const wxString& name)
90 {
91 SetName(name);
92 #if wxUSE_VALIDATORS
93 SetValidator(validator);
94 #endif // wxUSE_VALIDATORS
95
96 if (parent) parent->AddChild(this);
97 m_rangeMax = range;
98 m_gaugePos = 0;
99
100 m_windowStyle = style;
101
102 if ( id == -1 )
103 m_windowId = (int)NewControlId();
104 else
105 m_windowId = id;
106
107 int x = pos.x;
108 int y = pos.y;
109 int width = size.x;
110 int height = size.y;
111
112 WXDWORD exStyle = 0;
113 long msFlags = MSWGetStyle(style, & exStyle) ;
114
115 if (m_windowStyle & wxGA_VERTICAL)
116 msFlags |= PBS_VERTICAL;
117
118 if (m_windowStyle & wxGA_SMOOTH)
119 msFlags |= PBS_SMOOTH;
120
121 HWND wx_button =
122 CreateWindowEx(exStyle, PROGRESS_CLASS, NULL, msFlags,
123 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
124 wxGetInstance(), NULL);
125
126 m_hWnd = (WXHWND)wx_button;
127
128 SetBackgroundColour(parent->GetBackgroundColour());
129 SetForegroundColour(parent->GetForegroundColour());
130
131 // Subclass again for purposes of dialog editing mode
132 SubclassWin((WXHWND) wx_button);
133
134 SendMessage((HWND) GetHWND(), PBM_SETRANGE, 0, MAKELPARAM(0, range));
135
136 SetFont(parent->GetFont());
137
138 if (width == -1)
139 width = 50;
140 if (height == -1)
141 height = 28;
142 SetSize(x, y, width, height);
143
144 ShowWindow((HWND) GetHWND(), SW_SHOW);
145
146 return TRUE;
147 }
148
149 void wxGauge95::SetShadowWidth(int WXUNUSED(w))
150 {
151 }
152
153 void wxGauge95::SetBezelFace(int WXUNUSED(w))
154 {
155 }
156
157 void wxGauge95::SetRange(int r)
158 {
159 m_rangeMax = r;
160
161 SendMessage((HWND) GetHWND(), PBM_SETRANGE, 0, MAKELPARAM(0, r));
162 }
163
164 void wxGauge95::SetValue(int pos)
165 {
166 m_gaugePos = pos;
167
168 SendMessage((HWND) GetHWND(), PBM_SETPOS, pos, 0);
169 }
170
171 int wxGauge95::GetShadowWidth() const
172 {
173 return 0;
174 }
175
176 int wxGauge95::GetBezelFace() const
177 {
178 return 0;
179 }
180
181 int wxGauge95::GetRange() const
182 {
183 return m_rangeMax;
184 }
185
186 int wxGauge95::GetValue() const
187 {
188 return m_gaugePos;
189 }
190
191 bool wxGauge95::SetForegroundColour(const wxColour& col)
192 {
193 if ( !wxControl::SetForegroundColour(col) )
194 return FALSE;
195
196 SendMessage(GetHwnd(), PBM_SETBARCOLOR, 0, (LPARAM)wxColourToRGB(col));
197
198 return TRUE;
199 }
200
201 bool wxGauge95::SetBackgroundColour(const wxColour& col)
202 {
203 if ( !wxControl::SetBackgroundColour(col) )
204 return FALSE;
205
206 SendMessage(GetHwnd(), PBM_SETBKCOLOR, 0, (LPARAM)wxColourToRGB(col));
207
208 return TRUE;
209 }
210
211 #endif // wxUSE_GAUGE