1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/statusbr.cpp
3 // Purpose: wxStatusBar implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/statusbr.h"
31 #include "wx/settings.h"
32 #include "wx/dcclient.h"
33 #include "wx/toplevel.h"
36 #include "wx/univ/renderer.h"
38 // ============================================================================
40 // ============================================================================
42 BEGIN_EVENT_TABLE(wxStatusBarUniv
, wxStatusBarBase
)
43 EVT_SIZE(wxStatusBarUniv::OnSize
)
45 WX_EVENT_TABLE_INPUT_CONSUMER(wxStatusBarUniv
)
48 WX_FORWARD_TO_INPUT_CONSUMER(wxStatusBarUniv
)
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 void wxStatusBarUniv::Init()
58 bool wxStatusBarUniv::Create(wxWindow
*parent
,
63 if ( !wxWindow::Create(parent
, id
,
64 wxDefaultPosition
, wxDefaultSize
,
72 CreateInputHandler(wxINP_HANDLER_STATUSBAR
);
74 SetSize(DoGetBestSize());
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
83 wxRect
wxStatusBarUniv::GetTotalFieldRect(wxCoord
*borderBetweenFields
)
85 wxRect rect
= GetClientRect();
87 // no, don't do this - the borders are meant to be inside this rect
88 // wxSize sizeBorders =
89 m_renderer
->GetStatusBarBorders(borderBetweenFields
);
90 //rect.Deflate(sizeBorders.x, sizeBorders.y);
92 // recalc the field widths if needed
93 if ( m_widthsAbs
.IsEmpty() )
95 // the total width for the fields doesn't include the borders between
97 m_widthsAbs
= CalculateAbsWidths(rect
.width
-
98 *borderBetweenFields
*(m_nFields
- 1));
104 void wxStatusBarUniv::DoDraw(wxControlRenderer
*renderer
)
106 // get the fields rect
107 wxCoord borderBetweenFields
;
108 wxRect rect
= GetTotalFieldRect(&borderBetweenFields
);
111 wxDC
& dc
= renderer
->GetDC();
112 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
114 // do draw the fields
115 int flags
= IsEnabled() ? 0 : (int)wxCONTROL_DISABLED
;
116 for ( int n
= 0; n
< m_nFields
; n
++ )
118 rect
.width
= m_widthsAbs
[n
];
120 if ( IsExposed(rect
) )
122 wxTopLevelWindow
*parentTLW
= wxDynamicCast(GetParent(), wxTopLevelWindow
);
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
) &&
130 parentTLW
&& !parentTLW
->IsMaximized() )
132 flags
|= wxCONTROL_SIZEGRIP
;
137 style
= m_statusStyles
[n
];
140 m_renderer
->DrawStatusField(dc
, rect
, m_statusText
[n
], flags
, style
);
143 rect
.x
+= rect
.width
+ borderBetweenFields
;
147 void wxStatusBarUniv::RefreshField(int i
)
150 if ( GetFieldRect(i
, rect
) )
156 // ----------------------------------------------------------------------------
158 // ----------------------------------------------------------------------------
160 void wxStatusBarUniv::SetStatusText(const wxString
& text
, int number
)
162 wxCHECK_RET( number
>= 0 && number
< m_nFields
,
163 _T("invalid status bar field index in SetStatusText()") );
165 if ( text
== m_statusText
[number
] )
171 m_statusText
[number
] = text
;
173 RefreshField(number
);
176 wxString
wxStatusBarUniv::GetStatusText(int number
) const
178 wxCHECK_MSG( number
>= 0 && number
< m_nFields
, wxEmptyString
,
179 _T("invalid status bar field index") );
181 return m_statusText
[number
];
184 // ----------------------------------------------------------------------------
185 // fields count/widths
186 // ----------------------------------------------------------------------------
188 void wxStatusBarUniv::SetFieldsCount(int number
, const int *widths
)
190 m_statusText
.SetCount(number
);
191 wxStatusBarBase::SetFieldsCount(number
, widths
);
195 void wxStatusBarUniv::SetStatusWidths(int n
, const int widths
[])
197 wxStatusBarBase::SetStatusWidths(n
, widths
);
202 // ----------------------------------------------------------------------------
204 // ----------------------------------------------------------------------------
206 void wxStatusBarUniv::OnSize(wxSizeEvent
& event
)
208 // we don't need to refresh the fields whose width didn't change, so find
209 // the first field whose width did change and refresh starting from it
211 if ( m_statusWidths
)
213 for ( field
= 0; field
< m_nFields
; field
++ )
215 if ( m_statusWidths
[field
] < 0 )
222 else // all fields have the same width
224 // hence all fields widths have changed
228 if ( field
< m_nFields
)
230 // call this before invalidating the old widths as we want to use them,
232 wxRect rect
= DoGetFieldRect(field
);
234 // invalidate the widths, we'll have to recalc them
237 // refresh everything after the first invalid field
239 rect
.SetRight(event
.GetSize().x
);
240 rect
.height
= event
.GetSize().y
;
247 bool wxStatusBarUniv::GetFieldRect(int n
, wxRect
& rect
) const
249 wxCHECK_MSG( n
>= 0 && n
< m_nFields
, false,
250 _T("invalid field index in GetFieldRect()") );
252 // this is a fix for a bug exhibited by the statbar sample: if
253 // GetFieldRect() is called from the derived class OnSize() handler, then
254 // our geometry info is wrong as our OnSize() didn't invalidate m_widthsAbs
255 // yet - so recalc it just in case
256 wxConstCast(this, wxStatusBarUniv
)->m_widthsAbs
.Empty();
258 rect
= DoGetFieldRect(n
);
263 wxRect
wxStatusBarUniv::DoGetFieldRect(int n
) const
265 wxStatusBarUniv
*self
= wxConstCast(this, wxStatusBarUniv
);
267 wxCoord borderBetweenFields
;
268 wxRect rect
= self
->GetTotalFieldRect(&borderBetweenFields
);
270 // it's the caller responsability to check this, if unsure - call
271 // GetFieldRect() instead
272 wxCHECK_MSG( !m_widthsAbs
.IsEmpty(), rect
,
273 _T("can't be called if we don't have the widths") );
275 for ( int i
= 0; i
<= n
; i
++ )
277 rect
.width
= m_widthsAbs
[i
];
280 rect
.x
+= rect
.width
+ borderBetweenFields
;
286 wxCoord
wxStatusBarUniv::GetHeight() const
288 return GetCharHeight() + 2*GetBorderY();
291 wxSize
wxStatusBarUniv::DoGetBestSize() const
293 return wxSize(100, GetHeight());
296 void wxStatusBarUniv::DoSetSize(int x
, int y
,
297 int width
, int WXUNUSED(height
),
300 wxStatusBarBase::DoSetSize(x
, y
, width
, GetHeight(), sizeFlags
);
303 // ----------------------------------------------------------------------------
305 // ----------------------------------------------------------------------------
307 void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height
))
309 // nothing to do here, we don't support it - and why would we?
312 int wxStatusBarUniv::GetBorderX() const
314 return m_renderer
->GetStatusBarBorders(NULL
).x
;
317 int wxStatusBarUniv::GetBorderY() const
319 return m_renderer
->GetStatusBarBorders(NULL
).y
;
322 #endif // wxUSE_STATUSBAR