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

📄 fontview.cpp

📁 Resource editor base speadrum Chinese mobile
💻 CPP
字号:
// FontLibView.cpp : implementation file
//

#include "stdafx.h"
#include "resourceeditor.h"
#include "FontView.h"
#include "FontDlg.h"
#include "FontExDlg.h"
#include "DirFileInfo.h"

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


_TCHAR CFontView::ARR_CLMN_NAME[] = _T("ID,Type");
/////////////////////////////////////////////////////////////////////////////
// CFontView

IMPLEMENT_DYNCREATE(CFontView, CListView)

CFontView::CFontView()
{
}

CFontView::~CFontView()
{
}


BEGIN_MESSAGE_MAP(CFontView, CListView)
	//{{AFX_MSG_MAP(CFontView)
	ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
	ON_COMMAND(IDM_FONT_ADD, OnFontAdd)
	ON_COMMAND(IDM_FONT_DEL, OnFontDel)
	ON_COMMAND(IDM_FONT_REPLACE, OnFontReplace)
	ON_UPDATE_COMMAND_UI(IDM_FONT_ADD, OnUpdateFontAdd)
	ON_UPDATE_COMMAND_UI(IDM_FONT_DEL, OnUpdateFontDel)
	ON_UPDATE_COMMAND_UI(IDM_FONT_REPLACE, OnUpdateFontReplace)
	ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
	ON_UPDATE_COMMAND_UI(IDM_FONT_EXPORT, OnUpdateFontExport)
	//}}AFX_MSG_MAP
	ON_COMMAND(IDM_FONT_EXPORT, OnFontExport)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFontView drawing

void CFontView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CFontView diagnostics

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

void CFontView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFontView message handlers

void CFontView::OnInitialUpdate() 
{
	CListView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
    CListCtrl &ls = GetListCtrl();

	DWORD dwStyle = ls.GetExtendedStyle();
    dwStyle |= LVS_EX_GRIDLINES;
    dwStyle |= LVS_EX_FULLROWSELECT;
    ls.SetExtendedStyle( dwStyle );

	// TODO: Add your specialized code here and/or call the base class
	FillColumn();

    m_pInfo = g_theApp.m_pFontInfo;
    _ASSERTE( m_pInfo != NULL );
    
    CDirFileNode * pRoot  = (CDirFileNode *)m_pInfo->GetRoot();
    CDirFileNode * pChild = (CDirFileNode *)m_pInfo->GetChild(pRoot);
    
    for( int i = 0; pChild != NULL; ++i )
    {        
        ls.InsertItem(i, pChild->szID);
        ls.SetItemText(i, 1, pChild->szID);
        ls.SetItemData(i, (DWORD)pChild);

        pChild = (CDirFileNode *)m_pInfo->GetNext(pChild);
    }
}

BOOL CFontView::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: Add your specialized code here and/or call the base class
	cs.style |= LVS_REPORT;
    cs.style |= LVS_SHOWSELALWAYS;

	return CListView::PreCreateWindow(cs);
}

void CFontView::FillColumn(void)
{
    CListCtrl &ls = GetListCtrl();

    LPTSTR pStart = ARR_CLMN_NAME;
    LPTSTR pFind  = _tcschr(pStart, _T(','));
    for( int i = 0; pFind != NULL; ++i )
    {
        *pFind = 0;
        ls.InsertColumn(i, pStart, LVCFMT_LEFT, 200 + i * 40);
        *pFind = _T(',');
        pStart = pFind + 1;
        pFind = _tcschr(pStart, _T(','));
    }

    ls.InsertColumn(i, pStart, LVCFMT_LEFT, 200 + i * 40);
}

void CFontView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	LPNMITEMACTIVATE pnia = (LPNMITEMACTIVATE)pNMHDR;
    
    CMenu menu;
	VERIFY( menu.LoadMenu(IDM_POPUP_FONT) );

	CMenu * pMenu = menu.GetSubMenu(0);

    if( PreTrackPopupMenu(pMenu, pnia->iItem) )
    {
	    POINT pt = pnia->ptAction;
        ClientToScreen(&pt);
	    pMenu->TrackPopupMenu(TPM_LEFTALIGN, pt.x, pt.y, this);

	    *pResult = 1;
    }
    else
    {
        *pResult = 0;
    }
}

BOOL CFontView::PreTrackPopupMenu( CMenu * pMenu, int nIdx )
{
	_ASSERTE( pMenu != NULL );

	if( !g_theApp.IsSuperUser() )
	{
		if( nIdx == -1 )
		{
			return FALSE;
		}
		else
		{
			pMenu->DeleteMenu(IDM_FONT_ADD, MF_BYCOMMAND);
			pMenu->DeleteMenu(IDM_FONT_DEL, MF_BYCOMMAND);
			pMenu->DeleteMenu(IDM_FONT_EXPORT, MF_BYCOMMAND);
		}
	}
	else
	{
		if( nIdx == -1 )
		{
            pMenu->EnableMenuItem( IDM_FONT_REPLACE, MF_BYCOMMAND | MF_GRAYED );
            pMenu->EnableMenuItem( IDM_FONT_DEL,  MF_BYCOMMAND | MF_GRAYED );
			pMenu->EnableMenuItem( IDM_FONT_EXPORT,  MF_BYCOMMAND | MF_GRAYED );
		}
	}

    if( nIdx != -1 )
    {
        CListCtrl &ls = GetListCtrl();
        if( ls.GetSelectedCount() > 1 )
            pMenu->EnableMenuItem( IDM_FONT_REPLACE,  MF_BYCOMMAND | MF_GRAYED );
    }

    return  TRUE;
}

