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"
35 #include "wx/toplevel.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 wxRect rect
= GetClientRect();
88 // no, don't do this - the borders are meant to be inside this rect
89 // wxSize sizeBorders =
90 m_renderer
->GetStatusBarBorders(borderBetweenFields
);
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::GetFont(wxSYS_DEFAULT_GUI_FONT
));
115 // do draw the fields
116 int flags
= IsEnabled() ? 0 : (int)wxCONTROL_DISABLED
;
117 for ( int n
= 0; n
< m_nFields
; n
++ )
119 rect
.width
= m_widthsAbs
[n
];
121 if ( IsExposed(rect
) )
123 wxTopLevelWindow
*parentTLW
= wxDynamicCast(GetParent(), wxTopLevelWindow
);
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
) &&
131 parentTLW
&& !parentTLW
->IsMaximized() )
133 // NB: we use wxCONTROL_ISDEFAULT for this because it doesn't
134 // have any meaning for the status bar otherwise anyhow
135 // (it's still ugly, of course, but there are too few flags
136 // to squander them for things like this)
137 flags
|= wxCONTROL_ISDEFAULT
;
142 style
= m_statusStyles
[n
];
145 m_renderer
->DrawStatusField(dc
, rect
, m_statusText
[n
], flags
, style
);
148 rect
.x
+= rect
.width
+ borderBetweenFields
;
152 void wxStatusBarUniv::RefreshField(int i
)
155 if ( GetFieldRect(i
, rect
) )
161 // ----------------------------------------------------------------------------
163 // ----------------------------------------------------------------------------
165 void wxStatusBarUniv::SetStatusText(const wxString
& text
, int number
)
167 wxCHECK_RET( number
>= 0 && number
< m_nFields
,
168 _T("invalid status bar field index in SetStatusText()") );
170 if ( text
== m_statusText
[number
] )
176 m_statusText
[number
] = text
;
178 RefreshField(number
);
181 wxString
wxStatusBarUniv::GetStatusText(int number
) const
183 wxCHECK_MSG( number
>= 0 && number
< m_nFields
, wxEmptyString
,
184 _T("invalid status bar field index") );
186 return m_statusText
[number
];
189 // ----------------------------------------------------------------------------
190 // fields count/widths
191 // ----------------------------------------------------------------------------
193 void wxStatusBarUniv::SetFieldsCount(int number
, const int *widths
)
195 m_statusText
.SetCount(number
);
196 wxStatusBarBase::SetFieldsCount(number
, widths
);
200 void wxStatusBarUniv::SetStatusWidths(int n
, const int widths
[])
202 wxStatusBarBase::SetStatusWidths(n
, widths
);
207 // ----------------------------------------------------------------------------
209 // ----------------------------------------------------------------------------
211 void wxStatusBarUniv::OnSize(wxSizeEvent
& event
)
213 // we don't need to refresh the fields whose width didn't change, so find
214 // the first field whose width did change and refresh starting from it
216 if ( m_statusWidths
)
218 for ( field
= 0; field
< m_nFields
; field
++ )
220 if ( m_statusWidths
[field
] < 0 )
227 else // all fields have the same width
229 // hence all fields widths have changed
233 if ( field
< m_nFields
)
235 // call this before invalidating the old widths as we want to use them,
237 wxRect rect
= DoGetFieldRect(field
);
239 // invalidate the widths, we'll have to recalc them
242 // refresh everything after the first invalid field
244 rect
.SetRight(event
.GetSize().x
);
245 rect
.height
= event
.GetSize().y
;
252 bool wxStatusBarUniv::GetFieldRect(int n
, wxRect
& rect
) const
254 wxCHECK_MSG( n
>= 0 && n
< m_nFields
, false,
255 _T("invalid field index in GetFieldRect()") );
257 // this is a fix for a bug exhibited by the statbar sample: if
258 // GetFieldRect() is called from the derived class OnSize() handler, then
259 // our geometry info is wrong as our OnSize() didn't invalidate m_widthsAbs
260 // yet - so recalc it just in case
261 wxConstCast(this, wxStatusBarUniv
)->m_widthsAbs
.Empty();
263 rect
= DoGetFieldRect(n
);
268 wxRect
wxStatusBarUniv::DoGetFieldRect(int n
) const
270 wxStatusBarUniv
*self
= wxConstCast(this, wxStatusBarUniv
);
272 wxCoord borderBetweenFields
;
273 wxRect rect
= self
->GetTotalFieldRect(&borderBetweenFields
);
275 // it's the caller responsability to check this, if unsure - call
276 // GetFieldRect() instead
277 wxCHECK_MSG( !m_widthsAbs
.IsEmpty(), rect
,
278 _T("can't be called if we don't have the widths") );
280 for ( int i
= 0; i
<= n
; i
++ )
282 rect
.width
= m_widthsAbs
[i
];
285 rect
.x
+= rect
.width
+ borderBetweenFields
;
291 wxCoord
wxStatusBarUniv::GetHeight() const
293 wxClientDC
dc(wxConstCast(this, wxStatusBarUniv
));
294 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
296 return dc
.GetCharHeight() + 2*GetBorderY();
299 wxSize
wxStatusBarUniv::DoGetBestSize() const
301 return wxSize(100, GetHeight());
304 void wxStatusBarUniv::DoSetSize(int x
, int y
,
305 int width
, int WXUNUSED(height
),
308 wxStatusBarBase::DoSetSize(x
, y
, width
, GetHeight(), sizeFlags
);
311 // ----------------------------------------------------------------------------
313 // ----------------------------------------------------------------------------
315 void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height
))
317 // nothing to do here, we don't support it - and why would we?
320 int wxStatusBarUniv::GetBorderX() const
322 return m_renderer
->GetStatusBarBorders(NULL
).x
;
325 int wxStatusBarUniv::GetBorderY() const
327 return m_renderer
->GetStatusBarBorders(NULL
).y
;
330 #endif // wxUSE_STATUSBAR