]>
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
);
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 // windowsx.h and commctrl.h don't define those, so we do it here
54 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
55 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
56 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
57 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
59 // ============================================================================
61 // ============================================================================
63 // ----------------------------------------------------------------------------
64 // wxStatusBar95 class
65 // ----------------------------------------------------------------------------
67 wxStatusBar95::wxStatusBar95()
74 bool wxStatusBar95::Create(wxWindow
*parent
,
79 wxCHECK_MSG( parent
, FALSE
, wxT("status bar must have a parent") );
82 SetWindowStyleFlag(style
);
85 parent
->AddChild(this);
87 m_windowId
= id
== -1 ? NewControlId() : id
;
89 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
91 if ( style
& wxCLIP_SIBLINGS
)
92 wstyle
|= WS_CLIPSIBLINGS
;
94 // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default
95 // (at least in the version of comctl32.dll I'm using), and the only way to
96 // turn it off is to use CCS_TOP style - as we position the status bar
97 // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP
99 if ( !(style
& wxST_SIZEGRIP
) )
105 // may be some versions of comctl32.dll do need it - anyhow, it won't
107 wstyle
|= SBARS_SIZEGRIP
;
110 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
116 wxLogSysError(_("Failed to create a status bar."));
127 wxStatusBar95::~wxStatusBar95()
131 void wxStatusBar95::CopyFieldsWidth(const int widths
[])
133 if (widths
&& !m_statusWidths
)
134 m_statusWidths
= new int[m_nFields
];
136 if ( widths
!= NULL
)
138 for ( int i
= 0; i
< m_nFields
; i
++ )
139 m_statusWidths
[i
] = widths
[i
];
143 delete [] m_statusWidths
;
144 m_statusWidths
= NULL
;
148 void wxStatusBar95::SetFieldsCount(int nFields
, const int *widths
)
150 // this is a Windows limitation
151 wxASSERT_MSG( (nFields
> 0) && (nFields
< 255), _T("too many fields") );
155 CopyFieldsWidth(widths
);
159 void wxStatusBar95::SetStatusWidths(int WXUNUSED_UNLESS_DEBUG(n
), const int widths
[])
161 wxASSERT_MSG( n
== m_nFields
, _T("field number mismatch") );
163 CopyFieldsWidth(widths
);
167 void wxStatusBar95::SetFieldsWidth()
173 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
175 int extraWidth
= aBorders
[2]; // space between fields
177 int *pWidths
= new int[m_nFields
];
180 GetClientSize(&nWindowWidth
, &y
);
182 if ( m_statusWidths
== NULL
) {
183 // default: all fields have the same width
184 int nWidth
= nWindowWidth
/ m_nFields
;
185 for ( int i
= 0; i
< m_nFields
; i
++ )
186 pWidths
[i
] = (i
+ 1) * nWidth
;
189 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
193 for ( i
= 0; i
< m_nFields
; i
++ ) {
194 if ( m_statusWidths
[i
] == -1 )
197 nTotalWidth
+= m_statusWidths
[i
] + extraWidth
;
200 if ( nVarCount
== 0 ) {
201 wxFAIL_MSG( _T("at least one field must be of variable width") );
206 int nVarWidth
= (nWindowWidth
- nTotalWidth
) / nVarCount
;
210 for ( i
= 0; i
< m_nFields
; i
++ ) {
211 if ( m_statusWidths
[i
] == -1 )
212 nCurPos
+= nVarWidth
;
214 nCurPos
+= m_statusWidths
[i
] + extraWidth
;
215 pWidths
[i
] = nCurPos
;
219 if ( !StatusBar_SetParts(GetHwnd(), m_nFields
, pWidths
) ) {
220 wxLogLastError(wxT("StatusBar_SetParts"));
226 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
228 wxCHECK_RET( (nField
>= 0) && (nField
< m_nFields
),
229 _T("invalid statusbar field index") );
231 if ( !StatusBar_SetText(GetHwnd(), nField
, strText
) )
233 wxLogLastError(wxT("StatusBar_SetText"));
237 wxString
wxStatusBar95::GetStatusText(int nField
) const
239 wxCHECK_MSG( (nField
>= 0) && (nField
< m_nFields
), wxEmptyString
,
240 _T("invalid statusbar field index") );
243 int len
= StatusBar_GetTextLen(GetHwnd(), nField
);
246 StatusBar_GetText(GetHwnd(), nField
, str
.GetWriteBuf(len
));
253 int wxStatusBar95::GetBorderX() const
256 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
261 int wxStatusBar95::GetBorderY() const
264 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
269 void wxStatusBar95::SetMinHeight(int height
)
271 SendMessage(GetHwnd(), SB_SETMINHEIGHT
, height
+ 2*GetBorderY(), 0);
273 // have to send a (dummy) WM_SIZE to redraw it now
274 SendMessage(GetHwnd(), WM_SIZE
, 0, 0);
277 bool wxStatusBar95::GetFieldRect(int i
, wxRect
& rect
) const
279 wxCHECK_MSG( (i
>= 0) && (i
< m_nFields
), FALSE
,
280 _T("invalid statusbar field index") );
283 if ( !::SendMessage(GetHwnd(), SB_GETRECT
, i
, (LPARAM
)&r
) )
285 wxLogLastError(wxT("SendMessage(SB_GETRECT)"));
288 wxCopyRECTToRect(r
, rect
);
293 void wxStatusBar95::DoMoveWindow(int x
, int y
, int width
, int height
)
295 // the status bar wnd proc must be forwarded the WM_SIZE message whenever
296 // the stat bar position/size is changed because it normally positions the
297 // control itself along bottom or top side of the parent window - failing
298 // to do so will result in nasty visual effects
299 FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED
, x
, y
, SendMessage
);
301 // but now, when the standard status bar wnd proc did all it wanted to do,
302 // move the status bar to its correct location - usually this call may be
303 // omitted because for normal status bars (positioned along the bottom
304 // edge) the position is already set correctly, but if the user wants to
305 // position them in some exotic location, this is really needed
306 wxWindow::DoMoveWindow(x
, y
, width
, height
);
308 // adjust fields widths to the new size
311 // we have to trigger wxSizeEvent if there are children window in status
312 // bar because GetFieldRect returned incorrect (not updated) values up to
313 // here, which almost certainly resulted in incorrectly redrawn statusbar
314 if ( m_children
.GetCount() > 0 )
316 wxSizeEvent
event(GetClientSize(), m_windowId
);
317 event
.SetEventObject(this);
318 GetEventHandler()->ProcessEvent(event
);
322 #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR