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"
35 #include "wx/statusbr.h"
37 #include "wx/univ/renderer.h"
39 // ============================================================================
41 // ============================================================================
43 BEGIN_EVENT_TABLE(wxStatusBarUniv
, wxStatusBarBase
)
44 EVT_SIZE(wxStatusBarUniv::OnSize
)
46 WX_EVENT_TABLE_INPUT_CONSUMER(wxStatusBarUniv
)
49 WX_FORWARD_TO_INPUT_CONSUMER(wxStatusBarUniv
)
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 void wxStatusBarUniv::Init()
59 bool wxStatusBarUniv::Create(wxWindow
*parent
,
64 if ( !wxWindow::Create(parent
, id
,
65 wxDefaultPosition
, wxDefaultSize
,
73 CreateInputHandler(wxINP_HANDLER_STATUSBAR
);
75 SetSize(DoGetBestSize());
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 wxRect
wxStatusBarUniv::GetTotalFieldRect(wxCoord
*borderBetweenFields
)
86 // determine the space we have for the fields
87 wxSize sizeBorders
= m_renderer
->GetStatusBarBorders(borderBetweenFields
);
89 wxRect rect
= GetClientRect();
91 // no, don't do this - the borders are meant to be inside this rect
92 //rect.Deflate(sizeBorders.x, sizeBorders.y);
94 // recalc the field widths if needed
95 if ( m_widthsAbs
.IsEmpty() )
97 // the total width for the fields doesn't include the borders between
99 m_widthsAbs
= CalculateAbsWidths(rect
.width
-
100 *borderBetweenFields
*(m_nFields
- 1));
106 void wxStatusBarUniv::DoDraw(wxControlRenderer
*renderer
)
108 // get the fields rect
109 wxCoord borderBetweenFields
;
110 wxRect rect
= GetTotalFieldRect(&borderBetweenFields
);
113 wxDC
& dc
= renderer
->GetDC();
114 dc
.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
116 // do draw the fields
117 int flags
= IsEnabled() ? 0 : wxCONTROL_DISABLED
;
118 for ( int n
= 0; n
< m_nFields
; n
++ )
120 rect
.width
= m_widthsAbs
[n
];
122 if ( IsExposed(rect
) )
124 // the size grip may be drawn only on the last field and only if we
125 // have the corresponding style and even then only if we really can
127 if ( n
== m_nFields
- 1 &&
128 HasFlag(wxST_SIZEGRIP
) &&
129 GetParent()->HasFlag(wxRESIZE_BORDER
) )
131 // NB: we use wxCONTROL_ISDEFAULT for this because it doesn't
132 // have any meaning for the status bar otherwise anyhow
133 // (it's still ugly, of course, but there are too few flags
134 // to squander them for things like this)
135 flags
|= wxCONTROL_ISDEFAULT
;
138 m_renderer
->DrawStatusField(dc
, rect
, m_statusText
[n
], flags
);
141 rect
.x
+= rect
.width
+ borderBetweenFields
;
145 void wxStatusBarUniv::RefreshField(int i
)
148 if ( GetFieldRect(i
, rect
) )
154 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
158 void wxStatusBarUniv::SetStatusText(const wxString
& text
, int number
)
160 wxCHECK_RET( number
>= 0 && number
< m_nFields
,
161 _T("invalid status bar field index in SetStatusText()") );
163 if ( text
== m_statusText
[number
] )
169 m_statusText
[number
] = text
;
171 RefreshField(number
);
174 wxString
wxStatusBarUniv::GetStatusText(int number
) const
176 wxCHECK_MSG( number
>= 0 && number
< m_nFields
, _T(""),
177 _T("invalid status bar field index") );
179 return m_statusText
[number
];
182 // ----------------------------------------------------------------------------
183 // fields count/widths
184 // ----------------------------------------------------------------------------
186 void wxStatusBarUniv::SetFieldsCount(int number
, const int *widths
)
188 wxStatusBarBase::SetFieldsCount(number
, widths
);
190 m_statusText
.SetCount(number
);
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::GetSystemFont(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