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

📄 formattabdlg.cpp

📁 mtext,编辑器,支持潜入对象
💻 CPP
字号:
// FormatTabDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FormatTabDlg.h"
#include "DDXM.h"
#include "MtextDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define DDXM_BLANK INT_MAX

/////////////////////////////////////////////////////////////////////////////
// CFormatTabDlg dialog


CMTextFormatTabDlg::CMTextFormatTabDlg(PARAFORMAT& pf,CWnd* pParent /*=NULL*/)
	: CDialog(CMTextFormatTabDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFormatTabDlg)
	m_nAlignment = -1;
	//}}AFX_DATA_INIT
////////////////////////左边//////////////////////////////////////////////////////
	m_nWordWrap=-1;
	m_pf = pf;
	if (m_pf.dwMask & PFM_ALIGNMENT)
	{
		if (m_pf.wAlignment & PFA_LEFT && m_pf.wAlignment & PFA_RIGHT)
			m_nAlignment = 2;
		else
			m_nAlignment = (m_pf.wAlignment & PFA_LEFT) ? 0 : 1;
	}
	else
		m_nAlignment = -1;

////////////////////////右边/////////////////////////////////////////////////////
	m_tabarray = new LONG[MAX_TAB_STOPS];
	m_nCount = 0;
	if (m_pf.dwMask & PFM_TABSTOPS)
	{
		m_nCount = m_pf.cTabCount;
		ASSERT(m_pf.cTabCount <= MAX_TAB_STOPS);
		for (int i=0;i<m_pf.cTabCount;i++)
			m_tabarray[i] = m_pf.rgxTabs[i];
	}

	CMTextDDXM::Initial();
}


void CMTextFormatTabDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFormatTabDlg)
	DDX_Control(pDX, IDC_BUTTON1_Set, m_buttonSet);
	DDX_Control(pDX, IDC_BUTTON2_Clear, m_buttonClear);
	DDX_Control(pDX, IDC_BUTTON2_ClearAll, m_buttonClearAll);
	DDX_Control(pDX, IDC_COMBO2_table, m_comboBox);
	DDX_CBIndex(pDX, IDC_COMBO_ALIGNMENT, m_nAlignment);
	//}}AFX_DATA_MAP
	if (!pDX->m_bSaveAndValidate)
		UpdateListBox();
}


BEGIN_MESSAGE_MAP(CMTextFormatTabDlg, CDialog)
	//{{AFX_MSG_MAP(CFormatTabDlg)
	ON_BN_CLICKED(IDC_BUTTON1_Set, OnBUTTON1Set)
	ON_BN_CLICKED(IDC_BUTTON2_Clear, OnBUTTON2Clear)
	ON_BN_CLICKED(IDC_BUTTON2_ClearAll, OnBUTTON2ClearAll)
	ON_CBN_EDITCHANGE(IDC_COMBO2_table, OnEditchangeCOMBO2table)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFormatTabDlg message handlers

void CMTextFormatTabDlg::OnOK() 
{
	// TODO: Add extra validation here
	CDialog::OnOK();
	m_pf.dwMask = 0;
	if (m_nAlignment >= 0)
	{
		ASSERT(m_nAlignment < 3);
		m_pf.dwMask |= PFM_ALIGNMENT;
		m_pf.wAlignment = (WORD)((m_nAlignment == 0) ? PFA_LEFT :
		(m_nAlignment == 1) ? PFA_RIGHT : PFA_CENTER);
	}
	if (m_lRight != DDXM_BLANK)
		m_pf.dwMask |= PFM_RIGHTINDENT;
	if (m_lLeft  != DDXM_BLANK && m_lFirst != DDXM_BLANK)
		m_pf.dwMask |= PFM_STARTINDENT;
	if (m_lFirst != DDXM_BLANK)
		m_pf.dwMask |= PFM_OFFSET;

	
	
/*
	int nTab;
	CDataExchange dx(this, TRUE);
	CMTextDDXM::DDX_Twips(&dx, IDC_EDIT_First, nTab);
//	CDDXM::DDV_MinMaxTwips(&dx, nTab, 0, 31680);
	m_lFirst=nTab;
	
//	CDataExchange dx(this, TRUE);
	CMTextDDXM::DDX_Twips(&dx, IDC_EDIT_Left, nTab);
//	CDDXM::DDV_MinMaxTwips(&dx, nTab, 0, 31680);
	m_lLeft=nTab;
	
//	CDataExchange dx(this, TRUE);
	CMTextDDXM::DDX_Twips(&dx, IDC_EDIT_Right, nTab);
	//CDDXM::DDV_MinMaxTwips(&dx, nTab, 0, 31680);
	m_lRight=nTab;
	CMTextDlg::ConvertTextHeightToTwips()
	m_lFirst/=m_FontSizeScale;
	m_lRight/=m_FontSizeScale;
	m_lLeft/=m_FontSizeScale;*/


	CString strSize;
	GetDlgItem(IDC_EDIT_First)->GetWindowText(strSize);
	CMTextDlg::ConvertTextHeightToTwips(atof(strSize),m_lFirst);
	GetDlgItem(IDC_EDIT_Left)->GetWindowText(strSize);
	CMTextDlg::ConvertTextHeightToTwips(atof(strSize),m_lLeft);
	GetDlgItem(IDC_EDIT_Right)->GetWindowText(strSize);
	CMTextDlg::ConvertTextHeightToTwips(atof(strSize),m_lRight);
	
	m_lFirst/=m_FontSizeScale;
	m_lRight/=m_FontSizeScale;
	m_lLeft/=m_FontSizeScale;

	m_pf.dxRightIndent = LONG(m_lRight);
	m_pf.dxOffset = -LONG(m_lFirst);
	m_pf.dxStartIndent = LONG(m_lLeft + m_lFirst);

	m_pf.cTabCount = (SHORT) m_nCount;
	for (int i=0;i<m_nCount;i++)
		m_pf.rgxTabs[i] = m_tabarray[i];
	m_pf.dwMask |= PFM_TABSTOPS;

}

BOOL CMTextFormatTabDlg::OnInitDialog() 
{

	CMTextDDXM::m_FontSizeScale=m_FontSizeScale;
	// TODO: Add extra initialization here
	CComboBox* pBox = (CComboBox*)GetDlgItem(IDC_COMBO_ALIGNMENT);
	CString str;
	str.LoadString(IDS_LEFT);
	pBox->AddString(str);
	str.LoadString(IDS_RIGHT);
	pBox->AddString(str);
	str.LoadString(IDS_CENTER);
	pBox->AddString(str);



	if (m_nWordWrap == 0)
	{
		GetDlgItem(IDC_COMBO_ALIGNMENT)->EnableWindow(FALSE);
	//	GetDlgItem(IDC_TEXT_ALIGNMENT)->EnableWindow(FALSE);
	}
	
	m_lRight =(m_pf.dwMask & PFM_RIGHTINDENT) ? m_pf.dxRightIndent : DDXM_BLANK;
	if (m_pf.dwMask & PFM_OFFSET)
	{
		m_lFirst = -m_pf.dxOffset;
		m_lLeft = (m_pf.dwMask & PFM_STARTINDENT) ?
			m_pf.dxStartIndent + m_pf.dxOffset : DDXM_BLANK;
	}
	else
		m_lLeft = m_lFirst =DDXM_BLANK;


	TCHAR szT[64];
	
	m_lLeft*=m_FontSizeScale;
	m_lRight*=m_FontSizeScale;
	m_lFirst*=m_FontSizeScale;
	sds_real lfSize;
	CMTextDlg::ConvertTwipsToTextHeight(lfSize,m_lLeft);
	//CMTextDDXM::PrintTwips(szT, m_lLeft, 2);
	sprintf(szT,"%lf",lfSize);
	GetDlgItem(IDC_EDIT_Left)->SetWindowText(szT);

	CMTextDlg::ConvertTwipsToTextHeight(lfSize,m_lRight);
//	CMTextDDXM::PrintTwips(szT, m_lRight, 2);
	sprintf(szT,"%lf",lfSize);
	GetDlgItem(IDC_EDIT_Right)->SetWindowText(szT);

	CMTextDlg::ConvertTwipsToTextHeight(lfSize,m_lFirst);
//	CMTextDDXM::PrintTwips(szT, m_lFirst, 2);
	sprintf(szT,"%lf",lfSize);
	GetDlgItem(IDC_EDIT_First)->SetWindowText(szT);


	CDialog::OnInitDialog();
	 UpdateButtons();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

CMTextFormatTabDlg::~CMTextFormatTabDlg()
{
	delete [] m_tabarray;
}

BOOL CMTextFormatTabDlg::Set()
{
	int nTab;
	CDataExchange dx(this, TRUE);
	CMTextDDXM::DDX_Twips(&dx, IDC_COMBO2_table, nTab);
	CMTextDDXM::DDV_MinMaxTwips(&dx, nTab, 0, 31680);
	if (nTab != DDXM_BLANK)
	{
		if (m_nCount == MAX_TAB_STOPS)
		{
			AfxMessageBox(IDS_NOMORETABS);
			m_comboBox.Clear();
			return FALSE;
		}
		if (AddTabToArray(nTab))
			UpdateListBox();
		return TRUE;
	}
	return FALSE;
}

BOOL CMTextFormatTabDlg::AddTabToArray(LONG lTab)
{
	int i;
	BOOL bInsert = FALSE;
	LONG lTemp;
	for (i=0;i<m_nCount;i++)
	{
		if (!bInsert && lTab < m_tabarray[i])
			bInsert = TRUE;
		else if (lTab == m_tabarray[i]) // we don't want repeats
			return FALSE;
		if (bInsert)
		{
			lTemp = m_tabarray[i];
			m_tabarray[i] = lTab;
			lTab = lTemp;
		}
	}
	m_tabarray[m_nCount++] = lTab;
	return TRUE;
}

void CMTextFormatTabDlg::UpdateListBox()
{
	int i;
	TCHAR szT[64];
	ASSERT(m_nCount >= 0);
	m_comboBox.ResetContent();
	for (i=0;i<m_nCount;i++)
	{
		CMTextDDXM::PrintTwips(szT, m_tabarray[i], 2);
		m_comboBox.AddString(szT);
	}
}

void CMTextFormatTabDlg::OnBUTTON1Set() 
{
	// TODO: Add your control notification handler code here
	Set();
	UpdateButtons();
	SetEditFocus();
}

void CMTextFormatTabDlg::OnBUTTON2Clear() 
{
	// TODO: Add your control notification handler code here
	int nTab;
	int nSel = m_comboBox.GetCurSel();
	if (nSel == CB_ERR)
	{
		CDataExchange dx(this, TRUE);
		CMTextDDXM::DDX_Twips(&dx, IDC_COMBO2_table, nTab);
		CMTextDDXM::DDV_MinMaxTwips(&dx, nTab, 0, 31680);
		if (nTab != DDXM_BLANK)
		{
				if (RemoveTabFromArray(nTab))
					UpdateListBox();
		}
	}
	else
	{
		ASSERT(nSel < m_nCount);
		RemoveTabFromArrayByIndex(nSel);
		UpdateListBox();
	}
	UpdateButtons();
	SetEditFocus();
}
BOOL CMTextFormatTabDlg::RemoveTabFromArray(LONG lTab)
{
	int i;
	for (i=0;i<m_nCount;i++)
	{
		if (m_tabarray[i] == lTab)
		{
			RemoveTabFromArrayByIndex(i);
			return TRUE;
		}
	}
	return FALSE;
}
void CMTextFormatTabDlg::RemoveTabFromArrayByIndex(int nIndex)
{
	memmove(&m_tabarray[nIndex], &m_tabarray[nIndex+1],
		(m_nCount-nIndex-1)*sizeof(LONG));
	m_nCount--;
}

void CMTextFormatTabDlg::OnBUTTON2ClearAll() 
{
	// TODO: Add your control notification handler code here
	m_nCount = 0;
	m_comboBox.ResetContent();
	UpdateButtons();
	SetEditFocus();
}

void CMTextFormatTabDlg::UpdateButtons()
{
	UpdateButton(m_buttonClearAll, m_nCount > 0);
	BOOL bHasText = (m_comboBox.GetWindowTextLength() > 0);
	UpdateButton(m_buttonSet, bHasText);
	UpdateButton(m_buttonClear, bHasText);
	WORD wID = LOWORD(GetDefID());
	if (bHasText && wID != IDC_BUTTON1_Set)
		SetDefID(IDC_BUTTON1_Set);
	else if (!bHasText && wID != IDOK)
		SetDefID(IDOK);
}
void CMTextFormatTabDlg::UpdateButton(CButton& button, BOOL b)
{
	if (b != button.IsWindowEnabled())
		button.EnableWindow(b);
}
void CMTextFormatTabDlg::SetEditFocus()
{
	m_comboBox.SetFocus();
	m_comboBox.SetEditSel(0,-1);
}

void CMTextFormatTabDlg::OnEditchangeCOMBO2table() 
{
	// TODO: Add your control notification handler code here
	UpdateButtons();
}


⌨️ 快捷键说明

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