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

📄 markupdlg.cpp

📁 MarkUP ,用于VC环境下
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// MarkupDlg.cpp : implementation file
//
// Markup Release 9.0
// Copyright (C) 1999-2007 First Objective Software, Inc. All rights reserved
// Go to www.firstobject.com for the latest CMarkup and EDOM documentation
// Use in commercial applications requires written permission
// This software is provided "as is", with no warranty.

#include "stdafx.h"
#include "MarkupApp.h"
#include "MarkupDlg.h"
#include <afxpriv.h>
#include <io.h>
#include <locale.h>

#ifdef MARKUP_MSXML
#include "MarkupMSXML.h"
#define MCD_STR CString
#define MCD_2PCSZ(s) ((LPCTSTR)s)
#define MCD_STRCLEAR(s) s.Empty()
#define MCD_STRISEMPTY(s) s.IsEmpty()
#else
#include "Markup.h"
#endif

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

/////////////////////////////////////////////////////////////////////////////
// CMarkupDlg dialog

CMarkupDlg::CMarkupDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMarkupDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMarkupDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMarkupDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMarkupDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMarkupDlg, CDialog)
	//{{AFX_MSG_MAP(CMarkupDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
	ON_BN_CLICKED(IDC_BUTTON_PARSE, OnButtonParse)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CMarkupDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

HCURSOR CMarkupDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
/////////////////////////////////////////////////////////////////////////////
// CMarkupDlg message handlers

BOOL CMarkupDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	SystemSettings( TRUE );

	m_nErrorCount = 0;
	m_nTotalZones = 0;
	m_nTotalChecks = 0;

	SetWindowText( _T("CMarkup Evaluation Test Dialog") );

	// Determine version
	CString csVersion, csV0, csV1;
	CString csTitle;
	csVersion.LoadString( ID_APP_VERSION );
	AfxExtractSubString( csV0, csVersion, 0, ',' );
	AfxExtractSubString( csV1, csVersion, 1, ',' );
	CString csClass = _T("CMarkup");
	CString csBuild;
	#if defined( MARKUP_MSXML )
	csClass += _T("MSXML");
	#if defined( MARKUP_MSXML3 )
	csClass += _T(" MSXML3");
	#elif defined( MARKUP_MSXML4 )
	csClass += _T(" MSXML4");
	#endif
	#endif
	#if defined( MARKUP_STL )
	csBuild += _T(" STL");
	#endif
	#if defined( _DEBUG )
	csBuild += _T(" Debug");
	#endif
	#if defined( _UNICODE )
	csBuild += _T(" Unicode");
	#endif
	#if defined( _MBCS )
	csBuild += _T(" MBCS");
	#endif
	csTitle.Format( _T("%s %s.%s%s\r\n"), csClass, csV0, csV1, csBuild );
	OutputTestResults( csTitle );
	OutputParseResults( _T("") );

	RunTest();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMarkupDlg::OnDestroy() 
{
	SystemSettings( FALSE );
	CDialog::OnDestroy();
}

void CMarkupDlg::OutputTestResults( CString csMsg )
{
	m_csTestResults += csMsg;
	GetDlgItem( IDC_ST_TEST_RESULTS )->SetWindowText( m_csTestResults );
}

int CMarkupDlg::Alert( CString csMsg )
{
	m_csChecks += csMsg + _T("\r\n");
	++m_nErrorCount;
	return -1;
}

void CMarkupDlg::StartCheckZone( CString csCheckZone )
{
	m_nCheckCount = 0;
	++m_nTotalZones;
	m_csCheckZone = csCheckZone;
}

int CMarkupDlg::Check( BOOL bCorrect )
{
	++m_nCheckCount;
	++m_nTotalChecks;
	if ( ! bCorrect )
	{
		if ( m_csCheckZone.IsEmpty() )
			m_csCheckZone = _T("Unknown Check Zone");
		CString csMsg;
		csMsg.Format( _T("Error: %s, check %d"), m_csCheckZone, m_nCheckCount );
		return Alert( csMsg );
	}
	return 0;
}

#ifdef MARKUP_MSXML
void SetEntry( CMarkupMSXML& xml, MCD_STR strSection, MCD_STR strEntry, MCD_STR strValue )
#else
void SetEntry( CMarkup& xml, MCD_STR strSection, MCD_STR strEntry, MCD_STR strValue )
#endif
{
	// Find/Create root element of xml document
	xml.ResetPos();
	if ( ! xml.FindElem() )
		xml.AddElem( _T("Settings") ); // or whatever root element name is

	// Find/Create section
	BOOL bFoundSection = FALSE;
	while ( xml.FindChildElem(_T("Section")) )
	{
		// Is this the right section?
		if ( xml.GetChildAttrib(_T("name")) == strSection )
		{
			bFoundSection = TRUE;
			break;
		}
	}
	if ( ! bFoundSection )
	{
		xml.AddChildElem( _T("Section") );
		xml.SetChildAttrib( _T("name"), strSection );
	}

	// Find/Create entry
	xml.IntoElem();
	BOOL bFoundEntry = FALSE;
	while ( xml.FindChildElem(_T("Entry")) )
	{
		// Is this the right entry?
		if ( xml.GetChildAttrib(_T("name")) == strEntry )
		{
			bFoundEntry = TRUE;
			break;
		}
	}
	if ( ! bFoundEntry )
	{
		xml.AddChildElem( _T("Entry") );
		xml.SetChildAttrib( _T("name"), strEntry );
	}

	// Set value
	xml.SetChildData( strValue );
}

#ifdef MARKUP_MSXML
bool FindEntry( CMarkupMSXML& xml, MCD_STR strSection, MCD_STR strEntry, MCD_STR& strValue )
#else
bool FindEntry( CMarkup& xml, MCD_STR strSection, MCD_STR strEntry, MCD_STR& strValue )
#endif
{
	// Loop through sections
	xml.ResetPos();
	while ( xml.FindChildElem(_T("Section")) )
	{
		// Is this the right section?
		if ( xml.GetChildAttrib(_T("name")) == strSection )
		{
			// Check entries in this section
			xml.IntoElem();
			while ( xml.FindChildElem(_T("Entry")) )
			{
				// Is this the right entry?
				if ( xml.GetChildAttrib(_T("name")) == strEntry )
				{
					strValue = xml.GetChildData();
					return TRUE;
				}
			}
			break; // don't check any other sections
		}
	}
	return FALSE;
}

CString CMarkupDlg::GetSpecialPath( int nFolderID )
{
	CString csPath;
	TCHAR szSpecialPath[MAX_PATH];
	LPITEMIDLIST pidl;
	if( SUCCEEDED(SHGetSpecialFolderLocation(0,nFolderID,&pidl)) )
	{
		SHGetPathFromIDList( pidl, szSpecialPath );
		LPMALLOC pMalloc = NULL;
		SHGetMalloc(&pMalloc);
		pMalloc->Free( pidl );
		pMalloc->Release();
		csPath = szSpecialPath;
		csPath += "\\";
	}
	return csPath;
}

#if ! defined(_UNICODE)
CString CMarkupDlg::WinAToUTF8( CString csText )
{
	int nMBLen = csText.GetLength();
	if ( nMBLen )
	{
		wchar_t* pwszWide = new wchar_t[nMBLen+1];
		int nWideLen = MultiByteToWideChar(CP_ACP,0,csText,nMBLen,pwszWide,nMBLen);
		pwszWide[nWideLen] = (wchar_t)0;
		int nUTF8Len = nWideLen * 4 + 1;
		char* pUTF8 = csText.GetBuffer( nUTF8Len );
		nUTF8Len = WideCharToMultiByte(CP_UTF8,0,pwszWide,nWideLen,pUTF8,nUTF8Len,NULL,NULL);
		delete[] pwszWide;
		csText.ReleaseBuffer( nUTF8Len );
	}
	return csText;
}

CString CMarkupDlg::WinUTF8ToA( CString csText )
{
	int nUTF8Len = csText.GetLength();
	if ( nUTF8Len )
	{
		wchar_t* pwszWide = new wchar_t[nUTF8Len+1];
		int nWideLen = MultiByteToWideChar(CP_UTF8,0,csText,nUTF8Len,pwszWide,nUTF8Len);
		pwszWide[nWideLen] = (wchar_t)0;
		int nMBLen = nWideLen * 2 + 1;
		char* pMB = csText.GetBuffer( nMBLen );
		BOOL bUsedDefault = FALSE;
		nMBLen = WideCharToMultiByte(CP_ACP,0,pwszWide,nWideLen,pMB,nMBLen,"?",&bUsedDefault);
		delete[] pwszWide;
		csText.ReleaseBuffer( nMBLen );
	}
	return csText;
}
#endif

void CMarkupDlg::SystemSettings( BOOL bLoad )
{
#ifdef MARKUP_MSXML
	CMarkupMSXML xmlSettings;
#else
	CMarkup xmlSettings;
#endif

	// Find/Create app data folder
	CString csUserAppDataPath = GetSpecialPath( 0x001a ); // CSIDL_APPDATA
	if ( csUserAppDataPath.IsEmpty() )
		return;
	CString csCompanyFolder = csUserAppDataPath + "firstobject";
	CString csSettingsFolder = csCompanyFolder + "\\CMarkup";
	CString csSettingsPathName = csSettingsFolder + "\\settings.xml";
#if defined( _MBCS )
	setlocale( LC_ALL, "C" );
	setlocale( LC_ALL, "" );
#endif
	if ( ! xmlSettings.Load((LPCTSTR)csSettingsPathName) )
	{
		if ( _taccess(csCompanyFolder,0) != 0 )
		{
			if ( ! CreateDirectory(csCompanyFolder,NULL) )
				return;
		}
		if ( _taccess(csSettingsFolder,0) != 0 )
		{
			if ( ! CreateDirectory(csSettingsFolder,NULL) )
				return;
		}
	}

	if ( bLoad )
	{
		MCD_STR strFilename;
		if ( FindEntry(xmlSettings,_T("Settings"),_T("Filename"),strFilename) && strFilename != _T("") )
		{
			CString csFilename = MCD_2PCSZ(strFilename);
#if ! defined(_UNICODE) && ! defined(_MBCS)
			csFilename = WinUTF8ToA( csFilename );
#endif
			GetDlgItem( IDC_EDIT_FILE )->SetWindowText( csFilename );
		}
		MCD_STR csPos;
		if ( FindEntry(xmlSettings,_T("Settings"),_T("Position"),csPos) )
		{
			CPoint ptDlg;
			if ( _stscanf( MCD_2PCSZ(csPos), _T("%d,%d"), &ptDlg.x, &ptDlg.y ) == 2 )
			{
				CRect rect;
				GetWindowRect( &rect );
				if ( rect.Width() > 10 )
				{
					rect.OffsetRect( ptDlg.x - rect.left, ptDlg.y - rect.top ); 
					MoveWindow( &rect );
				}
			}
		}
	}
	else // save
	{
		CString csFilename;
		GetDlgItem( IDC_EDIT_FILE )->GetWindowText( csFilename );
#if ! defined(_UNICODE) && ! defined(_MBCS)
		csFilename = WinAToUTF8( csFilename );
#endif
		MCD_STR strFilename = csFilename;
		SetEntry( xmlSettings, _T("Settings"), _T("Filename"), strFilename );
		CRect rect;
		GetWindowRect( &rect );
		CString csPos;
		csPos.Format( _T("%d,%d"), rect.left, rect.top );
		MCD_STR strPos = csPos;
		SetEntry( xmlSettings, _T("Settings"), _T("Position"), strPos );
		xmlSettings.Save( (LPCTSTR)csSettingsPathName );
	}
}

#ifdef MARKUP_MSXML
void SimpleMerge( CMarkupMSXML& xmlMaster, CMarkupMSXML& xmlUpdate )
#else
void SimpleMerge( CMarkup& xmlMaster, CMarkup& xmlUpdate )
#endif
{
	// Generic merge xmlUpdate into xmlMaster when element names are unique among siblings
	// removing elements from xmlUpdate as added to or overrided in xmlMaster
	//
	MCD_STR strMergeName;
	xmlMaster.ResetPos();
	xmlUpdate.ResetPos();
	BOOL bMergeFinished = FALSE;
	if ( ! xmlMaster.FindChildElem() )
	{
		xmlMaster = xmlUpdate;
		bMergeFinished = TRUE;
	}
	xmlUpdate.FindChildElem();
	while ( ! bMergeFinished )
	{
		// Process Element
		xmlMaster.IntoElem();
		xmlUpdate.IntoElem();
		strMergeName = xmlMaster.GetTagName();

		// Did this one match?
		xmlUpdate.ResetMainPos();
		BOOL bMatched = xmlUpdate.FindElem( strMergeName );
		if ( bMatched )
		{
			// Merge attributes
			for ( int nAttrib=0; !MCD_STRISEMPTY((strMergeName=xmlUpdate.GetAttribName(nAttrib))); ++nAttrib )
				xmlMaster.SetAttrib( strMergeName, xmlUpdate.GetAttrib(strMergeName) );
		}

		// Next element (depth first)
		BOOL bChildFound = xmlMaster.FindChildElem();
		while ( ! bChildFound && ! bMergeFinished )
		{
			if ( bMatched )

⌨️ 快捷键说明

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