365 lines
11 KiB
C++
365 lines
11 KiB
C++
// GridStylePage.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "resource.h"
|
|
#include "GridStylePage.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
extern int g_nHorModeNum, g_nVerModeNum, g_nFactorNum, g_nTextSizeNum;
|
|
|
|
//extern TARCH_IMPEXP XString GetSymbolName(AcDbObjectId idSymbolRec);
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CGridStylePage property page
|
|
|
|
IMPLEMENT_DYNCREATE(CGridStylePage, CPropertyPage)
|
|
|
|
void CGridStylePage::_CGridStylePage()
|
|
{
|
|
m_bInherit=FALSE;
|
|
//{{AFX_DATA_INIT(CGridStylePage)
|
|
m_nHorMode = -1;
|
|
m_csLineSpaceFactor = _T("");
|
|
m_csTextSize = _T("");
|
|
m_nTextStyle = -1;
|
|
m_bTextWrap = FALSE;
|
|
m_nVerMode = -1;
|
|
//}}AFX_DATA_INIT
|
|
m_nTextColor=0;
|
|
}
|
|
|
|
CGridStylePage::CGridStylePage()
|
|
{
|
|
_CGridStylePage();
|
|
}
|
|
|
|
CGridStylePage::CGridStylePage(UINT id) : CPropertyPage(id)
|
|
{
|
|
_CGridStylePage();
|
|
}
|
|
|
|
CGridStylePage::~CGridStylePage()
|
|
{
|
|
}
|
|
|
|
|
|
// 继承性质存在时
|
|
void CGridStylePage::Obj2Dlg(const TGridStyle &styleLocal, const TGridStyle &styleParent)
|
|
{
|
|
//水平对齐
|
|
BOOL bLocal=styleLocal.TestFlagBit(OF_HORMODE);
|
|
if(bLocal) {
|
|
m_nHorMode=HorMode2Index(styleLocal.GetHorMode());
|
|
} else {
|
|
m_nHorMode=0;
|
|
}
|
|
XString sHorMode;
|
|
int nParentHorMode=HorMode2Index(styleParent.GetHorMode());
|
|
sHorMode << g_szHorModes[nParentHorMode] << _T("(继承)");
|
|
*m_lstHorModes[0]=sHorMode;
|
|
|
|
|
|
//垂直对齐
|
|
bLocal=styleLocal.TestFlagBit(OF_VERMODE);
|
|
m_nVerMode=bLocal? VerMode2Index(styleLocal.GetVerMode()) : 0;
|
|
int nParentVerMode=VerMode2Index(styleParent.GetVerMode());
|
|
XString sVerMode;
|
|
sVerMode << g_szVerModes[nParentVerMode] << _T("(继承)");
|
|
*m_lstVerModes[0]=sVerMode;
|
|
|
|
|
|
// 行距系数
|
|
bLocal=styleLocal.TestFlagBit(OF_LINESPACE);
|
|
if(bLocal) {
|
|
m_csLineSpaceFactor.Format(_T("%.1f"), styleLocal.GetLineSpaceFactor());
|
|
} else {
|
|
m_csLineSpaceFactor.Format(_T("%.1f"), styleParent.GetLineSpaceFactor());
|
|
}
|
|
*m_lstFactors[0]=XString(_T("%.1f(继承)"), styleParent.GetLineSpaceFactor());
|
|
|
|
|
|
//文字高度
|
|
bLocal=styleLocal.TestFlagBit(OF_TEXTHEIGHT);
|
|
if(bLocal) {
|
|
m_csTextSize.Format(_T("%.1f"), styleLocal.GetTextHeight());
|
|
} else {
|
|
m_csTextSize.Format(_T("%.1f"), styleParent.GetTextHeight());
|
|
}
|
|
*m_lstTextSizes[0]=XString(_T("%.1f(继承)"), styleParent.GetTextHeight());
|
|
|
|
|
|
//文字样式
|
|
bLocal=styleLocal.TestFlagBit(OF_TEXTSTYLE);
|
|
if(bLocal) {
|
|
AcDbObjectId idLocal=styleLocal.GetTextStyleId();
|
|
if(!!idLocal) {
|
|
XString szStyle=GetSymbolName(idLocal);
|
|
for(int i=1; i<m_lstTextStyles.Length(); i++) {
|
|
if(_tcsicmp(*m_lstTextStyles[i], szStyle)==0) {
|
|
m_nTextStyle=i;
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
m_nTextStyle=-1;
|
|
}
|
|
} else {
|
|
m_nTextStyle=0;
|
|
}
|
|
AcDbObjectId idParent=styleParent.GetTextStyleId();
|
|
if(!!idParent) {
|
|
XString sParentStyle=GetSymbolName(idParent);
|
|
*m_lstTextStyles[0]=XString(_T("%s(继承)"), (const TCHAR *)sParentStyle);
|
|
}
|
|
|
|
//换行属性
|
|
bLocal=styleLocal.TestFlagBit(OF_TEXTWRAP);
|
|
m_bTextWrap=bLocal? styleLocal.IsTextWrap() : styleParent.IsTextWrap();
|
|
m_bParentTextWrap=styleParent.IsTextWrap();
|
|
m_bInheritWrapText=!bLocal;
|
|
|
|
//颜色
|
|
bLocal=styleLocal.TestFlagBit(OF_TEXTCOLOR);
|
|
m_nTextColor = bLocal? styleLocal.GetTextColor() : 0;
|
|
if(styleParent.GetTextColor())
|
|
m_colorComboBox.SetBlockColorIndex(styleParent.GetTextColor());
|
|
}
|
|
|
|
void CGridStylePage::Dlg2Obj(TGridStyle &styleLocal, const TGridStyle &styleParent) const
|
|
{
|
|
//水平对齐
|
|
styleLocal.SetFlagBit(OF_HORMODE, m_nHorMode!=0);
|
|
if(m_nHorMode>0)
|
|
styleLocal.SetHorMode(Index2HorMode(m_nHorMode));
|
|
else
|
|
styleLocal.SetHorMode(styleParent.GetHorMode());
|
|
|
|
|
|
//垂直对齐
|
|
styleLocal.SetFlagBit(OF_VERMODE, m_nVerMode!=0);
|
|
if(m_nVerMode>0)
|
|
styleLocal.SetVerMode(Index2VerMode(m_nVerMode));
|
|
else
|
|
styleLocal.SetVerMode(styleParent.GetVerMode());
|
|
|
|
// 行距系数
|
|
if(_tcsicmp(m_csLineSpaceFactor, m_lstFactors[0])==0) {
|
|
styleLocal.SetFlagBit(OF_LINESPACE, FALSE);
|
|
styleLocal.SetLineSpaceFactor(styleParent.GetLineSpaceFactor());
|
|
} else if(!m_csLineSpaceFactor.IsEmpty() && _tstof(m_csLineSpaceFactor)>-1.0E-3) {
|
|
styleLocal.SetFlagBit(OF_LINESPACE, TRUE);
|
|
styleLocal.SetLineSpaceFactor(_tstof(m_csLineSpaceFactor));
|
|
}
|
|
|
|
//文字高度
|
|
if(_tcscmp(m_csTextSize, m_lstTextSizes[0])==0) {
|
|
styleLocal.SetFlagBit(OF_TEXTHEIGHT, FALSE);
|
|
styleLocal.SetTextHeight(styleParent.GetTextHeight());
|
|
} else if(!m_csTextSize.IsEmpty() && _tstof(m_csTextSize)>0.0) {
|
|
styleLocal.SetFlagBit(OF_TEXTHEIGHT, TRUE);
|
|
styleLocal.SetTextHeight(_tstof(m_csTextSize));
|
|
}
|
|
|
|
//文字样式
|
|
if(m_nTextStyle==0) {
|
|
styleLocal.SetFlagBit(OF_TEXTSTYLE, FALSE);
|
|
styleLocal.SetTextStyleId(styleParent.GetTextStyleId());
|
|
} else if(m_nTextStyle>0) {
|
|
styleLocal.SetFlagBit(OF_TEXTSTYLE, TRUE);
|
|
styleLocal.SetTextStyleId(GetTextStyleId(m_lstTextStyles[m_nTextStyle]));
|
|
}
|
|
|
|
//换行属性
|
|
if(m_bInheritWrapText) {
|
|
styleLocal.SetFlagBit(OF_TEXTWRAP, FALSE);
|
|
styleLocal.SetTextWrap(styleParent.IsTextWrap());
|
|
} else {
|
|
styleLocal.SetFlagBit(OF_TEXTWRAP, TRUE);
|
|
styleLocal.SetTextWrap(m_bTextWrap);
|
|
}
|
|
|
|
|
|
//颜色
|
|
if(m_nTextColor==0) {
|
|
styleLocal.SetFlagBit(OF_TEXTCOLOR, FALSE);
|
|
styleLocal.SetTextColor(styleParent.GetTextColor());
|
|
} else if(m_nTextColor>0) {
|
|
styleLocal.SetFlagBit(OF_TEXTCOLOR, TRUE);
|
|
styleLocal.SetTextColor(m_nTextColor);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 没有继承的时候
|
|
void
|
|
CGridStylePage::Obj2Dlg(const TGridStyle &style)
|
|
{
|
|
//水平对齐
|
|
AcDb::TextHorzMode nHorMode=style.GetHorMode();
|
|
m_nHorMode=HorMode2Index(nHorMode)-1;
|
|
|
|
//垂直对齐
|
|
AcDb::TextVertMode nVerMode=style.GetVerMode();
|
|
m_nVerMode=VerMode2Index(nVerMode)-1;
|
|
|
|
// 行距系数
|
|
double nFactor=style.GetLineSpaceFactor();
|
|
m_csLineSpaceFactor.Format(_T("%.1f"), nFactor);
|
|
|
|
//文字高度
|
|
double nTextSize=style.GetTextHeight();
|
|
m_csTextSize.Format(_T("%.1f"), nTextSize);
|
|
|
|
//文字样式
|
|
AcDbObjectId idStyle=style.GetTextStyleId();
|
|
if(!!idStyle) {
|
|
XString szStyle=GetSymbolName(idStyle);
|
|
for(int i=0; i<m_lstTextStyles.Length(); i++) {
|
|
if(_tcsicmp(*m_lstTextStyles[i], szStyle)==0) {
|
|
m_nTextStyle=i;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//换行属性
|
|
m_bTextWrap=style.IsTextWrap();
|
|
|
|
//颜色
|
|
m_nTextColor = style.GetTextColor();
|
|
}
|
|
|
|
void
|
|
CGridStylePage::Dlg2Obj(TGridStyle &gridStyle) const
|
|
{
|
|
//水平对齐
|
|
gridStyle.SetHorMode(Index2HorMode(m_nHorMode+1));
|
|
//垂直对齐
|
|
gridStyle.SetVerMode(Index2VerMode(m_nVerMode+1));
|
|
|
|
// 行距系数
|
|
if(_tstof(m_csLineSpaceFactor)>-1.0E-3)
|
|
gridStyle.SetLineSpaceFactor(_tstof(m_csLineSpaceFactor));
|
|
|
|
//文字高度
|
|
if(_tstof(m_csTextSize)>1.0E-3)
|
|
gridStyle.SetTextHeight(_tstof(m_csTextSize));
|
|
//文字样式
|
|
if(m_nTextStyle>=0)
|
|
gridStyle.SetTextStyleId(GetTextStyleId(m_lstTextStyles[m_nTextStyle]));
|
|
//换行属性
|
|
gridStyle.SetTextWrap(m_bTextWrap);
|
|
//颜色
|
|
gridStyle.SetTextColor(m_nTextColor);
|
|
}
|
|
|
|
|
|
void CGridStylePage::InitComBox(CComboBox& combox, const DList<XString> &lstString)
|
|
{
|
|
combox.ResetContent();
|
|
for (int i = 0 ; i < lstString.Length(); i++) {
|
|
combox.AddString(lstString[i]);
|
|
}
|
|
}
|
|
|
|
|
|
void CGridStylePage::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CPropertyPage::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CGridStylePage)
|
|
DDX_Control(pDX, IDC_LINESPACEFACTOR, m_factorBox);
|
|
DDX_Control(pDX, IDC_TEXTSIZE, m_textSizeBox);
|
|
DDX_Control(pDX, IDC_VERMODE, m_verModeBox);
|
|
DDX_Control(pDX, IDC_TEXTSTYLE, m_textStyleBox);
|
|
DDX_Control(pDX, IDC_HORMODE, m_horModeBox);
|
|
DDX_Control(pDX, IDC_TEXTCOLOR, m_colorComboBox);
|
|
DDX_CBIndex(pDX, IDC_HORMODE, m_nHorMode);
|
|
DDX_CBString(pDX, IDC_LINESPACEFACTOR, m_csLineSpaceFactor);
|
|
DDX_CBString(pDX, IDC_TEXTSIZE, m_csTextSize);
|
|
DDX_CBIndex(pDX, IDC_TEXTSTYLE, m_nTextStyle);
|
|
DDX_Check(pDX, IDC_TEXTWRAP, m_bTextWrap);
|
|
DDX_CBIndex(pDX, IDC_VERMODE, m_nVerMode);
|
|
//}}AFX_DATA_MAP
|
|
if(m_bInherit)
|
|
DDX_Check(pDX, IDC_INHERIT_TEXTWRAP, m_bInheritWrapText);
|
|
|
|
if(pDX->m_bSaveAndValidate) {
|
|
// 检查对话框输入是否合法
|
|
//...
|
|
int nIndex=m_colorComboBox.GetCurrentItemColorIndex();
|
|
if(nIndex>=0)
|
|
m_nTextColor=nIndex;
|
|
|
|
if(_tstof(m_csTextSize)<1.0E-3 || _tstof(m_csLineSpaceFactor)<-1.0E-3)
|
|
pDX->Fail();
|
|
}
|
|
}
|
|
|
|
void CGridStylePage::InitDataMember(BOOL bInherit)
|
|
{
|
|
m_bInherit=bInherit;
|
|
|
|
int nFrom=m_bInherit? 0 : 1;
|
|
for(int i=nFrom; i<5; i++)
|
|
m_lstHorModes.Append(new XString(g_szHorModes[i]));
|
|
for(i=nFrom; i<4; i++)
|
|
m_lstVerModes.Append(new XString(g_szVerModes[i]));
|
|
for(i=nFrom; i<g_nFactorNum; i++)
|
|
m_lstFactors.Append(new XString(g_szFactors[i]));
|
|
for(i=nFrom; i<g_nTextSizeNum; i++)
|
|
m_lstTextSizes.Append(new XString(g_szTextSizes[i]));
|
|
|
|
XSymbolList lstStyles(_T("STYLE"));
|
|
if(m_bInherit)
|
|
m_lstTextStyles.Append(new XString(_T("继承")));
|
|
for(i=0; i<lstStyles.Length(); i++)
|
|
m_lstTextStyles.Append(new XString(lstStyles[i]));
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CGridStylePage, CPropertyPage)
|
|
//{{AFX_MSG_MAP(CGridStylePage)
|
|
ON_BN_CLICKED(IDC_INHERIT_TEXTWRAP, OnInheritTextwrap)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CGridStylePage message handlers
|
|
BOOL CGridStylePage::OnInitDialog()
|
|
{
|
|
CPropertyPage::OnInitDialog();
|
|
|
|
InitComBox(m_textSizeBox, m_lstTextSizes);
|
|
InitComBox(m_horModeBox, m_lstHorModes);
|
|
InitComBox(m_verModeBox, m_lstVerModes);
|
|
InitComBox(m_textStyleBox, m_lstTextStyles);
|
|
InitComBox(m_factorBox, m_lstFactors);
|
|
int nItem=m_colorComboBox.FindItemByColorIndex(m_nTextColor);
|
|
if(nItem<0) {
|
|
m_colorComboBox.AddColorToMRU(m_nTextColor);
|
|
nItem=m_colorComboBox.FindItemByColorIndex(m_nTextColor);
|
|
}
|
|
if(nItem>=0) m_colorComboBox.SetCurSel(nItem);
|
|
UpdateData(FALSE);
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
|
|
void CGridStylePage::OnInheritTextwrap()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData(TRUE);
|
|
GetDlgItem(IDC_TEXTWRAP)->EnableWindow(!m_bInheritWrapText);
|
|
if(m_bInheritWrapText)
|
|
m_bTextWrap=m_bParentTextWrap;
|
|
UpdateData(FALSE);
|
|
}
|
|
|