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

📄 emfexplorerview.cpp

📁 Source code for EMFexplorer 1.0
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*
*	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 "EMFexplorerDoc.h"
#include "EMFexplorerView.h"
#include "MainFrm.h"

#include "SCGenInclude.h"
#include SC_INC_WINLIB(SCPreviewView.h)
#include SC_INC_WINLIB(SCWinFile.h)
#include SC_INC_WINLIB(SCRegistry.h)
#include SC_INC_EMFLIB(SCEMFRasterizer.h) // for fonts clean up
#include SC_INC_SHARED(SCZoomShrd.h)
#include SC_INC_SHARED(SCPropStrLists.h)

#include "SCEMFInspectDlg.h"
#include "SCEMFDlgOptions.h"
#include "EMFexplorerReg.h"
#include "SCDocReflow.h"

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

#define SC_TBUPDATE_PAGE	0x01
#define SC_TBUPDATE_ZOOM	0x02
#define SC_TBUPDATE_COLOR	0x04
#define SC_TBUPDATE_ALL		(SC_TBUPDATE_PAGE|SC_TBUPDATE_ZOOM|SC_TBUPDATE_COLOR)

extern CLIPFORMAT s_cfRTF;

/////////////////////////////////////////////////////////////////////////////
// CEMFexplorerView

IMPLEMENT_DYNCREATE(CEMFexplorerView, CView)

