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 m_statusText
.SetCount(number
);
190 wxStatusBarBase::SetFieldsCount(number
, widths
);
194 void wxStatusBarUniv::SetStatusWidths(int n
, const int widths
[])
196 wxStatusBarBase::SetStatusWidths(n
, widths
);
201 // ----------------------------------------------------------------------------
203 // ----------------------------------------------------------------------------
205 void wxStatusBarUniv::OnSize(wxSizeEvent
& event
)
207 // invalidate the widths, we'll have to recalc them
210 // refresh entirely, shouldn't matter much as the statusbar is quick to
211 // redraw and it would be difficult to avoid it as we'd need to find out
212 // which fields exactly were affected...
218 bool wxStatusBarUniv::GetFieldRect(int n
, wxRect
& rect
) const
220 wxCHECK_MSG( n
>= 0 && n
< m_nFields
, FALSE
,
221 _T("invalid field index in GetFieldRect()") );
223 // this is a fix for a bug exhibited by the statbar sample: if
224 // GetFieldRect() is called from the derived class OnSize() handler, then
225 // our geometry info is wrong as our OnSize() didn't invalidate m_widthsAbs
226 // yet - so recalc it just in case
227 wxStatusBarUniv
*self
= wxConstCast(this, wxStatusBarUniv
);
228 self
->m_widthsAbs
.Empty();
230 wxCoord borderBetweenFields
;
231 rect
= self
->GetTotalFieldRect(&borderBetweenFields
);
232 for ( int i
= 0; i
<= n
; i
++ )
234 rect
.width
= m_widthsAbs
[i
];
237 rect
.x
+= rect
.width
+ borderBetweenFields
;
243 wxCoord
wxStatusBarUniv::GetHeight() const
245 wxClientDC
dc(wxConstCast(this, wxStatusBarUniv
));
246 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
248 return dc
.GetCharHeight() + 2*GetBorderY();
251 wxSize
wxStatusBarUniv::DoGetBestSize() const
253 return wxSize(100, GetHeight());
256 void wxStatusBarUniv::DoSetSize(int x
, int y
,
257 int width
, int WXUNUSED(height
),
260 wxStatusBarBase::DoSetSize(x
, y
, width
, GetHeight(), sizeFlags
);
263 // ----------------------------------------------------------------------------
265 // ----------------------------------------------------------------------------
267 void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height
))
269 // nothing to do here, we don't support it - and why would we?
272 int wxStatusBarUniv::GetBorderX() const
274 return m_renderer
->GetStatusBarBorders(NULL
).x
;
277 int wxStatusBarUniv::GetBorderY() const
279 return m_renderer
->GetStatusBarBorders(NULL
).y
;
282 #endif // wxUSE_STATUSBAR