Move repeating code to the dedicated template wxVector function
This commit is contained in:
@@ -24,6 +24,10 @@
|
|||||||
#include "wx/longlong.h"
|
#include "wx/longlong.h"
|
||||||
#include "wx/clntdata.h"
|
#include "wx/clntdata.h"
|
||||||
|
|
||||||
|
#if wxUSE_STD_CONTAINERS
|
||||||
|
#include <numeric>
|
||||||
|
#endif // wxUSE_STD_CONTAINERS
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -760,6 +764,20 @@ inline void wxPGRemoveItemFromVector(wxVector<T>& vector, const T& item)
|
|||||||
#endif // wxUSE_STL/!wxUSE_STL
|
#endif // wxUSE_STL/!wxUSE_STL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Utility to calaculate sum of all elements of the vector.
|
||||||
|
template<typename T>
|
||||||
|
inline T wxPGGetSumVectorItems(const wxVector<T>& vector, T init)
|
||||||
|
{
|
||||||
|
#if wxUSE_STD_CONTAINERS
|
||||||
|
return std::accumulate(vector.begin(), vector.end(), init);
|
||||||
|
#else
|
||||||
|
for (typename wxVector<T>::const_iterator it = vector.begin(); it != vector.end(); ++it)
|
||||||
|
init += *it;
|
||||||
|
|
||||||
|
return init;
|
||||||
|
#endif // wxUSE_STD_CONTAINERS/!wxUSE_STD_CONTAINERS
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
#endif // wxUSE_PROPGRID
|
#endif // wxUSE_PROPGRID
|
||||||
|
@@ -1015,9 +1015,7 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
|
|||||||
m_width, clientWidth);
|
m_width, clientWidth);
|
||||||
|
|
||||||
|
|
||||||
int colsWidth = pg->GetMarginWidth();
|
int colsWidth = wxPGGetSumVectorItems<int>(m_colWidths, pg->GetMarginWidth());
|
||||||
for (wxVector<int>::const_iterator it = m_colWidths.begin(); it != m_colWidths.end(); ++it)
|
|
||||||
colsWidth += *it;
|
|
||||||
|
|
||||||
wxLogTrace("propgrid",
|
wxLogTrace("propgrid",
|
||||||
wxS(" HasVirtualWidth: %i colsWidth: %i"),
|
wxS(" HasVirtualWidth: %i colsWidth: %i"),
|
||||||
@@ -1144,9 +1142,7 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
|
|||||||
void wxPropertyGridPageState::ResetColumnSizes( int setSplitterFlags )
|
void wxPropertyGridPageState::ResetColumnSizes( int setSplitterFlags )
|
||||||
{
|
{
|
||||||
// Calculate sum of proportions
|
// Calculate sum of proportions
|
||||||
int psum = 0;
|
int psum = wxPGGetSumVectorItems<int>(m_columnProportions, 0);
|
||||||
for (wxVector<int>::const_iterator it = m_columnProportions.begin(); it != m_columnProportions.end(); ++it)
|
|
||||||
psum += *it;
|
|
||||||
int puwid = (m_pPropGrid->m_width*256) / psum;
|
int puwid = (m_pPropGrid->m_width*256) / psum;
|
||||||
int cpos = 0;
|
int cpos = 0;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user