void CFontView::OnFontAdd() 
{
	// TODO: Add your command handler code here
/*	CFontDlg dlg;

    dlg.m_bEdit = FALSE;
    if( dlg.DoModal() == IDOK )
    {
        CStringArray arrFile;
        arrFile.Add(dlg.m_strAscii);
        arrFile.Add(dlg.m_strChinese);

        CMMIRes &mmires = g_theApp.m_MMIRes;
        if(! mmires.AddFont(dlg.m_strID, dlg.m_nType, arrFile) )
        {
            AfxMessageBox(mmires.GetErrMsg());
            return;
        }

        CDirFileNode * pNode = (CDirFileNode *)m_pInfo->MallocNode();
        if( NULL == pNode )
        {
            mmires.DeleteFont(dlg.m_strID);
            return;
        }

        _tcscpy(pNode->szID,   dlg.m_strID);
        _tcscpy(pNode->szName, dlg.m_strID);
        m_pInfo->AddChild((CDirFileNode *)m_pInfo->GetRoot(), pNode);

        CListCtrl &ls = GetListCtrl();
        int nItem = ls.GetItemCount();

        ls.InsertItem(nItem, pNode->szID);
        ls.SetItemText(nItem, 1, pNode->szID);
        ls.SetItemData(nItem, (DWORD)pNode);
    }
*/
	CFontExDlg dlg;
    dlg.m_bEdit = FALSE;
    if( dlg.DoModal() == IDOK )
    {
        //CStringArray arrFile;
        //arrFile.Add(dlg.m_strAscii);
        //arrFile.Add(dlg.m_strOther);

        CMMIRes &mmires = g_theApp.m_MMIRes;
        //if(! mmires.AddFont(dlg.m_strID, dlg.m_nType, arrFile) )
		if(! mmires.AddFontEx(dlg.m_strID, dlg.m_nType, dlg.m_strArrDB) )
        {
            AfxMessageBox(mmires.GetErrMsg());
            return;
        }

        CDirFileNode * pNode = (CDirFileNode *)m_pInfo->MallocNode();
        if( NULL == pNode )
        {
            mmires.DeleteFont(dlg.m_strID);
            return;
        }

        _tcscpy(pNode->szID,   dlg.m_strID);
        _tcscpy(pNode->szName, dlg.m_strID);
        m_pInfo->AddChild((CDirFileNode *)m_pInfo->GetRoot(), pNode);

        CListCtrl &ls = GetListCtrl();
        int nItem = ls.GetItemCount();

        ls.InsertItem(nItem, pNode->szID);
        ls.SetItemText(nItem, 1, pNode->szID);
        ls.SetItemData(nItem, (DWORD)pNode);
		SetModifiedFlag();
    }

}

void CFontView::OnFontDel() 
{
	// TODO: Add your command handler code here
	if( AfxMessageBox(_T("Are you sure delete the selected items!"), MB_YESNO) == IDNO )
        return;
    CStringArray &strArrType = g_theApp.m_strArrFontType;
	//FONT_MAP     &fontMap   = g_theApp.m_MMIRes.m_mapFont;//x
	FONTEX_MAP     &fontMap   = g_theApp.m_MMIRes.m_mapFontEx;
    CListCtrl &ls = GetListCtrl();

    POSITION pos = ls.GetFirstSelectedItemPosition();
    _ASSERTE( pos != NULL );

    CUIntArray arrSel;
    while( pos != NULL )
    {
        arrSel.Add( ls.GetNextSelectedItem(pos) );
    }

    int nCount = arrSel.GetSize();
    CString strID;
	//PGUI_FONT_INFO_T pFontInfo =NULL; //x
	PGUI_FONT_INFO_EX_T pFontInfo =NULL;
    for( int i = nCount - 1; i >= 0; --i )
    {
		//strArrType.RemoveAt(arrSel[i]);
		int nTypeNum = strArrType.GetSize();
		for(UINT j = nTypeNum -1; j > arrSel[i];--j)
		{
			fontMap.Lookup(strArrType.GetAt(j), pFontInfo);
			pFontInfo->type--;
		}
		strArrType.RemoveAt(arrSel[i]);

        strID = ls.GetItemText(arrSel[i], 0);
        //if( g_theApp.m_MMIRes.DeleteFont(strID) ) //x
        if( g_theApp.m_MMIRes.DeleteFontEx(strID) )
        {
            CDirFileNode * pNode = (CDirFileNode *)ls.GetItemData(arrSel[i]);
            m_pInfo->RemoveNode(pNode);

            ls.DeleteItem(arrSel[i]);            
        }
        else
        {
            _ASSERTE( 0 );
        }
    }

    arrSel.RemoveAll();

    SetModifiedFlag();
}

