#include "merge.h"
#include "DirColsDlg.h"
#include "dllver.h"
+#include <algorithm>
#ifdef _DEBUG
#define new DEBUG_NEW
*/
void CDirColsDlg::LoadLists()
{
- for (int i = 0; i < m_cols.GetSize(); i++)
+ for (ColumnArray::iterator iter = m_cols.begin(); iter != m_cols.end(); ++iter)
{
- const column & c = m_cols[i];
+ const column & c = *iter;
int x = m_listColumns.InsertItem(m_listColumns.GetItemCount(),
- m_cols[i].name);
+ c.name.c_str());
m_listColumns.SetItemData(x, c.log_col);
if (c.phy_col >= 0)
m_listColumns.SetCheck(x, TRUE);
*/
void CDirColsDlg::LoadDefLists()
{
- for (int i=0; i<m_cols.GetSize(); ++i)
+ for (ColumnArray::iterator iter = m_defCols.begin(); iter != m_defCols.end(); ++iter)
{
- const column & c = m_defCols[i];
+ const column & c = *iter;
int x = m_listColumns.InsertItem(m_listColumns.GetItemCount(),
- m_cols[i].name);
+ c.name.c_str());
m_listColumns.SetItemData(x, c.log_col);
if (c.phy_col >= 0)
m_listColumns.SetCheck(x, TRUE);
*/
void CDirColsDlg::SortArrayToLogicalOrder()
{
- qsort(m_cols.GetData(), m_cols.GetSize(), sizeof(m_cols[0]), &cmpcols);
+ std::sort(m_cols.begin(), m_cols.end(), &CompareColumnsByLogicalOrder);
}
/**
* @param [in] el2 Second column to compare.
* @return Column order.
*/
-int __cdecl CDirColsDlg::cmpcols(const void * el1, const void * el2)
+bool CDirColsDlg::CompareColumnsByLogicalOrder( const column & el1, const column & el2 )
{
- const column * col1 = reinterpret_cast<const column *>(el1);
- const column * col2 = reinterpret_cast<const column *>(el2);
- return col1->log_col - col2->log_col;
+ return el1.log_col < el2.log_col;
}
/**
{
BOOL checked = m_listColumns.GetCheck(i);
DWORD_PTR data = m_listColumns.GetItemData(i);
- column * col1 = &m_cols[data];
+ column & col1 = m_cols[data];
if (checked)
- col1->phy_col = i;
+ col1.phy_col = i;
else
- col1->phy_col = -1;
+ col1.phy_col = -1;
}
CDialog::OnOK();
int ind = m_listColumns.GetNextSelectedItem(pos);
DWORD_PTR data = m_listColumns.GetItemData(ind);
- int j = 0;
- for (j = 0; j < m_cols.GetSize(); j++)
+ ColumnArray::size_type j;
+ for (j = 0; j < m_cols.size(); j++)
{
- if (m_cols.GetAt(j).log_col == data)
+ if (m_cols[j].log_col == data)
break;
}
- GetDlgItem(IDC_COLDLG_DESC)->SetWindowText(m_cols[j].desc);
+ GetDlgItem(IDC_COLDLG_DESC)->SetWindowText(m_cols[j].desc.c_str());
// Disable Up/Down -buttons when first/last items are selected.
if (ind == 0)
#define AFX_DIRCOLSDLG_H__2FCB576C_C609_4623_8C55_F3870F22CA0B__INCLUDED_
#pragma once
+#include <vector>
+#include "UnicodeString.h"
/////////////////////////////////////////////////////////////////////////////
// CDirColsDlg dialog
/** @brief One column's information. */
struct column
{
- CString name; /**< Column name */
- CString desc; /**< Description for column */
+ String name; /**< Column name */
+ String desc; /**< Description for column */
int log_col; /**< Logical (shown) order number */
int phy_col; /**< Physical (in memory) order number */
- column() : log_col(-1), phy_col(-1) { } /**< default constructor for use in CArray */
- column(LPCTSTR sz, LPCTSTR dsc, int log, int phy) : name(sz), desc(dsc), log_col(log), phy_col(phy) { }
+ column(const String & colName, const String & dsc, int log, int phy)
+ : name(colName), desc(dsc), log_col(log), phy_col(phy)
+ { }
};
- typedef CArray<column, column> ColumnArray;
+ typedef std::vector<column> ColumnArray;
// Construction
public:
CDirColsDlg(CWnd* pParent = NULL); // standard constructor
- void AddColumn(LPCTSTR name, LPCTSTR desc, int log, int phy=-1)
- { column c(name, desc, log, phy); m_cols.Add(c); }
- void AddDefColumn(LPCTSTR name, int log, int phy=-1)
- { column c(name, _T(""), log, phy); m_defCols.Add(c); }
+ void AddColumn(const String & name, const String & desc, int log, int phy=-1)
+ { column c(name, desc, log, phy); m_cols.push_back(c); }
+ void AddDefColumn(const String & name, int log, int phy=-1)
+ { column c(name, _T(""), log, phy); m_defCols.push_back(c); }
const ColumnArray & GetColumns() const { return m_cols; }
// Dialog Data
void MoveItem(int index, int newIndex);
void MoveSelectedItems(BOOL bUp);
void SanitizeOrder();
- static int cmpcols(const void * el1, const void * el2);
// Implementation data
private:
ColumnArray m_cols; /**< Column list. */
ColumnArray m_defCols; /**< Default columns. */
+ static bool CompareColumnsByLogicalOrder( const column & el1, const column & el2 );
// Generated message map functions
//{{AFX_MSG(CDirColsDlg)
for (int col=0; col<GetListCtrl().GetHeaderCtrl()->GetItemCount(); ++col)
{
int l = ColPhysToLog(col);
- dlg.AddColumn(GetColDisplayName(l).c_str(), GetColDescription(l).c_str(), l, col);
+ dlg.AddColumn(GetColDisplayName(l), GetColDescription(l), l, col);
}
// Now add all the columns not currently displayed
int l=0;
{
if (ColLogToPhys(l)==-1)
{
- dlg.AddColumn(GetColDisplayName(l).c_str(), GetColDescription(l).c_str(), l);
+ dlg.AddColumn(GetColDisplayName(l), GetColDescription(l), l);
}
}
for (l = 0; l < m_numcols; ++l)
{
int phy = GetColDefaultOrder(l);
- dlg.AddDefColumn(GetColDisplayName(l).c_str(), l, phy);
+ dlg.AddDefColumn(GetColDisplayName(l), l, phy);
}
if (dlg.DoModal() != IDOK)
ClearColumnOrders();
m_dispcols = 0;
const int sortColumn = GetOptionsMgr()->GetInt(OPT_DIRVIEW_SORT_COLUMN);
- for (int i=0; i<cols.GetSize(); ++i)
+ for (CDirColsDlg::ColumnArray::const_iterator iter = cols.begin();
+ iter != cols.end(); ++iter)
{
- int log = cols[i].log_col;
- int phy = cols[i].phy_col;
+ int log = iter->log_col;
+ int phy = iter->phy_col;
m_colorder[log] = phy;
if (phy>=0)
{