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_OLD__) || defined(__TWIN32__))
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95
, wxWindow
);
48 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar
, wxStatusBar95
)
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
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)
56 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
57 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
58 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 // static WNDPROC gs_wndprocStatBar = NULL;
65 static WXFARPROC gs_wndprocStatBar
= (WXFARPROC
) NULL
;
67 LRESULT APIENTRY
wxStatusBarProc(HWND hwnd
,
79 case WM_LBUTTONDBLCLK
:
82 case WM_RBUTTONDBLCLK
:
85 case WM_MBUTTONDBLCLK
:
86 wxStatusBar95
*sb
= (wxStatusBar95
*)GetWindowLong(hwnd
, GWL_USERDATA
);
87 sb
->MSWWindowProc(message
, wParam
, lParam
);
91 return ::CallWindowProc(CASTWNDPROC gs_wndprocStatBar
, hwnd
, message
, wParam
, lParam
);
94 // ============================================================================
96 // ============================================================================
98 // ----------------------------------------------------------------------------
99 // wxStatusBar95 class
100 // ----------------------------------------------------------------------------
102 wxStatusBar95::wxStatusBar95()
109 bool wxStatusBar95::Create(wxWindow
*parent
,
112 const wxString
& name
)
114 wxCHECK_MSG( parent
, FALSE
, wxT("status bar must have a parent") );
117 SetWindowStyleFlag(style
);
120 parent
->AddChild(this);
122 m_windowId
= id
== -1 ? NewControlId() : id
;
124 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
126 // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default
127 // (at least in the version of comctl32.dll I'm using), and the only way to
128 // turn it off is to use CCS_TOP style - as we position the status bar
129 // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP
131 if ( !(style
& wxST_SIZEGRIP
) )
137 // may be some versions of comctl32.dll do need it - anyhow, it won't
139 wstyle
|= SBARS_SIZEGRIP
;
142 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
148 wxLogSysError(_("Failed to create a status bar."));
155 // we can't subclass this window as usual because the status bar window
156 // proc processes WM_SIZE and WM_PAINT specially
157 // SubclassWin(m_hWnd);
159 // but we want to process the messages from it still, so do custom
161 gs_wndprocStatBar
= (WXFARPROC
)GetWindowLong(GetHwnd(), GWL_WNDPROC
);
162 SetWindowLong(GetHwnd(), GWL_WNDPROC
, (LONG
)wxStatusBarProc
);
163 SetWindowLong(GetHwnd(), GWL_USERDATA
, (LONG
)this);
168 wxStatusBar95::~wxStatusBar95()
170 delete [] m_statusWidths
;
173 void wxStatusBar95::CopyFieldsWidth(const int widths
[])
175 if (widths
&& !m_statusWidths
)
176 m_statusWidths
= new int[m_nFields
];
178 if ( widths
!= NULL
) {
179 for ( int i
= 0; i
< m_nFields
; i
++ )
180 m_statusWidths
[i
] = widths
[i
];
183 delete [] m_statusWidths
;
184 m_statusWidths
= NULL
;
188 void wxStatusBar95::SetFieldsCount(int nFields
, const int *widths
)
190 // this is Windows limitation
191 wxASSERT_MSG( (nFields
> 0) && (nFields
< 255), _T("too many fields") );
195 CopyFieldsWidth(widths
);
199 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
201 wxASSERT_MSG( n
== m_nFields
, _T("field number mismatch") );
203 CopyFieldsWidth(widths
);
207 void wxStatusBar95::SetFieldsWidth()
213 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
215 int extraWidth
= aBorders
[2]; // space between fields
217 int *pWidths
= new int[m_nFields
];
220 GetClientSize(&nWindowWidth
, &y
);
222 if ( m_statusWidths
== NULL
) {
223 // default: all fields have the same width
224 int nWidth
= nWindowWidth
/ m_nFields
;
225 for ( int i
= 0; i
< m_nFields
; i
++ )
226 pWidths
[i
] = (i
+ 1) * nWidth
;
229 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
233 for ( i
= 0; i
< m_nFields
; i
++ ) {
234 if ( m_statusWidths
[i
] == -1 )
237 nTotalWidth
+= m_statusWidths
[i
] + extraWidth
;
240 if ( nVarCount
== 0 ) {
241 wxFAIL_MSG( _T("at least one field must be of variable width") );
246 int nVarWidth
= (nWindowWidth
- nTotalWidth
) / nVarCount
;
250 for ( i
= 0; i
< m_nFields
; i
++ ) {
251 if ( m_statusWidths
[i
] == -1 )
252 nCurPos
+= nVarWidth
;
254 nCurPos
+= m_statusWidths
[i
] + extraWidth
;
255 pWidths
[i
] = nCurPos
;
259 if ( !StatusBar_SetParts(GetHwnd(), m_nFields
, pWidths
) ) {
260 wxLogLastError(wxT("StatusBar_SetParts"));
266 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
268 wxCHECK_RET( (nField
>= 0) && (nField
< m_nFields
),
269 _T("invalid statusbar field index") );
271 if ( !StatusBar_SetText(GetHwnd(), nField
, strText
) ) {
272 wxLogLastError(wxT("StatusBar_SetText"));
276 wxString
wxStatusBar95::GetStatusText(int nField
) const
278 wxCHECK_MSG( (nField
>= 0) && (nField
< m_nFields
), wxEmptyString
,
279 _T("invalid statusbar field index") );
282 int len
= StatusBar_GetTextLen(GetHwnd(), nField
);
285 StatusBar_GetText(GetHwnd(), nField
, str
.GetWriteBuf(len
));
291 int wxStatusBar95::GetBorderX() const
294 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
299 int wxStatusBar95::GetBorderY() const
302 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
307 void wxStatusBar95::SetMinHeight(int height
)
309 SendMessage(GetHwnd(), SB_SETMINHEIGHT
, height
+ 2*GetBorderY(), 0);
311 // have to send a (dummy) WM_SIZE to redraw it now
312 SendMessage(GetHwnd(), WM_SIZE
, 0, 0);
315 bool wxStatusBar95::GetFieldRect(int i
, wxRect
& rect
) const
317 wxCHECK_MSG( (i
>= 0) && (i
< m_nFields
), FALSE
,
318 _T("invalid statusbar field index") );
321 if ( !::SendMessage(GetHwnd(), SB_GETRECT
, i
, (LPARAM
)&r
) )
323 wxLogLastError("SendMessage(SB_GETRECT)");
326 wxCopyRECTToRect(r
, rect
);
331 void wxStatusBar95::DoMoveWindow(int x
, int y
, int width
, int height
)
333 // the status bar wnd proc must be forwarded the WM_SIZE message whenever
334 // the stat bar position/size is changed because it normally positions the
335 // control itself along bottom or top side of the parent window - failing
336 // to do so will result in nasty visual effects
337 FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED
, x
, y
, SendMessage
);
339 // but now, when the standard status bar wnd proc did all it wanted to do,
340 // move the status bar to its correct location - usually this call may be
341 // omitted because for normal status bars (positioned along the bottom
342 // edge) the position is already set correctly, but if the user wants to
343 // position them in some exotic location, this is really needed
344 wxWindow::DoMoveWindow(x
, y
, width
, height
);
346 // adjust fields widths to the new size
350 #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR