This repository has been archived on 2024-03-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
ContactBook/OrdPage.cpp
2024-03-20 09:28:18 -05:00

174 lines
4 KiB
C++

// OrdPage.cpp : implementation file
//
#include "stdafx.h"
#include "CB32.h"
#include "ComboBar.h"
#include "MainFrm.h"
#include "CB32Doc.h"
#include "CB32View.h"
#include "OrdPage.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COrdPage property page
IMPLEMENT_DYNCREATE(COrdPage, CPropertyPage)
COrdPage::COrdPage() : CPropertyPage(COrdPage::IDD)
{
//{{AFX_DATA_INIT(COrdPage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
COrdPage::~COrdPage()
{
}
void COrdPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(COrdPage)
DDX_Control(pDX, IDC_COLUP, m_colup);
DDX_Control(pDX, IDC_COLDOWN, m_coldown);
DDX_Control(pDX, IDC_COLBOX, m_colbox);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(COrdPage, CPropertyPage)
//{{AFX_MSG_MAP(COrdPage)
ON_BN_CLICKED(IDC_COLUP, OnColup)
ON_BN_CLICKED(IDC_COLDOWN, OnColdown)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_RESETCOL, OnResetcol)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COrdPage message handlers
BOOL COrdPage::OnInitDialog()
{
CPropertyPage::OnInitDialog();
CCB32View* pView = GetApplicationView();
int colpos[COLS];
for (int p=0; p<COLS; p++)
colpos[p] = p;
CString strBuffer = theApp.GetProfileString(_T("Columns"),_T("Order"));
if (!strBuffer.IsEmpty())
{
int tempcol[COLS];
for (int i=0; i<COLS; i++)
tempcol[i] = 0;
int nRead = _stscanf(strBuffer, _T("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"),
&tempcol[0],&tempcol[1],&tempcol[2],&tempcol[3],&tempcol[4],
&tempcol[5],&tempcol[6],&tempcol[7],&tempcol[8],&tempcol[9],
&tempcol[10],&tempcol[11],&tempcol[12],&tempcol[13],&tempcol[14],
&tempcol[15],&tempcol[16],&tempcol[17],&tempcol[18],&tempcol[19],
&tempcol[20],&tempcol[21],&tempcol[22],&tempcol[23],&tempcol[24],
&tempcol[25],&tempcol[26],&tempcol[27],&tempcol[28],&tempcol[29],
&tempcol[30],&tempcol[31]);
if (nRead == COLS)
{
for (int z=0; z<COLS; z++)
colpos[z]=tempcol[z];
}
}
for (int y=0; y<COLS; y++)
m_colbox.AddString(pView->arLabel[colpos[y]]);
m_colbox.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void COrdPage::OnColup()
{
int iIndex;
CString strItem;
iIndex = m_colbox.GetCurSel();
if (iIndex <= 0 || iIndex == LB_ERR)
return;
m_colbox.GetText(iIndex, strItem);
m_colbox.DeleteString(iIndex);
m_colbox.InsertString(iIndex-1, strItem);
m_colbox.SetCurSel(iIndex-1);
return;
}
void COrdPage::OnColdown()
{
int iIndex;
CString strItem;
iIndex = m_colbox.GetCurSel();
if ((iIndex >= m_colbox.GetCount()-1) || iIndex == LB_ERR)
return;
m_colbox.GetText(iIndex, strItem);
m_colbox.DeleteString(iIndex);
m_colbox.InsertString(iIndex+1, strItem);
m_colbox.SetCurSel(iIndex+1);
return;
}
void COrdPage::OnDestroy()
{
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberPos"),1))
{
CCB32View* pView = GetApplicationView();
int colpos[COLS];
for (int p = 0; p<COLS; p++)
colpos[p] = p; //initialize
for (int y = 0; y<COLS; y++)
{
int item = m_colbox.FindStringExact(-1,pView->arLabel[y]);
if (item != LB_ERR)
colpos[item] = y;
}
CString strBuffer;
strBuffer.Format("%d",colpos[0]);
for (int z=1; z<COLS; z++)
{
CString temp;
temp.Format("%d",colpos[z]);
strBuffer += ','+temp;
}
theApp.WriteProfileString(_T("Columns"),_T("Order"),strBuffer);
}
CPropertyPage::OnDestroy();
return;
}
void COrdPage::OnResetcol()
{
CCB32View* pView = GetApplicationView();
m_colbox.ResetContent();
for (int y=0; y<COLS; y++)
m_colbox.AddString(pView->arLabel[y]);
m_colbox.SetCurSel(0);
}