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
,
72 if ( message
== WM_COMMAND
)
74 wxStatusBar95
*sb
= (wxStatusBar95
*)GetWindowLong(hwnd
, GWL_USERDATA
);
75 sb
->MSWWindowProc(message
, wParam
, lParam
);
78 return ::CallWindowProc(CASTWNDPROC gs_wndprocStatBar
, hwnd
, message
, wParam
, lParam
);
81 // ============================================================================
83 // ============================================================================
85 // ----------------------------------------------------------------------------
86 // wxStatusBar95 class
87 // ----------------------------------------------------------------------------
89 wxStatusBar95::wxStatusBar95()
96 bool wxStatusBar95::Create(wxWindow
*parent
,
101 wxCHECK_MSG( parent
, FALSE
, wxT("status bar must have a parent") );
104 SetWindowStyleFlag(style
);
107 parent
->AddChild(this);
109 m_windowId
= id
== -1 ? NewControlId() : id
;
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 // we can't subclass this window as usual because the status bar window
127 // proc processes WM_SIZE and WM_PAINT specially
128 // SubclassWin(m_hWnd);
130 // but we want to process the messages from it still, so do custom
132 gs_wndprocStatBar
= (WXFARPROC
)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::DoMoveWindow(int x
, int y
, int width
, int height
)
304 FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED
, x
, y
, SendMessage
);
306 // adjust fields widths to the new size
310 #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR