]>
git.saurik.com Git - wxWidgets.git/blob - src/common/statbar.cpp
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
)
130 // default: all fields have the same width
131 int nWidth
= widthTotal
/ m_nFields
;
132 for ( int i
= 0; i
< m_nFields
; i
++ )
137 else // have explicit status widths
139 // calculate the total width of all the fixed width fields and the
140 // total number of var field widths counting with multiplicity
144 for ( i
= 0; i
< m_nFields
; i
++ )
146 if ( m_statusWidths
[i
] >= 0 )
148 nTotalWidth
+= m_statusWidths
[i
];
152 nVarCount
+= -m_statusWidths
[i
];
156 // the amount of extra width we have per each var width field
160 int widthExtra
= widthTotal
- nTotalWidth
;
161 nVarWidth
= widthExtra
> 0 ? widthExtra
/ nVarCount
: 0;
163 else // no var width fields at all
169 for ( i
= 0; i
< m_nFields
; i
++ )
171 if ( m_statusWidths
[i
] >= 0 )
173 widths
.Add(m_statusWidths
[i
]);
177 widths
.Add(-m_statusWidths
[i
]*nVarWidth
);
185 #endif // wxUSE_STATUSBAR