]> git.saurik.com Git - wxWidgets.git/blame - src/univ/statusbr.cpp
1. implemented system menu handling in wxUniv (win32 theme only)
[wxWidgets.git] / src / univ / statusbr.cpp
CommitLineData
71e03035
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: univ/statusbr.cpp
3// Purpose: wxStatusBar implementation
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 14.10.01
7// RCS-ID: $Id$
8// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
21 #pragma implementation "univstatusbr.h"
22#endif
23
24#include "wx/wxprec.h"
25
26#ifdef __BORLANDC__
27 #pragma hdrstop
28#endif
29
30#if wxUSE_STATUSBAR
31
32#ifndef WX_PRECOMP
fe9fea7e
VS
33 #include "wx/settings.h"
34 #include "wx/dcclient.h"
71e03035
VZ
35#endif
36
37#include "wx/statusbr.h"
c60ba92d 38#include "wx/toplevel.h"
71e03035
VZ
39
40#include "wx/univ/renderer.h"
41
42// ============================================================================
43// implementation
44// ============================================================================
45
46BEGIN_EVENT_TABLE(wxStatusBarUniv, wxStatusBarBase)
47 EVT_SIZE(wxStatusBarUniv::OnSize)
48
49 WX_EVENT_TABLE_INPUT_CONSUMER(wxStatusBarUniv)
50END_EVENT_TABLE()
51
52WX_FORWARD_TO_INPUT_CONSUMER(wxStatusBarUniv)
53
54// ----------------------------------------------------------------------------
55// creation
56// ----------------------------------------------------------------------------
57
58void wxStatusBarUniv::Init()
59{
60}
61
62bool wxStatusBarUniv::Create(wxWindow *parent,
63 wxWindowID id,
64 long style,
65 const wxString& name)
66{
67 if ( !wxWindow::Create(parent, id,
68 wxDefaultPosition, wxDefaultSize,
69 style, name) )
70 {
71 return FALSE;
72 }
73
74 SetFieldsCount(1);
75
76 CreateInputHandler(wxINP_HANDLER_STATUSBAR);
77
78 SetSize(DoGetBestSize());
79
80 return TRUE;
81}
82
83// ----------------------------------------------------------------------------
84// drawing
85// ----------------------------------------------------------------------------
86
87wxRect wxStatusBarUniv::GetTotalFieldRect(wxCoord *borderBetweenFields)
88{
71e03035
VZ
89 wxRect rect = GetClientRect();
90
91 // no, don't do this - the borders are meant to be inside this rect
cece1d88
VZ
92 // wxSize sizeBorders =
93 m_renderer->GetStatusBarBorders(borderBetweenFields);
71e03035
VZ
94 //rect.Deflate(sizeBorders.x, sizeBorders.y);
95
96 // recalc the field widths if needed
97 if ( m_widthsAbs.IsEmpty() )
98 {
99 // the total width for the fields doesn't include the borders between
100 // them
101 m_widthsAbs = CalculateAbsWidths(rect.width -
102 *borderBetweenFields*(m_nFields - 1));
103 }
104
105 return rect;
106}
107
108void wxStatusBarUniv::DoDraw(wxControlRenderer *renderer)
109{
110 // get the fields rect
111 wxCoord borderBetweenFields;
112 wxRect rect = GetTotalFieldRect(&borderBetweenFields);
113
114 // prepare the DC
115 wxDC& dc = renderer->GetDC();
a756f210 116 dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
71e03035
VZ
117
118 // do draw the fields
119 int flags = IsEnabled() ? 0 : wxCONTROL_DISABLED;
120 for ( int n = 0; n < m_nFields; n++ )
121 {
122 rect.width = m_widthsAbs[n];
123
124 if ( IsExposed(rect) )
125 {
c60ba92d
VS
126 wxTopLevelWindow *parentTLW = wxDynamicCast(GetParent(), wxTopLevelWindow);
127
71e03035
VZ
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
130 // resize this frame
131 if ( n == m_nFields - 1 &&
132 HasFlag(wxST_SIZEGRIP) &&
c60ba92d
VS
133 GetParent()->HasFlag(wxRESIZE_BORDER) &&
134 parentTLW && !parentTLW->IsMaximized() )
71e03035
VZ
135 {
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;
141 }
142
143 m_renderer->DrawStatusField(dc, rect, m_statusText[n], flags);
144 }
145
146 rect.x += rect.width + borderBetweenFields;
147 }
148}
149
150void wxStatusBarUniv::RefreshField(int i)
151{
152 wxRect rect;
153 if ( GetFieldRect(i, rect) )
154 {
155 RefreshRect(rect);
156 }
157}
158
159// ----------------------------------------------------------------------------
160// fields text
161// ----------------------------------------------------------------------------
162
163void wxStatusBarUniv::SetStatusText(const wxString& text, int number)
164{
165 wxCHECK_RET( number >= 0 && number < m_nFields,
166 _T("invalid status bar field index in SetStatusText()") );
167
168 if ( text == m_statusText[number] )
169 {
170 // nothing changed
171 return;
172 }
173
174 m_statusText[number] = text;
175
176 RefreshField(number);
177}
178
179wxString wxStatusBarUniv::GetStatusText(int number) const
180{
181 wxCHECK_MSG( number >= 0 && number < m_nFields, _T(""),
182 _T("invalid status bar field index") );
183
184 return m_statusText[number];
185}
186
187// ----------------------------------------------------------------------------
188// fields count/widths
189// ----------------------------------------------------------------------------
190
191void wxStatusBarUniv::SetFieldsCount(int number, const int *widths)
192{
71e03035 193 m_statusText.SetCount(number);
ca7497c2 194 wxStatusBarBase::SetFieldsCount(number, widths);
71e03035
VZ
195 m_widthsAbs.Empty();
196}
197
198void wxStatusBarUniv::SetStatusWidths(int n, const int widths[])
199{
200 wxStatusBarBase::SetStatusWidths(n, widths);
201
202 m_widthsAbs.Empty();
203}
204
205// ----------------------------------------------------------------------------
206// geometry
207// ----------------------------------------------------------------------------
208
209void wxStatusBarUniv::OnSize(wxSizeEvent& event)
210{
211 // invalidate the widths, we'll have to recalc them
212 m_widthsAbs.Empty();
213
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...
217 Refresh();
218
219 event.Skip();
220}
221
222bool wxStatusBarUniv::GetFieldRect(int n, wxRect& rect) const
223{
224 wxCHECK_MSG( n >= 0 && n < m_nFields, FALSE,
225 _T("invalid field index in GetFieldRect()") );
226
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();
233
234 wxCoord borderBetweenFields;
235 rect = self->GetTotalFieldRect(&borderBetweenFields);
236 for ( int i = 0; i <= n; i++ )
237 {
238 rect.width = m_widthsAbs[i];
239
240 if ( i < n )
241 rect.x += rect.width + borderBetweenFields;
242 }
243
244 return TRUE;
245}
246
247wxCoord wxStatusBarUniv::GetHeight() const
248{
249 wxClientDC dc(wxConstCast(this, wxStatusBarUniv));
a756f210 250 dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
71e03035
VZ
251
252 return dc.GetCharHeight() + 2*GetBorderY();
253}
254
255wxSize wxStatusBarUniv::DoGetBestSize() const
256{
257 return wxSize(100, GetHeight());
258}
259
260void wxStatusBarUniv::DoSetSize(int x, int y,
261 int width, int WXUNUSED(height),
262 int sizeFlags)
263{
264 wxStatusBarBase::DoSetSize(x, y, width, GetHeight(), sizeFlags);
265}
266
267// ----------------------------------------------------------------------------
268// misc
269// ----------------------------------------------------------------------------
270
271void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height))
272{
273 // nothing to do here, we don't support it - and why would we?
274}
275
276int wxStatusBarUniv::GetBorderX() const
277{
278 return m_renderer->GetStatusBarBorders(NULL).x;
279}
280
281int wxStatusBarUniv::GetBorderY() const
282{
283 return m_renderer->GetStatusBarBorders(NULL).y;
284}
285
286#endif // wxUSE_STATUSBAR
287