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;
69 static WXFARPROC gs_wndprocStatBar
= (WXFARPROC
) NULL
;
71 LRESULT APIENTRY
wxStatusBarProc(HWND hwnd
,
76 if ( message
== WM_COMMAND
)
78 wxStatusBar95
*sb
= (wxStatusBar95
*)GetWindowLong(hwnd
, GWL_USERDATA
);
79 sb
->MSWWindowProc(message
, wParam
, lParam
);
82 return ::CallWindowProc(CASTWNDPROC gs_wndprocStatBar
, hwnd
, message
, wParam
, lParam
);
85 // ============================================================================
87 // ============================================================================
89 // ----------------------------------------------------------------------------
90 // wxStatusBar95 class
91 // ----------------------------------------------------------------------------
93 wxStatusBar95::wxStatusBar95()
100 bool wxStatusBar95::Create(wxWindow
*parent
,
103 const wxString
& name
)
109 m_windowId
= NewControlId();
113 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
114 if ( style
& wxST_SIZEGRIP
)
115 wstyle
|= SBARS_SIZEGRIP
;
117 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
123 wxLogSysError(_("Failed to create a status bar."));
128 // for some reason, subclassing in the usual way doesn't work at all - many
129 // strange things start happening (status bar is not positioned correctly,
130 // all methods fail...)
131 // SubclassWin(m_hWnd);
133 // but we want to process the messages from it still, so must subclass it
134 gs_wndprocStatBar
= (WXFARPROC
)GetWindowLong(GetHwnd(), GWL_WNDPROC
);
135 SetWindowLong(GetHwnd(), GWL_WNDPROC
, (LONG
)wxStatusBarProc
);
136 SetWindowLong(GetHwnd(), GWL_USERDATA
, (LONG
)this);
141 wxStatusBar95::~wxStatusBar95()
143 delete [] m_statusWidths
;
146 void wxStatusBar95::CopyFieldsWidth(const int widths
[])
148 if (widths
&& !m_statusWidths
)
149 m_statusWidths
= new int[m_nFields
];
151 if ( widths
!= NULL
) {
152 for ( int i
= 0; i
< m_nFields
; i
++ )
153 m_statusWidths
[i
] = widths
[i
];
156 delete [] m_statusWidths
;
157 m_statusWidths
= NULL
;
161 void wxStatusBar95::SetFieldsCount(int nFields
, const int *widths
)
163 // this is Windows limitation
164 wxASSERT_MSG( (nFields
> 0) && (nFields
< 255), _T("too many fields") );
168 CopyFieldsWidth(widths
);
172 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
174 wxASSERT_MSG( n
== m_nFields
, _T("field number mismatch") );
176 CopyFieldsWidth(widths
);
180 void wxStatusBar95::SetFieldsWidth()
186 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
188 int extraWidth
= aBorders
[2]; // space between fields
190 int *pWidths
= new int[m_nFields
];
193 GetClientSize(&nWindowWidth
, &y
);
195 if ( m_statusWidths
== NULL
) {
196 // default: all fields have the same width
197 int nWidth
= nWindowWidth
/ m_nFields
;
198 for ( int i
= 0; i
< m_nFields
; i
++ )
199 pWidths
[i
] = (i
+ 1) * nWidth
;
202 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
206 for ( i
= 0; i
< m_nFields
; i
++ ) {
207 if ( m_statusWidths
[i
] == -1 )
210 nTotalWidth
+= m_statusWidths
[i
] + extraWidth
;
213 if ( nVarCount
== 0 ) {
214 wxFAIL_MSG( _T("at least one field must be of variable width") );
219 int nVarWidth
= (nWindowWidth
- nTotalWidth
) / nVarCount
;
223 for ( i
= 0; i
< m_nFields
; i
++ ) {
224 if ( m_statusWidths
[i
] == -1 )
225 nCurPos
+= nVarWidth
;
227 nCurPos
+= m_statusWidths
[i
] + extraWidth
;
228 pWidths
[i
] = nCurPos
;
232 if ( !StatusBar_SetParts(GetHwnd(), m_nFields
, pWidths
) ) {
233 wxLogLastError(wxT("StatusBar_SetParts"));
239 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
241 wxCHECK_RET( (nField
>= 0) && (nField
< m_nFields
),
242 _T("invalid statusbar field index") );
244 if ( !StatusBar_SetText(GetHwnd(), nField
, strText
) ) {
245 wxLogLastError(wxT("StatusBar_SetText"));
249 wxString
wxStatusBar95::GetStatusText(int nField
) const
251 wxCHECK_MSG( (nField
>= 0) && (nField
< m_nFields
), wxEmptyString
,
252 _T("invalid statusbar field index") );
255 int len
= StatusBar_GetTextLen(GetHwnd(), nField
);
258 StatusBar_GetText(GetHwnd(), nField
, str
.GetWriteBuf(len
));
264 int wxStatusBar95::GetBorderX() const
267 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
272 int wxStatusBar95::GetBorderY() const
275 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
280 void wxStatusBar95::SetMinHeight(int height
)
282 SendMessage(GetHwnd(), SB_SETMINHEIGHT
, height
+ 2*GetBorderY(), 0);
284 // have to send a (dummy) WM_SIZE to redraw it now
285 SendMessage(GetHwnd(), WM_SIZE
, 0, 0);
288 bool wxStatusBar95::GetFieldRect(int i
, wxRect
& rect
) const
290 wxCHECK_MSG( (i
>= 0) && (i
< m_nFields
), FALSE
,
291 _T("invalid statusbar field index") );
294 if ( !::SendMessage(GetHwnd(), SB_GETRECT
, i
, (LPARAM
)&r
) )
296 wxLogLastError("SendMessage(SB_GETRECT)");
299 wxCopyRECTToRect(r
, rect
);
304 void wxStatusBar95::OnSize(wxSizeEvent
& event
)
306 FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED
,
307 event
.GetSize().x
, event
.GetSize().y
,
310 // adjust fields widths to the new size
314 #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR