]> git.saurik.com Git - wxWidgets.git/blame - src/univ/statusbr.cpp
Allow absent checkbox when transferring dimension data
[wxWidgets.git] / src / univ / statusbr.cpp
CommitLineData
71e03035 1/////////////////////////////////////////////////////////////////////////////
3304646d 2// Name: src/univ/statusbr.cpp
71e03035
VZ
3// Purpose: wxStatusBar implementation
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 14.10.01
71e03035 7// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
65571936 8// Licence: wxWindows licence
71e03035
VZ
9/////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
71e03035
VZ
19#include "wx/wxprec.h"
20
21#ifdef __BORLANDC__
22 #pragma hdrstop
23#endif
24
25#if wxUSE_STATUSBAR
26
3304646d
WS
27#include "wx/statusbr.h"
28
71e03035 29#ifndef WX_PRECOMP
fe9fea7e
VS
30 #include "wx/settings.h"
31 #include "wx/dcclient.h"
1832043f 32 #include "wx/toplevel.h"
71e03035
VZ
33#endif
34
71e03035
VZ
35#include "wx/univ/renderer.h"
36
37// ============================================================================
38// implementation
39// ============================================================================
40
41BEGIN_EVENT_TABLE(wxStatusBarUniv, wxStatusBarBase)
42 EVT_SIZE(wxStatusBarUniv::OnSize)
43
44 WX_EVENT_TABLE_INPUT_CONSUMER(wxStatusBarUniv)
45END_EVENT_TABLE()
46
47WX_FORWARD_TO_INPUT_CONSUMER(wxStatusBarUniv)
48
49// ----------------------------------------------------------------------------
50// creation
51// ----------------------------------------------------------------------------
52
53void wxStatusBarUniv::Init()
54{
55}
56
57bool wxStatusBarUniv::Create(wxWindow *parent,
58 wxWindowID id,
59 long style,
60 const wxString& name)
61{
62 if ( !wxWindow::Create(parent, id,
63 wxDefaultPosition, wxDefaultSize,
64 style, name) )
65 {
a290fa5a 66 return false;
71e03035
VZ
67 }
68
69 SetFieldsCount(1);
b480f61b 70
71e03035
VZ
71 CreateInputHandler(wxINP_HANDLER_STATUSBAR);
72
73 SetSize(DoGetBestSize());
74
a290fa5a 75 return true;
71e03035
VZ
76}
77
78// ----------------------------------------------------------------------------
79// drawing
80// ----------------------------------------------------------------------------
81
82wxRect wxStatusBarUniv::GetTotalFieldRect(wxCoord *borderBetweenFields)
83{
71e03035
VZ
84 wxRect rect = GetClientRect();
85
86 // no, don't do this - the borders are meant to be inside this rect
cece1d88 87 // wxSize sizeBorders =
283c797c
VS
88 if ( borderBetweenFields )
89 *borderBetweenFields = m_renderer->GetStatusBarBorderBetweenFields();
71e03035
VZ
90 //rect.Deflate(sizeBorders.x, sizeBorders.y);
91
92 // recalc the field widths if needed
93 if ( m_widthsAbs.IsEmpty() )
94 {
95 // the total width for the fields doesn't include the borders between
96 // them
97 m_widthsAbs = CalculateAbsWidths(rect.width -
7b6fefbe 98 *borderBetweenFields*(m_panes.GetCount() - 1));
71e03035
VZ
99 }
100
101 return rect;
102}
103
104void wxStatusBarUniv::DoDraw(wxControlRenderer *renderer)
105{
106 // get the fields rect
107 wxCoord borderBetweenFields;
108 wxRect rect = GetTotalFieldRect(&borderBetweenFields);
109
110 // prepare the DC
111 wxDC& dc = renderer->GetDC();
686ca1b5
VS
112 dc.SetFont(GetFont());
113 dc.SetTextForeground(GetForegroundColour());
71e03035
VZ
114
115 // do draw the fields
b480f61b 116 int flags = IsEnabled() ? 0 : (int)wxCONTROL_DISABLED;
7b6fefbe 117 for ( int n = 0; n < (int)m_panes.GetCount(); n++ )
71e03035
VZ
118 {
119 rect.width = m_widthsAbs[n];
120
121 if ( IsExposed(rect) )
122 {
c60ba92d 123 wxTopLevelWindow *parentTLW = wxDynamicCast(GetParent(), wxTopLevelWindow);
5057e659 124
71e03035
VZ
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
127 // resize this frame
7b6fefbe 128 if ( n == (int)m_panes.GetCount() - 1 &&
c4c178c1 129 HasFlag(wxSTB_SIZEGRIP) &&
c60ba92d
VS
130 GetParent()->HasFlag(wxRESIZE_BORDER) &&
131 parentTLW && !parentTLW->IsMaximized() )
71e03035 132 {
fb61f58a 133 flags |= wxCONTROL_SIZEGRIP;
71e03035
VZ
134 }
135
b31eaa5c 136 m_renderer->DrawStatusField(dc, rect, GetStatusText(n), flags, m_panes[n].GetStyle());
71e03035
VZ
137 }
138
139 rect.x += rect.width + borderBetweenFields;
140 }
141}
142
6cf68971 143void wxStatusBarUniv::DoUpdateStatusText(int i)
71e03035
VZ
144{
145 wxRect rect;
146 if ( GetFieldRect(i, rect) )
147 {
148 RefreshRect(rect);
149 }
150}
151
71e03035
VZ
152// ----------------------------------------------------------------------------
153// fields count/widths
154// ----------------------------------------------------------------------------
155
156void wxStatusBarUniv::SetFieldsCount(int number, const int *widths)
157{
ca7497c2 158 wxStatusBarBase::SetFieldsCount(number, widths);
7b6fefbe 159
71e03035
VZ
160 m_widthsAbs.Empty();
161}
162
163void wxStatusBarUniv::SetStatusWidths(int n, const int widths[])
164{
165 wxStatusBarBase::SetStatusWidths(n, widths);
166
167 m_widthsAbs.Empty();
168}
169
170// ----------------------------------------------------------------------------
171// geometry
172// ----------------------------------------------------------------------------
173
174void wxStatusBarUniv::OnSize(wxSizeEvent& event)
175{
5057e659
VZ
176 // we don't need to refresh the fields whose width didn't change, so find
177 // the first field whose width did change and refresh starting from it
7b6fefbe
FM
178 size_t field;
179 if ( m_bSameWidthForAllPanes )
180 {
181 // hence all fields widths have changed
182 field = 0;
183 }
184 else
5057e659 185 {
7b6fefbe 186 for ( field = 0; field < m_panes.GetCount(); field++ )
5057e659 187 {
b31eaa5c 188 if ( m_panes[field].GetWidth() < 0 )
5057e659
VZ
189 {
190 // var width field
191 break;
192 }
193 }
194 }
71e03035 195
7b6fefbe 196 if ( field < m_panes.GetCount() )
5057e659
VZ
197 {
198 // call this before invalidating the old widths as we want to use them,
199 // not the new ones
200 wxRect rect = DoGetFieldRect(field);
201
202 // invalidate the widths, we'll have to recalc them
203 m_widthsAbs.Empty();
204
205 // refresh everything after the first invalid field
206 rect.y = 0;
207 rect.SetRight(event.GetSize().x);
208 rect.height = event.GetSize().y;
209 RefreshRect(rect);
210 }
71e03035
VZ
211
212 event.Skip();
213}
214
215bool wxStatusBarUniv::GetFieldRect(int n, wxRect& rect) const
216{
7b6fefbe 217 wxCHECK_MSG( n >= 0 && (size_t)n < m_panes.GetCount(), false,
9a83f860 218 wxT("invalid field index in GetFieldRect()") );
71e03035
VZ
219
220 // this is a fix for a bug exhibited by the statbar sample: if
221 // GetFieldRect() is called from the derived class OnSize() handler, then
222 // our geometry info is wrong as our OnSize() didn't invalidate m_widthsAbs
223 // yet - so recalc it just in case
5057e659
VZ
224 wxConstCast(this, wxStatusBarUniv)->m_widthsAbs.Empty();
225
226 rect = DoGetFieldRect(n);
227
a290fa5a 228 return true;
5057e659
VZ
229}
230
231wxRect wxStatusBarUniv::DoGetFieldRect(int n) const
232{
71e03035 233 wxStatusBarUniv *self = wxConstCast(this, wxStatusBarUniv);
71e03035
VZ
234
235 wxCoord borderBetweenFields;
5057e659
VZ
236 wxRect rect = self->GetTotalFieldRect(&borderBetweenFields);
237
238 // it's the caller responsability to check this, if unsure - call
239 // GetFieldRect() instead
240 wxCHECK_MSG( !m_widthsAbs.IsEmpty(), rect,
9a83f860 241 wxT("can't be called if we don't have the widths") );
5057e659 242
71e03035
VZ
243 for ( int i = 0; i <= n; i++ )
244 {
245 rect.width = m_widthsAbs[i];
246
247 if ( i < n )
248 rect.x += rect.width + borderBetweenFields;
249 }
250
5057e659 251 return rect;
71e03035
VZ
252}
253
254wxCoord wxStatusBarUniv::GetHeight() const
255{
3083f142 256 return GetCharHeight() + 2*GetBorderY();
71e03035
VZ
257}
258
259wxSize wxStatusBarUniv::DoGetBestSize() const
260{
261 return wxSize(100, GetHeight());
262}
263
264void wxStatusBarUniv::DoSetSize(int x, int y,
265 int width, int WXUNUSED(height),
266 int sizeFlags)
267{
268 wxStatusBarBase::DoSetSize(x, y, width, GetHeight(), sizeFlags);
269}
270
271// ----------------------------------------------------------------------------
272// misc
273// ----------------------------------------------------------------------------
274
275void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height))
276{
277 // nothing to do here, we don't support it - and why would we?
278}
279
280int wxStatusBarUniv::GetBorderX() const
281{
283c797c
VS
282 return m_renderer->GetStatusBarBorders().x +
283 m_renderer->GetStatusBarFieldMargins().x;
71e03035
VZ
284}
285
286int wxStatusBarUniv::GetBorderY() const
287{
283c797c
VS
288 return m_renderer->GetStatusBarBorders().y +
289 m_renderer->GetStatusBarFieldMargins().y;
71e03035
VZ
290}
291
292#endif // wxUSE_STATUSBAR