BEGIN_MESSAGE_MAP(CEMFexplorerView, CView)
	ON_MESSAGE(AM_USER_CHANGE_OPTIONS, OnChangeOptions)
	//{{AFX_MSG_MAP(CEMFexplorerView)
	ON_WM_SIZE()
	ON_COMMAND(ID_FILE_SAVEPAGE, OnFileSavePage)
	ON_UPDATE_COMMAND_UI(ID_FILE_SAVEPAGE, OnUpdateFileSavePage)
	ON_COMMAND(ID_FILE_SAVEALL, OnFileSaveAll)
	ON_UPDATE_COMMAND_UI(ID_FILE_SAVEALL, OnUpdateFileSaveAll)
	ON_UPDATE_COMMAND_UI(ID_TBNAV_FIRST, OnUpdateTbnavFirst)
	ON_COMMAND(ID_TBNAV_FIRST, OnTbnavFirst)
	ON_UPDATE_COMMAND_UI(ID_TBNAV_PREV, OnUpdateTbnavPrev)
	ON_COMMAND(ID_TBNAV_PREV, OnTbnavPrev)
	ON_UPDATE_COMMAND_UI(ID_TBNAV_NEXT, OnUpdateTbnavNext)
	ON_COMMAND(ID_TBNAV_NEXT, OnTbnavNext)
	ON_UPDATE_COMMAND_UI(ID_TBNAV_LAST, OnUpdateTbnavLast)
	ON_COMMAND(ID_TBNAV_LAST, OnTbnavLast)
	ON_WM_CREATE()
	ON_UPDATE_COMMAND_UI(ID_TB_DPI_DEC, OnUpdateTbDpiDec)
	ON_COMMAND(ID_TB_DPI_DEC, OnTbDpiDec)
	ON_UPDATE_COMMAND_UI(ID_TB_DPI_INC, OnUpdateTbDpiInc)
	ON_COMMAND(ID_TB_DPI_INC, OnTbDpiInc)
	ON_WM_ERASEBKGND()
	ON_UPDATE_COMMAND_UI(ID_TB_DPI_100, OnUpdateTbDpi100)
	ON_COMMAND(ID_TB_DPI_100, OnTbDpi100)
	ON_UPDATE_COMMAND_UI(ID_TB_DPI_MONITOR, OnUpdateTbDpiMonitor)
	ON_COMMAND(ID_TB_DPI_MONITOR, OnTbDpiMonitor)
	ON_UPDATE_COMMAND_UI(ID_TB_PAGE_ROTATELEFT, OnUpdateTbPageRotateleft)
	ON_COMMAND(ID_TB_PAGE_ROTATELEFT, OnTbPageRotateleft)
	ON_UPDATE_COMMAND_UI(ID_TB_PAGE_ROTATERIGHT, OnUpdateTbPageRotateright)
	ON_COMMAND(ID_TB_PAGE_ROTATERIGHT, OnTbPageRotateright)
	ON_UPDATE_COMMAND_UI(ID_TBDOC_BKCOLOR, OnUpdateTbdocBkcolor)
	ON_UPDATE_COMMAND_UI(ID_TB_PAGE_REVERSEVIDEO, OnUpdateTbPageReversevideo)
	ON_COMMAND(ID_TB_PAGE_REVERSEVIDEO, OnTbPageReversevideo)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
	ON_UPDATE_COMMAND_UI(ID_VIEW_EMF_ASTEXT, OnUpdateViewEmfAstext)
	ON_COMMAND(ID_VIEW_EMF_ASTEXT, OnViewEmfAstext)
	ON_UPDATE_COMMAND_UI(ID_TBDOC_USEGDIP, OnUpdateTbdocUseGDIp)
	ON_COMMAND(ID_TBDOC_USEGDIP, OnTbdocUseGDIp)
	ON_COMMAND(ID_TOOLS_OPTIONS, OnToolsOptions)
	ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
	ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
	ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
	ON_WM_DRAWCLIPBOARD()
	ON_WM_DESTROY()
	ON_WM_CHANGECBCHAIN()
	ON_COMMAND(ID_TBDOC_SETTINGS, OnTbdocSettings)
	ON_UPDATE_COMMAND_UI(ID_TBDOC_SETTINGS, OnUpdateTbdocSettings)
	ON_COMMAND(ID_TBDOC_REFLOW, OnTbdocReflow)
	ON_UPDATE_COMMAND_UI(ID_TBDOC_REFLOW, OnUpdateTbdocReflow)
	ON_COMMAND(ID_TOOLS_PAGE_URL, OnToolsPageUrl)
	ON_UPDATE_COMMAND_UI(ID_TOOLS_PAGE_URL, OnUpdateToolsPageUrl)
	ON_COMMAND(ID_TBDOC_ADD_PAGES, OnTbdocAddPages)
	ON_UPDATE_COMMAND_UI(ID_TBDOC_ADD_PAGES, OnUpdateTbdocAddPages)
	ON_COMMAND(ID_TBDOC_REMOVE_PAGE, OnTbdocRemovePage)
	ON_UPDATE_COMMAND_UI(ID_TBDOC_REMOVE_PAGE, OnUpdateTbdocRemovePage)
	ON_COMMAND(ID_EDIT_CUT, OnEditCut)
	ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEMFexplorerView construction/destruction

CEMFexplorerView::CEMFexplorerView():
	m_hPopupMenu(NULL),
	m_pEMFTxtDlg(NULL),
	m_iCurPage(0),
	m_bCanPaste(FALSE),
	m_hWndNext(NULL),
	m_pFrame(NULL),
	m_pEMFDoc(NULL),
	m_bCreditURL(FALSE)
{
}

CEMFexplorerView::~CEMFexplorerView()
{
	if (m_hPopupMenu)
		DestroyMenu(m_hPopupMenu);
	SCSaveLastSettings();
	if (m_pEMFTxtDlg)
	{
		m_pEMFTxtDlg->DestroyWindow();
		delete m_pEMFTxtDlg;
	}
	CSCEMFdcRenderer::SCCleanFontCopies();
}

BOOL CEMFexplorerView::PreCreateWindow(CREATESTRUCT& cs)
{
	// Modify the Window class or styles here by modifying the CREATESTRUCT cs
	cs.style &= ~(WS_HSCROLL|WS_VSCROLL);
	return CView::PreCreateWindow(cs);
}

void CEMFexplorerView::SCResetView()
{
	m_CtlImage.SCReset();

	// App settings
	m_iCurPage = 0;
	m_bCreditURL = FALSE;
	CSCEMFdcRenderer::SCCleanFontCopies();
}

int CEMFexplorerView::SCGetNumPages()
{
	if (!m_pEMFDoc)
		return 0;
	return m_pEMFDoc->SCGetNbPages();
}


/////////////////////////////////////////////////////////////////////////////
// CEMFexplorerView drawing

void CEMFexplorerView::OnDraw(CDC* pDC)
{
}

/////////////////////////////////////////////////////////////////////////////
// CEMFexplorerView diagnostics

#ifdef _DEBUG
void CEMFexplorerView::AssertValid() const
{
	CView::AssertValid();
}

void CEMFexplorerView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

// Allows to get the view from anywhere, in a SDI app.
// Note: This technique is valid only for SDI applications that do not create multiple views
CEMFexplorerDoc* s_pSDI_Doc = NULL;	// the single doc
CEMFexplorerView* s_pSDI_View = NULL; // the single view

/*static*/
CEMFexplorerView* CEMFexplorerView::SCGetView()
{
	return s_pSDI_View;
}

/*static*/
void CEMFexplorerView::SCSetView(CEMFexplorerView* pView)
{
	ASSERT(pView);
	ASSERT(NULL==s_pSDI_View || pView==s_pSDI_View);
	if (!s_pSDI_View)
	if ( pView->IsKindOf( RUNTIME_CLASS(CEMFexplorerView) ) )
	{
		s_pSDI_View = pView;
		s_pSDI_Doc = pView->GetDocument();
	}
}

/*static*/
CEMFexplorerDoc* CEMFexplorerView::SCGetDoc()
{
	return s_pSDI_Doc;
}

/*static*/
SCZoomEntry* CEMFexplorerView::SCGetZoomList(USHORT& rusCount)
{
	rusCount = cs_usZoomCount;
	return (SCZoomEntry*)sc_ZoomList;
}

/*static*/
void CEMFexplorerView::SCGetZoomInfo(int& riFactor, int& riMin, int& riMax)
{
	riFactor = SC_FLOATFACTOR;
	riMin = SC_MIN_ZOOM;
	riMax = SC_MAX_ZOOM;
}

/////////////////////////////////////////////////////////////////////////////
// CEMFexplorerView message handlers
void CEMFexplorerView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	if (m_pEMFTxtDlg)
	{
		m_pEMFTxtDlg->MoveWindow(0, 0 ,cx, cy);
		return;
	}

	// Add your message handler code here
	if (::IsWindow(m_CtlImage.m_hWnd))
		m_CtlImage.MoveWindow(0, 0, cx, cy);
}

void CEMFexplorerView::OnInitialUpdate() 
{
	SCResetView();
	CView::OnInitialUpdate();
	
	// Specialized code here
	if (m_pEMFDoc) // not first load
		SCSaveLastSettings();

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

	m_pEMFDoc = pDoc->GetEMFDoc();
	ASSERT(m_pEMFDoc);

	m_CtlImage.SCSetEMFDoc(m_pEMFDoc);

	// User settings
	if (!SCReadDocSettings())
	{
		CWinApp* pApp = AfxGetApp();
		switch (pApp->GetProfileInt(s_szAppSection, SC_EMFREG_ON_DOCLOAD,
			CSCEMFOptGenPane::SCE_DLSettingsDefault))
		{
		case CSCEMFOptGenPane::SCE_DLSettingsDefault:
			SCReadSettings();
			break;
			
		case CSCEMFOptGenPane::SCE_DLSettingsLast:
			SCReadSettings(_T("Last"));
			break;
			
		default:
			ASSERT(0);
		}
	}

	// Update Frame
	m_pFrame = (CMainFrame*)AfxGetMainWnd();
	ASSERT(m_pFrame);
	ASSERT_KINDOF(CMainFrame, m_pFrame);
	SCResetToolbars();

	// Show
	SCGotoPage(1);
}

void CEMFexplorerView::SCResetToolbars()
{
	ASSERT(m_pFrame);
	if (m_pFrame)
	{
		CEMFToolBar& rToolBar = m_pFrame->SCGetToolbar();
		
		rToolBar.SCReset();
		rToolBar.SCSetNbPages(SCGetNumPages());
		rToolBar.SCSetZoomMultiplier(SC_FLOATFACTOR);
		rToolBar.SCSetZoomLimits(SC_MIN_ZOOM, SC_MAX_ZOOM);
		rToolBar.SCSetZoomsList((SCZoomEntry*)sc_ZoomList, cs_usZoomCount);
		switch (m_CtlImage.SCGetFitMode())
		{
		default:
			ASSERT(0);
		case SC_FIT_NONE:
			rToolBar.SCSetCurZoom(m_CtlImage.SCGetCurZoom());
			break;

		case SC_FIT_WIDTH:
			rToolBar.SCSelectZoom(SC_ZOOM_FITWITDH);
			break;
			
		case SC_FIT_PAGE:
			rToolBar.SCSelectZoom(SC_ZOOM_FITPAGE);
			break;
		}
		rToolBar.SCSetCurColor(m_CtlImage.SCGetPaperColor());
		rToolBar.SCEnableBoxes(SCGetNumPages()>0);

		SCGDIpDrawingAttributes& rDrawingAttributes = m_CtlImage.SCGetDrawingAttributes();

		CSCGDIpToolBar& rGDIpToolBar = m_pFrame->SCGetGDIPToolbar();
		rGDIpToolBar.SCSetDrawingAttributes(&rDrawingAttributes);
		rGDIpToolBar.SCEnableControls(SCGetNumPages()>0);
		m_pFrame->SCEnableGDIPlus(m_CtlImage.SCGetGDIplusEnabled());
	}
}

void CEMFexplorerView::SCUpdateToolbar(DWORD dwFlags) 
{
	ASSERT(m_pFrame);
	if (m_pFrame)
	{
		CEMFToolBar& rToolBar = m_pFrame->SCGetToolbar();
		if (dwFlags & SC_TBUPDATE_PAGE)
			rToolBar.SCSetCurPage(m_iCurPage);
		if (dwFlags & SC_TBUPDATE_ZOOM)
		{
			switch (m_CtlImage.SCGetFitMode())
			{
			default:
				ASSERT(0);
			case SC_FIT_NONE:
				rToolBar.SCSetCurZoom(m_CtlImage.SCGetCurZoom());
				break;
				
			case SC_FIT_WIDTH:
				rToolBar.SCSelectZoom(SC_ZOOM_FITWITDH);
				break;
				
			case SC_FIT_PAGE:
				rToolBar.SCSelectZoom(SC_ZOOM_FITPAGE);
				break;
			}
		}
		if (dwFlags & SC_TBUPDATE_COLOR)
			rToolBar.SCSetCurColor(m_CtlImage.SCGetPaperColor());
	}
}

void CEMFexplorerView::SCGotoPage(int iPage, BOOL bUpdateToolbar/*=TRUE*/) 
{
	CEMFexplorerDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!m_pEMFDoc || !m_pEMFDoc->SCGetNbPages())
		return;
	
	ASSERT(iPage>=1 && iPage<=(int)m_pEMFDoc->SCGetNbPages());
	m_iCurPage = iPage;
	if (bUpdateToolbar)
		SCUpdateToolbar(SC_TBUPDATE_PAGE);
	
	// load
	m_CtlImage.SCGotoPage(iPage);
	pDoc->SCUpdateTitle(m_iCurPage-1);

	// page context
	CString strURL = m_pEMFDoc->SCGetPageURL(m_iCurPage-1);
	m_bCreditURL = (!strURL.IsEmpty());
}

void CEMFexplorerView::SCRefresh()
{
	m_CtlImage.SCRefresh();
}

⌨️ 快捷键说明

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