1 /////////////////////////////////////////////////////////////////////////////
2 // Name: univ/statusbr.cpp
3 // Purpose: wxStatusBar implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "univstatusbr.h"
24 #include "wx/wxprec.h"
33 #include "wx/settings.h"
34 #include "wx/dcclient.h"
37 #include "wx/statusbr.h"
39 #include "wx/univ/renderer.h"
41 // ============================================================================
43 // ============================================================================
45 BEGIN_EVENT_TABLE(wxStatusBarUniv
, wxStatusBarBase
)
46 EVT_SIZE(wxStatusBarUniv::OnSize
)
48 WX_EVENT_TABLE_INPUT_CONSUMER(wxStatusBarUniv
)
51 WX_FORWARD_TO_INPUT_CONSUMER(wxStatusBarUniv
)
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 void wxStatusBarUniv::Init()
61 bool wxStatusBarUniv::Create(wxWindow
*parent
,
66 if ( !wxWindow::Create(parent
, id
,
67 wxDefaultPosition
, wxDefaultSize
,
75 CreateInputHandler(wxINP_HANDLER_STATUSBAR
);
77 SetSize(DoGetBestSize());
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 wxRect
wxStatusBarUniv::GetTotalFieldRect(wxCoord
*borderBetweenFields
)
88 wxRect rect
= GetClientRect();
90 // no, don't do this - the borders are meant to be inside this rect
91 // wxSize sizeBorders =
92 m_renderer
->GetStatusBarBorders(borderBetweenFields
);
93 //rect.Deflate(sizeBorders.x, sizeBorders.y);
95 // recalc the field widths if needed
96 if ( m_widthsAbs
.IsEmpty() )
98 // the total width for the fields doesn't include the borders between
100 m_widthsAbs
= CalculateAbsWidths(rect
.width
-
101 *borderBetweenFields
*(m_nFields
- 1));
107 void wxStatusBarUniv::DoDraw(wxControlRenderer
*renderer
)
109 // get the fields rect
110 wxCoord borderBetweenFields
;
111 wxRect rect
= GetTotalFieldRect(&borderBetweenFields
);
114 wxDC
& dc
= renderer
->GetDC();
115 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
117 // do draw the fields
118 int flags
= IsEnabled() ? 0 : wxCONTROL_DISABLED
;
119 for ( int n
= 0; n
< m_nFields
; n
++ )
121 rect
.width
= m_widthsAbs
[n
];
123 if ( IsExposed(rect
) )
125 // the size grip may be drawn only on the last field and only if we
126 // have the corresponding style and even then only if we really can
128 if ( n
== m_nFields
- 1 &&
129 HasFlag(wxST_SIZEGRIP
) &&
130 GetParent()->HasFlag(wxRESIZE_BORDER
) )
132 // NB: we use wxCONTROL_ISDEFAULT for this because it doesn't
133 // have any meaning for the status bar otherwise anyhow
134 // (it's still ugly, of course, but there are too few flags
135 // to squander them for things like this)
136 flags
|= wxCONTROL_ISDEFAULT
;
139 m_renderer
->DrawStatusField(dc
, rect
, m_statusText
[n
], flags
);
142 rect
.x
+= rect
.width
+ borderBetweenFields
;
146 void wxStatusBarUniv::RefreshField(int i
)
149 if ( GetFieldRect(i
, rect
) )
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 void wxStatusBarUniv::SetStatusText(const wxString
& text
, int number
)
161 wxCHECK_RET( number
>= 0 && number
< m_nFields
,
162 _T("invalid status bar field index in SetStatusText()") );
164 if ( text
== m_statusText
[number
] )
170 m_statusText
[number
] = text
;
172 RefreshField(number
);
175 wxString
wxStatusBarUniv::GetStatusText(int number
) const
177 wxCHECK_MSG( number
>= 0 && number
< m_nFields
, _T(""),
178 _T("invalid status bar field index") );
180 return m_statusText
[number
];
183 // ----------------------------------------------------------------------------
184 // fields count/widths
185 // ----------------------------------------------------------------------------
187 void wxStatusBarUniv::SetFieldsCount(int number
, const int *widths
)
189 wxStatusBarBase::SetFieldsCount(number
, widths
);
191 m_statusText
.SetCount(number
);
195 void wxStatusBarUniv::SetStatusWidths(int n
, const int widths
[])
197 wxStatusBarBase::SetStatusWidths(n
, widths
);
202 // ----------------------------------------------------------------------------
204 // ----------------------------------------------------------------------------
206 void wxStatusBarUniv::OnSize(wxSizeEvent
& event
)
208 // invalidate the widths, we'll have to recalc them
211 // refresh entirely, shouldn't matter much as the statusbar is quick to
212 // redraw and it would be difficult to avoid it as we'd need to find out
213 // which fields exactly were affected...
219 bool wxStatusBarUniv::GetFieldRect(int n
, wxRect
& rect
) const
221 wxCHECK_MSG( n
>= 0 && n
< m_nFields
, FALSE
,
222 _T("invalid field index in GetFieldRect()") );
224 // this is a fix for a bug exhibited by the statbar sample: if
225 // GetFieldRect() is called from the derived class OnSize() handler, then
226 // our geometry info is wrong as our OnSize() didn't invalidate m_widthsAbs
227 // yet - so recalc it just in case
228 wxStatusBarUniv
*self
= wxConstCast(this, wxStatusBarUniv
);
229 self
->m_widthsAbs
.Empty();
231 wxCoord borderBetweenFields
;
232 rect
= self
->GetTotalFieldRect(&borderBetweenFields
);
233 for ( int i
= 0; i
<= n
; i
++ )
235 rect
.width
= m_widthsAbs
[i
];
238 rect
.x
+= rect
.width
+ borderBetweenFields
;
244 wxCoord
wxStatusBarUniv::GetHeight() const
246 wxClientDC
dc(wxConstCast(this, wxStatusBarUniv
));
247 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
249 return dc
.GetCharHeight() + 2*GetBorderY();
252 wxSize
wxStatusBarUniv::DoGetBestSize() const
254 return wxSize(100, GetHeight());
257 void wxStatusBarUniv::DoSetSize(int x
, int y
,
258 int width
, int WXUNUSED(height
),
261 wxStatusBarBase::DoSetSize(x
, y
, width
, GetHeight(), sizeFlags
);
264 // ----------------------------------------------------------------------------
266 // ----------------------------------------------------------------------------
268 void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height
))
270 // nothing to do here, we don't support it - and why would we?
273 int wxStatusBarUniv::GetBorderX() const
275 return m_renderer
->GetStatusBarBorders(NULL
).x
;
278 int wxStatusBarUniv::GetBorderY() const
280 return m_renderer
->GetStatusBarBorders(NULL
).y
;
283 #endif // wxUSE_STATUSBAR