]> git.saurik.com Git - wxWidgets.git/blame - src/msw/statbr95.cpp
no message
[wxWidgets.git] / src / msw / statbr95.cpp
CommitLineData
2bda0e17
KB
1///////////////////////////////////////////////////////////////////////////////
2// Name: msw/statbr95.cpp
3// Purpose: native implementation of wxStatusBar
4// Author: Vadim Zeitlin
ed791986 5// Modified by:
2bda0e17
KB
6// Created: 04.04.98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9// Licence: wxWindows license
10///////////////////////////////////////////////////////////////////////////////
11
cfe780fb
JS
12#ifdef __GNUG__
13#pragma implementation "statbr95.h"
14#endif
15
2bda0e17
KB
16// for compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20 #pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24 #include "wx/setup.h"
25 #include "wx/frame.h"
26 #include "wx/settings.h"
27 #include "wx/dcclient.h"
28#endif
29
ed791986 30#if defined(__WIN95__) && wxUSE_NATIVE_STATUSBAR
2432b92d 31
608eeb0f 32#include "wx/intl.h"
2bda0e17 33#include "wx/log.h"
ed791986 34#include "wx/statusbr.h"
2bda0e17 35
42e69d6b
VZ
36#include "wx/msw/private.h"
37#include <windowsx.h>
2bda0e17 38
c42404a5
VZ
39#if !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__))
40 #include <commctrl.h>
ce3ed50d
JS
41#endif
42
ed791986
VZ
43// ----------------------------------------------------------------------------
44// wxWindows macros
45// ----------------------------------------------------------------------------
2bda0e17 46
ed791986
VZ
47IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95, wxWindow);
48IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxStatusBar95)
2bda0e17 49
2bda0e17
KB
50// ----------------------------------------------------------------------------
51// macros
52// ----------------------------------------------------------------------------
53
54// windowsx.h and commctrl.h don't define those, so we do it here
55#define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
837e5743 56#define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
2bda0e17 57#define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
837e5743 58#define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
2bda0e17 59
ed791986
VZ
60// ----------------------------------------------------------------------------
61//
62// ----------------------------------------------------------------------------
63
457e6c54
JS
64// static WNDPROC gs_wndprocStatBar = NULL;
65static WXFARPROC gs_wndprocStatBar = (WXFARPROC) NULL;
ed791986
VZ
66
67LRESULT APIENTRY wxStatusBarProc(HWND hwnd,
68 UINT message,
69 WPARAM wParam,
70 LPARAM lParam)
71{
72 if ( message == WM_COMMAND )
73 {
74 wxStatusBar95 *sb = (wxStatusBar95 *)GetWindowLong(hwnd, GWL_USERDATA);
75 sb->MSWWindowProc(message, wParam, lParam);
76 }
77
66e33344 78 return ::CallWindowProc(CASTWNDPROC gs_wndprocStatBar, hwnd, message, wParam, lParam);
ed791986 79}
2bda0e17
KB
80
81// ============================================================================
82// implementation
83// ============================================================================
84
85// ----------------------------------------------------------------------------
86// wxStatusBar95 class
87// ----------------------------------------------------------------------------
88
89wxStatusBar95::wxStatusBar95()
90{
91 SetParent(NULL);
92 m_hWnd = 0;
93 m_windowId = 0;
94}
95
ed791986
VZ
96bool wxStatusBar95::Create(wxWindow *parent,
97 wxWindowID id,
98 long style,
99 const wxString& name)
2bda0e17 100{
cbc66a27
VZ
101 wxCHECK_MSG( parent, FALSE, wxT("status bar must have a parent") );
102
ed791986 103 SetName(name);
cbc66a27 104 SetWindowStyleFlag(style);
ed791986
VZ
105 SetParent(parent);
106
cbc66a27
VZ
107 parent->AddChild(this);
108
109 m_windowId = id == -1 ? NewControlId() : id;
ed791986
VZ
110
111 DWORD wstyle = WS_CHILD | WS_VISIBLE;
112 if ( style & wxST_SIZEGRIP )
113 wstyle |= SBARS_SIZEGRIP;
114
115 m_hWnd = (WXHWND)CreateStatusWindow(wstyle,
116 wxEmptyString,
117 GetHwndOf(parent),
118 m_windowId);
119 if ( m_hWnd == 0 )
120 {
121 wxLogSysError(_("Failed to create a status bar."));
122
123 return FALSE;
124 }
2bda0e17 125
cbc66a27
VZ
126 // we can't subclass this window as usual because the status bar window
127 // proc processes WM_SIZE and WM_PAINT specially
ed791986
VZ
128 // SubclassWin(m_hWnd);
129
cbc66a27
VZ
130 // but we want to process the messages from it still, so do custom
131 // subclassing here
457e6c54 132 gs_wndprocStatBar = (WXFARPROC)GetWindowLong(GetHwnd(), GWL_WNDPROC);
ed791986
VZ
133 SetWindowLong(GetHwnd(), GWL_WNDPROC, (LONG)wxStatusBarProc);
134 SetWindowLong(GetHwnd(), GWL_USERDATA, (LONG)this);
2bda0e17 135
ed791986
VZ
136 return TRUE;
137}
2bda0e17 138
ed791986
VZ
139wxStatusBar95::~wxStatusBar95()
140{
141 delete [] m_statusWidths;
2bda0e17
KB
142}
143
8b9518ee 144void wxStatusBar95::CopyFieldsWidth(const int widths[])
2bda0e17
KB
145{
146 if (widths && !m_statusWidths)
147 m_statusWidths = new int[m_nFields];
148
149 if ( widths != NULL ) {
150 for ( int i = 0; i < m_nFields; i++ )
151 m_statusWidths[i] = widths[i];
152 }
153 else {
154 delete [] m_statusWidths;
155 m_statusWidths = NULL;
156 }
157}
158
790ad94f 159void wxStatusBar95::SetFieldsCount(int nFields, const int *widths)
2bda0e17 160{
ed791986
VZ
161 // this is Windows limitation
162 wxASSERT_MSG( (nFields > 0) && (nFields < 255), _T("too many fields") );
2bda0e17
KB
163
164 m_nFields = nFields;
165
166 CopyFieldsWidth(widths);
167 SetFieldsWidth();
168}
169
8b9518ee 170void wxStatusBar95::SetStatusWidths(int n, const int widths[])
2bda0e17 171{
ed791986 172 wxASSERT_MSG( n == m_nFields, _T("field number mismatch") );
2bda0e17
KB
173
174 CopyFieldsWidth(widths);
175 SetFieldsWidth();
176}
177
178void wxStatusBar95::SetFieldsWidth()
179{
3175c712
VZ
180 if ( !m_nFields )
181 return;
182
ed791986
VZ
183 int aBorders[3];
184 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
2bda0e17 185
ed791986 186 int extraWidth = aBorders[2]; // space between fields
2bda0e17 187
ed791986 188 int *pWidths = new int[m_nFields];
2bda0e17 189
ed791986
VZ
190 int nWindowWidth, y;
191 GetClientSize(&nWindowWidth, &y);
2bda0e17 192
ed791986
VZ
193 if ( m_statusWidths == NULL ) {
194 // default: all fields have the same width
195 int nWidth = nWindowWidth / m_nFields;
196 for ( int i = 0; i < m_nFields; i++ )
197 pWidths[i] = (i + 1) * nWidth;
2bda0e17 198 }
ed791986
VZ
199 else {
200 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
201 int nTotalWidth = 0,
202 nVarCount = 0,
203 i;
204 for ( i = 0; i < m_nFields; i++ ) {
205 if ( m_statusWidths[i] == -1 )
206 nVarCount++;
207 else
208 nTotalWidth += m_statusWidths[i] + extraWidth;
209 }
210
211 if ( nVarCount == 0 ) {
212 wxFAIL_MSG( _T("at least one field must be of variable width") );
213
214 nVarCount++;
215 }
216
217 int nVarWidth = (nWindowWidth - nTotalWidth) / nVarCount;
218
219 // do fill the array
220 int nCurPos = 0;
221 for ( i = 0; i < m_nFields; i++ ) {
222 if ( m_statusWidths[i] == -1 )
223 nCurPos += nVarWidth;
224 else
225 nCurPos += m_statusWidths[i] + extraWidth;
226 pWidths[i] = nCurPos;
227 }
2bda0e17 228 }
2bda0e17 229
ed791986
VZ
230 if ( !StatusBar_SetParts(GetHwnd(), m_nFields, pWidths) ) {
231 wxLogLastError(wxT("StatusBar_SetParts"));
232 }
2bda0e17 233
ed791986 234 delete [] pWidths;
2bda0e17
KB
235}
236
debe6624 237void wxStatusBar95::SetStatusText(const wxString& strText, int nField)
2bda0e17 238{
ed791986
VZ
239 wxCHECK_RET( (nField >= 0) && (nField < m_nFields),
240 _T("invalid statusbar field index") );
241
242 if ( !StatusBar_SetText(GetHwnd(), nField, strText) ) {
223d09f6 243 wxLogLastError(wxT("StatusBar_SetText"));
2bda0e17
KB
244 }
245}
246
247wxString wxStatusBar95::GetStatusText(int nField) const
248{
ed791986
VZ
249 wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString,
250 _T("invalid statusbar field index") );
2bda0e17 251
ed791986
VZ
252 wxString str;
253 int len = StatusBar_GetTextLen(GetHwnd(), nField);
b7346a70
JS
254 if (len > 0)
255 {
ed791986
VZ
256 StatusBar_GetText(GetHwnd(), nField, str.GetWriteBuf(len));
257 str.UngetWriteBuf();
b7346a70 258 }
2bda0e17
KB
259 return str;
260}
261
ed791986
VZ
262int wxStatusBar95::GetBorderX() const
263{
264 int aBorders[3];
265 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
266
267 return aBorders[0];
268}
269
270int wxStatusBar95::GetBorderY() const
271{
272 int aBorders[3];
273 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
274
275 return aBorders[1];
276}
277
278void wxStatusBar95::SetMinHeight(int height)
279{
280 SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0);
281
282 // have to send a (dummy) WM_SIZE to redraw it now
283 SendMessage(GetHwnd(), WM_SIZE, 0, 0);
284}
285
286bool wxStatusBar95::GetFieldRect(int i, wxRect& rect) const
287{
288 wxCHECK_MSG( (i >= 0) && (i < m_nFields), FALSE,
289 _T("invalid statusbar field index") );
290
291 RECT r;
292 if ( !::SendMessage(GetHwnd(), SB_GETRECT, i, (LPARAM)&r) )
293 {
294 wxLogLastError("SendMessage(SB_GETRECT)");
295 }
296
297 wxCopyRECTToRect(r, rect);
298
299 return TRUE;
300}
301
cbc66a27 302void wxStatusBar95::DoMoveWindow(int x, int y, int width, int height)
2bda0e17 303{
cbc66a27 304 FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED, x, y, SendMessage);
2bda0e17
KB
305
306 // adjust fields widths to the new size
307 SetFieldsWidth();
308}
309
ed791986 310#endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR
ba681060 311