get rid of the wxListString class in wxStatusBar code; introduce a wxStatusBarPane class which enormously simplifies the code handling stacks/widths/styles of panes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57686 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2008-12-31 12:28:05 +00:00
parent 6f97a0d599
commit 7b6fefbed1
9 changed files with 172 additions and 336 deletions

View File

@@ -19,6 +19,11 @@
#include "wx/pen.h" #include "wx/pen.h"
#include "wx/arrstr.h" #include "wx/arrstr.h"
// ----------------------------------------------------------------------------
// wxStatusBarGeneric
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxStatusBarGeneric : public wxStatusBarBase class WXDLLIMPEXP_CORE wxStatusBarGeneric : public wxStatusBarBase
{ {
public: public:
@@ -87,11 +92,13 @@ protected:
// common part of all ctors // common part of all ctors
void Init(); void Init();
// the array of the currently displayed strings
wxArrayString m_statusStrings; wxArrayString m_statusStrings;
// the last known width of the client rect (used to rebuild cache) // the last known width of the client rect (used to rebuild cache)
int m_lastClientWidth; int m_lastClientWidth;
// the widths of the status bar panes in pixels
// the absolute widths of the status bar panes in pixels
wxArrayInt m_widthsAbs; wxArrayInt m_widthsAbs;
int m_borderX; int m_borderX;

View File

@@ -63,7 +63,7 @@ public:
protected: protected:
void CopyFieldsWidth(const int widths[]); void CopyFieldsWidth(const int widths[]);
void SetFieldsWidth(); void SetFieldsWidth();
/*
// store the text in the status bar // store the text in the status bar
wxListString **StatusTextBuffer; wxListString **StatusTextBuffer;
void SetStatusBufferText(const wxString& text, int number); void SetStatusBufferText(const wxString& text, int number);
@@ -72,6 +72,9 @@ protected:
wxListString *GetStatusBufferStack(int i) const; wxListString *GetStatusBufferStack(int i) const;
void DeleteStatusBuffer(); void DeleteStatusBuffer();
TODO: reuse wxStatusBarBase's stack routines instead of reimplementing them here
*/
// override base class virtual // override base class virtual
void DoMoveWindow(int x, int y, int width, int height); void DoMoveWindow(int x, int y, int width, int height);

View File

@@ -22,8 +22,6 @@
extern WXDLLIMPEXP_DATA_CORE(const char) wxStatusBarNameStr[]; extern WXDLLIMPEXP_DATA_CORE(const char) wxStatusBarNameStr[];
WX_DECLARE_LIST(wxString, wxListString);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxStatusBar constants // wxStatusBar constants
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -33,6 +31,27 @@ WX_DECLARE_LIST(wxString, wxListString);
#define wxSB_FLAT 0x0001 #define wxSB_FLAT 0x0001
#define wxSB_RAISED 0x0002 #define wxSB_RAISED 0x0002
// ----------------------------------------------------------------------------
// wxStatusBarPane: an helper for wxStatusBar
// ----------------------------------------------------------------------------
class wxStatusBarPane
{
public:
wxStatusBarPane(int style = wxSB_NORMAL, size_t width = 0)
: nStyle(style), nWidth(width) {}
int nStyle;
int nWidth; // the width maybe negative, indicating a variable-width field
// this is the array of the stacked strings of this pane; note that this
// stack does not include the string currently displayed in this pane
// as it's stored in the native status bar control
wxArrayString arrStack;
};
WX_DECLARE_OBJARRAY(wxStatusBarPane, wxStatusBarPaneArray);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxStatusBar: a window near the bottom of the frame used for status info // wxStatusBar: a window near the bottom of the frame used for status info
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -50,7 +69,7 @@ public:
// set the number of fields and call SetStatusWidths(widths) if widths are // set the number of fields and call SetStatusWidths(widths) if widths are
// given // given
virtual void SetFieldsCount(int number = 1, const int *widths = NULL); virtual void SetFieldsCount(int number = 1, const int *widths = NULL);
int GetFieldsCount() const { return m_nFields; } int GetFieldsCount() const { return m_panes.GetCount(); }
// field text // field text
// ---------- // ----------
@@ -102,45 +121,14 @@ public:
protected: protected:
virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
// set the widths array to NULL
void InitWidths();
// free the status widths arrays
void FreeWidths();
// reset the widths
void ReinitWidths() { FreeWidths(); InitWidths(); }
// same, for field styles
void InitStyles();
void FreeStyles();
void ReinitStyles() { FreeStyles(); InitStyles(); }
// same, for text stacks
void InitStacks();
void FreeStacks();
void ReinitStacks() { FreeStacks(); InitStacks(); }
// calculate the real field widths for the given total available size // calculate the real field widths for the given total available size
wxArrayInt CalculateAbsWidths(wxCoord widthTotal) const; wxArrayInt CalculateAbsWidths(wxCoord widthTotal) const;
// use these functions to access the stacks of field strings // the array with the pane infos:
wxListString *GetStatusStack(int i) const; wxStatusBarPaneArray m_panes;
wxListString *GetOrCreateStatusStack(int i);
// the current number of fields // if true overrides the width info of the wxStatusBarPanes
int m_nFields; bool m_bSameWidthForAllPanes;
// the widths of the fields in pixels if !NULL, all fields have the same
// width otherwise
int *m_statusWidths;
// the styles of the fields
int *m_statusStyles;
// stacks of previous values for PushStatusText/PopStatusText
// this is created on demand, use GetStatusStack/GetOrCreateStatusStack
wxListString **m_statusTextStacks;
DECLARE_NO_COPY_CLASS(wxStatusBarBase) DECLARE_NO_COPY_CLASS(wxStatusBarBase)
}; };
@@ -151,22 +139,18 @@ protected:
#if defined(__WXUNIVERSAL__) #if defined(__WXUNIVERSAL__)
#define wxStatusBarUniv wxStatusBar #define wxStatusBarUniv wxStatusBar
#include "wx/univ/statusbr.h" #include "wx/univ/statusbr.h"
#elif defined(__WXPALMOS__) #elif defined(__WXPALMOS__)
#define wxStatusBarPalm wxStatusBar #define wxStatusBarPalm wxStatusBar
#include "wx/palmos/statusbr.h" #include "wx/palmos/statusbr.h"
#elif defined(__WIN32__) && wxUSE_NATIVE_STATUSBAR #elif defined(__WIN32__) && wxUSE_NATIVE_STATUSBAR
#include "wx/msw/statusbar.h" #include "wx/msw/statusbar.h"
#elif defined(__WXMAC__) #elif defined(__WXMAC__)
#define wxStatusBarMac wxStatusBar #define wxStatusBarMac wxStatusBar
#include "wx/generic/statusbr.h" #include "wx/generic/statusbr.h"
#include "wx/osx/statusbr.h" #include "wx/osx/statusbr.h"
#else #else
#define wxStatusBarGeneric wxStatusBar #define wxStatusBarGeneric wxStatusBar
#include "wx/generic/statusbr.h" #include "wx/generic/statusbr.h"
#endif #endif

