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