]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/statbr95.cpp
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(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
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 // ----------------------------------------------------------------------------
65 // wxStatusBar95 class
66 // ----------------------------------------------------------------------------
68 wxStatusBar95::wxStatusBar95()
75 bool wxStatusBar95::Create(wxWindow
*parent
,
80 wxCHECK_MSG( parent
, FALSE
, wxT("status bar must have a parent") );
83 SetWindowStyleFlag(style
);
86 parent
->AddChild(this);
88 m_windowId
= id
== -1 ? NewControlId() : id
;
90 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
92 if ( style
& wxCLIP_SIBLINGS
)
93 wstyle
|= WS_CLIPSIBLINGS
;
95 // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default
96 // (at least in the version of comctl32.dll I'm using), and the only way to
97 // turn it off is to use CCS_TOP style - as we position the status bar
98 // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP
100 if ( !(style
& wxST_SIZEGRIP
) )
106 // may be some versions of comctl32.dll do need it - anyhow, it won't
108 wstyle
|= SBARS_SIZEGRIP
;
111 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
117 wxLogSysError(_("Failed to create a status bar."));
128 wxStatusBar95::~wxStatusBar95()
130 delete [] m_statusWidths
;
133 void wxStatusBar95::CopyFieldsWidth(const int widths
[])
135 if (widths
&& !m_statusWidths
)
136 m_statusWidths
= new int[m_nFields
];
138 if ( widths
!= NULL
)
140 for ( int i
= 0; i
< m_nFields
; i
++ )
141 m_statusWidths
[i
] = widths
[i
];
145 delete [] m_statusWidths
;
146 m_statusWidths
= NULL
;
150 void wxStatusBar95::SetFieldsCount(int nFields
, const int *widths
)
152 // this is a Windows limitation
153 wxASSERT_MSG( (nFields
> 0) && (nFields
< 255), _T("too many fields") );
157 CopyFieldsWidth(widths
);
161 void wxStatusBar95::SetStatusWidths(int WXUNUSED_UNLESS_DEBUG(n
), const int widths
[])
163 wxASSERT_MSG( n
== m_nFields
, _T("field number mismatch") );
165 CopyFieldsWidth(widths
);
169 void wxStatusBar95::SetFieldsWidth()
175 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
177 int extraWidth
= aBorders
[2]; // space between fields
179 int *pWidths
= new int[m_nFields
];
182 GetClientSize(&nWindowWidth
, &y
);
184 if ( m_statusWidths
== NULL
) {
185 // default: all fields have the same width
186 int nWidth
= nWindowWidth
/ m_nFields
;
187 for ( int i
= 0; i
< m_nFields
; i
++ )
188 pWidths
[i
] = (i
+ 1) * nWidth
;
191 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
195 for ( i
= 0; i
< m_nFields
; i
++ ) {
196 if ( m_statusWidths
[i
] == -1 )
199 nTotalWidth
+= m_statusWidths
[i
] + extraWidth
;
202 if ( nVarCount
== 0 ) {
203 wxFAIL_MSG( _T("at least one field must be of variable width") );
208 int nVarWidth
= (nWindowWidth
- nTotalWidth
) / nVarCount
;
212 for ( i
= 0; i
< m_nFields
; i
++ ) {
213 if ( m_statusWidths
[i
] == -1 )
214 nCurPos
+= nVarWidth
;
216 nCurPos
+= m_statusWidths
[i
] + extraWidth
;
217 pWidths
[i
] = nCurPos
;
221 if ( !StatusBar_SetParts(GetHwnd(), m_nFields
, pWidths
) ) {
222 wxLogLastError(wxT("StatusBar_SetParts"));
228 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
230 wxCHECK_RET( (nField
>= 0) && (nField
< m_nFields
),
231 _T("invalid statusbar field index") );
233 if ( !StatusBar_SetText(GetHwnd(), nField
, strText
) )
235 wxLogLastError(wxT("StatusBar_SetText"));
239 wxString
wxStatusBar95::GetStatusText(int nField
) const
241 wxCHECK_MSG( (nField
>= 0) && (nField
< m_nFields
), wxEmptyString
,
242 _T("invalid statusbar field index") );
245 int len
= StatusBar_GetTextLen(GetHwnd(), nField
);
248 StatusBar_GetText(GetHwnd(), nField
, str
.GetWriteBuf(len
));
255 int wxStatusBar95::GetBorderX() const
258 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
263 int wxStatusBar95::GetBorderY() const
266 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
271 void wxStatusBar95::SetMinHeight(int height
)
273 SendMessage(GetHwnd(), SB_SETMINHEIGHT
, height
+ 2*GetBorderY(), 0);
275 // have to send a (dummy) WM_SIZE to redraw it now
276 SendMessage(GetHwnd(), WM_SIZE
, 0, 0);
279 bool wxStatusBar95::GetFieldRect(int i
, wxRect
& rect
) const
281 wxCHECK_MSG( (i
>= 0) && (i
< m_nFields
), FALSE
,
282 _T("invalid statusbar field index") );
285 if ( !::SendMessage(GetHwnd(), SB_GETRECT
, i
, (LPARAM
)&r
) )
287 wxLogLastError(wxT("SendMessage(SB_GETRECT)"));
290 wxCopyRECTToRect(r
, rect
);
295 void wxStatusBar95::DoMoveWindow(int x
, int y
, int width
, int height
)
297 // the status bar wnd proc must be forwarded the WM_SIZE message whenever
298 // the stat bar position/size is changed because it normally positions the
299 // control itself along bottom or top side of the parent window - failing
300 // to do so will result in nasty visual effects
301 FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED
, x
, y
, SendMessage
);
303 // but now, when the standard status bar wnd proc did all it wanted to do,
304 // move the status bar to its correct location - usually this call may be
305 // omitted because for normal status bars (positioned along the bottom
306 // edge) the position is already set correctly, but if the user wants to
307 // position them in some exotic location, this is really needed
308 wxWindow::DoMoveWindow(x
, y
, width
, height
);
310 // adjust fields widths to the new size
314 #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR