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

📄 scdocreflow.cpp

📁 Source code for EMFexplorer 1.0
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		return TRUE;

	NMHDR* pNmhdr = (NMHDR*)lParam;
	switch (pNmhdr->idFrom)
	{
	case IDC_PICT_ALLPAGES_ACTUAL:
		if (THN_SELCHANGE==pNmhdr->code)
		{
			int idx = m_PictAllPages.SCGetCurSel();
			ASSERT(idx>=0 && idx<m_LstPages.GetCount());
			m_LstPages.SetCurSel(idx);
			SCSelChanged(FALSE);
			return TRUE;
		}

	//default:
		// let Windows manage it
	}
	return FALSE;
}

/////////////////////////////////////////////////////////////////////////////
///
/// Attempt to disable VK_RETURN, except for IDOK and IDCANCEL.
///
BOOL CSCDocReflow::PreTranslateMessage(MSG* pMsg) 
{
	if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
	{
        HWND hFocus = ::GetFocus();
		// detect the page pos edit box
		int iCtlId = (hFocus) ? ::GetDlgCtrlID(hFocus) : -1;
		switch (iCtlId)
		{
		case IDC_EDIT_PAGE_POS:
			{
				UpdateData();
				int iPos = _ttoi(LPCTSTR(m_strEdPagePos));
				if (iPos>=0 && iPos<(int)m_uiNbPages)
					SCMoveSelection(iPos, TRUE);
				else
				{
					m_strEdPagePos.Format(_T("%d"), m_LstPages.GetCurSel());
					UpdateData(FALSE);
				}
				return FALSE;    // Don't translate
			}
			break;

		case IDC_EDIT_CURFILE:
			{
				UpdateData();
				SCCheckRename();
				return FALSE;    // Don't translate
			}
			break;
			
		case IDOK:
		case IDCANCEL:
			break;
			
		case IDC_EDIT_CREDIT:
		case IDC_EDIT_URL:
		case IDC_EDIT_COMMENT:
			UpdateData();
			SCOnValidateCtlChange(iCtlId);
			// fall through

		default:
			return FALSE;    // Don't translate
		}
	};
	
	return CDialog::PreTranslateMessage(pMsg);
}

/////////////////////////////////////////////////////////////////////////////

void CSCDocReflow::OnBtnTop() 
{
	SCMoveSelection(0, TRUE);	
}

void CSCDocReflow::OnBtnBottom() 
{
	SCMoveSelection(m_uiNbPages-1, TRUE);	
}

void CSCDocReflow::OnBtnLeft() 
{
	SCMoveSelection(-1);	
}

void CSCDocReflow::OnBtnRight() 
{
	SCMoveSelection(1);	
}

void CSCDocReflow::OnBtnUp() 
{
	SCMoveSelection(-m_PictAllPages.SCGetNbPgCols());	
}

void CSCDocReflow::OnBtnDown() 
{
	SCMoveSelection(m_PictAllPages.SCGetNbPgCols());	
}


void CSCDocReflow::SCCheckRename() 
{
	int iNewSel = m_LstPages.GetCurSel();
	ASSERT(-1!=iNewSel);

	CString strOldPath;
	m_LstPages.GetText(iNewSel, strOldPath);

	CString strNewPath = SCFNameExtFromPath(m_strEdCurFile);
	if (0==strNewPath.CompareNoCase(strOldPath))
		return;

	SCPageInfo* pInfo = (SCPageInfo*)m_LstPages.GetItemDataPtr(iNewSel);
	ASSERT(pInfo);
	SCEMFDocPage* pDocPage = pInfo->pPage;
	ASSERT(pDocPage);
	pDocPage->SCSetFilePath(m_strDocDir + strNewPath); // just renaming
	if (pInfo->strOrigName.IsEmpty())
	{// keep old name on first rename
		pInfo->strOrigName = strOldPath;
		if (SCExistFile(m_strDocDir + strOldPath))
			m_iNbToRename++;
	} else
	if (SCExistFile(m_strDocDir + pInfo->strOrigName))
	{// would be renamed
		if (0==strNewPath.CompareNoCase(pInfo->strOrigName))
		{// restored
			pInfo->strOrigName.Empty();
			m_iNbToRename--;
		}
	}
	
	// Move list elements
	int nIndex = m_LstPages.InsertString(iNewSel, strNewPath);
	m_LstPages.SetItemDataPtr(nIndex, pInfo);
	m_LstPages.DeleteString(iNewSel + 1);

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

void CSCDocReflow::OnBtnReplace() 
{
	UpdateData();
	UINT uiFileType;
	CString strPath = SCGetAddReplaceFilename(m_strDocDir+m_strEdCurFile, uiFileType, _T("Replace File"));
	if (strPath.IsEmpty())
		return;

	if (!m_strDocDir.IsEmpty())
	{
		CString strDir = SCMakeupDocDir(strPath);
		if (0!=strDir.CompareNoCase(m_strDocDir))
		{
			AfxMessageBox(IDS_FILEMIX_ERR);
			return;
		}
	}

	HENHMETAFILE hEMF = SCEMFFromFile(strPath, uiFileType & SC_FTYPE_MASK);
	if (!hEMF)
	{
		AfxMessageBox(IDS_FILE_REPLACE_ERR);
		return;
	}

	// Copy source info
	int iNewSel = m_LstPages.GetCurSel();
	ASSERT(-1!=iNewSel);

	SCPageInfo* pInfo = (SCPageInfo*)m_LstPages.GetItemDataPtr(iNewSel);
	ASSERT(pInfo);
	SCEMFDocPage* pDocPage = pInfo->pPage;
	ASSERT(pDocPage);
	if (pInfo->pThumb)
	{
		delete pInfo->pThumb;
		pInfo->pThumb = NULL;
	}
	if (pInfo->iOrigIndex>=0)
	{
		pDocPage->SCDetachEMF();
		pInfo->iOrigIndex = -1;
	}
	pDocPage->SCAttachEMF(hEMF, strPath, uiFileType);

	// Move list elements
	int nIndex = m_LstPages.InsertString(iNewSel, SCFNameExtFromPath(strPath));
	m_LstPages.SetItemDataPtr(nIndex, pInfo);
	m_LstPages.DeleteString(iNewSel + 1);

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

void CSCDocReflow::OnBtnRemove() 
{
	int idx = m_LstPages.GetCurSel();
	if (-1==idx)
		return;
	ASSERT(m_uiNbPages>0);
	if (0==m_uiNbPages)
		return;

	if (idx==m_iDfltCrdPage)
		m_iDfltCrdPage = -1;
	else
	if (idx<m_iDfltCrdPage)
		m_iDfltCrdPage--;

	// Copy source info
	SCPageInfo* pSrcInfo = (SCPageInfo*)m_LstPages.GetItemDataPtr(idx);
	ASSERT(pSrcInfo);
	if (!pSrcInfo->strOrigName.IsEmpty())
	{// would be renamed
		if (SCExistFile(m_strDocDir + pSrcInfo->strOrigName))
			m_iNbToRename--;
	}

	// Prepare remove
	int iNewSel = idx;
	m_uiNbPages--;
	if (iNewSel>=m_uiNbPages)
		iNewSel--;
	
	// Delete element
	m_LstPages.DeleteString(idx);
	delete pSrcInfo;

	// Refresh
	m_PictAllPages.SCSetThumbsHolder(this, m_uiNbPages);
	m_LstPages.SetCurSel(iNewSel);
	SCSelChanged();
}

void CSCDocReflow::OnBtnAdd() 
{
	CStringList strLFiles;
	if (!SCGetFilesInsertList(strLFiles, m_strDocDir+m_strEdCurFile, TRUE))
		return;

	if (strLFiles.IsEmpty())
	{
		return;
		AfxMessageBox(IDS_EMFXMERGE_ERR);
	}
	// filter out, txt/rtf, etc..., and file in other directories
	BOOL bSetDir = m_strDocDir.IsEmpty();
	SCFilterDocDirFileList(strLFiles, m_strDocDir, TRUE);
	bSetDir = (bSetDir && !m_strDocDir.IsEmpty());
	if (bSetDir)
		UpdateData(FALSE);

	if (strLFiles.IsEmpty())
	{
		AfxMessageBox(IDS_REFLOWADDFILES_ERR);
		return;
	}

	POSITION pos = strLFiles.GetHeadPosition();
	while (pos)
	{
		SCPageInfo* pInfo = new SCPageInfo;
		CString strPgPath = strLFiles.GetNext(pos);
		SCEMFDocPage* pDocPage = new SCEMFDocPage(m_pEMFDoc);
		pInfo->pPage = pDocPage;
		pDocPage->SCSetFilePath(strPgPath); // just init
		
		int nIndex = m_LstPages.AddString(SCFNameExtFromPath(strPgPath));
		m_LstPages.SetItemDataPtr(nIndex, pInfo);
	}
	
	m_uiNbPages += strLFiles.GetCount();
	m_PictAllPages.SCSetThumbsHolder(this, m_uiNbPages);

	m_LstPages.SetCurSel(m_uiNbPages-1);
	SCSelChanged();
}

void CSCDocReflow::SCSetCtlText(UINT idCtl, LPCTSTR lpszText)
{
	CWnd* pWnd = GetDlgItem(idCtl);
	ASSERT(pWnd);
	if (pWnd)
		pWnd->SetWindowText(lpszText);
}

void CSCDocReflow::OnKillfocusEditCurfile() 
{
//		SCSetCtlText(IDC_EDIT_CURFILE, m_strEdCurFile);
}

void CSCDocReflow::OnKillfocusEditCredit() 
{
//		SCSetCtlText(IDC_EDIT_CREDIT, m_strEdCredit);
}

void CSCDocReflow::OnKillfocusEditUrl() 
{
//		SCSetCtlText(IDC_EDIT_URL, m_strEdURL);
}

void CSCDocReflow::OnKillfocusEditComment() 
{
//		SCSetCtlText(IDC_EDIT_COMMENT, m_strEdComment);
}

void CSCDocReflow::OnKillfocusEditPagePos() 
{
//		SCSetCtlText(IDC_EDIT_PAGE_POS, m_strEdPagePos);
}

void CSCDocReflow::OnChkDefault() 
{
	CButton* pBtn = (CButton*)GetDlgItem(IDC_CHK_DEFAULT);
	ASSERT(pBtn);
	if (pBtn)
	{
		if (pBtn->GetCheck())
		{
			m_iDfltCrdPage = m_LstPages.GetCurSel();
		} else
		{
			m_iDfltCrdPage = -1;
		}
//			SCSelChanged();
	}
}

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

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

	PSCEMFDocPage pDocPage = pInfo->pPage;
	ASSERT(pDocPage);
	pDocPage->SCSetCredit(m_strEdCredit);
	pDocPage->SCSetCreditURL(m_strEdURL);
	pDocPage->SCSetComment(m_strEdComment);
	SCCheckRename();
}

void CSCDocReflow::OnOK() 
{
	OnBtnValidate();
	BOOL bReflow = FALSE;
	UINT uiNbElems = m_LstPages.GetCount();
	if (m_iNbToRename)
	{
		if (IDYES!=AfxMessageBox(IDS_REFLOW_CONFIRM_RENAME, MB_YESNOCANCEL))
			return;
	}

	DOCPAGEVECTOR		vCurrent;
	INTVECTOR			vDescrip;
	int iNbMoveErr = 0;
	for (UINT idx=0; (idx<uiNbElems); idx++)
	{
		SCPageInfo* pInfo = (SCPageInfo*)m_LstPages.GetItemDataPtr(idx);
		ASSERT(pInfo);
		
		PSCEMFDocPage pDocPage = pInfo->pPage;
		ASSERT(pDocPage);

		vCurrent.push_back(pDocPage);
		vDescrip.push_back(pInfo->iOrigIndex);

		if (!pInfo->strOrigName.IsEmpty())
		{// rename now
			if (m_strDocDir.IsEmpty())
				continue;

			CString strOldPath = m_strDocDir + pInfo->strOrigName;
			if (!SCExistFile(strOldPath))
				continue;

			// XP may lock the file
			if (pInfo->iOrigIndex>=0)
			{
				m_pEMFDoc->SCUnlockEMF(pInfo->iOrigIndex, pDocPage);
			} else
				pDocPage->SCUnlockEMF();
			//

			if (!MoveFile(strOldPath, pDocPage->SCGetFilePath()))
			{
				DWORD dwError = GetLastError();
				CString strMsg;
				strMsg.Format(IDS_FILE_RENAME_ERR, strOldPath, pDocPage->SCGetFilePath());
				SCShowWinError(dwError, SC_PRODUCTNAME, strMsg);

				iNbMoveErr++;
			} else
			{
				m_iNbToRename--;
				pInfo->strOrigName.Empty();
			}
		}
	}
	if (iNbMoveErr)
	{
		AfxMessageBox(IDS_FILE_RENAME_ERRLAST);
		return;
	}
	m_pEMFDoc->SCReflow(vCurrent, vDescrip, m_strDocDir, m_iDfltCrdPage);

	{// pre-clean up
		for (UINT idx=0; (idx<uiNbElems); idx++)
		{
			SCPageInfo* pInfo = (SCPageInfo*)m_LstPages.GetItemDataPtr(idx);
			ASSERT(pInfo);
			pInfo->pPage = NULL; // don't delete page, as it is now owned by doc
		}
	}

	CDialog::OnOK();
}



⌨️ 快捷键说明

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