1.3 updates

This commit is contained in:
troyengel 2014-11-26 14:26:40 -06:00
parent bb4769dbba
commit 78071b1635
13 changed files with 627 additions and 725 deletions

View file

@ -17,6 +17,7 @@
#include "FindDlg.h"
#include "GetNew.h"
#include "PrefPage.h"
#include "PMerge.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@ -24,17 +25,6 @@
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
@ -87,6 +77,7 @@ BEGIN_MESSAGE_MAP(CCB32View, CListView)
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)
@ -99,7 +90,7 @@ END_MESSAGE_MAP()
CCB32View::CCB32View()
{
m_nHighlight = 1;
//m_nHighlight = 1;
m_iFirst = 0;
m_pFindDialog = new CFindDlg;
m_headerctrl.SetCallback( this, (void (CWnd::*)(int, int))DragColumn );
@ -132,9 +123,6 @@ void CCB32View::OnDraw(CDC* pDC)
{
CCB32Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
void CCB32View::OnInitialUpdate()
@ -150,6 +138,7 @@ void CCB32View::OnInitialUpdate()
// Add items to the list view.
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
FreeItems();
ctlList.DeleteAllItems();
ctlList.SetBkColor(GetSysColor(COLOR_WINDOW));
@ -288,648 +277,176 @@ void CCB32View::DrawItemText(CDC* pDC, CString text, CRect rect,
/////////////////////////////////////////////////////////////////////////////
// CCB32View printing
BOOL CCB32View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCB32View::OnBeginPrinting(CDC* pDC, CPrintInfo* 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
// nada
}
void CCB32View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
m_PrinterFont.DeleteObject();
// nada
}
void CCB32View::OnPrint(CDC* pDC, CPrintInfo* pInfo)
void CCB32View::OnFilePrintMerge()
{
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; pos<arLabel.GetSize(); pos++)
{
sTemp = arLabel[pos];
pDC->DrawText(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;
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);
}
}
rcLabel = rcCol;
rcLabel.left += offset;
rcLabel.right -= offset;
dtFlags &= ~DT_RIGHT;
dtFlags &= ~DT_CENTER;
dtFlags |= nJustify;
pDC->DrawText(sLabel, -1, rcLabel, dtFlags);
}
}
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;
}
//focus rect if required
if(lvi.state & LVIS_FOCUSED && (GetFocus() == this))
pDC->DrawFocusRect(rcHighlight);
pDC->RestoreDC(nSaveDC);
return 0;
// 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;
}
/////////////////////////////////////////////////////////////////////////////
@ -1409,7 +926,7 @@ BOOL CCB32View::AddDocItemToListView(CExpr* expr)
// Initialize the CStringArray structure's fields.
CString sText;
if(expr->GetAttributeValue("LastName", sText))
if(expr->GetAttributeValue(_T("LastName"), sText))
pItem->SetAt(0, sText);
if(expr->GetAttributeValue("FirstName", sText))
pItem->SetAt(1, sText);
@ -1660,7 +1177,7 @@ int CALLBACK CCB32View::CompareFuncDec (LPARAM lParam1, LPARAM lParam2,
BOOL CCB32View::MakeExpr(CExpr* expr, CStringArray* pItem)
{
expr->AddAttributeValueString("LastName", pItem->GetAt(0));
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));
@ -1711,7 +1228,7 @@ void CCB32View::MakeDatabase()
// db.ClearDatabase();
for (int i=0; i<iNumItems; i++)
{
CExpr *expr = new CExpr("contact");
CExpr *expr = new CExpr(_T("contact"));
pItem = (CStringArray*) ctlList.GetItemData(i);
MakeExpr(expr, pItem);
db.Append(expr);
@ -1734,7 +1251,7 @@ void CCB32View::AddDatabase()
{
CExpr *expr = (CExpr *)node->Data();
CString strType = expr->Functor();
if (strType == "contact")
if (strType == _T("contact"))
{
if (!AddDocItemToListView (expr))
break;