⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadfontview.cpp

📁 传真示例
💻 CPP
字号:
// $Header: /LoadFont/LoadFontView.cpp 6     6/24/96 11:05a Stonea $
// LoadFontView.cpp : implementation of the CLoadFontView class
//

#include "stdafx.h"
#include "LoadFont.h"
#include "LoadFontDoc.h"
#include "LoadFontView.h"
#include "MainFrm.h"
#include "DlgcLoadFont.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLoadFontView

IMPLEMENT_DYNCREATE(CLoadFontView, CListView)

BEGIN_MESSAGE_MAP(CLoadFontView, CListView)
	//{{AFX_MSG_MAP(CLoadFontView)
	ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
	ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
	ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CLoadFontView construction/destruction

CLoadFontView::CLoadFontView()
{
	// TODO: add construction code here
	m_pFontBox = 0;
	m_pLF = 0;
}

CLoadFontView::~CLoadFontView()
{
	if (m_pFontBox)
		delete m_pFontBox;
}

BOOL CLoadFontView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CListView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CLoadFontView drawing

void CLoadFontView::OnDraw(CDC* pDC)
{
	int height;
	TEXTMETRIC tm;

	CLoadFontDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: add draw code for native data here
	pDC->GetTextMetrics(&tm);
	height = tm.tmHeight+tm.tmExternalLeading;
	pDC->TextOut(100, 100, "Board Device    Board Type           Normal Font       Compressed Font");
	pDC->TextOut(100, 100+height, "----------------------------------------------------------------------");

	CDlgcLoadFont::CDlgcBoard *pBoard;
	CString str;
	for(int iIndex = 0; iIndex<m_pLF->m_BoardList.GetSize(); iIndex++)
	{
		pBoard = (CDlgcLoadFont::CDlgcBoard*)m_pLF->m_BoardList[iIndex];
		str.Format("%-15.15s %-20.20s %-17.17s %-15.15s", 
			pBoard->GetDeviceName(), pBoard->GetName(),
			pBoard->GetNormalFont(), pBoard->GetCompressedFont());
		pDC->TextOut(100, 100+(iIndex+2)*height, str);
	}
	

}

void CLoadFontView::OnInitialUpdate()
{
	CListView::OnInitialUpdate();

	// Load the pointer to our LoadFont class object.
	m_pLF = GetDocument()->m_pLF;

	// This is a reference to the CListCtrl in our ListView.
	CListCtrl &ListViewCtrl = GetListCtrl();

	// Reset the contents.
	ListViewCtrl.DeleteAllItems();

	// Put the Listview style into report mode.
	DWORD dwStyle = GetWindowLong(ListViewCtrl.m_hWnd, GWL_STYLE);
	SetWindowLong(ListViewCtrl.m_hWnd,
				  GWL_STYLE,
				  (dwStyle & ~LVS_TYPEMASK) | LVS_REPORT);

	// Setup a standard column width for all three columns.
	int width = ListViewCtrl.GetStringWidth("Compressed font (ID #3)")+20;

	// Create the columns in the ListView.
	ListViewCtrl.InsertColumn(0, "Board Device Name", LVCFMT_LEFT, width, BoardDeviceSubitem);
	ListViewCtrl.InsertColumn(1, "Board Type", LVCFMT_LEFT, width, BoardSubitem);
	ListViewCtrl.InsertColumn(2, "Normal font (ID #0)", LVCFMT_LEFT, width, NormalSubitem);
	ListViewCtrl.InsertColumn(3, "Compressed font (ID #3)", LVCFMT_LEFT, width, CompressedSubitem);

	// Add the Boards as 'items' to the view.
	CDlgcLoadFont::CDlgcBoard *pBoard;
	for(int iIndex = 0; iIndex<m_pLF->m_BoardList.GetSize(); iIndex++)
	{
		pBoard = (CDlgcLoadFont::CDlgcBoard*)m_pLF->m_BoardList[iIndex];
		ListViewCtrl.InsertItem(iIndex, pBoard->GetDeviceName());

		// Add the subitems.
		ListViewCtrl.SetItemText(iIndex, BoardSubitem, pBoard->GetName());
		ListViewCtrl.SetItemText(iIndex, NormalSubitem, pBoard->GetNormalFont());
		ListViewCtrl.SetItemText(iIndex, CompressedSubitem, pBoard->GetCompressedFont());
	}
	
	// Automagically size the window to match the size of the ListView control.
	CRect coord;
	GetParentFrame()->GetWindowRect(coord);
	int iMagicWidth = ListViewCtrl.GetColumnWidth(BoardDeviceSubitem)+
					  ListViewCtrl.GetColumnWidth(BoardSubitem)+
					  ListViewCtrl.GetColumnWidth(NormalSubitem)+
					  ListViewCtrl.GetColumnWidth(CompressedSubitem)+
					  4*2;	// Default Window edge size * 2 edges.
	GetParentFrame()->MoveWindow(coord.left, coord.top, iMagicWidth, 350);

	// Now create our 'floating' listbox.
	m_pFontBox = new CFontList(this);
	if (!m_pFontBox)
		AfxMessageBox("Error creating font list box.");
	CRect rect;
	rect.left = 10;  rect.right = 140;  rect.top = 30; rect.bottom = 90;
	m_pFontBox->Create(LBS_STANDARD, rect, this, 1);
	m_pFontBox->AddString("(none)");
}

/////////////////////////////////////////////////////////////////////////////
// CLoadFontView printing

BOOL CLoadFontView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	pInfo->SetMaxPage(1);
	return DoPreparePrinting(pInfo);
}

void CLoadFontView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CLoadFontView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CLoadFontView::PopUpListBox(NMHDR *pNMHDR)
{
    // Get the current mouse location and convert it to client
    // coordinates.
    DWORD pos = GetMessagePos();
    CPoint pt(LOWORD(pos), HIWORD(pos));
    ScreenToClient(&pt);

    // Get indexes of the first and last visible items in listview
    // control.
	CListCtrl &ctlList = GetListCtrl();
    int iIndex = ctlList.GetTopIndex();
    int last_visible_index = iIndex + ctlList.GetCountPerPage();
    if (last_visible_index > ctlList.GetItemCount())
        last_visible_index = ctlList.GetItemCount();

    // Loop until number visible items has been reached.
    CRect r;
	int fHitFlag = 0;
    while (iIndex <= last_visible_index)
    {
        // Get the bounding rectangle of an item. If the mouse
        // location is within the bounding rectangle of the item,
        // you know you have found the item that was being clicked.
        ctlList.GetItemRect(iIndex, &r, LVIR_BOUNDS);
        if (r.PtInRect(pt))
        {
            UINT flag = LVIS_SELECTED | LVIS_FOCUSED;
            ctlList.SetItemState(iIndex, flag, flag);
			fHitFlag = 1;
            break;
        }

        // Get the next item in listview control.
        iIndex++;
    }

	CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
	
	// Hit?
	if (!fHitFlag)
	{
		pFrame->SetMessageText("Select the font column of a VFX/40ESC+ card.");
		MessageBeep(0xFFFFFFFF);
		return;
	}

	// Is this a ESC+ ?
	CDlgcLoadFont::CDlgcBoard *pBoard = 
			(CDlgcLoadFont::CDlgcBoard*)m_pLF->m_BoardList[iIndex];
	if (!(pBoard->IsEscPlus()))
	{
		pFrame->SetMessageText("Not a VFX/40ESC+ card.");
		MessageBeep(0xFFFFFFFF);
		return;
	}

	// Check the subitem selection.
	int iSubItem=0;
	int w0 = ctlList.GetColumnWidth(BoardDeviceSubitem);
	int w1 = ctlList.GetColumnWidth(BoardSubitem);
	int w2 = ctlList.GetColumnWidth(NormalSubitem);
	int w3 = ctlList.GetColumnWidth(CompressedSubitem);

	if (pt.x <= w0)
		iSubItem = 0;
	if ((pt.x > w0) && (pt.x <= (w0+w1)))
		iSubItem = 0;
	if ((pt.x > (w0+w1)) && (pt.x <= (w0+w1+w2)))
		iSubItem = NormalSubitem;
	if ((pt.x > (w0+w1+w2)) && (pt.x <= (w0+w1+w2+w3)))
		iSubItem = CompressedSubitem;

	// Not in the selection area.
	if (iSubItem == 0)
	{
		pFrame->SetMessageText("Select the font column of a VFX/40ESC+ card.");
		MessageBeep(0xFFFFFFFF);
		return;
	}

	// Pop up the list box here...
	// Store the index and subitem offset in the control.
	m_pFontBox->SetListSelection(iIndex, iSubItem);

	// Clear the box.
	m_pFontBox->ResetContent();
	m_pFontBox->AddString("(none)");

	// Populate the list box with the right font set.
	if (iSubItem == NormalSubitem)
	{
		for (int i=0; i<m_pLF->NormalFonts.GetSize(); i++)
			m_pFontBox->AddString(m_pLF->NormalFonts[i]);
	}
	if (iSubItem == CompressedSubitem)
	{
		for (int i=0; i<m_pLF->CompressedFonts.GetSize(); i++)
			m_pFontBox->AddString(m_pLF->CompressedFonts[i]);
	}
	
	// Make it visible...
	m_pFontBox->ModifyStyle(WS_DISABLED, WS_VISIBLE);

	// Special case for right hand margin.
	// Prevents the pop-up from being clipped when the application
	// window is near the right edge of the screen.
	if (iSubItem == CompressedSubitem)
		m_pFontBox->MoveWindow(pt.x-w2, pt.y, 150, 90);
	else
		m_pFontBox->MoveWindow(pt.x, pt.y, 150, 90);

	// Point to the first selection, and grab focus.
	m_pFontBox->SetCurSel(0);
	m_pFontBox->SetFocus();
	m_pFontBox->Invalidate();
	UpdateWindow();
}


/////////////////////////////////////////////////////////////////////////////
// CLoadFontView diagnostics

#ifdef _DEBUG
void CLoadFontView::AssertValid() const
{
	CListView::AssertValid();
}

void CLoadFontView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}

CLoadFontDoc* CLoadFontView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLoadFontDoc)));
	return (CLoadFontDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CLoadFontView message handlers

void CLoadFontView::OnClick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	PopUpListBox(pNMHDR);
	*pResult = 0;
}

void CLoadFontView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	PopUpListBox(pNMHDR);
	*pResult = 0;
}

void CLoadFontView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	PopUpListBox(pNMHDR);
	*pResult = 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -