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
33 #include "wx/statusbr.h"
35 #include "wx/msw/private.h"
38 #if !defined(__GNUWIN32__) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95
, wxWindow
);
47 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar
, wxStatusBar95
)
49 BEGIN_EVENT_TABLE(wxStatusBar95
, wxWindow
)
50 EVT_SIZE(wxStatusBar95::OnSize
)
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 // windowsx.h and commctrl.h don't define those, so we do it here
58 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
59 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
60 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
61 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 static WNDPROC gs_wndprocStatBar
= NULL
;
69 LRESULT APIENTRY
wxStatusBarProc(HWND hwnd
,
74 if ( message
== WM_COMMAND
)
76 wxStatusBar95
*sb
= (wxStatusBar95
*)GetWindowLong(hwnd
, GWL_USERDATA
);
77 sb
->MSWWindowProc(message
, wParam
, lParam
);
80 return ::CallWindowProc(gs_wndprocStatBar
, hwnd
, message
, wParam
, lParam
);
83 // ============================================================================
85 // ============================================================================
87 // ----------------------------------------------------------------------------
88 // wxStatusBar95 class
89 // ----------------------------------------------------------------------------
91 wxStatusBar95::wxStatusBar95()
98 bool wxStatusBar95::Create(wxWindow
*parent
,
101 const wxString
& name
)
107 m_windowId
= NewControlId();
111 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
112 if ( style
& wxST_SIZEGRIP
)
113 wstyle
|= SBARS_SIZEGRIP
;
115 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
121 wxLogSysError(_("Failed to create a status bar."));
126 // for some reason, subclassing in the usual way doesn't work at all - many
127 // strange things start happening (status bar is not positioned correctly,
128 // all methods fail...)
129 // SubclassWin(m_hWnd);
131 // but we want to process the messages from it still, so must subclass it
132 gs_wndprocStatBar
= (WNDPROC
)GetWindowLong(GetHwnd(), GWL_WNDPROC
);
133 SetWindowLong(GetHwnd(), GWL_WNDPROC
, (LONG
)wxStatusBarProc
);
134 SetWindowLong(GetHwnd(), GWL_USERDATA
, (LONG
)this);
139 wxStatusBar95::~wxStatusBar95()
141 delete [] m_statusWidths
;
144 void wxStatusBar95::CopyFieldsWidth(const int widths
[])
146 if (widths
&& !m_statusWidths
)
147 m_statusWidths
= new int[m_nFields
];
149 if ( widths
!= NULL
) {
150 for ( int i
= 0; i
< m_nFields
; i
++ )
151 m_statusWidths
[i
] = widths
[i
];
154 delete [] m_statusWidths
;
155 m_statusWidths
= NULL
;
159 void wxStatusBar95::SetFieldsCount(int nFields
, const int widths
[])
161 // this is Windows limitation
162 wxASSERT_MSG( (nFields
> 0) && (nFields
< 255), _T("too many fields") );
166 CopyFieldsWidth(widths
);
170 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
172 wxASSERT_MSG( n
== m_nFields
, _T("field number mismatch") );
174 CopyFieldsWidth(widths
);
178 void wxStatusBar95::SetFieldsWidth()
184 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
186 int extraWidth
= aBorders
[2]; // space between fields
188 int *pWidths
= new int[m_nFields
];
191 GetClientSize(&nWindowWidth
, &y
);
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
;
200 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
204 for ( i
= 0; i
< m_nFields
; i
++ ) {
205 if ( m_statusWidths
[i
] == -1 )
208 nTotalWidth
+= m_statusWidths
[i
] + extraWidth
;
211 if ( nVarCount
== 0 ) {
212 wxFAIL_MSG( _T("at least one field must be of variable width") );
217 int nVarWidth
= (nWindowWidth
- nTotalWidth
) / nVarCount
;
221 for ( i
= 0; i
< m_nFields
; i
++ ) {
222 if ( m_statusWidths
[i
] == -1 )
223 nCurPos
+= nVarWidth
;
225 nCurPos
+= m_statusWidths
[i
] + extraWidth
;
226 pWidths
[i
] = nCurPos
;
230 if ( !StatusBar_SetParts(GetHwnd(), m_nFields
, pWidths
) ) {
231 wxLogLastError(wxT("StatusBar_SetParts"));
237 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
239 wxCHECK_RET( (nField
>= 0) && (nField
< m_nFields
),
240 _T("invalid statusbar field index") );
242 if ( !StatusBar_SetText(GetHwnd(), nField
, strText
) ) {
243 wxLogLastError(wxT("StatusBar_SetText"));
247 wxString
wxStatusBar95::GetStatusText(int nField
) const
249 wxCHECK_MSG( (nField
>= 0) && (nField
< m_nFields
), wxEmptyString
,
250 _T("invalid statusbar field index") );
253 int len
= StatusBar_GetTextLen(GetHwnd(), nField
);
256 StatusBar_GetText(GetHwnd(), nField
, str
.GetWriteBuf(len
));
262 int wxStatusBar95::GetBorderX() const
265 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
270 int wxStatusBar95::GetBorderY() const
273 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
278 void wxStatusBar95::SetMinHeight(int height
)
280 SendMessage(GetHwnd(), SB_SETMINHEIGHT
, height
+ 2*GetBorderY(), 0);
282 // have to send a (dummy) WM_SIZE to redraw it now
283 SendMessage(GetHwnd(), WM_SIZE
, 0, 0);
286 bool wxStatusBar95::GetFieldRect(int i
, wxRect
& rect
) const
288 wxCHECK_MSG( (i
>= 0) && (i
< m_nFields
), FALSE
,
289 _T("invalid statusbar field index") );
292 if ( !::SendMessage(GetHwnd(), SB_GETRECT
, i
, (LPARAM
)&r
) )
294 wxLogLastError("SendMessage(SB_GETRECT)");
297 wxCopyRECTToRect(r
, rect
);
302 void wxStatusBar95::OnSize(wxSizeEvent
& event
)
304 FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED
,
305 event
.GetSize().x
, event
.GetSize().y
,
308 // adjust fields widths to the new size
312 #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR