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