void CFontView::OnFontReplace() 
{
	// TODO: Add your command handler code here
/*	CFontDlg dlg;

    CListCtrl &ls = GetListCtrl();
    _ASSERTE( ls.GetSelectedCount() == 1 );

    POSITION pos = ls.GetFirstSelectedItemPosition();
    int nSel = ls.GetNextSelectedItem(pos);

    CDirFileNode * pNode = (CDirFileNode *)ls.GetItemData(nSel);

    dlg.m_strID = pNode->szID;
    dlg.m_bEdit = TRUE;
    if( dlg.DoModal() == IDOK )
    {
        CStringArray arrFile;
        arrFile.Add( dlg.m_strAscii );
        arrFile.Add( dlg.m_strChinese );

        CMMIRes &mmires = g_theApp.m_MMIRes;
        if( !mmires.ReplaceFont(dlg.m_strID, arrFile, !g_theApp.IsSuperUser()) )
            AfxMessageBox(mmires.GetErrMsg());
    }
*/
	CFontExDlg dlg;

    CListCtrl &ls = GetListCtrl();
    _ASSERTE( ls.GetSelectedCount() == 1 );

    POSITION pos = ls.GetFirstSelectedItemPosition();
    int nSel = ls.GetNextSelectedItem(pos);

    CDirFileNode * pNode = (CDirFileNode *)ls.GetItemData(nSel);

    dlg.m_strID = pNode->szID;
	dlg.m_strType = pNode->szID;

	CMMIRes &mmires = g_theApp.m_MMIRes;

	for(int i = 0 ; i<g_theApp.m_nUsedLangNum;i++)
	{
		dlg.m_strArrDB.Add(_T(""));
		dlg.m_strArrOldDB.Add(_T(""));
	}

    PGUI_FONT_INFO_EX_T pFontInfo = NULL;
    mmires.m_mapFontEx.Lookup(dlg.m_strID, pFontInfo);
	_ASSERT(pFontInfo != NULL);
	PGUI_FONT_DB_T pDBT;
	pDBT = (PGUI_FONT_DB_T)(pFontInfo->pDbtt);
	int nIdx = 0;
	CString str;
	while(nIdx < g_theApp.m_nUsedLangNum)
	{
		if(	nIdx == 0 || (nIdx != 0 && pDBT[nIdx].pdb != pDBT[0].pdb ))
		{
			str.Format(_T("%s_LANG%d.LIB"),dlg.m_strID,nIdx+1);
			dlg.m_strArrDB.SetAt(nIdx,str);
			dlg.m_strArrOldDB.SetAt(nIdx,str);
		}
		nIdx++;

	}

    dlg.m_bEdit = TRUE;

    if( dlg.DoModal() == IDOK )
    {

		if( !mmires.ReplaceFontEx(dlg.m_strID, dlg.m_strArrDB, !g_theApp.IsSuperUser()) )
            AfxMessageBox(mmires.GetErrMsg());
    }
}

void CFontView::OnUpdateFontAdd(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
}

void CFontView::OnUpdateFontDel(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CListCtrl &ls = GetListCtrl();
	pCmdUI->Enable( ls.GetSelectedCount() > 0 );
}

void CFontView::OnUpdateFontReplace(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CListCtrl &ls = GetListCtrl();

    pCmdUI->Enable( ls.GetSelectedCount() == 1 );
}

void CFontView::SetModifiedFlag( BOOL bModified /* = TRUE */)
{
    CDocument * pDoc = GetDocument();
    ASSERT_VALID(pDoc);

    pDoc->SetModifiedFlag( bModified );
}

void CFontView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	LPNMITEMACTIVATE pnia = (LPNMITEMACTIVATE)pNMHDR;
    if( pnia->iItem != -1 )
    {
        OnFontReplace();
    }

	*pResult = 0;
}

void CFontView::OnFontExport() 
{
    CFileDialog dlg(FALSE,
		_T(""),
		_T("Fonts"),
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		_T("All Files (*.*)|*.*|"));
    if(dlg.DoModal() == IDCANCEL)
		return;

    CString strDirName = dlg.GetPathName();
    if( strDirName.IsEmpty() )
        return;

	if( !::CreateDirectory(strDirName, NULL) )
	{
		if( GetLastError() != ERROR_ALREADY_EXISTS )
		{
			_ASSERTE( 0 );
			return;
		}
	}

	CListCtrl &lst = GetListCtrl();
    int nFontCount = lst.GetItemCount();
	CString strID;
	for(int i = 0; i< nFontCount;i++)
	{
		strID= lst.GetItemText(i,0);
		//g_theApp.m_MMIRes.ExportFont(strID,strDirName);//x
		g_theApp.m_MMIRes.ExportFontEx(strID,strDirName);
	}
}

void CFontView::OnUpdateFontExport(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CListCtrl &ls = GetListCtrl();
	pCmdUI->Enable( ls.GetSelectedCount() > 0 );	
}

⌨️ 快捷键说明

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