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 //rect.Deflate(sizeBorders.x, sizeBorders.y);
93 // recalc the field widths if needed
94 if ( m_widthsAbs
.IsEmpty() )
96 // the total width for the fields doesn't include the borders between
98 m_widthsAbs
= CalculateAbsWidths(rect
.width
-
99 *borderBetweenFields
*(m_nFields
- 1));
105 void wxStatusBarUniv::DoDraw(wxControlRenderer
*renderer
)
107 // get the fields rect
108 wxCoord borderBetweenFields
;
109 wxRect rect
= GetTotalFieldRect(&borderBetweenFields
);
112 wxDC
& dc
= renderer
->GetDC();
113 dc
.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
115 // do draw the fields
116 int flags
= IsEnabled() ? 0 : wxCONTROL_DISABLED
;
117 for ( int n
= 0; n
< m_nFields
; n
++ )
119 rect
.width
= m_widthsAbs
[n
];
121 if ( IsExposed(rect
) )
123 // the size grip may be drawn only on the last field and only if we
124 // have the corresponding style and even then only if we really can
126 if ( n
== m_nFields
- 1 &&
127 HasFlag(wxST_SIZEGRIP
) &&
128 GetParent()->HasFlag(wxRESIZE_BORDER
) )
130 // NB: we use wxCONTROL_ISDEFAULT for this because it doesn't
131 // have any meaning for the status bar otherwise anyhow
132 // (it's still ugly, of course, but there are too few flags
133 // to squander them for things like this)
134 flags
|= wxCONTROL_ISDEFAULT
;
137 m_renderer
->DrawStatusField(dc
, rect
, m_statusText
[n
], flags
);
140 rect
.x
+= rect
.width
+ borderBetweenFields
;
144 void wxStatusBarUniv::RefreshField(int i
)
147 if ( GetFieldRect(i
, rect
) )
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
157 void wxStatusBarUniv::SetStatusText(const wxString
& text
, int number
)
159 wxCHECK_RET( number
>= 0 && number
< m_nFields
,
160 _T("invalid status bar field index in SetStatusText()") );
162 if ( text
== m_statusText
[number
] )
168 m_statusText
[number
] = text
;
170 RefreshField(number
);
173 wxString
wxStatusBarUniv::GetStatusText(int number
) const
175 wxCHECK_MSG( number
>= 0 && number
< m_nFields
, _T(""),
176 _T("invalid status bar field index") );
178 return m_statusText
[number
];
181 // ----------------------------------------------------------------------------
182 // fields count/widths
183 // ----------------------------------------------------------------------------
185 void wxStatusBarUniv::SetFieldsCount(int number
, const int *widths
)
187 wxStatusBarBase::SetFieldsCount(number
, widths
);
189 m_statusText
.SetCount(number
);
193 void wxStatusBarUniv::SetStatusWidths(int n
, const int widths
[])
195 wxStatusBarBase::SetStatusWidths(n
, widths
);
200 // ----------------------------------------------------------------------------
202 // ----------------------------------------------------------------------------
204 void wxStatusBarUniv::OnSize(wxSizeEvent
& event
)
206 // invalidate the widths, we'll have to recalc them
209 // refresh entirely, shouldn't matter much as the statusbar is quick to
210 // redraw and it would be difficult to avoid it as we'd need to find out
211 // which fields exactly were affected...
217 bool wxStatusBarUniv::GetFieldRect(int n
, wxRect
& rect
) const
219 wxCHECK_MSG( n
>= 0 && n
< m_nFields
, FALSE
,
220 _T("invalid field index in GetFieldRect()") );
222 // this is a fix for a bug exhibited by the statbar sample: if
223 // GetFieldRect() is called from the derived class OnSize() handler, then
224 // our geometry info is wrong as our OnSize() didn't invalidate m_widthsAbs
225 // yet - so recalc it just in case
226 wxStatusBarUniv
*self
= wxConstCast(this, wxStatusBarUniv
);
227 self
->m_widthsAbs
.Empty();
229 wxCoord borderBetweenFields
;
230 rect
= self
->GetTotalFieldRect(&borderBetweenFields
);
231 for ( int i
= 0; i
<= n
; i
++ )
233 rect
.width
= m_widthsAbs
[i
];
236 rect
.x
+= rect
.width
+ borderBetweenFields
;
242 wxCoord
wxStatusBarUniv::GetHeight() const
244 wxClientDC
dc(wxConstCast(this, wxStatusBarUniv
));
245 dc
.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
247 return dc
.GetCharHeight() + 2*GetBorderY();
250 wxSize
wxStatusBarUniv::DoGetBestSize() const
252 return wxSize(100, GetHeight());
255 void wxStatusBarUniv::DoSetSize(int x
, int y
,
256 int width
, int WXUNUSED(height
),
259 wxStatusBarBase::DoSetSize(x
, y
, width
, GetHeight(), sizeFlags
);
262 // ----------------------------------------------------------------------------
264 // ----------------------------------------------------------------------------
266 void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height
))
268 // nothing to do here, we don't support it - and why would we?
271 int wxStatusBarUniv::GetBorderX() const
273 return m_renderer
->GetStatusBarBorders(NULL
).x
;
276 int wxStatusBarUniv::GetBorderY() const
278 return m_renderer
->GetStatusBarBorders(NULL
).y
;
281 #endif // wxUSE_STATUSBAR