]>
git.saurik.com Git - wxWidgets.git/blob - src/common/statbar.cpp
fbea0399796eebdfb15db33b2dc2d257a4c29bc6
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/statbar.cpp
3 // Purpose: wxStatusBarBase implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "statbar.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/statusbr.h"
37 // ============================================================================
38 // wxStatusBarBase implementation
39 // ============================================================================
41 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar
, wxWindow
)
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 wxStatusBarBase::wxStatusBarBase()
54 wxStatusBarBase::~wxStatusBarBase()
59 // ----------------------------------------------------------------------------
60 // widths array handling
61 // ----------------------------------------------------------------------------
63 void wxStatusBarBase::InitWidths()
65 m_statusWidths
= NULL
;
68 void wxStatusBarBase::FreeWidths()
70 delete [] m_statusWidths
;
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 void wxStatusBarBase::SetFieldsCount(int number
, const int *widths
)
79 wxCHECK_RET( number
> 0, _T("invalid field number in SetFieldsCount") );
83 if ( number
!= m_nFields
)
91 //else: keep the old m_statusWidths if we had them
95 SetStatusWidths(number
, widths
);
97 // already done from SetStatusWidths()
105 void wxStatusBarBase::SetStatusWidths(int WXUNUSED_UNLESS_DEBUG(n
),
108 wxCHECK_RET( widths
, _T("NULL pointer in SetStatusWidths") );
110 wxASSERT_MSG( n
== m_nFields
, _T("field number mismatch") );
112 if ( !m_statusWidths
)
113 m_statusWidths
= new int[m_nFields
];
115 for ( int i
= 0; i
< m_nFields
; i
++ )
117 m_statusWidths
[i
] = widths
[i
];
120 // update the display after the widths changed
124 wxArrayInt
wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal
) const
128 if ( m_statusWidths
== NULL
)
132 // default: all fields have the same width
133 int nWidth
= widthTotal
/ m_nFields
;
134 for ( int i
= 0; i
< m_nFields
; i
++ )
139 //else: we're empty anyhow
141 else // have explicit status widths
143 // calculate the total width of all the fixed width fields and the
144 // total number of var field widths counting with multiplicity
148 for ( i
= 0; i
< m_nFields
; i
++ )
150 if ( m_statusWidths
[i
] >= 0 )
152 nTotalWidth
+= m_statusWidths
[i
];
156 nVarCount
+= -m_statusWidths
[i
];
160 // the amount of extra width we have per each var width field
164 int widthExtra
= widthTotal
- nTotalWidth
;
165 nVarWidth
= widthExtra
> 0 ? widthExtra
/ nVarCount
: 0;
167 else // no var width fields at all
173 for ( i
= 0; i
< m_nFields
; i
++ )
175 if ( m_statusWidths
[i
] >= 0 )
177 widths
.Add(m_statusWidths
[i
]);
181 widths
.Add(-m_statusWidths
[i
]*nVarWidth
);
189 #endif // wxUSE_STATUSBAR