1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/statbr95.cpp
3 // Purpose: native implementation of wxStatusBar
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "statbr95.h"
16 // for compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/settings.h"
27 #include "wx/dcclient.h"
30 #if defined(__WIN95__) && wxUSE_NATIVE_STATUSBAR
34 #include "wx/statusbr.h"
36 #include "wx/msw/private.h"
39 #if !defined(__GNUWIN32__) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95
, wxWindow
);
48 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar
, wxStatusBar95
)
50 BEGIN_EVENT_TABLE(wxStatusBar95
, wxWindow
)
51 EVT_SIZE(wxStatusBar95::OnSize
)
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 // windowsx.h and commctrl.h don't define those, so we do it here
59 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
60 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
61 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
62 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 static WNDPROC gs_wndprocStatBar
= NULL
;
70 LRESULT APIENTRY
wxStatusBarProc(HWND hwnd
,
75 if ( message
== WM_COMMAND
)
77 wxStatusBar95
*sb
= (wxStatusBar95
*)GetWindowLong(hwnd
, GWL_USERDATA
);
78 sb
->MSWWindowProc(message
, wParam
, lParam
);
81 return ::CallWindowProc(CASTWNDPROC gs_wndprocStatBar
, hwnd
, message
, wParam
, lParam
);
84 // ============================================================================
86 // ============================================================================
88 // ----------------------------------------------------------------------------
89 // wxStatusBar95 class
90 // ----------------------------------------------------------------------------
92 wxStatusBar95::wxStatusBar95()
99 bool wxStatusBar95::Create(wxWindow
*parent
,
102 const wxString
& name
)
108 m_windowId
= NewControlId();
112 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
113 if ( style
& wxST_SIZEGRIP
)
114 wstyle
|= SBARS_SIZEGRIP
;
116 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
122 wxLogSysError(_("Failed to create a status bar."));
127 // for some reason, subclassing in the usual way doesn't work at all - many
128 // strange things start happening (status bar is not positioned correctly,
129 // all methods fail...)
130 // SubclassWin(m_hWnd);
132 // but we want to process the messages from it still, so must subclass it
133 gs_wndprocStatBar
= (WNDPROC
)GetWindowLong(GetHwnd(), GWL_WNDPROC
);
134 SetWindowLong(GetHwnd(), GWL_WNDPROC
, (LONG
)wxStatusBarProc
);
135 SetWindowLong(GetHwnd(), GWL_USERDATA
, (LONG
)this);
140 wxStatusBar95::~wxStatusBar95()
142 delete [] m_statusWidths
;
145 void wxStatusBar95::CopyFieldsWidth(const int widths
[])
147 if (widths
&& !m_statusWidths
)
148 m_statusWidths
= new int[m_nFields
];
150 if ( widths
!= NULL
) {
151 for ( int i
= 0; i
< m_nFields
; i
++ )
152 m_statusWidths
[i
] = widths
[i
];
155 delete [] m_statusWidths
;
156 m_statusWidths
= NULL
;
160 void wxStatusBar95::SetFieldsCount(int nFields
, const int widths
[])
162 // this is Windows limitation
163 wxASSERT_MSG( (nFields
> 0) && (nFields
< 255), _T("too many fields") );
167 CopyFieldsWidth(widths
);
171 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
173 wxASSERT_MSG( n
== m_nFields
, _T("field number mismatch") );
175 CopyFieldsWidth(widths
);
179 void wxStatusBar95::SetFieldsWidth()
185 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
187 int extraWidth
= aBorders
[2]; // space between fields
189 int *pWidths
= new int[m_nFields
];
192 GetClientSize(&nWindowWidth
, &y
);
194 if ( m_statusWidths
== NULL
) {
195 // default: all fields have the same width
196 int nWidth
= nWindowWidth
/ m_nFields
;
197 for ( int i
= 0; i
< m_nFields
; i
++ )
198 pWidths
[i
] = (i
+ 1) * nWidth
;
201 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
205 for ( i
= 0; i
< m_nFields
; i
++ ) {
206 if ( m_statusWidths
[i
] == -1 )
209 nTotalWidth
+= m_statusWidths
[i
] + extraWidth
;
212 if ( nVarCount
== 0 ) {
213 wxFAIL_MSG( _T("at least one field must be of variable width") );
218 int nVarWidth
= (nWindowWidth
- nTotalWidth
) / nVarCount
;
222 for ( i
= 0; i
< m_nFields
; i
++ ) {
223 if ( m_statusWidths
[i
] == -1 )
224 nCurPos
+= nVarWidth
;
226 nCurPos
+= m_statusWidths
[i
] + extraWidth
;
227 pWidths
[i
] = nCurPos
;
231 if ( !StatusBar_SetParts(GetHwnd(), m_nFields
, pWidths
) ) {
232 wxLogLastError(wxT("StatusBar_SetParts"));
238 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
240 wxCHECK_RET( (nField
>= 0) && (nField
< m_nFields
),
241 _T("invalid statusbar field index") );
243 if ( !StatusBar_SetText(GetHwnd(), nField
, strText
) ) {
244 wxLogLastError(wxT("StatusBar_SetText"));
248 wxString
wxStatusBar95::GetStatusText(int nField
) const
250 wxCHECK_MSG( (nField
>= 0) && (nField
< m_nFields
), wxEmptyString
,
251 _T("invalid statusbar field index") );
254 int len
= StatusBar_GetTextLen(GetHwnd(), nField
);
257 StatusBar_GetText(GetHwnd(), nField
, str
.GetWriteBuf(len
));
263 int wxStatusBar95::GetBorderX() const
266 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
271 int wxStatusBar95::GetBorderY() const
274 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
279 void wxStatusBar95::SetMinHeight(int height
)
281 SendMessage(GetHwnd(), SB_SETMINHEIGHT
, height
+ 2*GetBorderY(), 0);
283 // have to send a (dummy) WM_SIZE to redraw it now
284 SendMessage(GetHwnd(), WM_SIZE
, 0, 0);
287 bool wxStatusBar95::GetFieldRect(int i
, wxRect
& rect
) const
289 wxCHECK_MSG( (i
>= 0) && (i
< m_nFields
), FALSE
,
290 _T("invalid statusbar field index") );
293 if ( !::SendMessage(GetHwnd(), SB_GETRECT
, i
, (LPARAM
)&r
) )
295 wxLogLastError("SendMessage(SB_GETRECT)");
298 wxCopyRECTToRect(r
, rect
);
303 void wxStatusBar95::OnSize(wxSizeEvent
& event
)
305 FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED
,
306 event
.GetSize().x
, event
.GetSize().y
,
309 // adjust fields widths to the new size
313 #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR