2212 lines
65 KiB
C++
2212 lines
65 KiB
C++
// CB32View.cpp : implementation of the CCB32View class
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
|
|
#ifndef TAPI_CURRENT_VERSION
|
|
#define TAPI_CURRENT_VERSION 0x00010004
|
|
#endif
|
|
|
|
#include <tapi.h>
|
|
#include "CB32.h"
|
|
#include "ComboBar.h"
|
|
#include "MainFrm.h"
|
|
#include "CB32Doc.h"
|
|
#include "CB32View.h"
|
|
#include "resource.h"
|
|
#include "FindDlg.h"
|
|
#include "GetNew.h"
|
|
#include "PrefPage.h"
|
|
#include "PMerge.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CCB32View
|
|
|
|
IMPLEMENT_DYNCREATE(CCB32View, CListView)
|
|
|
|
BEGIN_MESSAGE_MAP(CCB32View, CListView)
|
|
//{{AFX_MSG_MAP(CCB32View)
|
|
ON_WM_MEASUREITEM_REFLECT()
|
|
ON_WM_DRAWITEM_REFLECT()
|
|
ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnclick)
|
|
ON_WM_DESTROY()
|
|
ON_WM_CREATE()
|
|
ON_COMMAND(ID_ENTRY_ADD, OnEntryAdd)
|
|
ON_COMMAND(ID_ENTRY_EDIT, OnEntryEdit)
|
|
ON_COMMAND(ID_ENTRY_DELETE, OnEntryDelete)
|
|
ON_UPDATE_COMMAND_UI(ID_ENTRY_EDIT, OnUpdateEntryEdit)
|
|
ON_UPDATE_COMMAND_UI(ID_ENTRY_DELETE, OnUpdateEntryDelete)
|
|
ON_WM_LBUTTONDBLCLK()
|
|
ON_COMMAND(ID_EDIT_FIND, OnEditFind)
|
|
ON_UPDATE_COMMAND_UI(ID_EDIT_FIND, OnUpdateEditFind)
|
|
ON_COMMAND(ID_VIEW_FIND_NEXT, OnViewFindNext)
|
|
ON_UPDATE_COMMAND_UI(ID_VIEW_FIND_NEXT, OnUpdateViewFindNext)
|
|
ON_COMMAND(ID_VIEW_COLSET, OnViewColset)
|
|
ON_WM_CONTEXTMENU()
|
|
ON_COMMAND(ID_DIAL_HOME, OnDialHome)
|
|
ON_COMMAND(ID_DIAL_WORK, OnDialWork)
|
|
ON_UPDATE_COMMAND_UI(ID_DIAL_HOME, OnUpdateDialHome)
|
|
ON_UPDATE_COMMAND_UI(ID_DIAL_WORK, OnUpdateDialWork)
|
|
ON_COMMAND(ID_DIAL_CELL, OnDialCell)
|
|
ON_UPDATE_COMMAND_UI(ID_DIAL_CELL, OnUpdateDialCell)
|
|
ON_COMMAND(ID_DIAL_PAGER, OnDialPager)
|
|
ON_UPDATE_COMMAND_UI(ID_DIAL_PAGER, OnUpdateDialPager)
|
|
ON_COMMAND(ID_DIAL_FAX, OnDialFax)
|
|
ON_UPDATE_COMMAND_UI(ID_DIAL_FAX, OnUpdateDialFax)
|
|
ON_COMMAND(ID_EMAIL_ADD1, OnEmailAdd1)
|
|
ON_UPDATE_COMMAND_UI(ID_EMAIL_ADD1, OnUpdateEmailAdd1)
|
|
ON_COMMAND(ID_EMAIL_ADD2, OnEmailAdd2)
|
|
ON_UPDATE_COMMAND_UI(ID_EMAIL_ADD2, OnUpdateEmailAdd2)
|
|
ON_COMMAND(ID_URL1, OnUrl1)
|
|
ON_UPDATE_COMMAND_UI(ID_URL1, OnUpdateUrl1)
|
|
ON_COMMAND(ID_URL2, OnUrl2)
|
|
ON_UPDATE_COMMAND_UI(ID_URL2, OnUpdateUrl2)
|
|
ON_COMMAND(ID_APP_PREFS, OnAppPrefs)
|
|
ON_COMMAND(ID_TBAR_DIAL, OnTbarDial)
|
|
ON_UPDATE_COMMAND_UI(ID_TBAR_DIAL, OnUpdateTbarDial)
|
|
ON_COMMAND(ID_TBAR_EMAIL, OnTbarEmail)
|
|
ON_UPDATE_COMMAND_UI(ID_TBAR_EMAIL, OnUpdateTbarEmail)
|
|
ON_COMMAND(ID_TBAR_WEB, OnTbarWeb)
|
|
ON_UPDATE_COMMAND_UI(ID_TBAR_WEB, OnUpdateTbarWeb)
|
|
ON_COMMAND(ID_VIEW_COLPOS, OnViewColpos)
|
|
ON_COMMAND(ID_ENTRY_COPY, OnEntryCopy)
|
|
ON_UPDATE_COMMAND_UI(ID_ENTRY_COPY, OnUpdateEntryCopy)
|
|
ON_COMMAND(ID_FILE_PRINT_MERGE, OnFilePrintMerge)
|
|
//}}AFX_MSG_MAP
|
|
// Standard printing commands
|
|
ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
|
|
ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
|
|
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CCB32View construction/destruction
|
|
|
|
CCB32View::CCB32View()
|
|
{
|
|
//m_nHighlight = 1;
|
|
m_iFirst = 0;
|
|
m_pFindDialog = new CFindDlg;
|
|
m_headerctrl.SetCallback( this, (void (CWnd::*)(int, int))DragColumn );
|
|
nSortedCol = theApp.GetProfileInt(_T("Preferences"),_T("SortIndex"),0);
|
|
if ((nSortedCol<0) || (nSortedCol>(COLS-1)))
|
|
nSortedCol = 0;
|
|
bSortAscending = theApp.GetProfileInt(_T("Preferences"),_T("SortDirection"),1);
|
|
}
|
|
|
|
CCB32View::~CCB32View()
|
|
{
|
|
delete m_pFindDialog;
|
|
}
|
|
|
|
BOOL CCB32View::PreCreateWindow(CREATESTRUCT& cs)
|
|
{
|
|
if (!CListView::PreCreateWindow (cs))
|
|
return FALSE;
|
|
|
|
// Make the list view an owner-drawn control.
|
|
cs.style |= LVS_OWNERDRAWFIXED;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CCB32View drawing
|
|
|
|
void CCB32View::OnDraw(CDC* pDC)
|
|
{
|
|
CCB32Doc* pDoc = GetDocument();
|
|
ASSERT_VALID(pDoc);
|
|
}
|
|
|
|
void CCB32View::OnInitialUpdate()
|
|
{
|
|
CListView::OnInitialUpdate();
|
|
|
|
// prepare header control
|
|
if (m_iFirst == 0)
|
|
{
|
|
m_headerctrl.SubclassWindow(::GetDlgItem(m_hWnd,0));
|
|
m_iFirst = 1;
|
|
}
|
|
|
|
// Add items to the list view.
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
|
|
FreeItems();
|
|
ctlList.DeleteAllItems();
|
|
ctlList.SetBkColor(GetSysColor(COLOR_WINDOW));
|
|
|
|
AddDatabase();
|
|
theApp.SetStatusMsg(AFX_IDS_IDLEMESSAGE);
|
|
}
|
|
|
|
void CCB32View::MeasureItem(LPMEASUREITEMSTRUCT lpmis)
|
|
{
|
|
// Compute the height of each line in the list view from the font height.
|
|
LOGFONT lf;
|
|
|
|
CFont* pFont = GetFont();
|
|
pFont->GetLogFont(&lf);
|
|
lpmis->itemHeight = abs ((int) lf.lfHeight) + 6;
|
|
|
|
}
|
|
|
|
void CCB32View::DrawItem(LPDRAWITEMSTRUCT lpdis)
|
|
{
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
|
|
// Create a CDC object from the DC handle provided to us.
|
|
CDC dc;
|
|
dc.Attach (lpdis->hDC);
|
|
|
|
// Initialize a CRect object with a rectangle that surrounds the item
|
|
// and its subitems.
|
|
CRect rect = lpdis->rcItem;
|
|
|
|
// Retrieve a pointer to the CStringArray structure that holds the item's
|
|
// data. lpdis->itemID is the 0-based index of the item that we're being
|
|
// being asked to paint.
|
|
CStringArray* pItem = (CStringArray*) ctlList.GetItemData(lpdis->itemID);
|
|
|
|
// If the item is selected, paint the rectangle with the system color
|
|
// COLOR_HIGHLIGHT. Otherwise, use COLOR_WINDOW.
|
|
CBrush* pBrush = new CBrush (::GetSysColor ((lpdis->itemState &
|
|
ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_WINDOW));
|
|
dc.FillRect (rect, pBrush);
|
|
delete pBrush;
|
|
|
|
// If the item has the input focus, draw a dotted focus rectangle.
|
|
if (lpdis->itemState & ODS_FOCUS)
|
|
dc.DrawFocusRect (rect);
|
|
|
|
// Draw the text of the item and its subitems. If the item is selected,
|
|
// the text color is set to COLOR_HIGHLIGHTTEXT first. Values for the
|
|
// item and subitems are retrieved through the CStringArray pointer
|
|
// initialized earlier, converted to text, and displayed by our own
|
|
// DrawItemText function.
|
|
if (lpdis->itemID != -1)
|
|
{
|
|
COLORREF crOld = NULL;
|
|
DWORD myColor;
|
|
if (lpdis->itemState & ODS_SELECTED)
|
|
myColor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
|
|
else
|
|
myColor = ::GetSysColor(COLOR_WINDOWTEXT);
|
|
|
|
crOld = dc.SetTextColor(myColor);
|
|
|
|
for (int nColumn = 0; nColumn<COLS; nColumn++)
|
|
{
|
|
LV_COLUMN lvc;
|
|
TCHAR sColText[160];
|
|
lvc.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT;
|
|
lvc.pszText = sColText;
|
|
lvc.cchTextMax = 159;
|
|
ctlList.GetColumn(nColumn, &lvc);
|
|
int nFormat = lvc.fmt & LVCFMT_JUSTIFYMASK;
|
|
int nWidth = lvc.cx;
|
|
|
|
for (int z = 0; z < COLS; z++)
|
|
{
|
|
if (lvc.pszText == arLabel[z])
|
|
{
|
|
DrawItemText(&dc, pItem->GetAt(z), rect, nWidth, nFormat);
|
|
break;
|
|
}
|
|
}
|
|
|
|
rect.left += nWidth;
|
|
}
|
|
|
|
dc.SetTextColor(crOld);
|
|
}
|
|
|
|
// Detach the control's DC from our own CDC object so the former won't
|
|
// be deleted when this function ends.
|
|
dc.Detach();
|
|
}
|
|
|
|
void CCB32View::DrawItemText(CDC* pDC, CString text, CRect rect,
|
|
int nWidth, int nFormat)
|
|
{
|
|
// Make sure the text will fit in the prescribed rectangle, and truncate
|
|
// it if it won't.
|
|
BOOL bNeedDots = FALSE;
|
|
int nMaxWidth = nWidth - 4;
|
|
|
|
if (nMaxWidth>1)
|
|
{
|
|
while (GetListCtrl().GetStringWidth((LPCTSTR) text) > (nMaxWidth - 4))
|
|
{
|
|
text = text.Left(text.GetLength() - 1);
|
|
bNeedDots = TRUE;
|
|
}
|
|
}
|
|
else
|
|
bNeedDots = TRUE;
|
|
|
|
if (bNeedDots)
|
|
{
|
|
if (text.GetLength() >= 1)
|
|
text = text.Left(text.GetLength() - 1);
|
|
text += "...";
|
|
}
|
|
|
|
// Draw the text into the rectangle using MFC's handy CDC::DrawText
|
|
// function.
|
|
rect.left += 2;
|
|
rect.right = rect.left + nMaxWidth;
|
|
|
|
UINT nStyle = DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX;
|
|
if (nFormat == LVCFMT_LEFT)
|
|
nStyle |= DT_LEFT;
|
|
else if (nFormat == LVCFMT_CENTER)
|
|
nStyle |= DT_CENTER;
|
|
else // nFormat == LVCFMT_RIGHT
|
|
nStyle |= DT_RIGHT;
|
|
|
|
pDC->DrawText(text, rect, nStyle);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CCB32View printing
|
|
BOOL CCB32View::OnPreparePrinting(CPrintInfo* pInfo)
|
|
{
|
|
// default preparation
|
|
return DoPreparePrinting(pInfo);
|
|
}
|
|
|
|
void CCB32View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
|
|
{
|
|
// nada
|
|
}
|
|
|
|
void CCB32View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
|
|
{
|
|
// nada
|
|
}
|
|
|
|
void CCB32View::OnFilePrintMerge()
|
|
{
|
|
CPMerge pmDlg;
|
|
|
|
if (pmDlg.DoModal() == IDOK) {
|
|
CString myTmpl = theApp.GetProfileString(_T("Print"),_T("Template"),NULL);
|
|
if (!myTmpl.IsEmpty()) {
|
|
CFileStatus fsTest;
|
|
CFile tFile;
|
|
CString myFile = theApp.m_pszPathToExe + "TMPL\\" + myTmpl;
|
|
if (tFile.GetStatus(myFile+".tpl", fsTest) &&
|
|
tFile.GetStatus(myFile+".hed", fsTest) &&
|
|
tFile.GetStatus(myFile+".bod", fsTest) &&
|
|
tFile.GetStatus(myFile+".fot", fsTest)) {
|
|
// theMeat.
|
|
PrintMerge(myFile);
|
|
// Launch?
|
|
if (GetPrivateProfileInt("Template","Launch",0, myFile+".tpl")) {
|
|
char chTmpOut[_MAX_PATH], chTmpView[_MAX_PATH];
|
|
// Output file?
|
|
GetPrivateProfileString("Template","Output",NULL,
|
|
chTmpOut, sizeof(chTmpOut), myFile+".tpl");
|
|
// Viewer?
|
|
GetPrivateProfileString("Template","Viewer",NULL,
|
|
chTmpView, sizeof(chTmpView), myFile+".tpl");
|
|
if (tFile.GetStatus(chTmpOut, fsTest)) {
|
|
if (chTmpView[0] == NULL)
|
|
ShellExecute(NULL,_T("open"),chTmpOut,NULL,NULL,SW_SHOW);
|
|
else
|
|
ShellExecute(NULL,_T("open"),chTmpView,chTmpOut,NULL,SW_SHOW);
|
|
}
|
|
}
|
|
} else {
|
|
AfxMessageBox(IDS_MISSTMPL, MB_OK | MB_ICONSTOP);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
BOOL CCB32View::PrintMerge(CString strTemplate)
|
|
{
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
CWaitCursor wait;
|
|
|
|
CFile iFile;
|
|
CFileException e;
|
|
CString fileName;
|
|
char cBuffer[4096];
|
|
|
|
// open input body and read contents
|
|
fileName.Format("%s", strTemplate + ".bod");
|
|
if (!iFile.Open(fileName, CFile::modeRead |
|
|
CFile::shareDenyWrite, &e)) {
|
|
AfxThrowFileException(e.m_cause, e.m_lOsError, fileName);
|
|
return FALSE;
|
|
}
|
|
UINT uLen = iFile.Read(cBuffer, sizeof(cBuffer));
|
|
if (!uLen) {
|
|
AfxThrowFileException(e.m_cause, e.m_lOsError, fileName);
|
|
iFile.Close();
|
|
return FALSE;
|
|
}
|
|
cBuffer[uLen] = '\0';
|
|
iFile.Close();
|
|
|
|
// open body output for writing
|
|
fileName.Empty();
|
|
fileName.Format("%s", strTemplate + ".out");
|
|
if (!iFile.Open(fileName, CFile::modeCreate | CFile::modeWrite |
|
|
CFile::shareDenyWrite, &e)) {
|
|
AfxThrowFileException(e.m_cause, e.m_lOsError, fileName);
|
|
return FALSE;
|
|
}
|
|
|
|
// parse and write body
|
|
CString strBuffer;
|
|
CStringArray *pItem;
|
|
int iCount = ctlList.GetItemCount();
|
|
for(int i=0; i<iCount; i++) {
|
|
strBuffer.Format("%s", cBuffer);
|
|
pItem = (CStringArray*) ctlList.GetItemData(i);
|
|
strBuffer = Sub("@LASTNAME@", pItem->GetAt(0), strBuffer);
|
|
strBuffer = Sub("@FIRSTNAME@", pItem->GetAt(1), strBuffer);
|
|
strBuffer = Sub("@MIDINIT@", pItem->GetAt(2), strBuffer);
|
|
strBuffer = Sub("@TITLE@", pItem->GetAt(3), strBuffer);
|
|
strBuffer = Sub("@ADDRESS1@", pItem->GetAt(4), strBuffer);
|
|
strBuffer = Sub("@ADDRESS2@", pItem->GetAt(5), strBuffer);
|
|
strBuffer = Sub("@CITY@", pItem->GetAt(6), strBuffer);
|
|
strBuffer = Sub("@COUNTRY@", pItem->GetAt(7), strBuffer);
|
|
strBuffer = Sub("@STATE@", pItem->GetAt(8), strBuffer);
|
|
strBuffer = Sub("@ZIPCODE@", pItem->GetAt(9), strBuffer);
|
|
strBuffer = Sub("@COMPANY@", pItem->GetAt(10), strBuffer);
|
|
strBuffer = Sub("@DEPARTMENT@", pItem->GetAt(11), strBuffer);
|
|
strBuffer = Sub("@POSITION@", pItem->GetAt(12), strBuffer);
|
|
strBuffer = Sub("@MANAGER@", pItem->GetAt(13), strBuffer);
|
|
strBuffer = Sub("@ADDITIONAL1@", pItem->GetAt(14), strBuffer);
|
|
strBuffer = Sub("@ADDITIONAL2@", pItem->GetAt(15), strBuffer);
|
|
strBuffer = Sub("@HOMEPHONE@", pItem->GetAt(16), strBuffer);
|
|
strBuffer = Sub("@HOMEEXT@", pItem->GetAt(17), strBuffer);
|
|
strBuffer = Sub("@WORKPHONE@", pItem->GetAt(18), strBuffer);
|
|
strBuffer = Sub("@WORKEXT", pItem->GetAt(19), strBuffer);
|
|
strBuffer = Sub("@CELLPHONE@", pItem->GetAt(20), strBuffer);
|
|
strBuffer = Sub("@CELLEXT@", pItem->GetAt(21), strBuffer);
|
|
strBuffer = Sub("@PAGER@", pItem->GetAt(22), strBuffer);
|
|
strBuffer = Sub("@PAGERCARD@", pItem->GetAt(23), strBuffer);
|
|
strBuffer = Sub("@PAGEREXT@", pItem->GetAt(24), strBuffer);
|
|
strBuffer = Sub("@FAXPHONE@", pItem->GetAt(25), strBuffer);
|
|
strBuffer = Sub("@FAXEXT@", pItem->GetAt(26), strBuffer);
|
|
strBuffer = Sub("@EMAIL1@", pItem->GetAt(27), strBuffer);
|
|
strBuffer = Sub("@EMAIL2@", pItem->GetAt(28), strBuffer);
|
|
strBuffer = Sub("@WEB1@", pItem->GetAt(29), strBuffer);
|
|
strBuffer = Sub("@WEB2@", pItem->GetAt(30), strBuffer);
|
|
strBuffer = Sub("@NOTES@", Sub("<p>","\x0d\x0a",
|
|
pItem->GetAt(31)), strBuffer);
|
|
iFile.Write(strBuffer, strBuffer.GetLength());
|
|
}
|
|
iFile.Close();
|
|
|
|
// open output file
|
|
char chTmp[_MAX_PATH];
|
|
GetPrivateProfileString("Template","Output",strTemplate+".tmp",
|
|
chTmp, sizeof(chTmp), strTemplate+".tpl");
|
|
fileName.Empty();
|
|
fileName.Format("%s", chTmp);
|
|
if (!iFile.Open(fileName, CFile::modeCreate | CFile::modeWrite |
|
|
CFile::shareDenyWrite, &e)) {
|
|
AfxThrowFileException(e.m_cause, e.m_lOsError, fileName);
|
|
return FALSE;
|
|
}
|
|
|
|
// read in .hed, .out, .fot and write to .rtf
|
|
char *files[3] = {".hed",".out",".fot"};
|
|
CFile tFile;
|
|
CString tName;
|
|
for (int z=0; z<3; z++) {
|
|
cBuffer[0] = '\0';
|
|
tName.Format("%s", strTemplate + files[z]);
|
|
if (!tFile.Open(tName, CFile::modeRead |
|
|
CFile::shareDenyWrite, &e)) {
|
|
AfxThrowFileException(e.m_cause, e.m_lOsError, fileName);
|
|
iFile.Close();
|
|
return FALSE;
|
|
}
|
|
uLen = tFile.Read(cBuffer, sizeof(cBuffer));
|
|
while (uLen) {
|
|
cBuffer[uLen+1] = '\0';
|
|
iFile.Write(cBuffer, uLen);
|
|
uLen = tFile.Read(cBuffer, sizeof(cBuffer));
|
|
}
|
|
tFile.Close();
|
|
}
|
|
|
|
iFile.Close();
|
|
return TRUE;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CCB32View diagnostics
|
|
|
|
#ifdef _DEBUG
|
|
void CCB32View::AssertValid() const
|
|
{
|
|
CListView::AssertValid();
|
|
}
|
|
|
|
void CCB32View::Dump(CDumpContext& dc) const
|
|
{
|
|
CListView::Dump(dc);
|
|
}
|
|
|
|
CCB32Doc* CCB32View::GetDocument() // non-debug version is inline
|
|
{
|
|
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCB32Doc)));
|
|
return (CCB32Doc*)m_pDocument;
|
|
}
|
|
#endif //_DEBUG
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CCB32View message handlers
|
|
|
|
BOOL CCB32View::PreTranslateMessage(MSG* pMsg)
|
|
{
|
|
// Shift+F10: show pop-up menu.
|
|
if ((((pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN) && // If we hit a key and
|
|
(pMsg->wParam == VK_F10) && (GetKeyState(VK_SHIFT) & ~1)) != 0) || // it's Shift+F10 OR
|
|
(pMsg->message == WM_CONTEXTMENU)) // Natural keyboard key
|
|
{
|
|
CRect rect;
|
|
GetClientRect(rect);
|
|
ClientToScreen(rect);
|
|
|
|
CPoint point = rect.TopLeft();
|
|
point.Offset(50, 50);
|
|
OnContextMenu(NULL, point);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
return CListView::PreTranslateMessage(pMsg);
|
|
}
|
|
|
|
void CCB32View::OnDestroy()
|
|
{
|
|
FreeItems();
|
|
|
|
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberCol"),1))
|
|
{
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
CString strCols, strTemp;
|
|
strCols.Format("%d",ctlList.GetColumnWidth(0));
|
|
for (int i=1;i<COLS;i++)
|
|
{
|
|
strTemp.Format("%d",ctlList.GetColumnWidth(i));
|
|
strCols += ',' + strTemp;
|
|
}
|
|
|
|
theApp.WriteProfileString(_T("Columns"),_T("Sizes"),strCols);
|
|
}
|
|
|
|
CListView::OnDestroy();
|
|
}
|
|
|
|
int CCB32View::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
|
{
|
|
if (CListView::OnCreate(lpCreateStruct) == -1)
|
|
return -1;
|
|
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
|
|
// Switch to report view.
|
|
ChangeListCtrlStyle(LVS_REPORT | LVS_SINGLESEL |
|
|
LVS_SORTASCENDING, TRUE);
|
|
|
|
// Initialise label array
|
|
CString strLabel;
|
|
arLabel.SetSize(COLS);
|
|
|
|
strLabel.LoadString(IDS_LNAME);
|
|
arLabel.SetAt(0, strLabel);
|
|
strLabel.LoadString(IDS_FNAME);
|
|
arLabel.SetAt(1, strLabel);
|
|
strLabel.LoadString(IDS_MI);
|
|
arLabel.SetAt(2, strLabel);
|
|
strLabel.LoadString(IDS_TITLE);
|
|
arLabel.SetAt(3, strLabel);
|
|
strLabel.LoadString(IDS_ADD1);
|
|
arLabel.SetAt(4, strLabel);
|
|
strLabel.LoadString(IDS_ADD2);
|
|
arLabel.SetAt(5, strLabel);
|
|
strLabel.LoadString(IDS_CITY);
|
|
arLabel.SetAt(6, strLabel);
|
|
strLabel.LoadString(IDS_COUNTRY);
|
|
arLabel.SetAt(7, strLabel);
|
|
strLabel.LoadString(IDS_STATE);
|
|
arLabel.SetAt(8, strLabel);
|
|
strLabel.LoadString(IDS_ZIPCODE);
|
|
arLabel.SetAt(9, strLabel);
|
|
|
|
strLabel.LoadString(IDS_COMP);
|
|
arLabel.SetAt(10, strLabel);
|
|
strLabel.LoadString(IDS_DEPT);
|
|
arLabel.SetAt(11, strLabel);
|
|
strLabel.LoadString(IDS_POSN);
|
|
arLabel.SetAt(12, strLabel);
|
|
strLabel.LoadString(IDS_MGR);
|
|
arLabel.SetAt(13, strLabel);
|
|
strLabel.LoadString(IDS_CADD1);
|
|
arLabel.SetAt(14, strLabel);
|
|
strLabel.LoadString(IDS_CADD2);
|
|
arLabel.SetAt(15, strLabel);
|
|
|
|
strLabel.LoadString(IDS_HPHONE);
|
|
arLabel.SetAt(16, strLabel);
|
|
strLabel.LoadString(IDS_HPHONEX);
|
|
arLabel.SetAt(17, strLabel);
|
|
strLabel.LoadString(IDS_WPHONE);
|
|
arLabel.SetAt(18, strLabel);
|
|
strLabel.LoadString(IDS_WPHONEX);
|
|
arLabel.SetAt(19, strLabel);
|
|
strLabel.LoadString(IDS_CELLULAR);
|
|
arLabel.SetAt(20, strLabel);
|
|
strLabel.LoadString(IDS_CELLULARX);
|
|
arLabel.SetAt(21, strLabel);
|
|
strLabel.LoadString(IDS_PAGER);
|
|
arLabel.SetAt(22, strLabel);
|
|
strLabel.LoadString(IDS_PAGERC);
|
|
arLabel.SetAt(23, strLabel);
|
|
strLabel.LoadString(IDS_PAGERX);
|
|
arLabel.SetAt(24, strLabel);
|
|
strLabel.LoadString(IDS_FAX);
|
|
arLabel.SetAt(25, strLabel);
|
|
strLabel.LoadString(IDS_FAXX);
|
|
arLabel.SetAt(26, strLabel);
|
|
|
|
strLabel.LoadString(IDS_EMAIL1);
|
|
arLabel.SetAt(27, strLabel);
|
|
strLabel.LoadString(IDS_EMAIL2);
|
|
arLabel.SetAt(28, strLabel);
|
|
strLabel.LoadString(IDS_WEB1);
|
|
arLabel.SetAt(29, strLabel);
|
|
strLabel.LoadString(IDS_WEB2);
|
|
arLabel.SetAt(30, strLabel);
|
|
strLabel.LoadString(IDS_NOTES);
|
|
arLabel.SetAt(31, strLabel);
|
|
|
|
// Setup column sizes
|
|
int colsize[COLS] = {100,100,40,40,170,170,110,90,60,100,
|
|
100,100,100,100,100,100,
|
|
120,60,120,60,120,60,120,120,60,120,60,
|
|
200,200,280,280,280};
|
|
|
|
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberCol"),1))
|
|
{
|
|
CString strBuffer = theApp.GetProfileString(_T("Columns"),_T("Sizes"));
|
|
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++)
|
|
colsize[z]=tempcol[z];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Setup column positions
|
|
int colpos[COLS];
|
|
for (int p=0; p<COLS; p++)
|
|
colpos[p] = p;
|
|
|
|
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberPos"),1))
|
|
{
|
|
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];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add columns to list view
|
|
for (int i=0; i < COLS; i++)
|
|
ctlList.InsertColumn(i, arLabel[colpos[i]], LVCFMT_LEFT, colsize[i]);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void CCB32View::OnEntryAdd()
|
|
{
|
|
CPropInfo propinfo(IDS_ENTRYADD);
|
|
propinfo.m_psh.dwFlags |= PSH_NOAPPLYNOW;
|
|
CStringArray* pItem;
|
|
|
|
propinfo.AddControlPages();
|
|
propinfo.m_propadd.m_city = theApp.GetProfileString(_T("Preferences"),_T("DefaultCity"),NULL);
|
|
propinfo.m_propadd.m_country = theApp.GetProfileString(_T("Preferences"),_T("DefaultCountry"),NULL);
|
|
propinfo.m_propcomp.m_comp = theApp.GetProfileString(_T("Preferences"),_T("DefaultComp"),NULL);
|
|
propinfo.m_proponline.m_email1 = theApp.GetProfileString(_T("Preferences"),_T("DefaultEmail"),NULL);
|
|
propinfo.m_propphone.m_hphone = theApp.GetProfileString(_T("Preferences"),_T("DefaultPrefix"),NULL);
|
|
propinfo.m_propadd.m_state = theApp.GetProfileString(_T("Preferences"),_T("DefaultState"),NULL);
|
|
propinfo.m_proponline.m_web1 = theApp.GetProfileString(_T("Preferences"),_T("DefaultWeb"),NULL);
|
|
propinfo.m_propadd.m_zipcode = theApp.GetProfileString(_T("Preferences"),_T("DefaultZip"),NULL);
|
|
|
|
if (propinfo.DoModal()==IDOK)
|
|
{
|
|
try
|
|
{
|
|
pItem = new CStringArray;
|
|
}
|
|
catch (CMemoryException* e)
|
|
{
|
|
e->Delete ();
|
|
return;
|
|
}
|
|
pItem->SetSize(COLS);
|
|
|
|
GetPropData(pItem, propinfo);
|
|
AddItemToListView(pItem);
|
|
SortDatabase();
|
|
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
LV_FINDINFO lvfind;
|
|
lvfind.flags = LVFI_PARAM;
|
|
lvfind.lParam = (LPARAM) pItem;
|
|
int iIndex = ctlList.FindItem(&lvfind, -1);
|
|
if (iIndex > -1)
|
|
{
|
|
ctlList.SetItemState(iIndex, LVIS_SELECTED | LVIS_FOCUSED,
|
|
LVIS_SELECTED | LVIS_FOCUSED);
|
|
ctlList.EnsureVisible(iIndex,FALSE);
|
|
}
|
|
|
|
GetDocument()->SetModifiedFlag();
|
|
GetDocument()->UpdateAllViews(NULL);
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnEntryEdit()
|
|
{
|
|
int iItemIndex;
|
|
CStringArray* pItem;
|
|
CPropInfo propinfo(IDS_ENTRYEDIT);
|
|
propinfo.m_psh.dwFlags |= PSH_NOAPPLYNOW;
|
|
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
iItemIndex = ctlList.GetNextItem(-1, LVNI_FOCUSED);
|
|
if (iItemIndex > -1)
|
|
{
|
|
pItem = (CStringArray*) GetListCtrl().GetItemData(iItemIndex);
|
|
|
|
propinfo.AddControlPages();
|
|
SetPropData(propinfo, pItem);
|
|
|
|
if (propinfo.DoModal()==IDOK)
|
|
{
|
|
GetPropData(pItem, propinfo);
|
|
UpdateItemInListView(pItem, iItemIndex);
|
|
ctlList.SetItemState(iItemIndex, LVIS_SELECTED | LVIS_FOCUSED,
|
|
LVIS_SELECTED | LVIS_FOCUSED);
|
|
SortDatabase();
|
|
iItemIndex = ctlList.GetNextItem(-1, LVNI_FOCUSED);
|
|
ctlList.EnsureVisible(iItemIndex, FALSE);
|
|
GetDocument()->SetModifiedFlag();
|
|
GetDocument()->UpdateAllViews(NULL);
|
|
}
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnEntryDelete()
|
|
{
|
|
int iItemIndex;
|
|
CStringArray* pItem;
|
|
UINT nState = LVIS_SELECTED | LVIS_FOCUSED;
|
|
UINT nMask = LVIS_SELECTED | LVIS_FOCUSED;
|
|
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
iItemIndex = ctlList.GetNextItem(-1, LVNI_FOCUSED);
|
|
if (iItemIndex > -1)
|
|
{
|
|
if (theApp.GetProfileInt(_T("Preferences"),_T("ConfirmDelete"),1))
|
|
{
|
|
if (AfxMessageBox(IDS_CONFIRM, MB_YESNO) == IDNO)
|
|
return;
|
|
}
|
|
|
|
pItem = (CStringArray*) ctlList.GetItemData(iItemIndex);
|
|
delete pItem;
|
|
ctlList.DeleteItem(iItemIndex);
|
|
GetDocument()->SetModifiedFlag();
|
|
GetDocument()->UpdateAllViews(NULL);
|
|
|
|
iItemIndex = ctlList.GetNextItem(-1, LVNI_FOCUSED);
|
|
if (iItemIndex > -1)
|
|
{
|
|
GetParentFrame()->ActivateFrame();
|
|
ctlList.EnsureVisible(iItemIndex, FALSE);
|
|
ctlList.SetItemState(iItemIndex, nState, nMask);
|
|
ctlList.SetRedraw(TRUE);
|
|
ctlList.Invalidate();
|
|
}
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnEntryCopy()
|
|
{
|
|
CPropInfo propinfo(IDS_ENTRYCOPY);
|
|
propinfo.m_psh.dwFlags |= PSH_NOAPPLYNOW;
|
|
CStringArray* pItemOrig;
|
|
CStringArray* pItemCopy;
|
|
int iItemIndex;
|
|
|
|
iItemIndex = GetListCtrl().GetNextItem(-1, LVNI_FOCUSED);
|
|
if (iItemIndex > -1)
|
|
{
|
|
pItemOrig = (CStringArray*) GetListCtrl().GetItemData(iItemIndex);
|
|
|
|
propinfo.AddControlPages();
|
|
SetPropData(propinfo, pItemOrig);
|
|
CString strCopy;
|
|
strCopy.LoadString(IDS_COPY);
|
|
propinfo.m_propadd.m_lname += strCopy;
|
|
|
|
if (propinfo.DoModal()==IDOK)
|
|
{
|
|
try
|
|
{
|
|
pItemCopy = new CStringArray;
|
|
}
|
|
catch (CMemoryException* e)
|
|
{
|
|
e->Delete ();
|
|
return;
|
|
}
|
|
pItemCopy->SetSize(COLS);
|
|
|
|
GetPropData(pItemCopy, propinfo);
|
|
AddItemToListView(pItemCopy);
|
|
SortDatabase();
|
|
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
LV_FINDINFO lvfind;
|
|
lvfind.flags = LVFI_PARAM;
|
|
lvfind.lParam = (LPARAM) pItemCopy;
|
|
int iIndex = ctlList.FindItem(&lvfind, -1);
|
|
if (iIndex > -1)
|
|
{
|
|
ctlList.SetItemState(iIndex, LVIS_SELECTED | LVIS_FOCUSED,
|
|
LVIS_SELECTED | LVIS_FOCUSED);
|
|
ctlList.EnsureVisible(iIndex,FALSE);
|
|
}
|
|
|
|
GetDocument()->SetModifiedFlag();
|
|
GetDocument()->UpdateAllViews(NULL);
|
|
}
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnUpdateEntryEdit(CCmdUI* pCmdUI)
|
|
{
|
|
int iItemIndex;
|
|
|
|
iItemIndex = GetListCtrl().GetNextItem(-1, LVNI_SELECTED);
|
|
if (iItemIndex < 0)
|
|
{
|
|
pCmdUI->Enable(FALSE);
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnUpdateEntryDelete(CCmdUI* pCmdUI)
|
|
{
|
|
int iItemIndex;
|
|
|
|
iItemIndex = GetListCtrl().GetNextItem(-1, LVNI_SELECTED);
|
|
if (iItemIndex < 0)
|
|
{
|
|
pCmdUI->Enable(FALSE);
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnUpdateEntryCopy(CCmdUI* pCmdUI)
|
|
{
|
|
int iItemIndex;
|
|
|
|
iItemIndex = GetListCtrl().GetNextItem(-1, LVNI_SELECTED);
|
|
if (iItemIndex < 0)
|
|
{
|
|
pCmdUI->Enable(FALSE);
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnLButtonDblClk(UINT nFlags, CPoint point)
|
|
{
|
|
OnEntryEdit();
|
|
|
|
CListView::OnLButtonDblClk(nFlags, point);
|
|
}
|
|
|
|
void CCB32View::OnContextMenu(CWnd* pWnd, CPoint point)
|
|
{
|
|
|
|
CMenu menu;
|
|
VERIFY(menu.LoadMenu(IDR_CONTEXTMENU));
|
|
|
|
CMenu* pPopup = menu.GetSubMenu(0);
|
|
ASSERT(pPopup != NULL);
|
|
|
|
CWnd* pWndPopupOwner = this;
|
|
while (pWndPopupOwner->GetStyle() & WS_CHILD)
|
|
pWndPopupOwner = pWndPopupOwner->GetParent();
|
|
|
|
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
|
|
pWndPopupOwner);
|
|
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Supporting functions
|
|
|
|
void CCB32View::ChangeListCtrlStyle(long lStyle, BOOL bSetBit)
|
|
{
|
|
long lStyleOld;
|
|
lStyleOld = GetWindowLong(m_hWnd, GWL_STYLE);
|
|
lStyleOld &= ~lStyle;
|
|
if (bSetBit)
|
|
lStyleOld |= lStyle;
|
|
|
|
SetWindowLong(m_hWnd, GWL_STYLE, lStyleOld);
|
|
SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_SHOWWINDOW);
|
|
}
|
|
|
|
BOOL CCB32View::AddDocItemToListView(CExpr* expr)
|
|
{
|
|
// Allocate an CStringArray structure to hold the item's data.
|
|
CStringArray* pItem;
|
|
try {
|
|
pItem = new CStringArray;
|
|
}
|
|
catch (CMemoryException* e) {
|
|
e->Delete ();
|
|
return FALSE;
|
|
}
|
|
pItem->SetSize(COLS);
|
|
|
|
// Initialize the CStringArray structure's fields.
|
|
CString sText;
|
|
if(expr->GetAttributeValue(_T("LastName"), sText))
|
|
pItem->SetAt(0, sText);
|
|
if(expr->GetAttributeValue("FirstName", sText))
|
|
pItem->SetAt(1, sText);
|
|
if(expr->GetAttributeValue("MiddleInitial", sText))
|
|
pItem->SetAt(2, sText);
|
|
if(expr->GetAttributeValue("Title", sText))
|
|
pItem->SetAt(3, sText);
|
|
if(expr->GetAttributeValue("Address1", sText))
|
|
pItem->SetAt(4, sText);
|
|
if(expr->GetAttributeValue("Address2", sText))
|
|
pItem->SetAt(5, sText);
|
|
if(expr->GetAttributeValue("City", sText))
|
|
pItem->SetAt(6, sText);
|
|
if(expr->GetAttributeValue("Country", sText))
|
|
pItem->SetAt(7, sText);
|
|
if(expr->GetAttributeValue("State", sText))
|
|
pItem->SetAt(8, sText);
|
|
if(expr->GetAttributeValue("ZipCode", sText))
|
|
pItem->SetAt(9, sText);
|
|
|
|
if(expr->GetAttributeValue("Company", sText))
|
|
pItem->SetAt(10, sText);
|
|
if(expr->GetAttributeValue("Department", sText))
|
|
pItem->SetAt(11, sText);
|
|
if(expr->GetAttributeValue("Position", sText))
|
|
pItem->SetAt(12, sText);
|
|
if(expr->GetAttributeValue("Manager", sText))
|
|
pItem->SetAt(13, sText);
|
|
if(expr->GetAttributeValue("Additional1", sText))
|
|
pItem->SetAt(14, sText);
|
|
if(expr->GetAttributeValue("Additional2", sText))
|
|
pItem->SetAt(15, sText);
|
|
|
|
if(expr->GetAttributeValue("HomePhone", sText))
|
|
pItem->SetAt(16, sText);
|
|
if(expr->GetAttributeValue("HomeExt", sText))
|
|
pItem->SetAt(17, sText);
|
|
if(expr->GetAttributeValue("WorkPhone", sText))
|
|
pItem->SetAt(18, sText);
|
|
if(expr->GetAttributeValue("WorkExt", sText))
|
|
pItem->SetAt(19, sText);
|
|
if(expr->GetAttributeValue("CellPhone", sText))
|
|
pItem->SetAt(20, sText);
|
|
if(expr->GetAttributeValue("CellExt", sText))
|
|
pItem->SetAt(21, sText);
|
|
if(expr->GetAttributeValue("Pager", sText))
|
|
pItem->SetAt(22, sText);
|
|
if(expr->GetAttributeValue("PagerCard", sText))
|
|
pItem->SetAt(23, sText);
|
|
if(expr->GetAttributeValue("PagerExt", sText))
|
|
pItem->SetAt(24, sText);
|
|
if(expr->GetAttributeValue("FaxPhone", sText))
|
|
pItem->SetAt(25, sText);
|
|
if(expr->GetAttributeValue("FaxExt", sText))
|
|
pItem->SetAt(26, sText);
|
|
|
|
if(expr->GetAttributeValue("Email1", sText))
|
|
pItem->SetAt(27, sText);
|
|
if(expr->GetAttributeValue("Email2", sText))
|
|
pItem->SetAt(28, sText);
|
|
if(expr->GetAttributeValue("Web1", sText))
|
|
pItem->SetAt(29, sText);
|
|
if(expr->GetAttributeValue("Web2", sText))
|
|
pItem->SetAt(30, sText);
|
|
if(expr->GetAttributeValue("Notes", sText))
|
|
pItem->SetAt(31, sText);
|
|
|
|
// Add an item to the list view control, and set the item's lParam
|
|
// equal to the address of the corresponding CStringArray structure.
|
|
LV_ITEM lvi;
|
|
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
|
|
lvi.iItem = GetListCtrl ().GetItemCount ();
|
|
lvi.iSubItem = 0;
|
|
lvi.iImage = 0;
|
|
lvi.pszText = NULL;
|
|
lvi.lParam = (LPARAM) pItem;
|
|
|
|
if (GetListCtrl ().InsertItem (&lvi) == -1)
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CCB32View::AddItemToListView(CStringArray* pItem)
|
|
{
|
|
// Add an item to the list view control, and set the item's lParam
|
|
// equal to the address of the corresponding CStringArray structure.
|
|
LV_ITEM lvi;
|
|
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
|
|
lvi.iItem = GetListCtrl ().GetItemCount ();
|
|
lvi.iSubItem = 0;
|
|
lvi.iImage = 0;
|
|
lvi.pszText = NULL;
|
|
lvi.lParam = (LPARAM) pItem;
|
|
|
|
if (GetListCtrl ().InsertItem (&lvi) == -1)
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CCB32View::UpdateItemInListView(CStringArray* pItem, int iIndex)
|
|
{
|
|
// Update an item to the list view control, and set the item's lParam
|
|
// equal to the address of the corresponding CStringArray structure.
|
|
LV_ITEM lvi;
|
|
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
|
|
lvi.iItem = iIndex;
|
|
lvi.iSubItem = 0;
|
|
lvi.iImage = 0;
|
|
lvi.pszText = NULL;
|
|
lvi.lParam = (LPARAM) pItem;
|
|
|
|
if (GetListCtrl().SetItem (&lvi) == -1)
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CCB32View::FreeItems()
|
|
{
|
|
// Delete the CStringArray structures allocated when the control was created.
|
|
int nCount = GetListCtrl ().GetItemCount ();
|
|
if (nCount) {
|
|
for (int i=0; i<nCount; i++)
|
|
delete (CStringArray*) GetListCtrl().GetItemData(i);
|
|
}
|
|
}
|
|
|
|
BOOL CCB32View::GetPropData(CStringArray* pItem, CPropInfo& propinfo)
|
|
{
|
|
pItem->SetAt(0, propinfo.m_propadd.m_lname);
|
|
pItem->SetAt(1, propinfo.m_propadd.m_fname);
|
|
pItem->SetAt(2, propinfo.m_propadd.m_mi);
|
|
pItem->SetAt(3, propinfo.m_propadd.m_title);
|
|
pItem->SetAt(4, propinfo.m_propadd.m_add1);
|
|
pItem->SetAt(5, propinfo.m_propadd.m_add2);
|
|
pItem->SetAt(6, propinfo.m_propadd.m_city);
|
|
pItem->SetAt(7, propinfo.m_propadd.m_country);
|
|
pItem->SetAt(8, propinfo.m_propadd.m_state);
|
|
pItem->SetAt(9, propinfo.m_propadd.m_zipcode);
|
|
|
|
pItem->SetAt(10, propinfo.m_propcomp.m_comp);
|
|
pItem->SetAt(11, propinfo.m_propcomp.m_dept);
|
|
pItem->SetAt(12, propinfo.m_propcomp.m_posn);
|
|
pItem->SetAt(13, propinfo.m_propcomp.m_mgr);
|
|
pItem->SetAt(14, propinfo.m_propcomp.m_cadd1);
|
|
pItem->SetAt(15, propinfo.m_propcomp.m_cadd2);
|
|
|
|
pItem->SetAt(16, propinfo.m_propphone.m_hphone);
|
|
pItem->SetAt(17, propinfo.m_propphone.m_hphonex);
|
|
pItem->SetAt(18, propinfo.m_propphone.m_wphone);
|
|
pItem->SetAt(19, propinfo.m_propphone.m_wphonex);
|
|
pItem->SetAt(20, propinfo.m_propphone.m_cellular);
|
|
pItem->SetAt(21, propinfo.m_propphone.m_cellularx);
|
|
pItem->SetAt(22, propinfo.m_propphone.m_pager);
|
|
pItem->SetAt(23, propinfo.m_propphone.m_pagerc);
|
|
pItem->SetAt(24, propinfo.m_propphone.m_pagerx);
|
|
pItem->SetAt(25, propinfo.m_propphone.m_fax);
|
|
pItem->SetAt(26, propinfo.m_propphone.m_faxx);
|
|
|
|
pItem->SetAt(27, propinfo.m_proponline.m_email1);
|
|
pItem->SetAt(28, propinfo.m_proponline.m_email2);
|
|
pItem->SetAt(29, propinfo.m_proponline.m_web1);
|
|
pItem->SetAt(30, propinfo.m_proponline.m_web2);
|
|
pItem->SetAt(31, Sub("\x0d\x0a","<p>",propinfo.m_propnote.m_notes));
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CCB32View::SetPropData (CPropInfo& propinfo, CStringArray* pItem)
|
|
{
|
|
propinfo.m_propadd.m_lname = pItem->GetAt(0);
|
|
propinfo.m_propadd.m_fname = pItem->GetAt(1);
|
|
propinfo.m_propadd.m_mi = pItem->GetAt(2);
|
|
propinfo.m_propadd.m_title = pItem->GetAt(3);
|
|
propinfo.m_propadd.m_add1 = pItem->GetAt(4);
|
|
propinfo.m_propadd.m_add2 = pItem->GetAt(5);
|
|
propinfo.m_propadd.m_city = pItem->GetAt(6);
|
|
propinfo.m_propadd.m_country = pItem->GetAt(7);
|
|
propinfo.m_propadd.m_state = pItem->GetAt(8);
|
|
propinfo.m_propadd.m_zipcode = pItem->GetAt(9);
|
|
|
|
propinfo.m_propcomp.m_comp = pItem->GetAt(10);
|
|
propinfo.m_propcomp.m_dept = pItem->GetAt(11);
|
|
propinfo.m_propcomp.m_posn = pItem->GetAt(12);
|
|
propinfo.m_propcomp.m_mgr = pItem->GetAt(13);
|
|
propinfo.m_propcomp.m_cadd1 = pItem->GetAt(14);
|
|
propinfo.m_propcomp.m_cadd2 = pItem->GetAt(15);
|
|
|
|
propinfo.m_propphone.m_hphone = pItem->GetAt(16);
|
|
propinfo.m_propphone.m_hphonex = pItem->GetAt(17);
|
|
propinfo.m_propphone.m_wphone = pItem->GetAt(18);
|
|
propinfo.m_propphone.m_wphonex = pItem->GetAt(19);
|
|
propinfo.m_propphone.m_cellular = pItem->GetAt(20);
|
|
propinfo.m_propphone.m_cellularx = pItem->GetAt(21);
|
|
propinfo.m_propphone.m_pager = pItem->GetAt(22);
|
|
propinfo.m_propphone.m_pagerc = pItem->GetAt(23);
|
|
propinfo.m_propphone.m_pagerx = pItem->GetAt(24);
|
|
propinfo.m_propphone.m_fax = pItem->GetAt(25);
|
|
propinfo.m_propphone.m_faxx = pItem->GetAt(26);
|
|
|
|
propinfo.m_proponline.m_email1 = pItem->GetAt(27);
|
|
propinfo.m_proponline.m_email2 = pItem->GetAt(28);
|
|
propinfo.m_proponline.m_web1 = pItem->GetAt(29);
|
|
propinfo.m_proponline.m_web2 = pItem->GetAt(30);
|
|
propinfo.m_propnote.m_notes = Sub("<p>","\x0d\x0a",pItem->GetAt(31));
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
CString CCB32View::Sub(const CString& from, const CString& to, CString& str)
|
|
{
|
|
CString strRet = str;
|
|
int find = strRet.Find(from);
|
|
while (find >=0) {
|
|
strRet = strRet.Left(find) + to + (strRet.Right(strRet.GetLength()-find-from.GetLength()));
|
|
find = strRet.Find(from);
|
|
}
|
|
return strRet;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// Callback functions for sorting
|
|
|
|
// Ascending
|
|
int CALLBACK CCB32View::CompareFuncAsc (LPARAM lParam1, LPARAM lParam2,
|
|
LPARAM lParamSort)
|
|
{
|
|
CStringArray* pItem1 = (CStringArray*) lParam1;
|
|
CStringArray* pItem2 = (CStringArray*) lParam2;
|
|
|
|
return pItem1->GetAt(lParamSort).CompareNoCase(pItem2->GetAt(lParamSort));
|
|
}
|
|
|
|
// Descending
|
|
int CALLBACK CCB32View::CompareFuncDec (LPARAM lParam1, LPARAM lParam2,
|
|
LPARAM lParamSort)
|
|
{
|
|
CStringArray* pItem1 = (CStringArray*) lParam1;
|
|
CStringArray* pItem2 = (CStringArray*) lParam2;
|
|
|
|
return pItem2->GetAt(lParamSort).CompareNoCase(pItem1->GetAt(lParamSort));
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
// translate items from ListView to database
|
|
|
|
BOOL CCB32View::MakeExpr(CExpr* expr, CStringArray* pItem)
|
|
{
|
|
expr->AddAttributeValueString(_T("LastName"), pItem->GetAt(0));
|
|
expr->AddAttributeValueString("FirstName", pItem->GetAt(1));
|
|
expr->AddAttributeValueString("MiddleInitial", pItem->GetAt(2));
|
|
expr->AddAttributeValueString("Title", pItem->GetAt(3));
|
|
expr->AddAttributeValueString("Address1", pItem->GetAt(4));
|
|
expr->AddAttributeValueString("Address2", pItem->GetAt(5));
|
|
expr->AddAttributeValueString("City", pItem->GetAt(6));
|
|
expr->AddAttributeValueString("Country", pItem->GetAt(7));
|
|
expr->AddAttributeValueString("State", pItem->GetAt(8));
|
|
expr->AddAttributeValueString("ZipCode", pItem->GetAt(9));
|
|
|
|
expr->AddAttributeValueString("Company", pItem->GetAt(10));
|
|
expr->AddAttributeValueString("Department", pItem->GetAt(11));
|
|
expr->AddAttributeValueString("Position", pItem->GetAt(12));
|
|
expr->AddAttributeValueString("Manager", pItem->GetAt(13));
|
|
expr->AddAttributeValueString("Additional1", pItem->GetAt(14));
|
|
expr->AddAttributeValueString("Additional2", pItem->GetAt(15));
|
|
|
|
expr->AddAttributeValueString("HomePhone", pItem->GetAt(16));
|
|
expr->AddAttributeValueString("HomeExt", pItem->GetAt(17));
|
|
expr->AddAttributeValueString("WorkPhone", pItem->GetAt(18));
|
|
expr->AddAttributeValueString("WorkExt", pItem->GetAt(19));
|
|
expr->AddAttributeValueString("CellPhone", pItem->GetAt(20));
|
|
expr->AddAttributeValueString("CellExt", pItem->GetAt(21));
|
|
expr->AddAttributeValueString("Pager", pItem->GetAt(22));
|
|
expr->AddAttributeValueString("PagerCard", pItem->GetAt(23));
|
|
expr->AddAttributeValueString("PagerExt", pItem->GetAt(24));
|
|
expr->AddAttributeValueString("FaxPhone", pItem->GetAt(25));
|
|
expr->AddAttributeValueString("FaxExt", pItem->GetAt(26));
|
|
|
|
expr->AddAttributeValueString("Email1", pItem->GetAt(27));
|
|
expr->AddAttributeValueString("Email2", pItem->GetAt(28));
|
|
expr->AddAttributeValueString("Web1", pItem->GetAt(29));
|
|
expr->AddAttributeValueString("Web2", pItem->GetAt(30));
|
|
expr->AddAttributeValueString("Notes", pItem->GetAt(31));
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CCB32View::MakeDatabase()
|
|
{
|
|
CWaitCursor wait;
|
|
CStringArray* pItem;
|
|
int iNumItems;
|
|
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
iNumItems = ctlList.GetItemCount();
|
|
CExprDatabase& db = GetDocument()->GetDB();
|
|
// db.ClearDatabase();
|
|
for (int i=0; i<iNumItems; i++)
|
|
{
|
|
CExpr *expr = new CExpr(_T("contact"));
|
|
pItem = (CStringArray*) ctlList.GetItemData(i);
|
|
MakeExpr(expr, pItem);
|
|
db.Append(expr);
|
|
}
|
|
}
|
|
|
|
void CCB32View::AddDatabase()
|
|
{
|
|
CWaitCursor wait;
|
|
CExprDatabase& db = GetDocument()->GetDB();
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
|
|
// get count of possible items
|
|
ctlList.SetRedraw(FALSE);
|
|
ctlList.SetItemCount(db.GetItemCount());
|
|
|
|
// add items to listview
|
|
wxNode *node = db.First();
|
|
while (node)
|
|
{
|
|
CExpr *expr = (CExpr *)node->Data();
|
|
CString strType = expr->Functor();
|
|
if (strType == _T("contact"))
|
|
{
|
|
if (!AddDocItemToListView (expr))
|
|
break;
|
|
}
|
|
node = node->Next();
|
|
}
|
|
db.ClearDatabase();
|
|
SortDatabase();
|
|
ctlList.SetRedraw(TRUE);
|
|
ctlList.Invalidate();
|
|
}
|
|
|
|
|
|
void CCB32View::OnEditFind()
|
|
{
|
|
int iItemIndex;
|
|
CComboBox& comboBox = ((CMainFrame*)AfxGetMainWnd())->m_wndToolBar.m_toolBarCombo;
|
|
|
|
if(m_pFindDialog->DoModal() != IDOK)
|
|
return;
|
|
|
|
ASSERT(m_pFindDialog->m_szText.GetLength());
|
|
|
|
// add it to the combo control on the toolbar
|
|
comboBox.SetWindowText(m_pFindDialog->m_szText);
|
|
m_searchHistory.AddString(m_pFindDialog->m_szText);
|
|
|
|
iItemIndex = -1;
|
|
if (!m_pFindDialog->m_bStartTop)
|
|
iItemIndex = GetListCtrl().GetNextItem(-1, LVNI_SELECTED);
|
|
|
|
if (m_pFindDialog->m_szText.GetLength())
|
|
FindNextItem(m_pFindDialog->m_szText, m_pFindDialog->m_nWhichName,
|
|
m_pFindDialog->m_nDirection, m_pFindDialog->m_bMatchCase,
|
|
iItemIndex);
|
|
}
|
|
|
|
void CCB32View::OnUpdateEditFind(CCmdUI* pCmdUI)
|
|
{
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
pCmdUI->Enable(ctlList.GetItemCount()>0);
|
|
}
|
|
|
|
void CCB32View::OnViewFindNext(CString &s1)
|
|
{
|
|
int iItemIndex = -1;
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
if (!m_pFindDialog->m_bStartTop)
|
|
{
|
|
iItemIndex = ctlList.GetNextItem(-1, LVNI_SELECTED) +1;
|
|
if ((iItemIndex + 1) >= ctlList.GetItemCount())
|
|
iItemIndex = -1;
|
|
}
|
|
|
|
FindNextItem(s1, m_pFindDialog->m_nWhichName, m_pFindDialog->m_nDirection,
|
|
m_pFindDialog->m_bMatchCase, iItemIndex);
|
|
}
|
|
|
|
void CCB32View::OnViewFindNext()
|
|
{
|
|
// if the user presses F3, see if there is a search pattern. if not, ask for one
|
|
if (m_pFindDialog->m_szText.GetLength())
|
|
{
|
|
int iItemIndex = -1;
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
if (!m_pFindDialog->m_bStartTop)
|
|
{
|
|
iItemIndex = ctlList.GetNextItem(-1, LVNI_SELECTED) + 1;
|
|
if ((iItemIndex + 1) >= ctlList.GetItemCount())
|
|
iItemIndex = -1;
|
|
}
|
|
|
|
FindNextItem(m_pFindDialog->m_szText, m_pFindDialog->m_nWhichName,
|
|
m_pFindDialog->m_nDirection, m_pFindDialog->m_bMatchCase,
|
|
iItemIndex);
|
|
}
|
|
else
|
|
PostMessage(WM_COMMAND, ID_EDIT_FIND);
|
|
}
|
|
|
|
void CCB32View::OnUpdateViewFindNext(CCmdUI* pCmdUI)
|
|
{
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
pCmdUI->Enable(ctlList.GetItemCount()>0);
|
|
}
|
|
|
|
void CCB32View::FindNextItem(CString szText, int iName, int iDir,
|
|
BOOL bMatch, int iStart)
|
|
{
|
|
CStringArray* pItem;
|
|
int iIndex;
|
|
CString szLookFor, szLookIn;
|
|
UINT nState = LVIS_SELECTED | LVIS_FOCUSED;
|
|
UINT nMask = LVIS_SELECTED | LVIS_FOCUSED;
|
|
|
|
if (szText.IsEmpty())
|
|
return;
|
|
|
|
szLookFor.Empty();
|
|
szLookIn.Empty();
|
|
|
|
iIndex = ((iStart > -1) ? iStart : 0);
|
|
|
|
szLookFor = szText;
|
|
if (bMatch == 0)
|
|
szLookFor.MakeLower();
|
|
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
|
|
if (ctlList.GetItemCount() < 2)
|
|
return;
|
|
|
|
while (iIndex > -1)
|
|
{
|
|
pItem = (CStringArray*) ctlList.GetItemData(iIndex);
|
|
szLookIn = pItem->GetAt(iName);
|
|
|
|
if (bMatch == 0)
|
|
szLookIn.MakeLower();
|
|
|
|
if (szLookIn.Find(szLookFor) > -1)
|
|
break;
|
|
|
|
iIndex = ctlList.GetNextItem(iIndex, (iDir==1 ? LVNI_BELOW : LVNI_ABOVE));
|
|
}
|
|
|
|
if (iIndex > -1)
|
|
{
|
|
GetParentFrame()->ActivateFrame();
|
|
ctlList.EnsureVisible(iIndex, FALSE);
|
|
ctlList.SetItemState(iIndex, nState, nMask);
|
|
ctlList.SetRedraw(TRUE);
|
|
ctlList.Invalidate();
|
|
}
|
|
else
|
|
AfxMessageBox(IDS_NOTEXT);
|
|
|
|
}
|
|
|
|
void CCB32View::SortDatabase()
|
|
{
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
|
|
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberSort"),1))
|
|
{
|
|
m_headerctrl.SetSortImage(nSortedCol, bSortAscending);
|
|
|
|
// convert column click to contents index
|
|
LV_COLUMN lvc;
|
|
int iSortCol = nSortedCol; // iSort;
|
|
TCHAR sColText[160];
|
|
lvc.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT;
|
|
lvc.pszText = sColText;
|
|
lvc.cchTextMax = 159;
|
|
ctlList.GetColumn(iSortCol, &lvc);
|
|
for (int z = 0; z < COLS; z++)
|
|
{
|
|
if (lvc.pszText == arLabel[z])
|
|
{
|
|
iSortCol = z;
|
|
break;
|
|
}
|
|
}
|
|
if (bSortAscending)
|
|
ctlList.SortItems (CompareFuncAsc, iSortCol);
|
|
else
|
|
ctlList.SortItems (CompareFuncDec, iSortCol);
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnViewColset()
|
|
{
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
CString strCols, strTemp;
|
|
strCols.Format("%d",ctlList.GetColumnWidth(0));
|
|
for (int i=1;i<COLS;i++)
|
|
{
|
|
strTemp.Format("%d",ctlList.GetColumnWidth(i));
|
|
strCols += ',' + strTemp;
|
|
}
|
|
|
|
theApp.WriteProfileString(_T("Columns"),_T("Sizes"),strCols);
|
|
|
|
AfxMessageBox(IDS_COLSAVE, MB_ICONINFORMATION);
|
|
}
|
|
|
|
void CCB32View::OnViewColpos()
|
|
{
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
CString strCols, strTemp;
|
|
|
|
LV_COLUMN lvc;
|
|
TCHAR sColText[160];
|
|
lvc.mask = LVCF_TEXT;
|
|
lvc.pszText = sColText;
|
|
lvc.cchTextMax = 159;
|
|
|
|
ctlList.GetColumn(0, &lvc);
|
|
for (int y = 0; y < COLS; y++)
|
|
{
|
|
if (lvc.pszText == arLabel[y])
|
|
{
|
|
strCols.Format("%d",y);
|
|
break;
|
|
}
|
|
}
|
|
|
|
for (int i=1; i<COLS; i++)
|
|
{
|
|
ctlList.GetColumn(i, &lvc);
|
|
for (int z = 0; z < COLS; z++)
|
|
{
|
|
if (lvc.pszText == arLabel[z])
|
|
{
|
|
strTemp.Format("%d",z);
|
|
strCols += ',' + strTemp;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
theApp.WriteProfileString(_T("Columns"),_T("Order"),strCols);
|
|
|
|
AfxMessageBox(IDS_POSSAVE, MB_ICONINFORMATION);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
// Dialling functions
|
|
|
|
void CCB32View::OnDialHome()
|
|
{
|
|
int iItemIndex;
|
|
CStringArray* pItem;
|
|
|
|
iItemIndex = GetListCtrl().GetNextItem(-1, LVNI_FOCUSED);
|
|
if (iItemIndex > -1)
|
|
{
|
|
pItem = (CStringArray*) GetListCtrl().GetItemData(iItemIndex);
|
|
TryToCall(pItem->GetAt(16), pItem->GetAt(1)+' '+pItem->GetAt(0));
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnUpdateDialHome(CCmdUI* pCmdUI)
|
|
{
|
|
pCmdUI->Enable(GetListCtrl().GetNextItem(-1,LVNI_FOCUSED) > -1);
|
|
}
|
|
|
|
void CCB32View::OnDialWork()
|
|
{
|
|
int iItemIndex;
|
|
CStringArray* pItem;
|
|
|
|
iItemIndex = GetListCtrl().GetNextItem(-1, LVNI_FOCUSED);
|
|
if (iItemIndex > -1)
|
|
{
|
|
pItem = (CStringArray*) GetListCtrl().GetItemData(iItemIndex);
|
|
TryToCall(pItem->GetAt(18), pItem->GetAt(1)+' '+pItem->GetAt(0));
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnUpdateDialWork(CCmdUI* pCmdUI)
|
|
{
|
|
pCmdUI->Enable(GetListCtrl().GetNextItem(-1,LVNI_FOCUSED) > -1);
|
|
}
|
|
|
|
void CCB32View::OnDialPager()
|
|
{
|
|
int iItemIndex;
|
|
CStringArray* pItem;
|
|
|
|
iItemIndex = GetListCtrl().GetNextItem(-1, LVNI_FOCUSED);
|
|
if (iItemIndex > -1)
|
|
{
|
|
pItem = (CStringArray*) GetListCtrl().GetItemData(iItemIndex);
|
|
TryToCall(pItem->GetAt(22), pItem->GetAt(1)+' '+pItem->GetAt(0));
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnUpdateDialPager(CCmdUI* pCmdUI)
|
|
{
|
|
pCmdUI->Enable(GetListCtrl().GetNextItem(-1,LVNI_FOCUSED) > -1);
|
|
}
|
|
|
|
void CCB32View::OnDialFax()
|
|
{
|
|
int iItemIndex;
|
|
CStringArray* pItem;
|
|
|
|
iItemIndex = GetListCtrl().GetNextItem(-1, LVNI_FOCUSED);
|
|
if (iItemIndex > -1)
|
|
{
|
|
pItem = (CStringArray*) GetListCtrl().GetItemData(iItemIndex);
|
|
TryToCall(pItem->GetAt(25), pItem->GetAt(1)+' '+pItem->GetAt(0));
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnUpdateDialFax(CCmdUI* pCmdUI)
|
|
{
|
|
pCmdUI->Enable(GetListCtrl().GetNextItem(-1,LVNI_FOCUSED) > -1);
|
|
}
|
|
|
|
void CCB32View::OnDialCell()
|
|
{
|
|
int iItemIndex;
|
|
CStringArray* pItem;
|
|
|
|
iItemIndex = GetListCtrl().GetNextItem(-1, LVNI_FOCUSED);
|
|
if (iItemIndex > -1)
|
|
{
|
|
pItem = (CStringArray*) GetListCtrl().GetItemData(iItemIndex);
|
|
TryToCall(pItem->GetAt(20), pItem->GetAt(1)+' '+pItem->GetAt(0));
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnUpdateDialCell(CCmdUI* pCmdUI)
|
|
{
|
|
pCmdUI->Enable(GetListCtrl().GetNextItem(-1,LVNI_FOCUSED) > -1);
|
|
}
|
|
|
|
void CCB32View::TryToCall(CString& dialme, CString myname)
|
|
{
|
|
if (!dialme.IsEmpty())
|
|
tapiRequestMakeCall(dialme,"",myname,"");
|
|
else
|
|
{
|
|
CGetNew getnew;
|
|
getnew.m_addinfo = theApp.GetProfileInt(_T("Preferences"),
|
|
_T("AddNewInfo"),1);
|
|
|
|
if (getnew.DoModal()==IDOK)
|
|
{
|
|
theApp.WriteProfileInt(_T("Preferences"),
|
|
_T("AddNewInfo"),getnew.m_addinfo);
|
|
|
|
if (!getnew.m_newinfo.IsEmpty())
|
|
{
|
|
if (getnew.m_addinfo)
|
|
dialme = getnew.m_newinfo;
|
|
|
|
tapiRequestMakeCall(getnew.m_newinfo,NULL,myname,NULL);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
// Email and Web functions
|
|
|
|
void CCB32View::OnEmailAdd1()
|
|
{
|
|
int iItemIndex;
|
|
CStringArray* pItem;
|
|
|
|
iItemIndex = GetListCtrl().GetNextItem(-1, LVNI_FOCUSED);
|
|
if (iItemIndex > -1)
|
|
{
|
|
pItem = (CStringArray*) GetListCtrl().GetItemData(iItemIndex);
|
|
TryToLaunch(pItem->GetAt(27),"mailto:");
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnUpdateEmailAdd1(CCmdUI* pCmdUI)
|
|
{
|
|
pCmdUI->Enable(GetListCtrl().GetNextItem(-1,LVNI_FOCUSED) > -1);
|
|
}
|
|
|
|
|
|
void CCB32View::OnEmailAdd2()
|
|
{
|
|
int iItemIndex;
|
|
CStringArray* pItem;
|
|
|
|
iItemIndex = GetListCtrl().GetNextItem(-1, LVNI_FOCUSED);
|
|
if (iItemIndex > -1)
|
|
{
|
|
pItem = (CStringArray*) GetListCtrl().GetItemData(iItemIndex);
|
|
TryToLaunch(pItem->GetAt(28),"mailto:");
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnUpdateEmailAdd2(CCmdUI* pCmdUI)
|
|
{
|
|
pCmdUI->Enable(GetListCtrl().GetNextItem(-1,LVNI_FOCUSED) > -1);
|
|
}
|
|
|
|
void CCB32View::OnUrl1()
|
|
{
|
|
int iItemIndex;
|
|
CStringArray* pItem;
|
|
|
|
iItemIndex = GetListCtrl().GetNextItem(-1, LVNI_FOCUSED);
|
|
if (iItemIndex > -1)
|
|
{
|
|
pItem = (CStringArray*) GetListCtrl().GetItemData(iItemIndex);
|
|
TryToLaunch(pItem->GetAt(29),"http://");
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnUpdateUrl1(CCmdUI* pCmdUI)
|
|
{
|
|
pCmdUI->Enable(GetListCtrl().GetNextItem(-1,LVNI_FOCUSED) > -1);
|
|
}
|
|
|
|
void CCB32View::OnUrl2()
|
|
{
|
|
int iItemIndex;
|
|
CStringArray* pItem;
|
|
|
|
iItemIndex = GetListCtrl().GetNextItem(-1, LVNI_FOCUSED);
|
|
if (iItemIndex > -1)
|
|
{
|
|
pItem = (CStringArray*) GetListCtrl().GetItemData(iItemIndex);
|
|
TryToLaunch(pItem->GetAt(30),"http://");
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnUpdateUrl2(CCmdUI* pCmdUI)
|
|
{
|
|
pCmdUI->Enable(GetListCtrl().GetNextItem(-1,LVNI_FOCUSED) > -1);
|
|
}
|
|
|
|
void CCB32View::TryToLaunch(CString& launchme, CString prefix)
|
|
{
|
|
if (!launchme.IsEmpty())
|
|
{
|
|
if (launchme.Find(prefix) == -1)
|
|
LaunchShortcut(prefix+launchme);
|
|
else
|
|
LaunchShortcut(launchme);
|
|
}
|
|
else
|
|
{
|
|
CGetNew getnew;
|
|
getnew.m_addinfo = theApp.GetProfileInt(_T("Preferences"),
|
|
_T("AddNewInfo"),1);
|
|
|
|
if (getnew.DoModal()==IDOK)
|
|
{
|
|
theApp.WriteProfileInt(_T("Preferences"),
|
|
_T("AddNewInfo"),getnew.m_addinfo);
|
|
|
|
if (!getnew.m_newinfo.IsEmpty())
|
|
{
|
|
if (getnew.m_addinfo)
|
|
launchme = getnew.m_newinfo;
|
|
|
|
if (getnew.m_newinfo.Find(prefix) == -1)
|
|
LaunchShortcut(prefix+getnew.m_newinfo);
|
|
else
|
|
LaunchShortcut(getnew.m_newinfo);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void CCB32View::LaunchShortcut(CString str_url)
|
|
{
|
|
CStdioFile outFile;
|
|
CFileException e;
|
|
|
|
if (!outFile.Open("CBLaunch.url", CFile::modeCreate | CFile::modeWrite |
|
|
CFile::shareDenyRead | CFile::shareDenyWrite |
|
|
CFile::typeText, &e))
|
|
{
|
|
AfxThrowFileException(e.m_cause, e.m_lOsError);
|
|
return;
|
|
}
|
|
outFile.WriteString("[InternetShortcut]\n");
|
|
outFile.WriteString("URL="+str_url+"\n");
|
|
outFile.Close();
|
|
ShellExecute((HWND)AfxGetMainWnd(),"open","CBLaunch.url",NULL,
|
|
NULL,SW_SHOWDEFAULT);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Preferences implementation
|
|
void CCB32View::OnAppPrefs()
|
|
{
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
CPrefPage prefpage(IDS_PREFS);
|
|
prefpage.m_psh.dwFlags |= PSH_NOAPPLYNOW;
|
|
prefpage.AddCtrlPages();
|
|
|
|
prefpage.m_prefset.m_setlastfile = theApp.GetProfileInt(_T("Preferences"),_T("UseLastBook"),1);
|
|
prefpage.m_prefset.m_setsort = theApp.GetProfileInt(_T("Preferences"),_T("RememberSort"),1);
|
|
prefpage.m_prefset.m_setcol = theApp.GetProfileInt(_T("Preferences"),_T("RememberCol"),1);
|
|
prefpage.m_prefset.m_setpos = theApp.GetProfileInt(_T("Preferences"),_T("RememberPos"),1);
|
|
prefpage.m_prefset.m_setexp = theApp.GetProfileInt(_T("Preferences"),_T("RememberExp"),1);
|
|
prefpage.m_prefset.m_setimp = theApp.GetProfileInt(_T("Preferences"),_T("RememberImp"),1);
|
|
prefpage.m_prefset.m_setwin = theApp.GetProfileInt(_T("Preferences"),_T("RememberWin"),1);
|
|
prefpage.m_prefset.m_settray = theApp.GetProfileInt(_T("Preferences"),_T("RememberTray"),1);
|
|
prefpage.m_prefset.m_setstart = theApp.GetProfileInt(_T("Preferences"),_T("StartMinimized"),0);
|
|
prefpage.m_prefset.m_setusemru = theApp.GetProfileInt(_T("Preferences"),_T("UseMRU"),1);
|
|
prefpage.m_prefset.m_setmru = theApp.GetProfileInt(_T("Preferences"),_T("NumMRU"),2);
|
|
prefpage.m_prefset.m_setcity = theApp.GetProfileString(_T("Preferences"),_T("DefaultCity"),NULL);
|
|
prefpage.m_prefset.m_setcountry = theApp.GetProfileString(_T("Preferences"),_T("DefaultCountry"),NULL);
|
|
prefpage.m_prefset.m_setcomp = theApp.GetProfileString(_T("Preferences"),_T("DefaultComp"),NULL);
|
|
prefpage.m_prefset.m_setemail = theApp.GetProfileString(_T("Preferences"),_T("DefaultEmail"),NULL);
|
|
prefpage.m_prefset.m_setprefix = theApp.GetProfileString(_T("Preferences"),_T("DefaultPrefix"),NULL);
|
|
prefpage.m_prefset.m_setstate = theApp.GetProfileString(_T("Preferences"),_T("DefaultState"),NULL);
|
|
prefpage.m_prefset.m_setweb = theApp.GetProfileString(_T("Preferences"),_T("DefaultWeb"),"http://");
|
|
prefpage.m_prefset.m_setzip = theApp.GetProfileString(_T("Preferences"),_T("DefaultZip"),NULL);
|
|
prefpage.m_prefset.m_setdelete = theApp.GetProfileInt(_T("Preferences"),_T("ConfirmDelete"),1);
|
|
|
|
prefpage.m_prefcol.m_clname = ctlList.GetColumnWidth(0);
|
|
prefpage.m_prefcol.m_cfname = ctlList.GetColumnWidth(1);
|
|
prefpage.m_prefcol.m_cmi = ctlList.GetColumnWidth(2);
|
|
prefpage.m_prefcol.m_ctitle = ctlList.GetColumnWidth(3);
|
|
prefpage.m_prefcol.m_cadd1 = ctlList.GetColumnWidth(4);
|
|
prefpage.m_prefcol.m_cadd2 = ctlList.GetColumnWidth(5);
|
|
prefpage.m_prefcol.m_ccity = ctlList.GetColumnWidth(6);
|
|
prefpage.m_prefcol.m_ccountry = ctlList.GetColumnWidth(7);
|
|
prefpage.m_prefcol.m_cstate = ctlList.GetColumnWidth(8);
|
|
prefpage.m_prefcol.m_czip = ctlList.GetColumnWidth(9);
|
|
|
|
prefpage.m_prefcol.m_ccomp = ctlList.GetColumnWidth(10);
|
|
prefpage.m_prefcol.m_cdept = ctlList.GetColumnWidth(11);
|
|
prefpage.m_prefcol.m_cposn = ctlList.GetColumnWidth(12);
|
|
prefpage.m_prefcol.m_cmgr = ctlList.GetColumnWidth(13);
|
|
prefpage.m_prefcol.m_ccadd1 = ctlList.GetColumnWidth(14);
|
|
prefpage.m_prefcol.m_ccadd2 = ctlList.GetColumnWidth(15);
|
|
|
|
prefpage.m_prefcol.m_chomep = ctlList.GetColumnWidth(16);
|
|
prefpage.m_prefcol.m_chomepx = ctlList.GetColumnWidth(17);
|
|
prefpage.m_prefcol.m_cworkp = ctlList.GetColumnWidth(18);
|
|
prefpage.m_prefcol.m_cworkpx = ctlList.GetColumnWidth(19);
|
|
prefpage.m_prefcol.m_ccell = ctlList.GetColumnWidth(20);
|
|
prefpage.m_prefcol.m_ccellx = ctlList.GetColumnWidth(21);
|
|
prefpage.m_prefcol.m_cpager = ctlList.GetColumnWidth(22);
|
|
prefpage.m_prefcol.m_cpagerc = ctlList.GetColumnWidth(23);
|
|
prefpage.m_prefcol.m_cpagerx = ctlList.GetColumnWidth(24);
|
|
prefpage.m_prefcol.m_cfax = ctlList.GetColumnWidth(25);
|
|
prefpage.m_prefcol.m_cfaxx = ctlList.GetColumnWidth(26);
|
|
|
|
prefpage.m_prefcol.m_cemail1 = ctlList.GetColumnWidth(27);
|
|
prefpage.m_prefcol.m_cemail2 = ctlList.GetColumnWidth(28);
|
|
prefpage.m_prefcol.m_cweb1 = ctlList.GetColumnWidth(29);
|
|
prefpage.m_prefcol.m_cweb2 = ctlList.GetColumnWidth(30);
|
|
prefpage.m_prefcol.m_cnotes = ctlList.GetColumnWidth(31);
|
|
|
|
if (prefpage.DoModal()==IDOK)
|
|
{
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("UseLastBook"),
|
|
prefpage.m_prefset.m_setlastfile);
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("RememberSort"),
|
|
prefpage.m_prefset.m_setsort);
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("RememberCol"),
|
|
prefpage.m_prefset.m_setcol);
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("RememberPos"),
|
|
prefpage.m_prefset.m_setpos);
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("RememberExp"),
|
|
prefpage.m_prefset.m_setexp);
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("RememberImp"),
|
|
prefpage.m_prefset.m_setimp);
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("RememberWin"),
|
|
prefpage.m_prefset.m_setwin);
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("RememberTray"),
|
|
prefpage.m_prefset.m_settray);
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("StartMinimized"),
|
|
prefpage.m_prefset.m_setstart);
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("UseMRU"),
|
|
prefpage.m_prefset.m_setusemru);
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("NumMRU"),
|
|
prefpage.m_prefset.m_setmru);
|
|
theApp.WriteProfileString(_T("Preferences"),_T("DefaultCity"),
|
|
prefpage.m_prefset.m_setcity);
|
|
theApp.WriteProfileString(_T("Preferences"),_T("DefaultCountry"),
|
|
prefpage.m_prefset.m_setcountry);
|
|
theApp.WriteProfileString(_T("Preferences"),_T("DefaultComp"),
|
|
prefpage.m_prefset.m_setcomp);
|
|
theApp.WriteProfileString(_T("Preferences"),_T("DefaultEmail"),
|
|
prefpage.m_prefset.m_setemail);
|
|
theApp.WriteProfileString(_T("Preferences"),_T("DefaultPrefix"),
|
|
prefpage.m_prefset.m_setprefix);
|
|
theApp.WriteProfileString(_T("Preferences"),_T("DefaultState"),
|
|
prefpage.m_prefset.m_setstate);
|
|
theApp.WriteProfileString(_T("Preferences"),_T("DefaultWeb"),
|
|
prefpage.m_prefset.m_setweb);
|
|
theApp.WriteProfileString(_T("Preferences"),_T("DefaultZip"),
|
|
prefpage.m_prefset.m_setzip);
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("ConfirmDelete"),
|
|
prefpage.m_prefset.m_setdelete);
|
|
|
|
if (prefpage.m_prefset.m_setcol == 1)
|
|
{
|
|
ctlList.SetRedraw(FALSE);
|
|
|
|
ctlList.SetColumnWidth(0,prefpage.m_prefcol.m_clname);
|
|
ctlList.SetColumnWidth(1,prefpage.m_prefcol.m_cfname);
|
|
ctlList.SetColumnWidth(2,prefpage.m_prefcol.m_cmi);
|
|
ctlList.SetColumnWidth(3,prefpage.m_prefcol.m_ctitle);
|
|
ctlList.SetColumnWidth(4,prefpage.m_prefcol.m_cadd1);
|
|
ctlList.SetColumnWidth(5,prefpage.m_prefcol.m_cadd2);
|
|
ctlList.SetColumnWidth(6,prefpage.m_prefcol.m_ccity);
|
|
ctlList.SetColumnWidth(7,prefpage.m_prefcol.m_ccountry);
|
|
ctlList.SetColumnWidth(8,prefpage.m_prefcol.m_cstate);
|
|
ctlList.SetColumnWidth(9,prefpage.m_prefcol.m_czip);
|
|
|
|
ctlList.SetColumnWidth(10,prefpage.m_prefcol.m_ccomp);
|
|
ctlList.SetColumnWidth(11,prefpage.m_prefcol.m_cdept);
|
|
ctlList.SetColumnWidth(12,prefpage.m_prefcol.m_cposn);
|
|
ctlList.SetColumnWidth(13,prefpage.m_prefcol.m_cmgr);
|
|
ctlList.SetColumnWidth(14,prefpage.m_prefcol.m_ccadd1);
|
|
ctlList.SetColumnWidth(15,prefpage.m_prefcol.m_ccadd2);
|
|
|
|
ctlList.SetColumnWidth(16,prefpage.m_prefcol.m_chomep);
|
|
ctlList.SetColumnWidth(17,prefpage.m_prefcol.m_chomepx);
|
|
ctlList.SetColumnWidth(18,prefpage.m_prefcol.m_cworkp);
|
|
ctlList.SetColumnWidth(19,prefpage.m_prefcol.m_cworkpx);
|
|
ctlList.SetColumnWidth(20,prefpage.m_prefcol.m_ccell);
|
|
ctlList.SetColumnWidth(21,prefpage.m_prefcol.m_ccellx);
|
|
ctlList.SetColumnWidth(22,prefpage.m_prefcol.m_cpager);
|
|
ctlList.SetColumnWidth(23,prefpage.m_prefcol.m_cpagerc);
|
|
ctlList.SetColumnWidth(24,prefpage.m_prefcol.m_cpagerx);
|
|
ctlList.SetColumnWidth(25,prefpage.m_prefcol.m_cfax);
|
|
ctlList.SetColumnWidth(26,prefpage.m_prefcol.m_cfaxx);
|
|
|
|
ctlList.SetColumnWidth(27,prefpage.m_prefcol.m_cemail1);
|
|
ctlList.SetColumnWidth(28,prefpage.m_prefcol.m_cemail2);
|
|
ctlList.SetColumnWidth(29,prefpage.m_prefcol.m_cweb1);
|
|
ctlList.SetColumnWidth(30,prefpage.m_prefcol.m_cweb2);
|
|
ctlList.SetColumnWidth(31,prefpage.m_prefcol.m_cnotes);
|
|
|
|
CString strCols, strTemp;
|
|
strCols.Format("%d",ctlList.GetColumnWidth(0));
|
|
for (int i=1;i<COLS;i++)
|
|
{
|
|
strTemp.Format("%d",ctlList.GetColumnWidth(i));
|
|
strCols += ',' + strTemp;
|
|
}
|
|
theApp.WriteProfileString(_T("Columns"),_T("Sizes"),strCols);
|
|
|
|
SetupColumns();
|
|
|
|
ctlList.SetRedraw(TRUE);
|
|
ctlList.Invalidate();
|
|
}
|
|
}
|
|
}
|
|
|
|
void CCB32View::OnTbarDial()
|
|
{
|
|
// TODO: Add your command handler code here
|
|
|
|
}
|
|
|
|
void CCB32View::OnUpdateTbarDial(CCmdUI* pCmdUI)
|
|
{
|
|
// TODO: Add your command update UI handler code here
|
|
|
|
}
|
|
|
|
void CCB32View::OnTbarEmail()
|
|
{
|
|
// TODO: Add your command handler code here
|
|
|
|
}
|
|
|
|
void CCB32View::OnUpdateTbarEmail(CCmdUI* pCmdUI)
|
|
{
|
|
// TODO: Add your command update UI handler code here
|
|
|
|
}
|
|
|
|
void CCB32View::OnTbarWeb()
|
|
{
|
|
// TODO: Add your command handler code here
|
|
|
|
}
|
|
|
|
void CCB32View::OnUpdateTbarWeb(CCmdUI* pCmdUI)
|
|
{
|
|
// TODO: Add your command update UI handler code here
|
|
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Column Dragging implementation
|
|
|
|
void CCB32View::DragColumn(int source, int dest)
|
|
{
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
TCHAR sColText[160];
|
|
|
|
// Insert a column at dest
|
|
LV_COLUMN lv_col;
|
|
lv_col.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
|
|
lv_col.pszText = sColText;
|
|
lv_col.cchTextMax = 159;
|
|
|
|
// Remember which column was sorted
|
|
int iSortCol = 0;
|
|
ctlList.GetColumn(nSortedCol, &lv_col);
|
|
for (int z=0; z<COLS; z++)
|
|
{
|
|
if (lv_col.pszText == arLabel[z])
|
|
{
|
|
iSortCol = z;
|
|
z = COLS;
|
|
}
|
|
}
|
|
|
|
ctlList.GetColumn( source, &lv_col );
|
|
lv_col.iSubItem = dest;
|
|
ctlList.InsertColumn( dest, &lv_col );
|
|
|
|
// Adjust source col number since it might have changed�
|
|
// because a new column was inserted
|
|
if (source > dest)
|
|
source++;
|
|
|
|
// Moving a col to position 0 is a special case
|
|
if (dest == 0)
|
|
for( int i = ctlList.GetItemCount()-1; i > -1 ; i-- )
|
|
ctlList.SetItemText(i, 1, ctlList.GetItemText( i, 0) );
|
|
|
|
// Copy sub item from source to dest
|
|
for( int i = ctlList.GetItemCount()-1; i > -1 ; i-- )
|
|
ctlList.SetItemText(i, dest, ctlList.GetItemText( i, source ) );
|
|
|
|
// Delete the source column, but not if it is the first
|
|
if( source != 0 )
|
|
ctlList.DeleteColumn( source );
|
|
else
|
|
{
|
|
// If source col is 0, then copy col# 1 to col#0
|
|
// and then delete col# 1
|
|
ctlList.GetColumn( 1, &lv_col );
|
|
lv_col.iSubItem = 0;
|
|
ctlList.SetColumn( 0, &lv_col );
|
|
for( int i = ctlList.GetItemCount()-1; i > -1 ; i-- )
|
|
ctlList.SetItemText(i, 0, ctlList.GetItemText( i, 1) );
|
|
ctlList.DeleteColumn( 1 );
|
|
}
|
|
|
|
Invalidate();
|
|
|
|
// Resort columns
|
|
for (int y=0; y<COLS; y++)
|
|
{
|
|
ctlList.GetColumn(y, &lv_col);
|
|
if (lv_col.pszText == arLabel[iSortCol])
|
|
{
|
|
nSortedCol = y;
|
|
y = COLS;
|
|
}
|
|
}
|
|
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberSort"),1))
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("SortIndex"),nSortedCol);
|
|
|
|
SortDatabase();
|
|
SaveColPos();
|
|
}
|
|
|
|
void CCB32View::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
|
|
{
|
|
int iItemIndex;
|
|
UINT nState = LVIS_SELECTED | LVIS_FOCUSED;
|
|
UINT nMask = LVIS_SELECTED | LVIS_FOCUSED;
|
|
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
|
|
// only change sort direction if same column clicked
|
|
if (nSortedCol == pNMListView->iSubItem)
|
|
bSortAscending = !bSortAscending;
|
|
|
|
nSortedCol = pNMListView->iSubItem;
|
|
|
|
// convert column click to contents index
|
|
LV_COLUMN lvc;
|
|
int iSortCol = nSortedCol; // pNMListView->iSubItem;
|
|
TCHAR sColText[160];
|
|
lvc.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT;
|
|
lvc.pszText = sColText;
|
|
lvc.cchTextMax = 159;
|
|
ctlList.GetColumn(iSortCol, &lvc);
|
|
for (int z = 0; z < COLS; z++)
|
|
{
|
|
if (lvc.pszText == arLabel[z])
|
|
{
|
|
iSortCol = z;
|
|
break;
|
|
}
|
|
}
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("SortDirection"),bSortAscending);
|
|
|
|
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberSort"),1))
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("SortIndex"),nSortedCol);
|
|
|
|
m_headerctrl.SetSortImage(nSortedCol, bSortAscending);
|
|
if (bSortAscending)
|
|
ctlList.SortItems(CompareFuncAsc, iSortCol);
|
|
else
|
|
ctlList.SortItems(CompareFuncDec, iSortCol);
|
|
|
|
iItemIndex = ctlList.GetNextItem(-1, LVNI_FOCUSED);
|
|
if (iItemIndex > -1)
|
|
{
|
|
GetParentFrame()->ActivateFrame();
|
|
ctlList.EnsureVisible(iItemIndex, FALSE);
|
|
ctlList.SetItemState(iItemIndex, nState, nMask);
|
|
ctlList.SetRedraw(TRUE);
|
|
ctlList.Invalidate();
|
|
}
|
|
|
|
*pResult = 0;
|
|
}
|
|
|
|
void CCB32View::SaveColPos()
|
|
{
|
|
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberPos"),1))
|
|
{
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
|
|
int colpos[COLS];
|
|
for (int p=0; p<COLS; p++)
|
|
colpos[p] = p;
|
|
|
|
// convert column to contents index
|
|
for (int y = 0; y<COLS; y++)
|
|
{
|
|
LV_COLUMN lvc;
|
|
TCHAR sColText[160];
|
|
lvc.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT;
|
|
lvc.pszText = sColText;
|
|
lvc.cchTextMax = 159;
|
|
ctlList.GetColumn(y, &lvc);
|
|
for (int z = 0; z < COLS; z++)
|
|
{
|
|
if (lvc.pszText == arLabel[z])
|
|
{
|
|
colpos[y] = z;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
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);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
void CCB32View::SetupColumns()
|
|
{
|
|
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
|
|
TCHAR sColText[160];
|
|
|
|
// Remember which column was sorted
|
|
LV_COLUMN lv_col;
|
|
lv_col.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
|
|
lv_col.pszText = sColText;
|
|
lv_col.cchTextMax = 159;
|
|
int iSortCol = 0;
|
|
ctlList.GetColumn(nSortedCol, &lv_col);
|
|
for (int z=0; z<COLS; z++)
|
|
{
|
|
if (lv_col.pszText == arLabel[z])
|
|
{
|
|
iSortCol = z;
|
|
z = COLS;
|
|
}
|
|
}
|
|
|
|
// delete all the columns
|
|
while (ctlList.GetColumn(0, &lv_col))
|
|
ctlList.DeleteColumn(0);
|
|
|
|
int colsize[COLS] = {100,100,40,40,170,170,110,90,60,100,
|
|
100,100,100,100,100,100,
|
|
120,60,120,60,120,60,120,120,60,120,60,
|
|
200,200,280,280,280};
|
|
|
|
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberCol"),1))
|
|
{
|
|
CString strBuffer = theApp.GetProfileString(_T("Columns"),_T("Sizes"));
|
|
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++)
|
|
colsize[z]=tempcol[z];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Setup column positions
|
|
int colpos[COLS];
|
|
for (int p=0; p<COLS; p++)
|
|
colpos[p] = p;
|
|
|
|
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberPos"),1))
|
|
{
|
|
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];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add columns to list view
|
|
for (int i=0; i < COLS; i++)
|
|
ctlList.InsertColumn(i, arLabel[colpos[i]], LVCFMT_LEFT, colsize[i]);
|
|
|
|
// Resort columns
|
|
for (int y=0; y<COLS; y++)
|
|
{
|
|
ctlList.GetColumn(y, &lv_col);
|
|
if (lv_col.pszText == arLabel[iSortCol])
|
|
{
|
|
nSortedCol = y;
|
|
y = COLS;
|
|
}
|
|
}
|
|
if (theApp.GetProfileInt(_T("Preferences"),_T("RememberSort"),1))
|
|
theApp.WriteProfileInt(_T("Preferences"),_T("SortIndex"),nSortedCol);
|
|
|
|
SortDatabase();
|
|
}
|