// CB32View.cpp : implementation of the CCB32View class // #include "stdafx.h" #ifndef TAPI_CURRENT_VERSION #define TAPI_CURRENT_VERSION 0x00010004 #endif #include #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" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define HEADER_HEIGHT 2 #define FOOTER_HEIGHT 2 #define LEFT_MARGIN 4 #define RIGHT_MARGIN 4 #define TOP_MARGIN 1 #define BOTTOM_MARGIN 1 #define GAP 1 #define HIGHLIGHT_NORMAL 1 #define HIGHLIGHT_ALLCOLUMNS 2 #define HIGHLIGHT_ROW 3 ///////////////////////////////////////////////////////////////////////////// // 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) //}}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); // TODO: add draw code for native data here } 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; nColumnGetAt(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) { CListCtrl& ctlList = (CListCtrl&) GetListCtrl(); TEXTMETRIC tm; CDC *pCurrentDC; // OnBeginPrinting() is called after the user has committed to // printing by OK'ing the Print dialog, and after the framework // has created a CDC object for the printer or the preview view. // This is the right opportunity to set up the page range. // Given the CDC object, we can determine how many rows will // fit on a page, so we can in turn determine how many printed // pages represent the entire document. ASSERT(pDC && pInfo); if (!pDC || !pInfo) return; int nMaxRowCount = ctlList.GetItemCount(); if (!nMaxRowCount) return; // Get a DC for the current window (will be a screen DC for print previewing) VERIFY(pCurrentDC = GetDC()); /* will have dimensions of the client area */ if (!pCurrentDC) return; CSize PaperPixelsPerInch(pDC->GetDeviceCaps(LOGPIXELSX), pDC->GetDeviceCaps(LOGPIXELSY)); CSize ScreenPixelsPerInch(pCurrentDC->GetDeviceCaps(LOGPIXELSX), pCurrentDC->GetDeviceCaps(LOGPIXELSY)); // Create the printer font int nFontSize = -9; CString strFontName = _T("Times New Roman"); nFontSize = MulDiv(nFontSize, PaperPixelsPerInch.cy, ScreenPixelsPerInch.cy); m_PrinterFont.CreateFont(nFontSize, 0,0,0, FW_NORMAL, 0,0,0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, strFontName); CFont *pOldFont = pDC->SelectObject(&m_PrinterFont); // Get the average character width (in ListCtrl units) pCurrentDC->GetTextMetrics(&tm); m_nCharWidth = tm.tmAveCharWidth; m_nCharWidth = MulDiv(m_nCharWidth, PaperPixelsPerInch.cy, ScreenPixelsPerInch.cy); int nMargins = (LEFT_MARGIN+RIGHT_MARGIN)*m_nCharWidth; // Scale the x axis to the ListCtrl's device units CRect rc; ctlList.GetItemRect(0, &rc, LVIR_BOUNDS); m_nRowHeight = rc.Height(); m_nRowHeight = MulDiv(m_nRowHeight, PaperPixelsPerInch.cy, ScreenPixelsPerInch.cy); // Get the page size CSize LogicalPageSize; CSize PaperSize(pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES)); LogicalPageSize.cx = rc.Width()+nMargins; LogicalPageSize.cy = MulDiv(LogicalPageSize.cx, PaperSize.cy, PaperSize.cx); pDC->SetMapMode(MM_ANISOTROPIC); pDC->SetWindowExt(LogicalPageSize); pDC->SetViewportExt(PaperSize); /* This should set the preview DC's extents so preview works. It don't work! :( if (pInfo->m_bPreview) { CSize PreviewPageSize = PaperSize; PreviewPageSize.cx = MulDiv(PaperSize.cx, ScreenPixelsPerInch.cx, PaperPixelsPerInch.cx); PreviewPageSize.cy = MulDiv(PaperSize.cy, ScreenPixelsPerInch.cy, PaperPixelsPerInch.cy); SetWindowExtEx(pDC->m_hAttribDC, LogicalPageSize.cx, LogicalPageSize.cy, NULL); SetViewportExtEx(pDC->m_hAttribDC, PreviewPageSize.cx, PreviewPageSize.cy, NULL); } */ // Calculate the number of rows per page m_nRowsPerPage = LogicalPageSize.cy / m_nRowHeight; m_nRowsPerPage -= (HEADER_HEIGHT+FOOTER_HEIGHT + 2*GAP); // Header and footer m_nRowsPerPage -= 1; // List control header int nMaxPage = nMaxRowCount/m_nRowsPerPage + 1; pInfo->SetMaxPage(nMaxPage); pInfo->m_nCurPage = 1; // start printing at page# 1 ReleaseDC(pCurrentDC); pDC->SelectObject(pOldFont); /* old code // OnBeginPrinting() is called after the user has committed to // printing by OK'ing the Print dialog, and after the framework // has created a CDC object for the printer or the preview view. // This is the right opportunity to set up the page range. // Given the CDC object, we can determine how many rows will // fit on a page, so we can in turn determine how many printed // pages represent the entire document. if(NULL == pDC || NULL == pInfo) return; int nMaxRowCount = ctlList.GetItemCount(); if(!nMaxRowCount) return; //let us do all dimesions in ListControl units (Device) rather than //printer device units. Since we have more control on them CDC *pCtlDC = GetDC(); if(NULL == pCtlDC) return; TEXTMETRIC tm; pCtlDC->GetTextMetrics(&tm); m_nCharWidth = tm.tmAveCharWidth; pDC->SetMapMode(MM_ANISOTROPIC); CRect rc; ctlList.GetItemRect(0, &rc, LVIR_BOUNDS); m_nRowHeight = rc.Height(); int nMargins = (LEFT_MARGIN+RIGHT_MARGIN)*m_nCharWidth; //this will optimize the column widths. If we have more column than //screen width and horizontal scroll on List control //this will reduce the column widths proportonately to fit all of them //on the page. If we have fewer column all the column //widths will increased propertionately. pDC->SetWindowExt(rc.Width() + nMargins, pCtlDC->GetDeviceCaps(LOGPIXELSX)); pDC->SetViewportExt(pDC->GetDeviceCaps(HORZRES),pDC->GetDeviceCaps(LOGPIXELSX)); double d = (double)pDC->GetDeviceCaps(LOGPIXELSY)/(double)pCtlDC->GetDeviceCaps(LOGPIXELSY); ReleaseDC(pCtlDC); nMargins = (int)(m_nRowHeight*d); int nPageHeight = pDC->GetDeviceCaps(VERTRES); m_nRowsPerPage = nPageHeight/nMargins; //nMargins reused m_nRowsPerPage -= (HEADER_HEIGHT+FOOTER_HEIGHT); m_nRowsPerPage -= 1; //adjustment for list control header int nMaxPage = nMaxRowCount/m_nRowsPerPage + 1; pInfo->SetMaxPage(nMaxPage); pInfo->m_nCurPage = 1; // start printing at page# 1 */ // old code } void CCB32View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { m_PrinterFont.DeleteObject(); } void CCB32View::OnPrint(CDC* pDC, CPrintInfo* pInfo) { CListCtrl& ctlList = (CListCtrl&) GetListCtrl(); if (!pDC || !pInfo) return; CFont *pOldFont = pDC->SelectObject(&m_PrinterFont); // Draw as many rows as will fit on the printed page. // Clip the printed page so that there is no partially shown // row at the bottom of the page (the same row which will be fully // shown at the top of the next page). int nStartRow = 0; int nEndRow = 0; int nMaxRowCount = ctlList.GetItemCount(); nStartRow = (pInfo->m_nCurPage - 1)*m_nRowsPerPage; nEndRow = nStartRow+m_nRowsPerPage; if(nEndRow > nMaxRowCount) nEndRow = nMaxRowCount; pDC->SetWindowOrg(-LEFT_MARGIN*m_nCharWidth, 0); CRect rcPage(pInfo->m_rectDraw); // Header pInfo->m_rectDraw.top = 0; pInfo->m_rectDraw.left = 0; pInfo->m_rectDraw.right = rcPage.right - (LEFT_MARGIN+RIGHT_MARGIN)*m_nCharWidth; pInfo->m_rectDraw.bottom = HEADER_HEIGHT*m_nRowHeight; PrintHeader(pDC, pInfo); pDC->OffsetWindowOrg(0, -HEADER_HEIGHT*m_nRowHeight); // Gap between header and List control heading pDC->OffsetWindowOrg(0, -GAP*m_nRowHeight); // Print the header control. CRect HeaderCtrlrc; m_headerctrl.GetClientRect(&HeaderCtrlrc); pInfo->m_rectDraw.bottom = HeaderCtrlrc.Height(); PrintColumnHeadings(pDC, pInfo); //pDC->OffsetWindowOrg(0, -HeaderCtrlrc.Height()); // Print the list control DRAWITEMSTRUCT DrawItemStruct; DrawItemStruct.hDC = pDC->m_hDC; for(int i = nStartRow; i < nEndRow; i++) { DrawItemStruct.itemID = i; DrawItem(&DrawItemStruct); } // Footer pInfo->m_rectDraw.bottom = FOOTER_HEIGHT*m_nRowHeight; pDC->SetWindowOrg(-LEFT_MARGIN*m_nCharWidth, -rcPage.bottom + pInfo->m_rectDraw.bottom); PrintFooter(pDC, pInfo); // SetWindowOrg back for next page pDC->SetWindowOrg(0,0); pDC->SelectObject(pOldFont); /* old code if(NULL == pDC || NULL == pInfo) return; // Draw as many rows as will fit on the printed page. // Clip the printed page so that there is no partially shown // row at the bottom of the page (the same row which will be fully // shown at the top of the next page). int nStartRow = 0; int nEndRow = 0; int nMaxRowCount = ctlList.GetItemCount(); nStartRow = (pInfo->m_nCurPage - 1)*m_nRowsPerPage; nEndRow = nStartRow+m_nRowsPerPage; if(nEndRow > nMaxRowCount) nEndRow = nMaxRowCount; //create bold font for header and footer CFont *pOldFont = NULL; CFont BoldFont; LOGFONT lf; pOldFont = GetFont(); pOldFont->GetLogFont(&lf); lf.lfWeight = FW_BOLD; BoldFont.CreateFontIndirect(&lf); pOldFont = pDC->SelectObject(&BoldFont); int nPrevBkMode = pDC->SetBkMode(TRANSPARENT); //print the header PrintHeader(pDC, pInfo); //Print the footer PrintFooter(pDC, pInfo); pDC->SetBkMode(nPrevBkMode); pDC->SelectObject(pOldFont); BoldFont.DeleteObject(); //Set origin to print header and Header control. Keep Y position at 0 to //print header information //Change Y position of origin to print List control header //Adjust the List control origin to start printing after page margins pDC->SetWindowOrg(-1*(LEFT_MARGIN*m_nCharWidth), -1*HEADER_HEIGHT*m_nRowHeight); //send a message to Header control to print itsef. There is little scope to improve printing header. //I have m_HeaderCtrl in my class. If not take by HeaderCtrl = GetDlgItem(0); m_headerctrl.SendMessage(WM_PAINT, (WPARAM)pDC->m_hDC); //Chage window position to take care of ListControl Horizontal scrolling. //if List control is scrolled to left horizontally the above window origin //will not start painting from first column, instead it starts painting from //first visible column, because rcBounds etc are will have -ve left value //Same thing with vertical scrolling also CRect rcBounds; ctlList.GetItemRect(nStartRow, &rcBounds, LVIR_BOUNDS); //offset top margin of rcBounds by ListControl header CRect rc; m_headerctrl.GetClientRect(&rc); rcBounds.OffsetRect(0, -rc.Height()); pDC->OffsetWindowOrg(rcBounds.left, rcBounds.top); //start printing rows for(int i = nStartRow; i < nEndRow; i++) DrawRow(pDC, i); //SetWindowOrg back for next page pDC->SetWindowOrg(0,0); return; */ // old code } void CCB32View::PrintColumnHeadings(CDC *pDC, CPrintInfo *pInfo) { CListCtrl& ctlList = (CListCtrl&) GetListCtrl(); int nColumns = m_headerctrl.GetItemCount(); //int nColumns = GetNumColumns(); //CHeaderCtrl *pHeader = GetHeaderCtrl(); int offset = pDC->GetTextExtent(_T(" "), 1 ).cx; CFont *pOldFont = pDC->SelectObject(&m_PrinterFont); // Get the bounds of the header control CRect rc; m_headerctrl.GetClientRect(rc); rc.bottom = m_nRowHeight; // Setup our HD_ITEM to get text, width and format TCHAR buf[256]; HD_ITEM hditem; hditem.mask = HDI_TEXT | HDI_FORMAT | HDI_WIDTH; hditem.pszText = buf; hditem.cchTextMax = 255; rc.right = 0; for (int i = 0; i < nColumns; i++) { // Get the column text and format and width m_headerctrl.GetItem(i, &hditem); //pHeader->GetItem(i, &hditem); rc.left = rc.right; rc.right += hditem.cxy; // Workout the justification for the column heading UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER; if (hditem.fmt & HDF_CENTER) uFormat |= DT_CENTER; else if( hditem.fmt & HDF_RIGHT) uFormat |= DT_RIGHT; else uFormat |= DT_LEFT; // Draw the column heading CRect rcLabel(rc); rcLabel.DeflateRect(offset, 0); pDC->DrawText(buf,-1, rcLabel, uFormat); } // Draw a border around the header control // NOTE: CDC::Rectangle doesn't draw to the edges of the bounding rectangle CBrush* pOldBrush = (CBrush*) pDC->SelectStockObject(NULL_BRUSH); CPen* pOldPen = (CPen*) pDC->SelectStockObject(BLACK_PEN); rc.left = 0; rc.right++; rc.bottom++; pDC->Rectangle(rc); pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); pDC->SelectObject(pOldFont); } void CCB32View::PrintHeader(CDC *pDC, CPrintInfo *pInfo) { CRect rc(pInfo->m_rectDraw); CString sTemp; CFont BoldFont; LOGFONT lf; //create bold font for header and footer m_PrinterFont.GetLogFont(&lf); lf.lfWeight = FW_BOLD; BoldFont.CreateFontIndirect(&lf); CFont *pNormalFont = pDC->SelectObject(&BoldFont); int nPrevBkMode = pDC->SetBkMode(TRANSPARENT); //print App title on top right margin sTemp.LoadString(AFX_IDS_APP_TITLE); pDC->DrawText(sTemp, &rc, DT_RIGHT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER); pDC->SetBkMode(nPrevBkMode); pDC->SelectObject(pNormalFont); BoldFont.DeleteObject(); pDC->MoveTo(rc.left, rc.bottom); pDC->LineTo(rc.right, rc.bottom); /* old code CRect rc(pInfo->m_rectDraw); CString sTemp; //Print App title rc.left += LEFT_MARGIN*m_nCharWidth; rc.right -= RIGHT_MARGIN*m_nCharWidth; rc.bottom = rc.top+m_nRowHeight; //print App title on top right margin sTemp.LoadString(AFX_IDS_APP_TITLE); pDC->DrawText(sTemp, &rc, DT_RIGHT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER); //print Header. One row for each string for (int pos = 0; posDrawText(sTemp, &rc, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER); rc.OffsetRect(0, m_nRowHeight); } */ // old code } //print footer with a line and date, and page number void CCB32View::PrintFooter(CDC *pDC, CPrintInfo *pInfo) { CRect rc(pInfo->m_rectDraw); CFont BoldFont; LOGFONT lf; //draw line pDC->MoveTo(rc.left, rc.top); pDC->LineTo(rc.right, rc.top); //create bold font for header and footer m_PrinterFont.GetLogFont(&lf); lf.lfWeight = FW_BOLD; BoldFont.CreateFontIndirect(&lf); CFont *pNormalFont = pDC->SelectObject(&BoldFont); int nPrevBkMode = pDC->SetBkMode(TRANSPARENT); //draw page number CString sTemp ; rc.OffsetRect(0, m_nRowHeight/2); sTemp.Format(IDS_PRINT_PAGE_TITLE, pInfo->m_nCurPage, pInfo->GetMaxPage()); pDC->DrawText(sTemp,-1,rc, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER); CTime t = CTime::GetCurrentTime(); sTemp = t.Format("%c"); pDC->DrawText(sTemp,-1,rc, DT_RIGHT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER); pDC->SetBkMode(nPrevBkMode); pDC->SelectObject(pNormalFont); BoldFont.DeleteObject(); /* old code CRect rc(pInfo->m_rectDraw); //draw line rc.left += LEFT_MARGIN*m_nCharWidth; rc.right -= RIGHT_MARGIN*m_nCharWidth; rc.top = rc.bottom - FOOTER_HEIGHT*m_nRowHeight; rc.bottom = rc.top + m_nRowHeight; pDC->MoveTo(rc.left, rc.top); pDC->LineTo(rc.right, rc.top); //draw page number CString sTemp ; rc.OffsetRect(0, m_nRowHeight/2); sTemp.Format(IDS_PRINT_PAGE_TITLE, pInfo->m_nCurPage); pDC->DrawText(sTemp,-1,rc, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER); CTime t = CTime::GetCurrentTime(); sTemp = t.Format("%c"); pDC->DrawText(sTemp,-1,rc, DT_RIGHT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER); */ // old code } //this is drawing code copied RowList sample and from www.codeguru.com site int CCB32View::DrawRow(CDC *pDC, int nItem) { CListCtrl& ctlList = (CListCtrl&) GetListCtrl(); CImageList *pImageList = NULL; CFont *pOldFont = NULL; CFont BoldFont; CString sLabel; UINT dtFlags = DT_SINGLELINE|DT_NOPREFIX|DT_VCENTER; int nSaveDC = pDC->SaveDC(); if(!pDC->IsPrinting()) dtFlags |= (DT_NOCLIP | DT_END_ELLIPSIS); //no clip because we add ellipsis at the end // get item data LV_ITEM lvi; lvi.mask = LVIF_IMAGE | LVIF_STATE | LVIF_INDENT; lvi.iItem=nItem; lvi.iSubItem=0; lvi.stateMask=0xFFFF; // get all state flags ctlList.GetItem(&lvi); BOOL bHighlight = ((lvi.state & LVIS_DROPHILITED) || ((lvi.state & LVIS_SELECTED) && ((GetFocus() == this) || (GetStyle() & LVS_SHOWSELALWAYS)))); //Get rectangles for painting CRect rcBounds, rcLabel, rcIcon; ctlList.GetItemRect(nItem, rcBounds, LVIR_BOUNDS); ctlList.GetItemRect(nItem, rcLabel, LVIR_LABEL); ctlList.GetItemRect(nItem, rcIcon, LVIR_ICON); CRect rcCol(rcBounds); CRect rcWnd; sLabel = ctlList.GetItemText(nItem, 0); //Label offset int offset = pDC->GetTextExtent(_T(" "), 1).cx; CRect rcHighlight; int nExt = 0; switch(m_nHighlight) { case HIGHLIGHT_NORMAL: nExt = pDC->GetOutputTextExtent(sLabel).cx + offset; rcHighlight = rcLabel; if(rcLabel.left + nExt < rcLabel.right) rcHighlight.right = rcLabel.left + nExt; break; case HIGHLIGHT_ALLCOLUMNS: rcHighlight = rcBounds; rcHighlight.left = rcLabel.left; break; case HIGHLIGHT_ROW: GetClientRect(&rcWnd); rcHighlight = rcBounds; rcHighlight.left = rcLabel.left; rcHighlight.right = rcWnd.right; break; default: rcHighlight.left = rcLabel.left; break; } //draw highlight. printing may not be required if(bHighlight) { pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT)); pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT)); pDC->FillRect(rcHighlight, &CBrush(::GetSysColor(COLOR_HIGHLIGHT))); } else { pDC->SetBkColor(::GetSysColor(COLOR_WINDOW)); pDC->FillRect(rcHighlight, &CBrush(::GetSysColor(COLOR_WINDOW))); } //set clip region rcCol.right = rcCol.left + ctlList.GetColumnWidth(0); //Nice to have regions but they are not working on printer DC we may need //to take get device caps to support regions. Does not seems to help much now //CRgn rgn; //rgn.CreateRectRgnIndirect(&rcCol); //pDC->SelectClipRgn(&rgn); //rgn.DeleteObject(); //Draw state icon if(lvi.state & LVIS_STATEIMAGEMASK) { int nImage = ((lvi.state & LVIS_STATEIMAGEMASK) >> 12) - 1; pImageList = ctlList.GetImageList(LVSIL_STATE); //offset the state image icon indent levels. nExt = rcCol.left + lvi.iIndent*rcIcon.Width(); //nExt reused if(pImageList) pImageList->Draw(pDC, nImage, CPoint(nExt, rcCol.top), ILD_TRANSPARENT); } //Draw Normal and overlay icon pImageList = ctlList.GetImageList(LVSIL_SMALL); //assuming printing in report mode only if(pImageList) { UINT nOvlImageMask = lvi.state & LVIS_OVERLAYMASK; pImageList->Draw(pDC, lvi.iImage, CPoint(rcIcon.left, rcIcon.top), (bHighlight?ILD_BLEND50:0)|ILD_TRANSPARENT|nOvlImageMask); } //if state image mask is on and indent is 0 then consider it as Server row if((lvi.state & LVIS_STATEIMAGEMASK) && !lvi.iIndent) { //create bold font LOGFONT lf; pOldFont = GetFont();; pOldFont->GetLogFont(&lf); lf.lfWeight = FW_BOLD; BoldFont.CreateFontIndirect(&lf); pOldFont = pDC->SelectObject(&BoldFont); rcLabel.right = rcBounds.right; //draw server name to full row width } //Draw item label rcLabel.left += offset/2; rcLabel.right -= offset; dtFlags |= DT_LEFT; pDC->DrawText(sLabel, rcLabel, dtFlags); if((lvi.state & LVIS_STATEIMAGEMASK) && !lvi.iIndent) { pOldFont = pDC->SelectObject(pOldFont); BoldFont.DeleteObject(); //focus rect if required if(lvi.state & LVIS_FOCUSED && (GetFocus() == this)) pDC->DrawFocusRect(rcHighlight); pDC->RestoreDC(nSaveDC); return 0; } //Draw labels for remaining columns LV_COLUMN lvc; lvc.mask = LVCF_FMT|LVCF_WIDTH; if(m_nHighlight == HIGHLIGHT_NORMAL) { pDC->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT)); pDC->SetBkColor(::GetSysColor(COLOR_WINDOW)); } rcBounds.right = rcHighlight.right > rcBounds.right ? rcHighlight.right:rcBounds.right; //Nice to have regions but they are not working on printer DC we may need //to take get device caps to support regions. Does not seems to help much now //rgn.CreateRectRgnIndirect(&rcBounds); //pDC->SelectClipRgn(&rgn); //rgn.DeleteObject(); for(int nColumn = 1; ctlList.GetColumn(nColumn, &lvc); nColumn++) { rcCol.left = rcCol.right; rcCol.right += lvc.cx; //draw background if needed if(m_nHighlight == HIGHLIGHT_NORMAL) pDC->FillRect(rcCol, &CBrush(::GetSysColor(COLOR_WINDOW))); sLabel = ctlList.GetItemText(nItem, nColumn); if(sLabel.IsEmpty()) continue; //Get the text justification UINT nJustify = DT_LEFT; switch(lvc.fmt & LVCFMT_JUSTIFYMASK) { case LVCFMT_RIGHT: nJustify = DT_RIGHT; break; case LVCFMT_CENTER: nJustify = DT_CENTER; break; default: break; } rcLabel = rcCol; rcLabel.left += offset; rcLabel.right -= offset; dtFlags &= ~DT_RIGHT; dtFlags &= ~DT_CENTER; dtFlags |= nJustify; pDC->DrawText(sLabel, -1, rcLabel, dtFlags); } //focus rect if required if(lvi.state & LVIS_FOCUSED && (GetFocus() == this)) pDC->DrawFocusRect(rcHighlight); pDC->RestoreDC(nSaveDC); return 0; } ///////////////////////////////////////////////////////////////////////////// // 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;iDelete (); 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("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; iSetAt(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","

",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("

","\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("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; iGetDB(); 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 == "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 -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 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; yiSubItem) 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