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

📄 scdocreflow.cpp

📁 Source code for EMFexplorer 1.0
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
*	This file is part of the EMFexplorer projet.
*	Copyright (C) 2004 Smith Charles.
*
*	This library is free software; you can redistribute it and/or
*	modify it under the terms of the GNU Lesser General Public
*	License as published by the Free Software Foundation; either
*	version 2.1 of the License, or (at your option) any later version.
*
*   This library is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
*   Lesser General Public License for more details.
*
*   You should have received a copy of the GNU Lesser General Public
*   License along with this library; if not, write to the Free Software
*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
*
*	Extension: for commercial use, apply the Equity Public License, which
*	adds to the normal terms of the GLPL a condition of donation to the author.
*   If you are interested in support for this source code,
*   contact Smith Charles <smith.charles@free.fr> for more information.
*/

#include "stdafx.h"
#include "emfexplorer.h"
#include "SCDocReflow.h"

#include SC_INC_WINLIB(SCWinFile.h)
#include SC_INC_COMMON(kSCProdDefs.h)
#include SC_INC_ERRLIB(wErr.h)

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

// Be careful! Resource editor is unaware of this ID
#define IDC_PICT_ALLPAGES_ACTUAL	(IDC_PICT_ALLPAGES+100)

/////////////////////////////////////////////////////////////////////////////
// CSCDocReflow dialog


CSCDocReflow::CSCDocReflow(CWnd* pParent /*=NULL*/)
	: CDialog(CSCDocReflow::IDD, pParent),
	m_pEMFDoc(NULL),
	m_uiNbPages(0),
	m_ThumbsSize(32, 32),
	m_iNbToRename(0),
	m_iDfltCrdPage(-1)
{
	//{{AFX_DATA_INIT(CSCDocReflow)
	m_strEdPagePos = _T("");
	m_strEdURL = _T("");
	m_strEdCurFile = _T("");
	m_strEdCredit = _T("");
	m_strEdComment = _T("");
	m_strDocDir = _T("");
	m_ChkAsDefault = FALSE;
	//}}AFX_DATA_INIT
}

void CSCDocReflow::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSCDocReflow)
	DDX_Control(pDX, IDC_PICT_CURPAGE, m_PictCurPage);
	DDX_Control(pDX, IDC_LST_PAGES, m_LstPages);
	DDX_Text(pDX, IDC_EDIT_PAGE_POS, m_strEdPagePos);
	DDX_Text(pDX, IDC_EDIT_URL, m_strEdURL);
	DDX_Text(pDX, IDC_EDIT_CURFILE, m_strEdCurFile);
	DDX_Text(pDX, IDC_EDIT_CREDIT, m_strEdCredit);
	DDX_Text(pDX, IDC_EDIT_COMMENT, m_strEdComment);
	DDX_Text(pDX, IDC_EDIT_DOC_DIR, m_strDocDir);
	DDX_Check(pDX, IDC_CHK_DEFAULT, m_ChkAsDefault);
	//}}AFX_DATA_MAP
}

SC_IMPLEMENT_ENABLE_CONTROL(CSCDocReflow)

BEGIN_MESSAGE_MAP(CSCDocReflow, CDialog)
	//{{AFX_MSG_MAP(CSCDocReflow)
	ON_LBN_SELCHANGE(IDC_LST_PAGES, OnSelchangeLstPages)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BTN_TOP, OnBtnTop)
	ON_BN_CLICKED(IDC_BTN_BOTTOM, OnBtnBottom)
	ON_BN_CLICKED(IDC_BTN_LEFT, OnBtnLeft)
	ON_BN_CLICKED(IDC_BTN_RIGHT, OnBtnRight)
	ON_BN_CLICKED(IDC_BTN_UP, OnBtnUp)
	ON_BN_CLICKED(IDC_BTN_DOWN, OnBtnDown)
	ON_BN_CLICKED(IDC_BTN_REPLACE, OnBtnReplace)
	ON_BN_CLICKED(IDC_BTN_REMOVE, OnBtnRemove)
	ON_BN_CLICKED(IDC_BTN_ADD, OnBtnAdd)
	ON_EN_KILLFOCUS(IDC_EDIT_CURFILE, OnKillfocusEditCurfile)
	ON_EN_KILLFOCUS(IDC_EDIT_CREDIT, OnKillfocusEditCredit)
	ON_EN_KILLFOCUS(IDC_EDIT_URL, OnKillfocusEditUrl)
	ON_EN_KILLFOCUS(IDC_EDIT_COMMENT, OnKillfocusEditComment)
	ON_EN_KILLFOCUS(IDC_EDIT_PAGE_POS, OnKillfocusEditPagePos)
	ON_BN_CLICKED(IDC_CHK_DEFAULT, OnChkDefault)
	ON_BN_CLICKED(IDC_BTN_VALIDATE, OnBtnValidate)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSCDocReflow I_SCThumbsHolder implementation

HENHMETAFILE CSCDocReflow::SCGetThumbEMF(int iThumbIdx)
{
	ASSERT(iThumbIdx>=0 && iThumbIdx<m_LstPages.GetCount());
	ASSERT(m_pEMFDoc);
	if (!m_pEMFDoc)
		return NULL;

	SCPageInfo* pInfo = (SCPageInfo*)m_LstPages.GetItemDataPtr(iThumbIdx);
	PSCEMFDocPage pDocPage = pInfo->pPage;
	ASSERT(pDocPage);

	return pDocPage->SCGetPageEMF();
}

void CSCDocReflow::SCSetThumbsSize(CSize& size)
{
	m_ThumbsSize = size;
}

PSCThumbImage CSCDocReflow::SCGetThumbImage(int iThumbIdx)
{
	ASSERT(iThumbIdx>=0 && iThumbIdx<m_LstPages.GetCount());
	SCPageInfo* pInfo = (SCPageInfo*)m_LstPages.GetItemDataPtr(iThumbIdx);
	PSCThumbImage pImage = pInfo->pThumb;
	if (pImage)
		return pImage;

	HENHMETAFILE hemf = SCGetThumbEMF(iThumbIdx);
	if (!hemf)
		return NULL;
	
#ifdef SC_UNSCALED_THUMBS
	pImage = new Gdiplus::Metafile(hemf);
#else
	// hope this will speed up painting
	Gdiplus::Metafile meta(hemf);
	GReal fScaleXY = (GReal)meta.GetWidth()/(GReal)meta.GetHeight();
	GReal height = m_ThumbsSize.cy;
	GReal width = height*fScaleXY;
	if (width>m_ThumbsSize.cx)
	{
		width = m_ThumbsSize.cx;
		height = width/fScaleXY;
	}
	pImage = meta.GetThumbnailImage(width, height, NULL, NULL);
#endif
	
	pInfo->pThumb = pImage;
	return pImage;
}

CString CSCDocReflow::SCGetAddReplaceFilename(LPCTSTR lpszFName, UINT& uiFileType, LPCTSTR lpszTitle/*=NULL*/)
{
	CString strPath = _T("");
	uiFileType = SC_FTYPE_UKN;

	CString sFilters(SC_EMFMODE_FILTERS_REPLACE);
	CFileDialog dlg(TRUE, NULL, lpszFName, OFN_HIDEREADONLY|OFN_PATHMUSTEXIST,
		(LPCTSTR)sFilters);
	dlg.m_ofn.lpstrTitle = lpszTitle;
	if (dlg.DoModal() != IDOK)
		return strPath;

	strPath = dlg.GetPathName();
	uiFileType = SCEMFDoc::SCGetFileType(strPath);
	
	if (SC_FTYPE_UKN==uiFileType)
	{
		AfxMessageBox(IDS_FILE_UNKNOWN);
		strPath = _T("");
	}
	return strPath;
}


/////////////////////////////////////////////////////////////////////////////
// CSCDocReflow utilities

void CSCDocReflow::SCCleanup()
{
}

void CSCDocReflow::SCCreateThumbsControl()
{
	CWnd* pWnd = GetDlgItem(IDC_PICT_ALLPAGES);
	CRect rcPict;
	pWnd->GetWindowRect(&rcPict);
	::MapWindowPoints(NULL, m_hWnd, LPPOINT(&rcPict), 2);

	RECT rc;
	::CopyRect(&rc, &rcPict);
	if (m_PictAllPages.Create(NULL, _T("SCWinThumbs"),
		WS_VISIBLE|WS_CHILD|WS_BORDER|WS_TABSTOP, rc, this, IDC_PICT_ALLPAGES_ACTUAL))
	{
		HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
		if (hFont)
		{
			LOGFONT LogFont;
			::GetObject(hFont, sizeof(LogFont), &LogFont);

			CFont* pFont = new CFont;
			pFont->CreateFontIndirect(&LogFont);
			
			m_PictAllPages.SCSetFont(pFont);
		}
	}
}

void CSCDocReflow::SCInitControls()
{
	if (m_pEMFDoc)
	{
		m_strDocDir = SCMakeupDocDir(m_pEMFDoc->SCGetUniDocName());
		//m_iDfltCrdPage = m_pEMFDoc->SCGetDefaultCreditPageIndex();

		m_uiNbPages = m_pEMFDoc->SCGetNbPages();
		for (UINT i=0; (i<m_uiNbPages); i++)
		{
			SCPageInfo* pInfo = new SCPageInfo;
			pInfo->iOrigIndex = (int)i;
			pInfo->pPage = m_pEMFDoc->SCGetDocPage(i, TRUE);
			
			int nIndex = m_LstPages.AddString(SCFNameExtFromPath(pInfo->pPage->SCGetFilePath()));
			m_LstPages.SetItemDataPtr(nIndex, pInfo);
		}
		m_PictAllPages.SCSetThumbsHolder(this, m_uiNbPages);
		m_LstPages.SetCurSel(0);
		SCSelChanged();  // won't be called automatically
	}
}

void CSCDocReflow::SCEnableControls()
{
	int idx = m_LstPages.GetCurSel();
	SCEnableControl(IDC_BTN_TOP, (idx > 0));
	SCEnableControl(IDC_BTN_UP, (idx >= m_PictAllPages.SCGetNbPgCols()));
	SCEnableControl(IDC_BTN_DOWN, (idx + m_PictAllPages.SCGetNbPgCols() <= (int)m_uiNbPages - 1));
	SCEnableControl(IDC_BTN_LEFT, (idx > 0));
	SCEnableControl(IDC_BTN_RIGHT, (idx < (int)m_uiNbPages - 1));
	SCEnableControl(IDC_BTN_BOTTOM, (idx < (int)m_uiNbPages - 1));
	SCEnableControl(IDC_EDIT_PAGE_POS, (m_uiNbPages>1));

	SCEnableControl(IDC_BTN_REMOVE, (m_uiNbPages>0));
	SCEnableControl(IDC_BTN_REPLACE, (m_uiNbPages>0));
	SCEnableControl(IDC_EDIT_CURFILE, (m_uiNbPages>0));
	SCEnableControl(IDC_EDIT_CREDIT, (m_uiNbPages>0));
	SCEnableControl(IDC_EDIT_URL, (m_uiNbPages>0));
	SCEnableControl(IDC_EDIT_COMMENT, (m_uiNbPages>0));

	SCEnableControl(IDC_CHK_DEFAULT, (m_uiNbPages>0));
	SCEnableControl(IDC_BTN_VALIDATE, (m_uiNbPages>0));
}

void CSCDocReflow::SCOnValidateCtlChange(int iCtl) 
{
	int idx = m_LstPages.GetCurSel();
	if (-1==idx)
		return;

	SCPageInfo* pInfo = (SCPageInfo*)m_LstPages.GetItemDataPtr(idx);
	ASSERT(pInfo);

	PSCEMFDocPage pDocPage = pInfo->pPage;
	ASSERT(pDocPage);
	switch (iCtl)
	{
	case IDC_EDIT_CURFILE:
		break;

	case IDC_EDIT_CREDIT:
		pDocPage->SCSetCredit(m_strEdCredit);
		break;

	case IDC_EDIT_URL:
		pDocPage->SCSetCreditURL(m_strEdURL);
		break;

	case IDC_EDIT_COMMENT:
		pDocPage->SCSetComment(m_strEdComment);
		break;

	case IDC_EDIT_PAGE_POS:
	default:
		ASSERT(0);
	}
}

void CSCDocReflow::SCSelChanged(BOOL bNotifyThumbs/*=TRUE*/) 
{
	int idx = m_LstPages.GetCurSel();
	if (-1==idx)
	{
		m_strEdPagePos = _T("");
		m_strEdURL = _T("");
		m_strEdCurFile = _T("");
		m_strEdCredit = _T("");
		m_strEdComment = _T("");
		m_PictCurPage.SCSetEMF(NULL);
		m_iDfltCrdPage = -1;
		m_ChkAsDefault = FALSE;

		SCEnableControls();
		UpdateData(FALSE);
		return;
	}

	SCPageInfo* pInfo = (SCPageInfo*)m_LstPages.GetItemDataPtr(idx);
	ASSERT(pInfo);

	PSCEMFDocPage pDocPage = pInfo->pPage;
	ASSERT(pDocPage);
	m_strEdPagePos.Format(_T("%d"), idx);
	m_strEdCurFile = SCFNameExtFromPath(pDocPage->SCGetFilePath());
	m_strEdURL = pDocPage->SCGetCreditURL();
	m_strEdCredit = pDocPage->SCGetCredit();
	m_strEdComment = pDocPage->SCGetComment();
	m_ChkAsDefault = (idx==m_iDfltCrdPage);
	if (!m_ChkAsDefault &&
		m_iDfltCrdPage>=0)
	{
		if (m_strEdURL.IsEmpty() &&
			m_strEdCredit.IsEmpty() &&
			m_strEdComment.IsEmpty())
		{
			SCPageInfo* pInfo = (SCPageInfo*)m_LstPages.GetItemDataPtr(m_iDfltCrdPage);
			ASSERT(pInfo);
			PSCEMFDocPage pDocPage = pInfo->pPage;
			ASSERT(pDocPage);
			m_strEdURL = pDocPage->SCGetCreditURL();
			m_strEdCredit = pDocPage->SCGetCredit();
			m_strEdComment = pDocPage->SCGetComment();
		}
	}

	m_PictCurPage.SCSetEMF(SCGetThumbEMF(idx));
	if (bNotifyThumbs)
		m_PictAllPages.SCSetCurSel(idx);

	SCEnableControls();
	UpdateData(FALSE);
}

void CSCDocReflow::SCMoveSelection(int iDestPos, BOOL bAbsolute/*=FALSE*/)
{
	int idx = m_LstPages.GetCurSel();
	if (-1==idx)
		return;

	if (!bAbsolute)
		iDestPos += idx;

	if (iDestPos==idx)
		return;
	ASSERT(iDestPos>=0 && iDestPos<(int)m_uiNbPages);

	if (idx==m_iDfltCrdPage)
		m_iDfltCrdPage = iDestPos;
	else
	if (idx<m_iDfltCrdPage)
	{
		if (iDestPos>m_iDfltCrdPage)
			m_iDfltCrdPage--;
	} else
	{
		if (iDestPos<=m_iDfltCrdPage)
			m_iDfltCrdPage++;
	}

	// Copy source info
	CString strSrc;
	m_LstPages.GetText(idx, strSrc);
	SCPageInfo* pSrcInfo = (SCPageInfo*)m_LstPages.GetItemDataPtr(idx);
	ASSERT(pSrcInfo);

	// Prepare move
	int iNewSel = iDestPos;
	if (iDestPos>idx)
		iDestPos++; // remove src (shift left)
	else
		idx++; // insert dest (shift right)
	
	// Move list elements
	int nIndex = m_LstPages.InsertString(iDestPos, strSrc);
	m_LstPages.SetItemDataPtr(nIndex, pSrcInfo);
	m_LstPages.DeleteString(idx);

	// Refresh
	m_LstPages.SetCurSel(iNewSel);
	SCSelChanged();
}

/////////////////////////////////////////////////////////////////////////////
// CSCDocReflow message handlers

BOOL CSCDocReflow::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// Extra initialization here
	SCCreateThumbsControl();
	SCInitControls();
	SCEnableControls();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSCDocReflow::OnSelchangeLstPages() 
{
	SCSelChanged();
}

void CSCDocReflow::OnDestroy() 
{
	SCCleanup();
	int iNbElems = m_LstPages.GetCount();
	for (int i=0; i<iNbElems; i++)
	{
		SCPageInfo* pInfo = (SCPageInfo*)m_LstPages.GetItemDataPtr(i);
		if (pInfo)
			delete pInfo;
	}
	m_LstPages.ResetContent();

	CDialog::OnDestroy();
}

BOOL CSCDocReflow::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
	if (CDialog::OnNotify(wParam, lParam, pResult))

⌨️ 快捷键说明

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