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"
38 #include "wx/toplevel.h"
40 #include "wx/univ/renderer.h"
42 // ============================================================================
44 // ============================================================================
46 BEGIN_EVENT_TABLE(wxStatusBarUniv
, wxStatusBarBase
)
47 EVT_SIZE(wxStatusBarUniv::OnSize
)
49 WX_EVENT_TABLE_INPUT_CONSUMER(wxStatusBarUniv
)
52 WX_FORWARD_TO_INPUT_CONSUMER(wxStatusBarUniv
)
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 void wxStatusBarUniv::Init()
62 bool wxStatusBarUniv::Create(wxWindow
*parent
,
67 if ( !wxWindow::Create(parent
, id
,
68 wxDefaultPosition
, wxDefaultSize
,
76 CreateInputHandler(wxINP_HANDLER_STATUSBAR
);
78 SetSize(DoGetBestSize());
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 wxRect
wxStatusBarUniv::GetTotalFieldRect(wxCoord
*borderBetweenFields
)
89 wxRect rect
= GetClientRect();
91 // no, don't do this - the borders are meant to be inside this rect
92 // wxSize sizeBorders =
93 m_renderer
->GetStatusBarBorders(borderBetweenFields
);
94 //rect.Deflate(sizeBorders.x, sizeBorders.y);
96 // recalc the field widths if needed
97 if ( m_widthsAbs
.IsEmpty() )
99 // the total width for the fields doesn't include the borders between
101 m_widthsAbs
= CalculateAbsWidths(rect
.width
-
102 *borderBetweenFields
*(m_nFields
- 1));
108 void wxStatusBarUniv::DoDraw(wxControlRenderer
*renderer
)
110 // get the fields rect
111 wxCoord borderBetweenFields
;
112 wxRect rect
= GetTotalFieldRect(&borderBetweenFields
);
115 wxDC
& dc
= renderer
->GetDC();
116 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
118 // do draw the fields
119 int flags
= IsEnabled() ? 0 : wxCONTROL_DISABLED
;
120 for ( int n
= 0; n
< m_nFields
; n
++ )
122 rect
.width
= m_widthsAbs
[n
];
124 if ( IsExposed(rect
) )
126 wxTopLevelWindow
*parentTLW
= wxDynamicCast(GetParent(), wxTopLevelWindow
);
128 // the size grip may be drawn only on the last field and only if we
129 // have the corresponding style and even then only if we really can
131 if ( n
== m_nFields
- 1 &&
132 HasFlag(wxST_SIZEGRIP
) &&
133 GetParent()->HasFlag(wxRESIZE_BORDER
) &&
134 parentTLW
&& !parentTLW
->IsMaximized() )
136 // NB: we use wxCONTROL_ISDEFAULT for this because it doesn't
137 // have any meaning for the status bar otherwise anyhow
138 // (it's still ugly, of course, but there are too few flags
139 // to squander them for things like this)
140 flags
|= wxCONTROL_ISDEFAULT
;
143 m_renderer
->DrawStatusField(dc
, rect
, m_statusText
[n
], flags
);
146 rect
.x
+= rect
.width
+ borderBetweenFields
;
150 void wxStatusBarUniv::RefreshField(int i
)
153 if ( GetFieldRect(i
, rect
) )
159 // ----------------------------------------------------------------------------
161 // ----------------------------------------------------------------------------
163 void wxStatusBarUniv::SetStatusText(const wxString
& text
, int number
)
165 wxCHECK_RET( number
>= 0 && number
< m_nFields
,
166 _T("invalid status bar field index in SetStatusText()") );
168 if ( text
== m_statusText
[number
] )
174 m_statusText
[number
] = text
;
176 RefreshField(number
);
179 wxString
wxStatusBarUniv::GetStatusText(int number
) const
181 wxCHECK_MSG( number
>= 0 && number
< m_nFields
, _T(""),
182 _T("invalid status bar field index") );
184 return m_statusText
[number
];
187 // ----------------------------------------------------------------------------
188 // fields count/widths
189 // ----------------------------------------------------------------------------
191 void wxStatusBarUniv::SetFieldsCount(int number
, const int *widths
)
193 m_statusText
.SetCount(number
);
194 wxStatusBarBase::SetFieldsCount(number
, widths
);
198 void wxStatusBarUniv::SetStatusWidths(int n
, const int widths
[])
200 wxStatusBarBase::SetStatusWidths(n
, widths
);
205 // ----------------------------------------------------------------------------
207 // ----------------------------------------------------------------------------
209 void wxStatusBarUniv::OnSize(wxSizeEvent
& event
)
211 // invalidate the widths, we'll have to recalc them
214 // refresh entirely, shouldn't matter much as the statusbar is quick to
215 // redraw and it would be difficult to avoid it as we'd need to find out
216 // which fields exactly were affected...
222 bool wxStatusBarUniv::GetFieldRect(int n
, wxRect
& rect
) const
224 wxCHECK_MSG( n
>= 0 && n
< m_nFields
, FALSE
,
225 _T("invalid field index in GetFieldRect()") );
227 // this is a fix for a bug exhibited by the statbar sample: if
228 // GetFieldRect() is called from the derived class OnSize() handler, then
229 // our geometry info is wrong as our OnSize() didn't invalidate m_widthsAbs
230 // yet - so recalc it just in case
231 wxStatusBarUniv
*self
= wxConstCast(this, wxStatusBarUniv
);
232 self
->m_widthsAbs
.Empty();
234 wxCoord borderBetweenFields
;
235 rect
= self
->GetTotalFieldRect(&borderBetweenFields
);
236 for ( int i
= 0; i
<= n
; i
++ )
238 rect
.width
= m_widthsAbs
[i
];
241 rect
.x
+= rect
.width
+ borderBetweenFields
;
247 wxCoord
wxStatusBarUniv::GetHeight() const
249 wxClientDC
dc(wxConstCast(this, wxStatusBarUniv
));
250 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
252 return dc
.GetCharHeight() + 2*GetBorderY();
255 wxSize
wxStatusBarUniv::DoGetBestSize() const
257 return wxSize(100, GetHeight());
260 void wxStatusBarUniv::DoSetSize(int x
, int y
,
261 int width
, int WXUNUSED(height
),
264 wxStatusBarBase::DoSetSize(x
, y
, width
, GetHeight(), sizeFlags
);
267 // ----------------------------------------------------------------------------
269 // ----------------------------------------------------------------------------
271 void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height
))
273 // nothing to do here, we don't support it - and why would we?
276 int wxStatusBarUniv::GetBorderX() const
278 return m_renderer
->GetStatusBarBorders(NULL
).x
;
281 int wxStatusBarUniv::GetBorderY() const
283 return m_renderer
->GetStatusBarBorders(NULL
).y
;
286 #endif // wxUSE_STATUSBAR