Skip to content

Commit

Permalink
Use wxVector<int> instead of wxArrayInt
Browse files Browse the repository at this point in the history
  • Loading branch information
a-wi committed Nov 1, 2018
1 parent e7357ea commit 161bb59
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
6 changes: 3 additions & 3 deletions include/wx/propgrid/propgridpagestate.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,13 +642,13 @@ class WXDLLIMPEXP_PROPGRID wxPropertyGridPageState
wxPGHashMapS2P m_dictName;

// List of column widths (first column does not include margin).
wxArrayInt m_colWidths;
wxVector<int> m_colWidths;

// List of indices of columns the user can edit by clicking it.
wxArrayInt m_editableColumns;
wxVector<int> m_editableColumns;

// Column proportions.
wxArrayInt m_columnProportions;
wxVector<int> m_columnProportions;

double m_fSplitterX;

Expand Down
40 changes: 19 additions & 21 deletions src/propgrid/propgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ DeletedObjects gs_deletedEditorObjects;
} // anonymous namespace
#endif

// Utility to check if specific item is in a vector.
template<typename T>
static bool wxPGItemExistsInVector(const wxVector<T>& vector, const T& item)
{
#if wxUSE_STL
return std::find(vector.begin(), vector.end(), item) != vector.end();
#else
for ( wxVector<T>::const_iterator it = vector.begin(); it != vector.end(); ++it )
{
if ( *it == item )
return true;
}
return false;
#endif // wxUSE_STL/!wxUSE_STL
}

// -----------------------------------------------------------------------

#if wxUSE_INTL
Expand Down Expand Up @@ -802,7 +818,7 @@ bool wxPropertyGrid::DoSelectAndEdit( wxPGProperty* prop,
// send event
DoClearSelection(false, wxPG_SEL_NO_REFRESH);

if ( m_pState->m_editableColumns.Index(colIndex) == wxNOT_FOUND )
if ( !wxPGItemExistsInVector<int>(m_pState->m_editableColumns, colIndex) )
{
res = DoAddToSelection(prop, selFlags);
}
Expand Down Expand Up @@ -972,7 +988,7 @@ void wxPropertyGrid::MakeColumnEditable( unsigned int column,
wxS("Set wxPG_PROP_READONLY property flag instead")
);

wxArrayInt& cols = m_pState->m_editableColumns;
wxVector<int>& cols = m_pState->m_editableColumns;

if ( editable )
{
Expand Down Expand Up @@ -2145,7 +2161,7 @@ int wxPropertyGrid::DoDrawItems( wxDC& dc,

const wxPGProperty* firstSelected = GetSelection();
const wxPropertyGridPageState* state = m_pState;
const wxArrayInt& colWidths = state->m_colWidths;
const wxVector<int>& colWidths = state->m_colWidths;
const unsigned int colCount = state->GetColumnCount();

// TODO: Only render columns that are within clipping region.
Expand Down Expand Up @@ -5587,24 +5603,6 @@ void wxPropertyGrid::ClearActionTriggers( int action )
while ( didSomething );
}

#if WXWIN_COMPATIBILITY_3_0
// Utility to check if specific item is in a vector.
template<typename T>
static bool wxPGItemExistsInVector(const wxVector<T>& vector, const T& item)
{
#if wxUSE_STL
return std::find(vector.begin(), vector.end(), item) != vector.end();
#else
for (wxVector<T>::const_iterator it = vector.begin(); it != vector.end(); ++it)
{
if ( *it == item )
return true;
}
return false;
#endif // wxUSE_STL/!wxUSE_STL
}
#endif // WXWIN_COMPATIBILITY_3_0

void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild )
{
//
Expand Down
7 changes: 2 additions & 5 deletions src/propgrid/propgridpagestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,11 +1219,8 @@ void wxPropertyGridPageState::ResetColumnSizes( int setSplitterFlags )
void wxPropertyGridPageState::SetColumnCount( int colCount )
{
wxASSERT( colCount >= 2 );
m_colWidths.SetCount( colCount, wxPG_DRAG_MARGIN );
m_columnProportions.SetCount( colCount, 1 );
if ( m_colWidths.size() > (unsigned int)colCount )
m_colWidths.RemoveAt( m_colWidths.size()-1,
m_colWidths.size() - colCount );
m_colWidths.resize(colCount, wxPG_DRAG_MARGIN);
m_columnProportions.resize(colCount, 1);

if ( m_pPropGrid->GetState() == this )
m_pPropGrid->RecalculateVirtualSize();
Expand Down

0 comments on commit 161bb59

Please sign in to comment.