View File

@@ -16,7 +16,7 @@
#include "wx/arrstr.h" #include "wx/arrstr.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxStatusBar: a window near the bottom of the frame used for status info // wxStatusBarUniv: a window near the bottom of the frame used for status info
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxStatusBarUniv : public wxStatusBarBase, class WXDLLIMPEXP_CORE wxStatusBarUniv : public wxStatusBarBase,
@@ -95,7 +95,7 @@ protected:
void Init(); void Init();
private: private:
// the status fields strings // the current status fields strings
wxArrayString m_statusText; wxArrayString m_statusText;
// the absolute status fields widths // the absolute status fields widths

View File

@@ -2,7 +2,7 @@
// Name: src/common/statbar.cpp // Name: src/common/statbar.cpp
// Purpose: wxStatusBarBase implementation // Purpose: wxStatusBarBase implementation
// Author: Vadim Zeitlin // Author: Vadim Zeitlin
// Modified by: // Modified by: Francesco Montorsi
// Created: 14.10.01 // Created: 14.10.01
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
@@ -32,71 +32,35 @@
#include "wx/frame.h" #include "wx/frame.h"
#endif //WX_PRECOMP #endif //WX_PRECOMP
#include "wx/listimpl.cpp"
WX_DEFINE_LIST(wxListString)
const char wxStatusBarNameStr[] = "statusBar"; const char wxStatusBarNameStr[] = "statusBar";
// ============================================================================ // ============================================================================
// wxStatusBarBase implementation // wxStatusBarBase implementation
// ============================================================================ // ============================================================================
IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxWindow) IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxWindow)
#include <wx/arrimpl.cpp> // This is a magic incantation which must be done!
WX_DEFINE_OBJARRAY(wxStatusBarPaneArray);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// ctor/dtor // ctor/dtor
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxStatusBarBase::wxStatusBarBase() wxStatusBarBase::wxStatusBarBase()
{ {
m_nFields = 0; m_bSameWidthForAllPanes = true;
InitWidths();
InitStacks();
InitStyles();
} }
wxStatusBarBase::~wxStatusBarBase() wxStatusBarBase::~wxStatusBarBase()
{ {
FreeWidths();
FreeStacks();
FreeStyles();
// notify the frame that it doesn't have a status bar any longer to avoid // notify the frame that it doesn't have a status bar any longer to avoid
// dangling pointers // dangling pointers
wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); wxFrame *frame = dynamic_cast<wxFrame*>(GetParent());
if ( frame && frame->GetStatusBar() == this ) if ( frame && frame->GetStatusBar() == this )
{
frame->SetStatusBar(NULL); frame->SetStatusBar(NULL);
}
}
// ----------------------------------------------------------------------------
// widths array handling
// ----------------------------------------------------------------------------
void wxStatusBarBase::InitWidths()
{
m_statusWidths = NULL;
}
void wxStatusBarBase::FreeWidths()
{
delete [] m_statusWidths;
}
// ----------------------------------------------------------------------------
// styles array handling
// ----------------------------------------------------------------------------
void wxStatusBarBase::InitStyles()
{
m_statusStyles = NULL;
}
void wxStatusBarBase::FreeStyles()
{
delete [] m_statusStyles;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -109,60 +73,22 @@ void wxStatusBarBase::SetFieldsCount(int number, const int *widths)
bool refresh = false; bool refresh = false;
if ( number != m_nFields ) if ( (size_t)number > m_panes.GetCount() )
{ {
// copy stacks if present wxStatusBarPane newPane;
if(m_statusTextStacks)
{
wxListString **newStacks = new wxListString*[number];
size_t i, j, max = wxMin(number, m_nFields);
// copy old stacks // add more entries with the default style and zero width
for(i = 0; i < max; ++i) // (this will be set later)
newStacks[i] = m_statusTextStacks[i]; for (size_t i = m_panes.GetCount(); i < (size_t)number; ++i)
// free old stacks in excess m_panes.Add(newPane);
for(j = i; j < (size_t)m_nFields; ++j)
{
if(m_statusTextStacks[j])
{
m_statusTextStacks[j]->Clear();
delete m_statusTextStacks[j];
}
}
// initialize new stacks to NULL
for(j = i; j < (size_t)number; ++j)
newStacks[j] = 0;
m_statusTextStacks = newStacks;
}
// Resize styles array
if (m_statusStyles)
{
int *oldStyles = m_statusStyles;
m_statusStyles = new int[number];
int i, max = wxMin(number, m_nFields);
// copy old styles
for (i = 0; i < max; ++i)
m_statusStyles[i] = oldStyles[i];
// initialize new styles to wxSB_NORMAL
for (i = max; i < number; ++i)
m_statusStyles[i] = wxSB_NORMAL;
// free old styles
delete [] oldStyles;
}
m_nFields = number;
ReinitWidths();
refresh = true;
} }
//else: keep the old m_statusWidths if we had them else if ( (size_t)number < m_panes.GetCount() )
{
// remove entries in excess
m_panes.RemoveAt(number, m_panes.GetCount()-number);
}
refresh = true;
if ( widths ) if ( widths )
{ {
@@ -181,15 +107,12 @@ void wxStatusBarBase::SetStatusWidths(int WXUNUSED_UNLESS_DEBUG(n),
{ {
wxCHECK_RET( widths, _T("NULL pointer in SetStatusWidths") ); wxCHECK_RET( widths, _T("NULL pointer in SetStatusWidths") );
wxASSERT_MSG( n == m_nFields, _T("field number mismatch") ); wxASSERT_MSG( (size_t)n == m_panes.GetCount(), _T("field number mismatch") );
if ( !m_statusWidths ) for ( size_t i = 0; i < m_panes.GetCount(); i++ )
m_statusWidths = new int[m_nFields]; m_panes[i].nWidth = widths[i];
for ( int i = 0; i < m_nFields; i++ ) m_bSameWidthForAllPanes = false;
{
m_statusWidths[i] = widths[i];
}
// update the display after the widths changed // update the display after the widths changed
Refresh(); Refresh();
@@ -200,15 +123,10 @@ void wxStatusBarBase::SetStatusStyles(int WXUNUSED_UNLESS_DEBUG(n),
{ {
wxCHECK_RET( styles, _T("NULL pointer in SetStatusStyles") ); wxCHECK_RET( styles, _T("NULL pointer in SetStatusStyles") );
wxASSERT_MSG( n == m_nFields, _T("field number mismatch") ); wxASSERT_MSG( (size_t)n == m_panes.GetCount(), _T("field number mismatch") );
if ( !m_statusStyles ) for ( size_t i = 0; i < m_panes.GetCount(); i++ )
m_statusStyles = new int[m_nFields]; m_panes[i].nStyle = styles[i];
for ( int i = 0; i < m_nFields; i++ )
{
m_statusStyles[i] = styles[i];
}
// update the display after the widths changed // update the display after the widths changed
Refresh(); Refresh();
@@ -218,61 +136,51 @@ wxArrayInt wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal) const
{ {
wxArrayInt widths; wxArrayInt widths;
if ( m_statusWidths == NULL ) if ( m_bSameWidthForAllPanes )
{ {
if ( m_nFields ) // Default: all fields have the same width. This is not always
// possible to do exactly (if widthTotal is not divisible by
// m_panes.GetCount()) - if that happens, we distribute the extra
// pixels among all fields:
int widthToUse = widthTotal;
for ( size_t i = m_panes.GetCount(); i > 0; i-- )
{ {
// Default: all fields have the same width. This is not always // divide the unassigned width evently between the
// possible to do exactly (if widthTotal is not divisible by // not yet processed fields:
// m_nFields) - if that happens, we distribute the extra pixels int w = widthToUse / i;
// among all fields: widths.Add(w);
int widthToUse = widthTotal; widthToUse -= w;
for ( int i = m_nFields; i > 0; i-- )
{
// divide the unassigned width evently between the
// not yet processed fields:
int w = widthToUse / i;
widths.Add(w);
widthToUse -= w;
}
} }
//else: we're empty anyhow
} }
else // have explicit status widths else // do not override explicit pane widths
{ {
// calculate the total width of all the fixed width fields and the // calculate the total width of all the fixed width fields and the
// total number of var field widths counting with multiplicity // total number of var field widths counting with multiplicity
int nTotalWidth = 0, size_t nTotalWidth = 0,
nVarCount = 0, nVarCount = 0,
i; i;
for ( i = 0; i < m_nFields; i++ )
for ( i = 0; i < m_panes.GetCount(); i++ )
{ {
if ( m_statusWidths[i] >= 0 ) if ( m_panes[i].nWidth >= 0 )
{ nTotalWidth += m_panes[i].nWidth;
nTotalWidth += m_statusWidths[i];
}
else else
{ nVarCount += -m_panes[i].nWidth;
nVarCount += -m_statusWidths[i];
}
} }
// the amount of extra width we have per each var width field // the amount of extra width we have per each var width field
int widthExtra = widthTotal - nTotalWidth; int widthExtra = widthTotal - nTotalWidth;
// do fill the array // do fill the array
for ( i = 0; i < m_nFields; i++ ) for ( i = 0; i < m_panes.GetCount(); i++ )
{ {
if ( m_statusWidths[i] >= 0 ) if ( m_panes[i].nWidth >= 0 )
{ widths.Add(m_panes[i].nWidth);
widths.Add(m_statusWidths[i]);
}
else else
{ {
int nVarWidth = widthExtra > 0 ? (widthExtra * -m_statusWidths[i]) / nVarCount : 0; int nVarWidth = widthExtra > 0 ? (widthExtra * (-m_panes[i].nWidth)) / nVarCount : 0;
nVarCount += m_statusWidths[i]; nVarCount += m_panes[i].nWidth;
widthExtra -= nVarWidth; widthExtra -= nVarWidth;
widths.Add(nVarWidth); widths.Add(nVarWidth);
} }
@@ -283,86 +191,25 @@ wxArrayInt wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal) const
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// text stacks handling // status text stacks
// ----------------------------------------------------------------------------
void wxStatusBarBase::InitStacks()
{
m_statusTextStacks = NULL;
}
void wxStatusBarBase::FreeStacks()
{
if ( !m_statusTextStacks )
return;
for ( size_t i = 0; i < (size_t)m_nFields; ++i )
{
if ( m_statusTextStacks[i] )
{
wxListString& t = *m_statusTextStacks[i];
WX_CLEAR_LIST(wxListString, t);
delete m_statusTextStacks[i];
}
}
delete[] m_statusTextStacks;
}
// ----------------------------------------------------------------------------
// text stacks
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxStatusBarBase::PushStatusText(const wxString& text, int number) void wxStatusBarBase::PushStatusText(const wxString& text, int number)
{ {
wxListString* st = GetOrCreateStatusStack(number); // save current status text in the stack
// This long-winded way around avoids an internal compiler error m_panes[number].arrStack.push_back(GetStatusText(number));
// in VC++ 6 with RTTI enabled
wxString tmp1(GetStatusText(number)); // update current status text
wxString* tmp = new wxString(tmp1);
st->Insert(tmp);
SetStatusText(text, number); SetStatusText(text, number);
} }
void wxStatusBarBase::PopStatusText(int number) void wxStatusBarBase::PopStatusText(int number)
{ {
wxListString *st = GetStatusStack(number); wxString text = m_panes[number].arrStack.back();
wxCHECK_RET( st, _T("Unbalanced PushStatusText/PopStatusText") ); m_panes[number].arrStack.pop_back(); // also remove it from the stack
wxListString::compatibility_iterator top = st->GetFirst();
SetStatusText(*top->GetData(), number); // restore the popped status text in the pane
delete top->GetData(); SetStatusText(text, number);
st->Erase(top);
if(st->GetCount() == 0)
{
delete st;
m_statusTextStacks[number] = 0;
}
}
wxListString *wxStatusBarBase::GetStatusStack(int i) const
{
if(!m_statusTextStacks)
return 0;
return m_statusTextStacks[i];
}
wxListString *wxStatusBarBase::GetOrCreateStatusStack(int i)
{
if(!m_statusTextStacks)
{
m_statusTextStacks = new wxListString*[m_nFields];
size_t j;
for(j = 0; j < (size_t)m_nFields; ++j) m_statusTextStacks[j] = 0;
}
if(!m_statusTextStacks[i])
{
m_statusTextStacks[i] = new wxListString();
}
return m_statusTextStacks[i];
} }
#endif // wxUSE_STATUSBAR #endif // wxUSE_STATUSBAR

View File

@@ -41,6 +41,14 @@
IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric, wxWindow) IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric, wxWindow)
#endif // wxUSE_NATIVE_STATUSBAR #endif // wxUSE_NATIVE_STATUSBAR
// Default status border dimensions
#define wxTHICK_LINE_BORDER 2
// ----------------------------------------------------------------------------
// wxStatusBarGeneric
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxStatusBarGeneric, wxWindow) BEGIN_EVENT_TABLE(wxStatusBarGeneric, wxWindow)
EVT_PAINT(wxStatusBarGeneric::OnPaint) EVT_PAINT(wxStatusBarGeneric::OnPaint)
EVT_LEFT_DOWN(wxStatusBarGeneric::OnLeftDown) EVT_LEFT_DOWN(wxStatusBarGeneric::OnLeftDown)
@@ -48,9 +56,6 @@ BEGIN_EVENT_TABLE(wxStatusBarGeneric, wxWindow)
EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged) EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged)
END_EVENT_TABLE() END_EVENT_TABLE()
// Default status border dimensions
#define wxTHICK_LINE_BORDER 2
void wxStatusBarGeneric::Init() void wxStatusBarGeneric::Init()
{ {
m_borderX = wxTHICK_LINE_BORDER; m_borderX = wxTHICK_LINE_BORDER;
@@ -98,7 +103,6 @@ bool wxStatusBarGeneric::Create(wxWindow *parent,
return true; return true;
} }
wxSize wxStatusBarGeneric::DoGetBestSize() const wxSize wxStatusBarGeneric::DoGetBestSize() const
{ {
int width, height; int width, height;
@@ -120,25 +124,26 @@ void wxStatusBarGeneric::SetFieldsCount(int number, const int *widths)
{ {
wxASSERT_MSG( number >= 0, _T("negative number of fields in wxStatusBar?") ); wxASSERT_MSG( number >= 0, _T("negative number of fields in wxStatusBar?") );
int i; // enlarge the m_statusStrings array if needed:
for(i = m_nFields; i < number; ++i) for (size_t i = m_panes.GetCount(); i < (size_t)number; ++i)
m_statusStrings.Add( wxEmptyString ); m_statusStrings.Add( wxEmptyString );
for (i = m_nFields - 1; i >= number; --i) // shrink the m_statusStrings array if needed:
m_statusStrings.RemoveAt(i); for (int j = (int)m_panes.GetCount() - 1; j >= number; --j)
m_statusStrings.RemoveAt(j);
// forget the old cached pixel widths // forget the old cached pixel widths
m_widthsAbs.Empty(); m_widthsAbs.Empty();
wxStatusBarBase::SetFieldsCount(number, widths); wxStatusBarBase::SetFieldsCount(number, widths);
wxASSERT_MSG( m_nFields == (int)m_statusStrings.GetCount(), wxASSERT_MSG( m_panes.GetCount() == m_statusStrings.GetCount(),
_T("This really should never happen, can we do away with m_nFields here?") ); _T("This really should never happen, can we do away with m_panes.GetCount() here?") );
} }
void wxStatusBarGeneric::SetStatusText(const wxString& text, int number) void wxStatusBarGeneric::SetStatusText(const wxString& text, int number)
{ {
wxCHECK_RET( (number >= 0) && (number < m_nFields), wxCHECK_RET( (number >= 0) && ((size_t)number < m_panes.GetCount()),
_T("invalid status bar field index") ); _T("invalid status bar field index") );
wxString oldText = m_statusStrings[number]; wxString oldText = m_statusStrings[number];
@@ -160,7 +165,7 @@ void wxStatusBarGeneric::SetStatusText(const wxString& text, int number)
wxString wxStatusBarGeneric::GetStatusText(int n) const wxString wxStatusBarGeneric::GetStatusText(int n) const
{ {
wxCHECK_MSG( (n >= 0) && (n < m_nFields), wxEmptyString, wxCHECK_MSG( (n >= 0) && ((size_t)n < m_panes.GetCount()), wxEmptyString,
_T("invalid status bar field index") ); _T("invalid status bar field index") );
return m_statusStrings[n]; return m_statusStrings[n];
@@ -168,14 +173,16 @@ wxString wxStatusBarGeneric::GetStatusText(int n) const
void wxStatusBarGeneric::SetStatusWidths(int n, const int widths_field[]) void wxStatusBarGeneric::SetStatusWidths(int n, const int widths_field[])
{ {
// only set status widths, when n == number of statuswindows // only set status widths when n == number of statuswindows
wxCHECK_RET( n == m_nFields, _T("status bar field count mismatch") ); wxCHECK_RET( (size_t)n == m_panes.GetCount(), _T("status bar field count mismatch") );
// delete the old widths in any case - this function may be used to reset // delete the old widths in any case - this function may be used to reset
// the widths to the default (all equal) // the widths to the default (all equal)
// MBN: this is incompatible with at least wxMSW and wxMAC and not // MBN: this is incompatible with at least wxMSW and wxMAC and not
// documented, but let's keep it for now // documented, but let's keep it for now
ReinitWidths(); m_bSameWidthForAllPanes = true;
// FM: what MBN's comment is saying is that allowing widths_field = NULL
// only for wxStatusBarGeneric is not documented...
// forget the old cached pixel widths // forget the old cached pixel widths
m_widthsAbs.Empty(); m_widthsAbs.Empty();
@@ -241,7 +248,7 @@ void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) )
dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
for (int i = 0; i < m_nFields; i ++) for (size_t i = 0; i < m_panes.GetCount(); i ++)
DrawField(dc, i); DrawField(dc, i);
} }
@@ -278,10 +285,7 @@ void wxStatusBarGeneric::DrawField(wxDC& dc, int i)
wxRect rect; wxRect rect;
GetFieldRect(i, rect); GetFieldRect(i, rect);
int style = wxSB_NORMAL; int style = m_panes[i].nStyle;
if (m_statusStyles)
style = m_statusStyles[i];
if (style != wxSB_FLAT) if (style != wxSB_FLAT)
{ {
// Draw border // Draw border
@@ -331,7 +335,7 @@ void wxStatusBarGeneric::DrawField(wxDC& dc, int i)
// Get the position and size of the field's internal bounding rectangle // Get the position and size of the field's internal bounding rectangle
bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const
{ {
wxCHECK_MSG( (n >= 0) && (n < m_nFields), false, wxCHECK_MSG( (n >= 0) && ((size_t)n < m_panes.GetCount()), false,
_T("invalid status bar field index") ); _T("invalid status bar field index") );
// FIXME: workarounds for OS/2 bugs have nothing to do here (VZ) // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)

View File

@@ -161,7 +161,7 @@ void wxStatusBar::SetStatusWidths(int n, const int widths[])
void wxStatusBar::SetFieldsWidth() void wxStatusBar::SetFieldsWidth()
{ {
if ( !m_nFields ) if ( m_panes.IsEmpty() )
return; return;
int aBorders[3]; int aBorders[3];
@@ -170,17 +170,17 @@ void wxStatusBar::SetFieldsWidth()
int extraWidth = aBorders[2]; // space between fields int extraWidth = aBorders[2]; // space between fields
wxArrayInt widthsAbs = wxArrayInt widthsAbs =
CalculateAbsWidths(GetClientSize().x - extraWidth*(m_nFields - 1)); CalculateAbsWidths(GetClientSize().x - extraWidth*(m_panes.GetCount() - 1));
int *pWidths = new int[m_nFields]; int *pWidths = new int[m_panes.GetCount()];
int nCurPos = 0; int nCurPos = 0;
for ( int i = 0; i < m_nFields; i++ ) { for ( int i = 0; i < m_panes.GetCount(); i++ ) {
nCurPos += widthsAbs[i] + extraWidth; nCurPos += widthsAbs[i] + extraWidth;
pWidths[i] = nCurPos; pWidths[i] = nCurPos;
} }
if ( !StatusBar_SetParts(GetHwnd(), m_nFields, pWidths) ) { if ( !StatusBar_SetParts(GetHwnd(), m_panes.GetCount(), pWidths) ) {
wxLogLastError(wxT("StatusBar_SetParts")); wxLogLastError(wxT("StatusBar_SetParts"));
} }
@@ -200,24 +200,20 @@ void wxStatusBar::SetStatusText(const wxString& strText, int nField)
// Get field style, if any // Get field style, if any
int style; int style;
if (m_statusStyles) switch(m_panes[nField].nStyle)
{ {
switch(m_statusStyles[nField]) case wxSB_RAISED:
{ style = SBT_POPOUT;
case wxSB_RAISED: break;
style = SBT_POPOUT; case wxSB_FLAT:
break; style = SBT_NOBORDERS;
case wxSB_FLAT: break;
style = SBT_NOBORDERS;
break; case wxSB_NORMAL:
case wxSB_NORMAL: default:
default:
style = 0;
break;
}
}
else
style = 0; style = 0;
break;
}
// Pass both field number and style. MSDN library doesn't mention // Pass both field number and style. MSDN library doesn't mention
// that nField and style have to be 'ORed' // that nField and style have to be 'ORed'
@@ -229,7 +225,7 @@ void wxStatusBar::SetStatusText(const wxString& strText, int nField)
wxString wxStatusBar::GetStatusText(int nField) const wxString wxStatusBar::GetStatusText(int nField) const
{ {
wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString, wxCHECK_MSG( (nField >= 0) && (nField < m_panes.GetCount()), wxEmptyString,
_T("invalid statusbar field index") ); _T("invalid statusbar field index") );
wxString str; wxString str;
@@ -268,7 +264,7 @@ void wxStatusBar::SetMinHeight(int height)
bool wxStatusBar::GetFieldRect(int i, wxRect& rect) const bool wxStatusBar::GetFieldRect(int i, wxRect& rect) const
{ {
wxCHECK_MSG( (i >= 0) && (i < m_nFields), false, wxCHECK_MSG( (i >= 0) && (i < m_panes.GetCount()), false,
_T("invalid statusbar field index") ); _T("invalid statusbar field index") );
RECT r; RECT r;
@@ -309,10 +305,10 @@ wxSize wxStatusBar::DoGetBestSize() const
// calculate width // calculate width
int width = 0; int width = 0;
for ( int i = 0; i < m_nFields; ++i ) for ( int i = 0; i < m_panes.GetCount(); ++i )
{ {
int widthField = m_statusWidths ? m_statusWidths[i] int widthField =
: DEFAULT_FIELD_WIDTH; m_bSameWidthForAllPanes ? DEFAULT_FIELD_WIDTH : m_panes[i].nWidth;
if ( widthField >= 0 ) if ( widthField >= 0 )
{ {
width += widthField; width += widthField;
@@ -384,7 +380,7 @@ void wxStatusBar::SetStatusStyles(int n, const int styles[])
{ {
wxStatusBarBase::SetStatusStyles(n, styles); wxStatusBarBase::SetStatusStyles(n, styles);
if (n != m_nFields) if (n != m_panes.GetCount())
return; return;
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)

View File

@@ -103,7 +103,7 @@ void wxStatusBarMac::DrawField(wxDC& dc, int i)
void wxStatusBarMac::SetStatusText(const wxString& text, int number) void wxStatusBarMac::SetStatusText(const wxString& text, int number)
{ {
wxCHECK_RET( (number >= 0) && (number < m_nFields), wxCHECK_RET( (number >= 0) && ((size_t)number < m_panes.GetCount()),
wxT("invalid status bar field index") ); wxT("invalid status bar field index") );
if ( m_statusStrings[number] == text ) if ( m_statusStrings[number] == text )
@@ -162,12 +162,11 @@ void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event))
dc.DrawLine(0, 0, w, 0); dc.DrawLine(0, 0, w, 0);
} }
int i;
if ( GetFont().Ok() ) if ( GetFont().Ok() )
dc.SetFont(GetFont()); dc.SetFont(GetFont());
dc.SetBackgroundMode(wxTRANSPARENT); dc.SetBackgroundMode(wxTRANSPARENT);
for ( i = 0; i < m_nFields; i ++ ) for ( size_t i = 0; i < m_panes.GetCount(); i ++ )
DrawField(dc, i); DrawField(dc, i);
} }

View File

@@ -96,7 +96,7 @@ wxRect wxStatusBarUniv::GetTotalFieldRect(wxCoord *borderBetweenFields)
// the total width for the fields doesn't include the borders between // the total width for the fields doesn't include the borders between
// them // them
m_widthsAbs = CalculateAbsWidths(rect.width - m_widthsAbs = CalculateAbsWidths(rect.width -
*borderBetweenFields*(m_nFields - 1)); *borderBetweenFields*(m_panes.GetCount() - 1));
} }
return rect; return rect;
@@ -115,7 +115,7 @@ void wxStatusBarUniv::DoDraw(wxControlRenderer *renderer)
// do draw the fields // do draw the fields
int flags = IsEnabled() ? 0 : (int)wxCONTROL_DISABLED; int flags = IsEnabled() ? 0 : (int)wxCONTROL_DISABLED;
for ( int n = 0; n < m_nFields; n++ ) for ( int n = 0; n < (int)m_panes.GetCount(); n++ )
{ {
rect.width = m_widthsAbs[n]; rect.width = m_widthsAbs[n];
@@ -126,7 +126,7 @@ void wxStatusBarUniv::DoDraw(wxControlRenderer *renderer)
// the size grip may be drawn only on the last field and only if we // the size grip may be drawn only on the last field and only if we
// have the corresponding style and even then only if we really can // have the corresponding style and even then only if we really can
// resize this frame // resize this frame
if ( n == m_nFields - 1 && if ( n == (int)m_panes.GetCount() - 1 &&
HasFlag(wxST_SIZEGRIP) && HasFlag(wxST_SIZEGRIP) &&
GetParent()->HasFlag(wxRESIZE_BORDER) && GetParent()->HasFlag(wxRESIZE_BORDER) &&
parentTLW && !parentTLW->IsMaximized() ) parentTLW && !parentTLW->IsMaximized() )
@@ -134,12 +134,7 @@ void wxStatusBarUniv::DoDraw(wxControlRenderer *renderer)
flags |= wxCONTROL_SIZEGRIP; flags |= wxCONTROL_SIZEGRIP;
} }
int style; m_renderer->DrawStatusField(dc, rect, m_statusText[n], flags, m_panes[n].nStyle);
if (m_statusStyles)
style = m_statusStyles[n];
else
style = wxSB_NORMAL;
m_renderer->DrawStatusField(dc, rect, m_statusText[n], flags, style);
} }
rect.x += rect.width + borderBetweenFields; rect.x += rect.width + borderBetweenFields;
@@ -161,7 +156,7 @@ void wxStatusBarUniv::RefreshField(int i)
void wxStatusBarUniv::SetStatusText(const wxString& text, int number) void wxStatusBarUniv::SetStatusText(const wxString& text, int number)
{ {
wxCHECK_RET( number >= 0 && number < m_nFields, wxCHECK_RET( number >= 0 && (size_t)number < m_panes.GetCount(),
_T("invalid status bar field index in SetStatusText()") ); _T("invalid status bar field index in SetStatusText()") );
if ( text == m_statusText[number] ) if ( text == m_statusText[number] )
@@ -177,7 +172,7 @@ void wxStatusBarUniv::SetStatusText(const wxString& text, int number)
wxString wxStatusBarUniv::GetStatusText(int number) const wxString wxStatusBarUniv::GetStatusText(int number) const
{ {
wxCHECK_MSG( number >= 0 && number < m_nFields, wxEmptyString, wxCHECK_MSG( number >= 0 && (size_t)number < m_panes.GetCount(), wxEmptyString,
_T("invalid status bar field index") ); _T("invalid status bar field index") );
return m_statusText[number]; return m_statusText[number];
@@ -191,6 +186,7 @@ void wxStatusBarUniv::SetFieldsCount(int number, const int *widths)
{ {
m_statusText.SetCount(number); m_statusText.SetCount(number);
wxStatusBarBase::SetFieldsCount(number, widths); wxStatusBarBase::SetFieldsCount(number, widths);
m_widthsAbs.Empty(); m_widthsAbs.Empty();
} }
@@ -209,25 +205,25 @@ void wxStatusBarUniv::OnSize(wxSizeEvent& event)
{ {
// we don't need to refresh the fields whose width didn't change, so find // we don't need to refresh the fields whose width didn't change, so find
// the first field whose width did change and refresh starting from it // the first field whose width did change and refresh starting from it
int field; size_t field;
if ( m_statusWidths ) if ( m_bSameWidthForAllPanes )
{ {
for ( field = 0; field < m_nFields; field++ ) // hence all fields widths have changed
field = 0;
}
else
{
for ( field = 0; field < m_panes.GetCount(); field++ )
{ {
if ( m_statusWidths[field] < 0 ) if ( m_panes[field].nWidth < 0 )
{ {
// var width field // var width field
break; break;
} }
} }
} }
else // all fields have the same width
{
// hence all fields widths have changed
field = 0;
}
if ( field < m_nFields ) if ( field < m_panes.GetCount() )
{ {
// call this before invalidating the old widths as we want to use them, // call this before invalidating the old widths as we want to use them,
// not the new ones // not the new ones
@@ -248,7 +244,7 @@ void wxStatusBarUniv::OnSize(wxSizeEvent& event)
bool wxStatusBarUniv::GetFieldRect(int n, wxRect& rect) const bool wxStatusBarUniv::GetFieldRect(int n, wxRect& rect) const
{ {
wxCHECK_MSG( n >= 0 && n < m_nFields, false, wxCHECK_MSG( n >= 0 && (size_t)n < m_panes.GetCount(), false,
_T("invalid field index in GetFieldRect()") ); _T("invalid field index in GetFieldRect()") );
// this is a fix for a bug exhibited by the statbar sample: if // this is a fix for a bug exhibited by the statbar sample: if