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 licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
;
145 style
= m_statusStyles
[n
];
148 m_renderer
->DrawStatusField(dc
, rect
, m_statusText
[n
], flags
, style
);
151 rect
.x
+= rect
.width
+ borderBetweenFields
;
155 void wxStatusBarUniv::RefreshField(int i
)
158 if ( GetFieldRect(i
, rect
) )
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 void wxStatusBarUniv::SetStatusText(const wxString
& text
, int number
)
170 wxCHECK_RET( number
>= 0 && number
< m_nFields
,
171 _T("invalid status bar field index in SetStatusText()") );
173 if ( text
== m_statusText
[number
] )
179 m_statusText
[number
] = text
;
181 RefreshField(number
);
184 wxString
wxStatusBarUniv::GetStatusText(int number
) const
186 wxCHECK_MSG( number
>= 0 && number
< m_nFields
, _T(""),
187 _T("invalid status bar field index") );
189 return m_statusText
[number
];
192 // ----------------------------------------------------------------------------
193 // fields count/widths
194 // ----------------------------------------------------------------------------
196 void wxStatusBarUniv::SetFieldsCount(int number
, const int *widths
)
198 m_statusText
.SetCount(number
);
199 wxStatusBarBase::SetFieldsCount(number
, widths
);
203 void wxStatusBarUniv::SetStatusWidths(int n
, const int widths
[])
205 wxStatusBarBase::SetStatusWidths(n
, widths
);
210 // ----------------------------------------------------------------------------
212 // ----------------------------------------------------------------------------
214 void wxStatusBarUniv::OnSize(wxSizeEvent
& event
)
216 // we don't need to refresh the fields whose width didn't change, so find
217 // the first field whose width did change and refresh starting from it
219 if ( m_statusWidths
)
221 for ( field
= 0; field
< m_nFields
; field
++ )
223 if ( m_statusWidths
[field
] < 0 )
230 else // all fields have the same width
232 // hence all fields widths have changed
236 if ( field
< m_nFields
)
238 // call this before invalidating the old widths as we want to use them,
240 wxRect rect
= DoGetFieldRect(field
);
242 // invalidate the widths, we'll have to recalc them
245 // refresh everything after the first invalid field
247 rect
.SetRight(event
.GetSize().x
);
248 rect
.height
= event
.GetSize().y
;
255 bool wxStatusBarUniv::GetFieldRect(int n
, wxRect
& rect
) const
257 wxCHECK_MSG( n
>= 0 && n
< m_nFields
, FALSE
,
258 _T("invalid field index in GetFieldRect()") );
260 // this is a fix for a bug exhibited by the statbar sample: if
261 // GetFieldRect() is called from the derived class OnSize() handler, then
262 // our geometry info is wrong as our OnSize() didn't invalidate m_widthsAbs
263 // yet - so recalc it just in case
264 wxConstCast(this, wxStatusBarUniv
)->m_widthsAbs
.Empty();
266 rect
= DoGetFieldRect(n
);
271 wxRect
wxStatusBarUniv::DoGetFieldRect(int n
) const
273 wxStatusBarUniv
*self
= wxConstCast(this, wxStatusBarUniv
);
275 wxCoord borderBetweenFields
;
276 wxRect rect
= self
->GetTotalFieldRect(&borderBetweenFields
);
278 // it's the caller responsability to check this, if unsure - call
279 // GetFieldRect() instead
280 wxCHECK_MSG( !m_widthsAbs
.IsEmpty(), rect
,
281 _T("can't be called if we don't have the widths") );
283 for ( int i
= 0; i
<= n
; i
++ )
285 rect
.width
= m_widthsAbs
[i
];
288 rect
.x
+= rect
.width
+ borderBetweenFields
;
294 wxCoord
wxStatusBarUniv::GetHeight() const
296 wxClientDC
dc(wxConstCast(this, wxStatusBarUniv
));
297 dc
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
299 return dc
.GetCharHeight() + 2*GetBorderY();
302 wxSize
wxStatusBarUniv::DoGetBestSize() const
304 return wxSize(100, GetHeight());
307 void wxStatusBarUniv::DoSetSize(int x
, int y
,
308 int width
, int WXUNUSED(height
),
311 wxStatusBarBase::DoSetSize(x
, y
, width
, GetHeight(), sizeFlags
);
314 // ----------------------------------------------------------------------------
316 // ----------------------------------------------------------------------------
318 void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height
))
320 // nothing to do here, we don't support it - and why would we?
323 int wxStatusBarUniv::GetBorderX() const
325 return m_renderer
->GetStatusBarBorders(NULL
).x
;
328 int wxStatusBarUniv::GetBorderY() const
330 return m_renderer
->GetStatusBarBorders(NULL
).y
;
333 #endif // wxUSE_STATUSBAR