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 // NB: we use wxCONTROL_ISDEFAULT for this because it doesn't
133 // have any meaning for the status bar otherwise anyhow
134 // (it's still ugly, of course, but there are too few flags
135 // to squander them for things like this)
136 flags
|= wxCONTROL_ISDEFAULT
;
141 style
= m_statusStyles
[n
];
144 m_renderer
->DrawStatusField(dc
, rect
, m_statusText
[n
], flags
, style
);
147 rect
.x
+= rect
.width
+ borderBetweenFields
;
151 void wxStatusBarUniv::RefreshField(int i
)
154 if ( GetFieldRect(i
, rect
) )
160 // ----------------------------------------------------------------------------
162 // ----------------------------------------------------------------------------
164 void wxStatusBarUniv::SetStatusText(const wxString
& text
, int number
)
166 wxCHECK_RET( number
>= 0 && number
< m_nFields
,
167 _T("invalid status bar field index in SetStatusText()") );
169 if ( text
== m_statusText
[number
] )
175 m_statusText
[number
] = text
;
177 RefreshField(number
);
180 wxString
wxStatusBarUniv::GetStatusText(int number
) const
182 wxCHECK_MSG( number
>= 0 && number
< m_nFields
, wxEmptyString
,
183 _T("invalid status bar field index") );
185 return m_statusText
[number
];
188 // ----------------------------------------------------------------------------
189 // fields count/widths
190 // ----------------------------------------------------------------------------
192 void wxStatusBarUniv::SetFieldsCount(int number
, const int *widths
)
194 m_statusText
.SetCount(number
);
195 wxStatusBarBase::SetFieldsCount(number
, widths
);
199 void wxStatusBarUniv::SetStatusWidths(int n
, const int widths
[])
201 wxStatusBarBase::SetStatusWidths(n
, widths
);
206 // ----------------------------------------------------------------------------
208 // ----------------------------------------------------------------------------
210 void wxStatusBarUniv::OnSize(wxSizeEvent
& event
)
212 // we don't need to refresh the fields whose width didn't change, so find
213 // the first field whose width did change and refresh starting from it
215 if ( m_statusWidths
)
217 for ( field
= 0; field
< m_nFields
; field
++ )
219 if ( m_statusWidths
[field
] < 0 )
226 else // all fields have the same width
228 // hence all fields widths have changed
232 if ( field
< m_nFields
)
234 // call this before invalidating the old widths as we want to use them,
236 wxRect rect
= DoGetFieldRect(field
);
238 // invalidate the widths, we'll have to recalc them
241 // refresh everything after the first invalid field
243 rect
.SetRight(event
.GetSize().x
);
244 rect
.height
= event
.GetSize().y
;
251 bool wxStatusBarUniv::GetFieldRect(int n
, wxRect
& rect
) const
253 wxCHECK_MSG( n
>= 0 && n
< m_nFields
, false,
254 _T("invalid field index in GetFieldRect()") );
256 // this is a fix for a bug exhibited by the statbar sample: if
257 // GetFieldRect() is called from the derived class OnSize() handler, then
258 // our geometry info is wrong as our OnSize() didn't invalidate m_widthsAbs
259 // yet - so recalc it just in case
260 wxConstCast(this, wxStatusBarUniv
)->m_widthsAbs
.Empty();
262 rect
= DoGetFieldRect(n
);
267 wxRect
wxStatusBarUniv::DoGetFieldRect(int n
) const
269 wxStatusBarUniv
*self
= wxConstCast(this, wxStatusBarUniv
);
271 wxCoord borderBetweenFields
;
272 wxRect rect
= self
->GetTotalFieldRect(&borderBetweenFields
);
274 // it's the caller responsability to check this, if unsure - call
275 // GetFieldRect() instead
276 wxCHECK_MSG( !m_widthsAbs
.IsEmpty(), rect
,
277 _T("can't be called if we don't have the widths") );
279 for ( int i
= 0; i
<= n
; i
++ )
281 rect
.width
= m_widthsAbs
[i
];
284 rect
.x
+= rect
.width
+ borderBetweenFields
;
290 wxCoord
wxStatusBarUniv::GetHeight() const
292 wxClientDC
dc(wxConstCast(this, wxStatusBarUniv
));
293 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
295 return dc
.GetCharHeight() + 2*GetBorderY();
298 wxSize
wxStatusBarUniv::DoGetBestSize() const
300 return wxSize(100, GetHeight());
303 void wxStatusBarUniv::DoSetSize(int x
, int y
,
304 int width
, int WXUNUSED(height
),
307 wxStatusBarBase::DoSetSize(x
, y
, width
, GetHeight(), sizeFlags
);
310 // ----------------------------------------------------------------------------
312 // ----------------------------------------------------------------------------
314 void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height
))
316 // nothing to do here, we don't support it - and why would we?
319 int wxStatusBarUniv::GetBorderX() const
321 return m_renderer
->GetStatusBarBorders(NULL
).x
;
324 int wxStatusBarUniv::GetBorderY() const
326 return m_renderer
->GetStatusBarBorders(NULL
).y
;
329 #endif // wxUSE_STATUSBAR