1449 lines
34 KiB
C++
1449 lines
34 KiB
C++
// MutiRowTextDlg.cpp : implementation file
|
||
//
|
||
#include "stdafx.h"
|
||
#include "MutiRowTextDlg.h"
|
||
#include "AcEdInputPointMonitorEx.h"
|
||
#include "xtext.h"
|
||
#include "chardlg.h"
|
||
#include <actrans.h>
|
||
|
||
#ifdef _DEBUG
|
||
#define new DEBUG_NEW
|
||
#undef THIS_FILE
|
||
static char THIS_FILE[] = __FILE__;
|
||
#endif
|
||
|
||
// void NewText2Old(AcDbObjectId idMTextNew)
|
||
// {
|
||
// AcDbObjectId idStyle;
|
||
// double dHeight = 0.0;
|
||
// double dLineSpace = 0.0;
|
||
// double dPageWidth = 0.0;
|
||
// XExplodeDraw::TextAlignment alignType;
|
||
// std::vector<std::pair<CString, AcGePoint3d> > vec;
|
||
// OPENOBJ_BEGIN(idMTextNew, AcDb::kForRead, TDbMTextNew, pTextNew);
|
||
// if(pTextNew != NULL)
|
||
// {
|
||
// pTextNew->Transform2OldMText(vec);
|
||
// idStyle = pTextNew->GetStyleId();
|
||
// dHeight = pTextNew->GetHeight();
|
||
// dLineSpace = pTextNew->GetLineSpace();
|
||
// dPageWidth = pTextNew->GetPageWidth();
|
||
// alignType = pTextNew->GetAlignment();
|
||
// }
|
||
// OPENOBJ_END();
|
||
//
|
||
// std::vector<std::pair<CString, AcGePoint3d> >::iterator it;
|
||
// for (it = vec.begin(); it != vec.end(); it++)
|
||
// {
|
||
// TDbMText *pMText = new TDbMText;
|
||
// pMText->SetText(it->first);
|
||
// pMText->SetLocation(it->second);
|
||
// pMText->SetStyleId(idStyle);
|
||
// pMText->SetHeight(dHeight);
|
||
//
|
||
// pMText->SetAlignment(alignType);
|
||
// pMText->SetLineSpace(dLineSpace);
|
||
// pMText->SetPageWidth(dPageWidth,TRUE);
|
||
// pMText->AddToCSpace(Adesk::kTrue);
|
||
// }
|
||
// }
|
||
//
|
||
// void NewText2Old()
|
||
// {
|
||
// RBList rbMask(RTDXF0, _T("ATS_MTEXTNEW"), NULL);
|
||
// Entity entTextOld;
|
||
// if(SelectEntity(_T("\n请选择要转换的多行文字:<退出>"), entTextOld, rbMask) != RTNORM)
|
||
// return;
|
||
//
|
||
// AcDbObjectId id;
|
||
// acdbGetObjectId(id, entTextOld);
|
||
// NewText2Old(id);
|
||
// }
|
||
|
||
// 希腊字符特殊处理
|
||
bool IsGreeceChar(const CString &sWord)
|
||
{
|
||
char charGreece[][3] = {"Α","Β","Γ","Δ","Ε","Ζ","Η",
|
||
"Θ","Ι","Κ","Λ","Μ","Ν","Ξ",
|
||
"Ο","Π","Ρ","Σ","Τ","Υ","Φ",
|
||
"Χ","Ψ","Ω","α","β","γ","δ",
|
||
"ε","ζ","η","θ","ι","κ","λ",
|
||
"μ","ν","ξ","ο","π","ρ","σ",
|
||
"τ","υ","φ","χ","ψ","ω"};
|
||
for (int n = 0; n < 48; n++)
|
||
{
|
||
if (sWord == charGreece[n])
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
// 编辑多行文字
|
||
int EditMutiText(AcDbObjectId id)
|
||
{
|
||
xg_setvar(_T("CMDECHO"), 0);
|
||
XPoint ptCur;
|
||
AcEdInputPointMonitorEx cMonitor(curDoc());
|
||
GetWcsCursor(ptCur);
|
||
ptCur = Ucs2Wcs(ptCur);
|
||
|
||
double nHeight = 0.0, nPageWidth = 0.0;
|
||
CMutiRowTextDlg dlg(TRUE, acedGetAcadFrame());
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbMTextNew, pText);
|
||
if(!pText)
|
||
return RTERROR;
|
||
dlg.Obj2Dlg(pText);
|
||
dlg.SetCursorPos(ptCur);
|
||
dlg.SetCurTextId(id);
|
||
OPENOBJ_END();
|
||
|
||
CTemporaryResourceOverride vTemp;
|
||
if(dlg.DoModal() != IDOK)
|
||
return RTNONE;
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbMTextNew, pText);
|
||
if(!pText)
|
||
return RTERROR;
|
||
if(pText->upgradeOpen()!=Acad::eOk)
|
||
return RTERROR;
|
||
|
||
pText->assertWriteEnabled();
|
||
|
||
dlg.Dlg2Obj(pText);
|
||
pText->downgradeOpen();
|
||
OPENOBJ_END();
|
||
|
||
return RTNORM;
|
||
}
|
||
|
||
// 多行文字 zxl 2012.10.26
|
||
void TextMLine()
|
||
{
|
||
double nHeight = 0.0,
|
||
nRot = 0.0,
|
||
nPageWidth = 0.0;
|
||
|
||
CMutiRowTextDlg dlg(FALSE, acedGetAcadFrame());
|
||
|
||
static XString sTextStyle;
|
||
sTextStyle = DocGetTgSingleTextStyle();
|
||
|
||
// 检查当前记忆的文字样式是否被PU掉
|
||
{
|
||
bool bExist = false;
|
||
|
||
AcDbDatabase *pCurDwg = acdbCurDwg();
|
||
AcDbTextStyleTable* pTT = NULL;
|
||
VERIFY(pCurDwg->getSymbolTable(pTT, AcDb::kForRead)==Acad::eOk);
|
||
|
||
AcDbTextStyleTableIterator* pIter= NULL;
|
||
VERIFY(pTT->newIterator(pIter)==Acad::eOk);
|
||
pTT->close();
|
||
|
||
for (pIter->start(); !pIter->done(); pIter->step())
|
||
{
|
||
AcDbTextStyleTableRecord* pTTR;
|
||
if (pIter->getRecord(pTTR, AcDb::kForRead) != Acad::eOk)
|
||
continue;
|
||
|
||
const TCHAR* pName = NULL;
|
||
if (pTTR->getName(pName) == Acad::eOk && pName != NULL)
|
||
{
|
||
if (_tcsicmp(pName, sTextStyle) == 0) // 如果存在该样式
|
||
{
|
||
pTTR->close();
|
||
bExist = true;
|
||
continue;
|
||
}
|
||
}
|
||
pTTR->close();
|
||
}
|
||
delete pIter;
|
||
|
||
if (!bExist)
|
||
{
|
||
TCHAR sStyle[256]=_T("");
|
||
xg_getvar(_T("TEXTSTYLE"), sStyle);
|
||
sTextStyle = sStyle;
|
||
}
|
||
}
|
||
|
||
// 文字样式不存在
|
||
if (sTextStyle == _T(""))
|
||
{
|
||
TCHAR sStyle[256]=_T("");
|
||
xg_getvar(_T("TEXTSTYLE"), sStyle);
|
||
sTextStyle = sStyle;
|
||
}
|
||
|
||
AcDbObjectId idTextStyle = GetTextStyleId(sTextStyle);
|
||
if (!idTextStyle)
|
||
return;
|
||
|
||
OPENOBJ_BEGIN(idTextStyle, AcDb::kForRead, AcDbTextStyleTableRecord, pStyle);
|
||
ASSERT(pStyle);
|
||
dlg.m_strHeight.Format(_T("%.1f"), pStyle->textSize()); //读文字风格的字高
|
||
OPENOBJ_END();
|
||
|
||
dlg.m_strStyle = (const TCHAR *)sTextStyle;
|
||
{
|
||
CTemporaryResourceOverride vTemp;
|
||
if(dlg.DoModal() != IDOK || dlg.m_strInputText == _T(""))
|
||
return;
|
||
}
|
||
|
||
XPoint ptText, ptRight;
|
||
if(XGetPoint(NULL, _T("\n左上角"), ptText)==RTNORM )
|
||
{
|
||
ptText=Ucs2Wcs(ptText);
|
||
TDbMTextNew *pText = new TDbMTextNew;
|
||
dlg.Dlg2Obj(pText);
|
||
pText->SetLocation(ptText);
|
||
InitLayer(LAY_TEXT);
|
||
pText->setLayer(LAY_TEXT);
|
||
pText->SetRotation(pText->GetRotation()+Ucs2Wcs(0.0));
|
||
// 记录文字样式
|
||
sTextStyle = dlg.m_strStyle;
|
||
|
||
// 保存文字样式到图纸中
|
||
DocSetTgSingleTextStyle(dlg.m_strStyle);
|
||
|
||
AddToCurrentSpace(pText, Adesk::kTrue);
|
||
}
|
||
}
|
||
|
||
|
||
/////////////////////////////////////////////////////////////////////////////
|
||
// CMutiRowTextDlg dialog
|
||
static CString g_strLineSpace = _T("0.4");
|
||
static CString g_strPageWidth = _T("200");
|
||
static double g_nHeight_muti = 3.5;
|
||
static int g_nAlignIndex_muti = 0;
|
||
static CString g_strOldText = _T("");
|
||
|
||
static CString g_strPageHeight = _T("200");
|
||
static CString g_strPageDist = _T("7.0");
|
||
static int g_nPageStyle = 0;
|
||
|
||
// add by xly on 101222初始化多行文字中的转角的变量
|
||
CString CMutiRowTextDlg::m_strRotation = _T("0");
|
||
|
||
static XExplodeDraw::TextAlignment
|
||
g_AlignList_muti[] = { XExplodeDraw::kLeft, XExplodeDraw::kRight ,
|
||
XExplodeDraw::kCenter, XExplodeDraw::kTextFit,};
|
||
|
||
IMPLEMENT_DYNAMIC(CMutiRowTextDlg, CCharToolbarDlg)
|
||
CMutiRowTextDlg::CMutiRowTextDlg(BOOL bEdit, CWnd* pParent /*=NULL*/)
|
||
: CCharToolbarDlg(CMutiRowTextDlg::IDD, pParent),m_bEditObj(bEdit)
|
||
{
|
||
//{{AFX_DATA_INIT(CMutiRowTextDlg)
|
||
m_strInputText = _T("");
|
||
m_strHeight = _T("");
|
||
m_strPageWidth = _T("");
|
||
m_strLineSpace = _T("");
|
||
m_strPageHeight = _T("");
|
||
m_strPageDist = _T("");
|
||
m_nPageStyle = 0;
|
||
//}}AFX_DATA_INIT
|
||
//m_uTimerID = 0;
|
||
m_bInit = FALSE;
|
||
m_nOldSizeX=495;
|
||
m_nOldSizeY=224;
|
||
m_bNeedSingleLineText = FALSE;
|
||
// zxl 2013.02.21 add 增加查找替换功能
|
||
m_strSearch = _T("");
|
||
m_strInstead = _T("");
|
||
m_nSearchStart = 0;
|
||
m_nSearchNum = 0;
|
||
m_nInsteadNum = 0;
|
||
m_bFromS = false;
|
||
m_nSelPos = 0;
|
||
|
||
// zxl 2013.02.21 add 增加设定文字字高和颜色的功能
|
||
m_nColorIndex = 255;
|
||
m_dCurTextHeight = 3.5;
|
||
m_nSelPos = 0;
|
||
}
|
||
|
||
|
||
void CMutiRowTextDlg::DoDataExchange(CDataExchange* pDX)
|
||
{
|
||
CCharToolbarDlg::DoDataExchange(pDX);
|
||
//{{AFX_DATA_MAP(CMutiRowTextDlg)
|
||
DDX_Control(pDX, IDOK, m_ctrlOk);
|
||
DDX_Control(pDX, IDCANCEL, m_ctrlCancel);
|
||
DDX_Control(pDX, IDC_INPUT_TEXT, m_editInputText);
|
||
DDX_Control(pDX, IDC_COMBO_FONGSTYLE, m_comboFontStyle);
|
||
DDX_Control(pDX, IDC_COMBO_ALIGNMENT, m_comboAlign);
|
||
DDX_Control(pDX, IDC_CMB_PAGESTYLE, m_comboPageStyle);
|
||
DDX_Text(pDX, IDC_INPUT_TEXT, m_strInputText);
|
||
DDX_CBString(pDX, IDC_COMBO_HEIGHT, m_strHeight);
|
||
DDX_Text(pDX, IDC_EDIT_PAGEHEIGHT, m_strPageHeight);
|
||
DDX_CBString(pDX, IDC_CMB_PAGEDIST, m_strPageDist);
|
||
DDX_Text(pDX, IDC_PAGE_WIDTH, m_strPageWidth);
|
||
DDX_Text(pDX, IDC_ROTATION, m_strRotation);
|
||
DDX_Text(pDX, IDC_ROWDIST, m_strLineSpace);
|
||
DDX_Text(pDX, IDC_EDIT_SEARCH, m_strSearch);
|
||
DDX_Text(pDX, IDC_EDIT_INSTEAD, m_strInstead);
|
||
//}}AFX_DATA_MAP
|
||
}
|
||
|
||
|
||
BEGIN_MESSAGE_MAP(CMutiRowTextDlg, CCharToolbarDlg)
|
||
//{{AFX_MSG_MAP(CMutiRowTextDlg)
|
||
ON_BN_CLICKED(IDC_BUTTON_PAGEWIDTH, OnButtonPagewidth)
|
||
ON_BN_CLICKED(IDC_BUTTON_TEXT_HEIGHT, OnButtonTextHeight)
|
||
ON_BN_CLICKED(IDC_BTN_PAGEDIST, OnButtonPageDist)
|
||
ON_BN_CLICKED(IDC_BTN_PAGEHEIGHT, OnButtonPageHeight)
|
||
ON_BN_CLICKED(IDC_BTN_ADDAROW, OnButtonAddArow)
|
||
ON_CBN_KILLFOCUS(IDC_COMBO_HEIGHT, OnSetTextHeight)
|
||
ON_CBN_SELCHANGE(IDC_COMBO_HEIGHT, OnSetTextHeight)
|
||
ON_BN_CLICKED(IDC_BTN_COLOR, OnSetTextColor)
|
||
ON_BN_CLICKED(IDC_BUTTON_SEARCH, OnBtnSearch)
|
||
ON_BN_CLICKED(IDC_BUTTON_INSTEAD, OnBtnInstead)
|
||
ON_WM_SIZE()
|
||
ON_WM_CREATE()
|
||
ON_COMMAND(ID_COPY, Copy)
|
||
ON_COMMAND(ID_CUT, Cut)
|
||
ON_COMMAND(ID_UNDO, Undo)
|
||
ON_COMMAND(ID_SELECTALLTEXT, SelAll)
|
||
ON_COMMAND(ID_PST, Paste)
|
||
ON_COMMAND(ID_DELETE, Delete)
|
||
//}}AFX_MSG_MAP
|
||
//ON_COMMAND_RANGE(ID_SPECIAL_CHAR, ID_ONE_STEEL, OnChar)
|
||
END_MESSAGE_MAP()
|
||
|
||
/////////////////////////////////////////////////////////////////////////////
|
||
// CMutiRowTextDlg message handlers
|
||
|
||
|
||
void CMutiRowTextDlg::Copy()
|
||
{
|
||
m_ctrlInputText->Copy();
|
||
}
|
||
void CMutiRowTextDlg::Cut()
|
||
{
|
||
m_ctrlInputText->Cut();
|
||
}
|
||
void CMutiRowTextDlg::Undo()
|
||
{
|
||
m_ctrlInputText->Undo();
|
||
}
|
||
void CMutiRowTextDlg::SelAll()
|
||
{
|
||
m_ctrlInputText->SetSel(0,-1);
|
||
}
|
||
void CMutiRowTextDlg::Paste()
|
||
{
|
||
m_ctrlInputText->Paste();
|
||
}
|
||
void CMutiRowTextDlg::Delete()
|
||
{
|
||
m_ctrlInputText->ReplaceSel(_T(""));
|
||
}
|
||
|
||
BOOL CMutiRowTextDlg::OnInitDialog()
|
||
{
|
||
CCharToolbarDlg::OnInitDialog();
|
||
m_bInit = TRUE;
|
||
CRect rectDlg;
|
||
GetClientRect(rectDlg);
|
||
sizeDlg.cx = rectDlg.Width();
|
||
sizeDlg.cy = rectDlg.Height();
|
||
ResetSize();
|
||
LoadTextStyle();
|
||
|
||
// zxl 2013.02.22 add 增加设定文字颜色功能
|
||
GetDlgItem(IDC_BTN_COLOR)->ModifyStyle(0,BS_OWNERDRAW,0);
|
||
m_btnColor.Attach(IDC_BTN_COLOR, this);
|
||
m_btnColor.SetBackgroundColor(RGB(255,255,255));
|
||
|
||
m_wndToolTip.Create(this);
|
||
m_wndToolTip.AddTool( GetDlgItem(IDC_BTN_COLOR), _T("应用于段落文字,改变段落文字颜色"));
|
||
m_wndToolTip.SetDelayTime(200);
|
||
m_wndToolTip.Activate(TRUE);
|
||
|
||
XPoint pt = m_ptCur;
|
||
TTextPosition pos;
|
||
CString csText;
|
||
if (!!pt)
|
||
{
|
||
ads_name name;
|
||
acdbGetAdsName(name, m_id);
|
||
Entity entSel = name;
|
||
OPENOBJ_BEGIN(m_id, AcDb::kForRead, TDbMTextNew, pText);
|
||
if(!pText)
|
||
return RTERROR;
|
||
csText = pText->GetText();
|
||
pText->GetCurWordPos(pos, pt);
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
if(m_strInputText == _T(""))
|
||
m_strInputText = g_strOldText;
|
||
|
||
m_comboAlign.SetCurSel(g_nAlignIndex_muti);
|
||
m_ctrlInputText = (CRichEditCtrl*)GetDlgItem(IDC_INPUT_TEXT);
|
||
|
||
m_strLineSpace = g_strLineSpace;
|
||
m_strPageWidth = g_strPageWidth;
|
||
m_strPageHeight = g_strPageHeight;
|
||
m_strPageDist = g_strPageDist;
|
||
m_nPageStyle = g_nPageStyle;
|
||
m_comboFontStyle.SetCurSel(m_comboFontStyle.FindStringExact(0, m_strStyle));
|
||
m_comboPageStyle.SetCurSel(m_nPageStyle);
|
||
|
||
UpdateData(FALSE);
|
||
m_editInputText.SetFocus();
|
||
|
||
m_wndToolTip.AddTool( GetDlgItem(IDC_BTN_ADDAROW), _T("应用于段落开头处,实现段落中文字对齐"));
|
||
m_wndToolTip.SetDelayTime(200);
|
||
m_wndToolTip.Activate(TRUE);
|
||
|
||
int nPos = SetCursorPostion(pos.m_nTextPos, csText);
|
||
SetDlgTextProp();
|
||
m_editInputText.SetSel(nPos, nPos, TRUE);
|
||
m_ctrlInputText->SetEventMask(ENM_MOUSEEVENTS);
|
||
|
||
pDXLoad = new CDataExchange(this, FALSE);
|
||
return FALSE; // return TRUE unless you set the focus to a control
|
||
// EXCEPTION: OCX Property Pages should return FALSE
|
||
}
|
||
|
||
// zxl 2013.01.28 add 获取字符个数(区分汉字)
|
||
int GetTextLength(const XString xsText)
|
||
{
|
||
int nLen = 0;
|
||
int nCount = (int)_tcslen(xsText);
|
||
for(int idx = 0; idx < nCount; idx++)
|
||
{
|
||
TCHAR c=xsText[idx];
|
||
if (c < 0 || c > 127)// 汉字
|
||
{
|
||
nLen++;
|
||
}
|
||
nLen++;
|
||
}
|
||
return nLen;
|
||
}
|
||
|
||
// ASCII转化为UNICODE zxl 2013.05.17 add
|
||
wstring ANSIToUnicode(CString& str)
|
||
{
|
||
int len = 0;
|
||
len = str.GetLength();
|
||
int unicodeLen = ::MultiByteToWideChar( CP_ACP,
|
||
0,
|
||
(LPCSTR)(LPCTSTR)str,
|
||
-1,
|
||
NULL,
|
||
0 );
|
||
wchar_t * pUnicode;
|
||
pUnicode = new wchar_t[unicodeLen+1];
|
||
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
|
||
::MultiByteToWideChar( CP_ACP,
|
||
0,
|
||
(LPCSTR)(LPCTSTR)str,
|
||
-1,
|
||
(LPWSTR)pUnicode,
|
||
unicodeLen );
|
||
wstring rt;
|
||
rt = ( wchar_t* )pUnicode;
|
||
delete pUnicode;
|
||
|
||
return rt;
|
||
}
|
||
|
||
void CMutiRowTextDlg::OnBtnSearch()
|
||
{
|
||
long hPos = 0l, lPos = 0l;
|
||
m_ctrlInputText->GetSel(hPos, lPos);
|
||
if (hPos == lPos && hPos == 0l)
|
||
{
|
||
m_bFromS = false;
|
||
m_nSelPos = 0;
|
||
}
|
||
|
||
if (hPos == lPos)
|
||
{
|
||
m_nSearchStart = lPos;
|
||
#if (ADS > 17)
|
||
m_ctrlInputText->SetSel(0, lPos);
|
||
CString szBuf;
|
||
szBuf = m_ctrlInputText->GetSelText();
|
||
// 17平台以上 获取到的字符为ASCII,需要转换为UNICODE zxl 2013.05.17 add
|
||
wstring strText = ANSIToUnicode(szBuf);
|
||
m_nSearchStart = strText.length();
|
||
m_nSelPos = m_nSearchStart;
|
||
|
||
m_ctrlInputText->SetSel(hPos, lPos);
|
||
#endif
|
||
}
|
||
#if (ADS == 17)
|
||
m_ctrlInputText->SetSel(0, lPos);
|
||
CString sText1 = m_ctrlInputText->GetSelText();
|
||
m_nSearchStart = sText1.GetLength();
|
||
m_ctrlInputText->SetSel(hPos, lPos);
|
||
#endif
|
||
|
||
CString sText = m_strSearch;
|
||
UpdateData(TRUE);
|
||
if ((!sText.IsEmpty() && sText.Compare(m_strSearch) != 0) || sText.IsEmpty())
|
||
{
|
||
m_nSearchNum = 0;
|
||
}
|
||
if (m_strSearch.IsEmpty())
|
||
{
|
||
return;
|
||
}
|
||
// 汉字和字符占用字节不同,查找2次
|
||
int nFind = m_strInputText.Find(m_strSearch, m_nSearchStart++);
|
||
int nFind2 = m_strInputText.Find(m_strSearch, m_nSearchStart);
|
||
|
||
if (nFind >= 0 && nFind2 >= 0)
|
||
{
|
||
nFind = nFind2 > nFind ? nFind : nFind2;
|
||
}
|
||
|
||
// 查找完整篇
|
||
if (m_bFromS && nFind >= m_nSelPos)
|
||
{
|
||
nFind = -1;
|
||
}
|
||
|
||
if (nFind < 0)
|
||
{
|
||
// 查找到段尾
|
||
if (!m_bFromS)
|
||
{
|
||
m_bFromS = true;
|
||
m_nSearchStart = 0;
|
||
nFind = m_strInputText.Find(m_strSearch, m_nSearchStart++);
|
||
nFind2 = m_strInputText.Find(m_strSearch, m_nSearchStart);
|
||
|
||
if (nFind >= 0 && nFind2 >= 0)
|
||
{
|
||
nFind = nFind2 > nFind ? nFind : nFind2;
|
||
}
|
||
|
||
if (nFind >= m_nSelPos)
|
||
{
|
||
nFind = -1;
|
||
OutPutMessageBox();
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
OutPutMessageBox();
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (nFind >= 0)
|
||
{
|
||
m_nSearchNum++;
|
||
int nFindEnd = 0;
|
||
nFindEnd = nFind + m_strSearch.GetLength();
|
||
int nFindPos = nFind;
|
||
|
||
#if (ADS >= 17)
|
||
CString sText = m_strInputText.Left(nFind);
|
||
nFindPos = GetTextLength(sText);
|
||
nFindEnd = nFindPos + GetTextLength(m_strSearch);
|
||
#endif
|
||
|
||
int nStart = 0;
|
||
while (nStart < nFind)
|
||
{
|
||
TCHAR c = m_strInputText[nStart++];
|
||
CString sWord = c;
|
||
if (c < 0 || c > 127)// 汉字
|
||
{
|
||
#if (ADS < 17)
|
||
sWord += m_strInputText[nStart++];
|
||
#endif
|
||
if (IsGreeceChar(sWord))// 希腊字符在richedit控件中占一个存储单元,而在字符串中占2个存储单元
|
||
{
|
||
nFindPos--;
|
||
nFindEnd--;
|
||
}
|
||
}
|
||
}
|
||
m_ctrlInputText->SetSel(nFindPos, nFindEnd);
|
||
char c = m_strSearch[0];
|
||
int nNum = 1;
|
||
if (c < 0 || c > 127)//汉字
|
||
{
|
||
nNum = 2;
|
||
}
|
||
m_nSearchStart = nFind + nNum;
|
||
}
|
||
else
|
||
{
|
||
OutPutMessageBox();
|
||
}
|
||
}
|
||
|
||
void CMutiRowTextDlg::OutPutMessageBox()
|
||
{
|
||
CString sSearch, sInstead;
|
||
sSearch.Format(_T("\n共找见%d个"), m_nSearchNum);
|
||
sInstead.Format(_T("\n共替换%d个"), m_nInsteadNum);
|
||
CString sNot = _T("\n搜索完成: ");
|
||
sNot += sSearch;
|
||
sNot += sInstead;
|
||
AfxMessageBox(sNot, MB_OK);
|
||
m_nSearchNum = 0;
|
||
m_nInsteadNum = 0;
|
||
m_ctrlInputText->SetSel(0, 0);
|
||
}
|
||
|
||
void CMutiRowTextDlg::OnBtnInstead()
|
||
{
|
||
long hPos = 0l, lPos = 0l;
|
||
m_ctrlInputText->GetSel(hPos, lPos);
|
||
if (hPos == lPos)
|
||
{
|
||
OnBtnSearch();
|
||
return;
|
||
}
|
||
m_nInsteadNum++;
|
||
m_ctrlInputText->ReplaceSel(m_strInstead);
|
||
m_ctrlInputText->SetSel(hPos, lPos);
|
||
OnBtnSearch();
|
||
}
|
||
|
||
void CMutiRowTextDlg::OnSetTextHeight()
|
||
{
|
||
long hPos = 0l, lPos = 0l;
|
||
m_ctrlInputText->GetSel(hPos, lPos);
|
||
|
||
UpdateData(TRUE);
|
||
CHARFORMAT cf;
|
||
ZeroMemory(&cf, sizeof(CHARFORMAT));
|
||
CComboBox *pBox = (CComboBox*)GetDlgItem(IDC_COMBO_HEIGHT);
|
||
if (pBox != NULL)
|
||
{
|
||
int nSel = pBox->GetCurSel();
|
||
if (nSel != -1)
|
||
{
|
||
CString sText;
|
||
pBox->GetLBText(nSel, sText);
|
||
m_strHeight = sText;
|
||
pBox->Invalidate();
|
||
}
|
||
}
|
||
|
||
double dHeight = _tstof(m_strHeight);
|
||
|
||
DWORD d = m_ctrlInputText->GetSelectionCharFormat(cf);
|
||
cf.cbSize = sizeof(CHARFORMAT);
|
||
cf.dwMask = CFM_SIZE;
|
||
cf.dwEffects = 0;
|
||
cf.yHeight = 50.5 * dHeight;
|
||
|
||
m_ctrlInputText->SetSel(hPos, lPos);
|
||
BOOL bRet = m_ctrlInputText->SetSelectionCharFormat(cf);
|
||
|
||
m_ctrlInputText->SetFocus();
|
||
m_ctrlInputText->SetSel(hPos, lPos);
|
||
m_ctrlInputText->Invalidate();
|
||
}
|
||
|
||
int CMutiRowTextDlg::SetCursorPostion(const int nPos,const CString &csText)
|
||
{
|
||
int nPosCur = nPos;
|
||
COLORREF col = GetCurColor(nPosCur);
|
||
g_nHeight_muti = m_dCurTextHeight;
|
||
m_strHeight.Format(_T("%.1f"), g_nHeight_muti);
|
||
UpdateData(FALSE);
|
||
|
||
int len = csText.GetLength();
|
||
int nNumLine = 0;
|
||
int nNumWord = 0;
|
||
while (nNumWord < nPosCur)
|
||
{
|
||
nNumWord += m_editInputText.LineLength(m_editInputText.LineIndex(nNumLine));
|
||
nNumLine ++;
|
||
}
|
||
m_editInputText.LineScroll(nNumLine - 5);
|
||
|
||
m_editInputText.HideCaret();
|
||
m_editInputText.CreateSolidCaret(3, 13);
|
||
|
||
m_editInputText.SetSel(nPosCur, nPosCur, TRUE);
|
||
m_editInputText.ShowCaret();
|
||
|
||
m_btnColor.SetBackgroundColor(col);
|
||
return nPosCur;
|
||
}
|
||
|
||
void CMutiRowTextDlg::SetCursorPos(const AcGePoint3d ptCur)
|
||
{
|
||
m_ptCur = ptCur;
|
||
}
|
||
|
||
void CMutiRowTextDlg::SetCurTextId(const AcDbObjectId id)
|
||
{
|
||
m_id = id;
|
||
}
|
||
|
||
void CMutiRowTextDlg::OnButtonAddArow()
|
||
{
|
||
int i = 0;
|
||
UpdateData(TRUE);
|
||
m_editInputText.SetFocus();
|
||
// zxl 2013.03.13 modify
|
||
// if(!GetPosition(h, l))
|
||
// return;
|
||
long h, l;
|
||
m_ctrlInputText->GetSel(h, l);
|
||
|
||
m_ctrlInputText->SetSel(h, l);
|
||
m_ctrlInputText->ReplaceSel( _T("↓"));
|
||
|
||
i=l+1;
|
||
CRichEditCtrl *pEdit = NULL;
|
||
if(m_ctrlInputText->IsKindOf(RUNTIME_CLASS(CEdit)))
|
||
{
|
||
pEdit = (CRichEditCtrl*)m_ctrlInputText;
|
||
}
|
||
|
||
if(pEdit)
|
||
pEdit->SetSel(i, i);
|
||
}
|
||
|
||
void CMutiRowTextDlg::ResetSize()
|
||
{
|
||
CRect rectEdit, rectCancel, rectOk;
|
||
m_editInputText.GetWindowRect(rectEdit);
|
||
ScreenToClient(rectEdit);
|
||
m_ctrlCancel.GetWindowRect(rectCancel);
|
||
ScreenToClient(rectCancel);
|
||
m_ctrlOk.GetWindowRect(rectOk);
|
||
ScreenToClient(rectOk);
|
||
|
||
long nIncY = sizeDlg.cy - m_nOldSizeY; // 对话框绝对尺寸
|
||
long nIncX = sizeDlg.cx - m_nOldSizeX;
|
||
|
||
m_editInputText.MoveWindow(rectEdit.left, rectEdit.top,
|
||
rectEdit.Width() + nIncX, rectEdit.Height() + nIncY);
|
||
m_ctrlCancel.MoveWindow(rectCancel.left + nIncX, rectCancel.top,
|
||
rectCancel.Width(), rectCancel.Height());
|
||
m_ctrlOk.MoveWindow(rectOk.left + nIncX, rectOk.top,
|
||
rectOk.Width(), rectOk.Height());
|
||
}
|
||
|
||
void CMutiRowTextDlg::LoadTextStyle()
|
||
{
|
||
AcDbDatabase *pCurDwg=acdbCurDwg();
|
||
AcDbTextStyleTable* pTT;
|
||
VERIFY(pCurDwg->getSymbolTable(pTT, AcDb::kForRead)==Acad::eOk);
|
||
|
||
AcDbTextStyleTableIterator* pIter = NULL;
|
||
VERIFY(pTT->newIterator(pIter)==Acad::eOk);
|
||
pTT->close();
|
||
for (pIter->start(); !pIter->done(); pIter->step())
|
||
{
|
||
AcDbTextStyleTableRecord* pTTR;
|
||
if (pIter->getRecord(pTTR, AcDb::kForRead) != Acad::eOk)
|
||
continue;
|
||
const TCHAR* pName = NULL;
|
||
if (pTTR->getName(pName) == Acad::eOk && pName != NULL)
|
||
{
|
||
if(m_lstStyle.Index(pName) < 0 ) // 如果没有重复
|
||
m_lstStyle.Append(tstrnew(pName)); // 读字体风格
|
||
}
|
||
pTTR->close();
|
||
}
|
||
delete pIter;
|
||
|
||
for (int m =0; m < m_lstStyle.Length(); m++)
|
||
m_comboFontStyle.AddString(m_lstStyle[m]);
|
||
UpdateData(false);
|
||
return;
|
||
}
|
||
|
||
|
||
void CMutiRowTextDlg::Obj2Dlg(TDbMTextNew *pText)
|
||
{
|
||
//m_strHeight.Format(_T("%.1f"), pText->GetHeight());
|
||
g_strPageDist.Format(_T("%.1f"), pText->GetPageDist(TRUE));
|
||
g_strPageHeight.Format(_T("%.1f"), pText->GetPageHeight(TRUE));
|
||
g_nPageStyle = pText->GetPageStyle();
|
||
|
||
m_strRotation = (const TCHAR *)Angle2Str(pText->GetRotation() * 180.0 / PI);
|
||
|
||
AcDbObjectId idTextStyle = pText->GetStyleId();
|
||
|
||
OPENOBJ_BEGIN(idTextStyle, AcDb::kForRead, AcDbTextStyleTableRecord, pStyle);
|
||
ASSERT(pStyle);
|
||
const TCHAR* pName = NULL;
|
||
if (pStyle->getName(pName) == Acad::eOk && pName != NULL)
|
||
m_strStyle = pName;
|
||
else
|
||
AfxMessageBox(_T("文字风格已删除!"));
|
||
OPENOBJ_END();
|
||
m_strInputText = pText->GetText();
|
||
XExplodeDraw::TextAlignment Align = pText->GetAlignment();
|
||
for(int i = 0; i < 4; i++)
|
||
{
|
||
if(Align == g_AlignList_muti[i])
|
||
g_nAlignIndex_muti = i;
|
||
}
|
||
g_strLineSpace.Format(_T("%.2f"), (pText->GetLineSpace() / 3.5));
|
||
g_strPageWidth.Format(_T("%.1f"), pText->GetPageWidth());
|
||
}
|
||
|
||
void CMutiRowTextDlg::Dlg2Obj(TDbMTextNew *pText)
|
||
{
|
||
XString sTextStyle = m_strStyle;
|
||
//xg_setvar(_T("TEXTSTYLE"), sTextStyle);
|
||
g_strOldText = m_strInputText;
|
||
AcDbObjectId idTextStyle = GetTextStyleId(sTextStyle);
|
||
if(!idTextStyle)
|
||
return;
|
||
|
||
pText->SetStyleId(idTextStyle);
|
||
g_strPageWidth = m_strPageWidth;
|
||
g_strLineSpace = m_strLineSpace;
|
||
|
||
g_strPageHeight = m_strPageHeight;
|
||
g_strPageDist = m_strPageDist;
|
||
g_nPageStyle = m_nPageStyle;
|
||
|
||
pText->SetHeight(3.5);
|
||
double nRotation = _tstof(m_strRotation);
|
||
pText->SetRotation(nRotation * PI / 180.0);
|
||
pText->SetText(m_strInputText);
|
||
pText->SetPageDist(_tstof(m_strPageDist), TRUE);
|
||
pText->SetPageHeight(_tstof(m_strPageHeight), TRUE);
|
||
pText->SetPageStyle(m_nPageStyle);
|
||
pText->SetAlignment(g_AlignList_muti[g_nAlignIndex_muti]);
|
||
pText->SetLineSpace(_tstof(m_strLineSpace) * 3.5);
|
||
|
||
pText->SetPageWidth(_tstof(m_strPageWidth), TRUE); // 对话框指定
|
||
}
|
||
|
||
void CMutiRowTextDlg::SaveText()
|
||
{
|
||
OPENOBJ_BEGIN(m_id, AcDb::kForRead, TDbMTextNew, pText);
|
||
if(!pText)
|
||
return;
|
||
if(pText->upgradeOpen()!=Acad::eOk)
|
||
return;
|
||
g_nAlignIndex_muti = m_comboAlign.GetCurSel();
|
||
m_nPageStyle = m_comboPageStyle.GetCurSel();
|
||
if(g_nAlignIndex_muti < 0)
|
||
g_nAlignIndex_muti = 0;
|
||
if(m_comboFontStyle.GetCurSel()>=0)
|
||
m_comboFontStyle.GetLBText(m_comboFontStyle.GetCurSel(), m_strStyle);
|
||
|
||
if(!m_bEditObj)
|
||
xg_setvar(_T("TEXTSTYLE"), m_strStyle);
|
||
GetDefaultTextProp();
|
||
pText->assertWriteEnabled();
|
||
Dlg2Obj(pText);
|
||
pText->downgradeOpen();
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
void CMutiRowTextDlg::OnChar(UINT nID)
|
||
{
|
||
UpdateData(TRUE);
|
||
int l = 0, h = 0;
|
||
m_editInputText.GetSel(h, l);
|
||
int nPos = m_editInputText.GetFirstVisibleLine();
|
||
switch (nID)
|
||
{
|
||
case ID_SAVE:
|
||
{
|
||
// 停止绘制,使编辑框保持当前状态
|
||
m_ctrlInputText->SetRedraw(FALSE);
|
||
SaveText();
|
||
// cad刷新
|
||
actrTransactionManager->queueForGraphicsFlush();
|
||
actrTransactionManager->flushGraphics();
|
||
acedUpdateDisplay();
|
||
|
||
m_editInputText.SetFocus();
|
||
m_editInputText.SetSel(h, l);
|
||
m_editInputText.LineScroll(nPos - m_editInputText.GetFirstVisibleLine());
|
||
m_ctrlInputText->SetRedraw(TRUE);// 解除停止绘制状态
|
||
}
|
||
return;
|
||
}
|
||
CCharToolbarDlg::OnChar(nID);
|
||
}
|
||
|
||
void CMutiRowTextDlg::OnOK()
|
||
{
|
||
g_nAlignIndex_muti = m_comboAlign.GetCurSel();
|
||
m_nPageStyle = m_comboPageStyle.GetCurSel();
|
||
if(g_nAlignIndex_muti < 0)
|
||
g_nAlignIndex_muti = 0;
|
||
if(m_comboFontStyle.GetCurSel()>=0)
|
||
m_comboFontStyle.GetLBText(m_comboFontStyle.GetCurSel(), m_strStyle);
|
||
|
||
CCharToolbarDlg::OnOK();
|
||
if(!m_bEditObj) // ZJQ modify on 2004/3/5
|
||
xg_setvar(_T("TEXTSTYLE"), m_strStyle);
|
||
|
||
GetDefaultTextProp();
|
||
}
|
||
|
||
void CMutiRowTextDlg::OnCancel()
|
||
{
|
||
CCharToolbarDlg::OnCancel();
|
||
}
|
||
|
||
|
||
void CMutiRowTextDlg::OnButtonPagewidth()
|
||
{
|
||
UpdateData(TRUE);
|
||
double nPageWidth = _tstof(m_strPageWidth)*DocGetPScale();
|
||
BeginEditorCommand();
|
||
LAB_REINPUT:
|
||
if(GetDist(_T("\n定义上华多行文字行宽"), nPageWidth, RSG_NOZERO|RSG_NONEG) == RTCAN) {
|
||
goto LAB_REINPUT;
|
||
} else {
|
||
|
||
CompleteEditorCommand();
|
||
nPageWidth /= DocGetPScale();
|
||
m_strPageWidth.Format(_T("%.1f"), nPageWidth);
|
||
//UpdateData(FALSE);
|
||
DDX_Text(pDXLoad, IDC_PAGE_WIDTH, m_strPageWidth);
|
||
}
|
||
|
||
}
|
||
|
||
void CMutiRowTextDlg::OnButtonTextHeight()
|
||
{
|
||
UpdateData(TRUE);
|
||
double nHeight = _tstof(m_strHeight)*DocGetPScale();
|
||
BeginEditorCommand();
|
||
LAB_REINPUT:
|
||
if(GetDist(_T("\n定义上华多行文字字高"), nHeight, RSG_NOZERO|RSG_NONEG) == RTCAN) {
|
||
goto LAB_REINPUT;
|
||
} else {
|
||
|
||
CompleteEditorCommand();
|
||
nHeight /= DocGetPScale();
|
||
m_strHeight.Format(_T("%.1f"), nHeight);
|
||
long hPos = 0l, lPos = 0l;
|
||
m_ctrlInputText->GetSel(hPos, lPos);
|
||
if (hPos == lPos)
|
||
{
|
||
hPos--;
|
||
m_ctrlInputText->SetSel(hPos, lPos);
|
||
}
|
||
|
||
CHARFORMAT cf;
|
||
ZeroMemory(&cf, sizeof(CHARFORMAT));
|
||
DDX_Text(pDXLoad, IDC_COMBO_HEIGHT, m_strHeight);
|
||
double dHeight = _tstof(m_strHeight);
|
||
UpdateData(TRUE);
|
||
DWORD d = m_ctrlInputText->GetSelectionCharFormat(cf);
|
||
cf.cbSize = sizeof(CHARFORMAT);
|
||
cf.dwMask = CFM_SIZE;
|
||
cf.dwEffects = 0;
|
||
cf.yHeight = 50.5 * dHeight;
|
||
m_ctrlInputText->SetSel(hPos, lPos);
|
||
BOOL bRet = m_ctrlInputText->SetSelectionCharFormat(cf);
|
||
m_ctrlInputText->SetDefaultCharFormat(cf);
|
||
|
||
m_ctrlInputText->SetFocus();
|
||
m_ctrlInputText->SetSel(hPos, lPos);
|
||
m_ctrlInputText->Invalidate();
|
||
}
|
||
|
||
}
|
||
|
||
void CMutiRowTextDlg::OnButtonPageDist()
|
||
{
|
||
UpdateData(TRUE);
|
||
double nDist = _tstof(m_strPageDist)*DocGetPScale();
|
||
BeginEditorCommand();
|
||
LAB_REINPUT:
|
||
if(GetDist(_T("\n定义上华多行文字页间距"), nDist, RSG_NOZERO|RSG_NONEG) == RTCAN) {
|
||
goto LAB_REINPUT;
|
||
} else {
|
||
|
||
CompleteEditorCommand();
|
||
nDist /= DocGetPScale();
|
||
m_strPageDist.Format(_T("%.1f"), nDist);
|
||
//UpdateData(FALSE);
|
||
DDX_Text(pDXLoad, IDC_CMB_PAGEDIST, m_strPageDist);
|
||
}
|
||
}
|
||
|
||
void CMutiRowTextDlg::OnButtonPageHeight()
|
||
{
|
||
UpdateData(TRUE);
|
||
double nHeight = _tstof(m_strPageHeight)*DocGetPScale();
|
||
BeginEditorCommand();
|
||
LAB_REINPUT:
|
||
if(GetDist(_T("\n定义上华多行文字页高"), nHeight, RSG_NOZERO|RSG_NONEG) == RTCAN) {
|
||
goto LAB_REINPUT;
|
||
} else {
|
||
|
||
CompleteEditorCommand();
|
||
nHeight /= DocGetPScale();
|
||
m_strPageHeight.Format(_T("%.1f"), nHeight);
|
||
//UpdateData(FALSE);
|
||
DDX_Text(pDXLoad, IDC_EDIT_PAGEHEIGHT, m_strPageHeight);
|
||
}
|
||
}
|
||
|
||
void CMutiRowTextDlg::OnSize(UINT nType, int cx, int cy)
|
||
{
|
||
//CCharToolbarDlg::OnSize(nType, cx, cy); // 不调用
|
||
if(m_bInit == TRUE && !nType ) {
|
||
CRect rectEdit;
|
||
m_editInputText.GetWindowRect(rectEdit);
|
||
ScreenToClient(rectEdit);
|
||
|
||
CRect rectCancel, rectOk;
|
||
m_ctrlCancel.GetWindowRect(rectCancel);
|
||
ScreenToClient(rectCancel);
|
||
m_ctrlOk.GetWindowRect(rectOk);
|
||
ScreenToClient(rectOk);
|
||
|
||
CSize sizeOld = sizeDlg;
|
||
sizeDlg.cx = cx;
|
||
sizeDlg.cy = cy;
|
||
|
||
long nIncY = sizeDlg.cy - sizeOld.cy;
|
||
long nIncX = sizeDlg.cx - sizeOld.cx;
|
||
m_editInputText.MoveWindow(rectEdit.left, rectEdit.top,
|
||
rectEdit.Width() + nIncX, rectEdit.Height() + nIncY);
|
||
m_ctrlCancel.MoveWindow(rectCancel.left + nIncX, rectCancel.top,
|
||
rectCancel.Width(), rectCancel.Height());
|
||
m_ctrlOk.MoveWindow(rectOk.left + nIncX, rectOk.top,
|
||
rectOk.Width(), rectOk.Height());
|
||
|
||
}
|
||
}
|
||
|
||
int CMutiRowTextDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
||
{
|
||
if (CCharToolbarDlg::OnCreate(lpCreateStruct) == -1)
|
||
return -1;
|
||
|
||
CRect rect;
|
||
GetClientRect(rect);
|
||
m_nOldSizeX=rect.Width();
|
||
m_nOldSizeY=rect.Height();
|
||
return 0;
|
||
}
|
||
|
||
BOOL CMutiRowTextDlg::PreTranslateMessage(MSG* pMsg)
|
||
{
|
||
if( pMsg->message == WM_LBUTTONUP)
|
||
{
|
||
HWND hWnd = ::GetFocus();
|
||
int iID = ::GetDlgCtrlID(hWnd);
|
||
bool bNoSel = false;
|
||
if(iID == IDC_INPUT_TEXT)
|
||
{
|
||
long h = 0l, l = 0l;
|
||
m_ctrlInputText->GetSel(h, l);
|
||
m_nSelPos = l;
|
||
#if (ADS >= 17)
|
||
m_ctrlInputText->SetSel(0, l);
|
||
CString sText = m_ctrlInputText->GetSelText();
|
||
m_nSelPos = sText.GetLength();
|
||
m_ctrlInputText->SetSel(h, l);
|
||
#endif
|
||
|
||
m_bFromS = false;
|
||
m_nSearchNum = 0;
|
||
m_nInsteadNum = 0;
|
||
if (h == l)
|
||
{
|
||
if (h > 0)
|
||
{
|
||
h--;
|
||
}
|
||
m_ctrlInputText->SetSel(h, l);
|
||
bNoSel = true;
|
||
}
|
||
|
||
CHARFORMAT cf;
|
||
m_ctrlInputText->GetSelectionCharFormat(cf);
|
||
m_nColorIndex = cf.crTextColor;
|
||
m_btnColor.SetBackgroundColor(m_nColorIndex);
|
||
CWnd *pWnd = GetDlgItem(IDC_COMBO_HEIGHT);
|
||
if (pWnd != NULL)
|
||
{
|
||
// 16进制转化为10进制
|
||
CString sOx;
|
||
sOx.Format(_T("%d"), cf.yHeight);
|
||
double dDec = _tstof(sOx);
|
||
double dHeight = dDec / 50.5;
|
||
if (fabs(dHeight - 3.5) < 0.1)// WINDOWS默认字高与3.5之间对应关系有误差,调整一下
|
||
{
|
||
dHeight = 3.5;
|
||
}
|
||
|
||
CString sText;
|
||
sText.Format(_T("%.1f"), dHeight);
|
||
pWnd->SetWindowText(sText);
|
||
}
|
||
m_btnColor.Invalidate();
|
||
if (bNoSel)
|
||
{
|
||
m_ctrlInputText->SetSel(l, l);
|
||
}
|
||
}
|
||
}
|
||
|
||
if (pMsg-> message ==WM_RBUTTONDOWN)
|
||
{
|
||
CWnd * pWnd = (CWnd*) GetDlgItem(IDC_INPUT_TEXT);
|
||
if (pWnd == GetFocus())
|
||
{
|
||
// tPopmenu.EnableMenuItem(ID_RICH_COPY, MF_BYCOMMAND|nSelText);//使能菜单
|
||
CMenu menu;
|
||
DWORD dwSelectionMade;
|
||
VERIFY(menu.LoadMenu(IDR_MUTIROW));
|
||
CMenu *pmenuPopup = menu.GetSubMenu(0);
|
||
ASSERT(pmenuPopup != NULL);
|
||
dwSelectionMade = pmenuPopup->TrackPopupMenu( (TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_NONOTIFY),pMsg-> pt.x, pMsg-> pt.y, this );
|
||
pmenuPopup-> DestroyMenu();
|
||
return TRUE;
|
||
}
|
||
}
|
||
|
||
return CDialog::PreTranslateMessage(pMsg);
|
||
}
|
||
|
||
// zxl 2013.02.22 add 增加设定文字颜色功能
|
||
void CMutiRowTextDlg::OnSetTextColor()
|
||
{
|
||
int i = 0;
|
||
int nColor = m_nColorIndex;
|
||
long hPos = 0l, lPos = 0l;
|
||
if (acedSetColorDialog(nColor, Adesk::kTrue, m_nColorIndex))
|
||
{
|
||
m_nColorIndex = nColor;
|
||
int nR = 0;
|
||
int nB = 0;
|
||
int nG = 0;
|
||
ColorToRGB(nColor, &nR, &nG, &nB);
|
||
COLORREF cBtn = RGB(nR, nG, nB);
|
||
m_btnColor.SetBackgroundColor(cBtn);
|
||
int nBar = 0;
|
||
if(m_ctrlInputText->IsKindOf(RUNTIME_CLASS(CEdit)))
|
||
{
|
||
CRichEditCtrl *pRichEdit = m_ctrlInputText;
|
||
pRichEdit->GetSel(hPos, lPos);
|
||
|
||
CHARFORMAT cf;
|
||
ZeroMemory(&cf, sizeof(CHARFORMAT));
|
||
DWORD d = pRichEdit->GetSelectionCharFormat(cf);
|
||
cf.cbSize = sizeof(CHARFORMAT);
|
||
cf.dwMask = CFM_COLOR;
|
||
cf.dwEffects = 0;
|
||
if (cBtn == 0xffffff)
|
||
{
|
||
cBtn = 0;
|
||
}
|
||
cf.crTextColor = cBtn; //文字颜色
|
||
pRichEdit->SetSel(hPos, lPos);
|
||
BOOL bRet = pRichEdit->SetSelectionCharFormat(cf);
|
||
|
||
CHARFORMAT cf1;
|
||
ZeroMemory(&cf1, sizeof(CHARFORMAT));
|
||
pRichEdit->GetSelectionCharFormat(cf1);
|
||
|
||
pRichEdit->SetFocus();
|
||
pRichEdit->SetSel(hPos, lPos);
|
||
}
|
||
}
|
||
}
|
||
|
||
void CMutiRowTextDlg::SetTextProp(CString &sText)
|
||
{
|
||
m_vecCol.clear();
|
||
m_vecHeight.clear();
|
||
m_vecUnderLine.clear();
|
||
CString sColor, sHeight, sUnderline;
|
||
COLORREF cf;
|
||
double dHeight = 3.5;
|
||
bool bUnderline = false;
|
||
XString xsText = sText;
|
||
CString sTextShow;
|
||
int nCount = xsText.Length();
|
||
for(int idx = 0; idx < nCount; idx++)
|
||
{
|
||
TCHAR c=xsText[idx];
|
||
if (c == _T('$'))
|
||
{
|
||
sColor = _T(""), sHeight = _T(""), sUnderline = _T("");
|
||
while(xsText[++idx] != _T('|'))
|
||
{
|
||
sColor += xsText[idx];
|
||
}
|
||
|
||
while(xsText[++idx] != _T('|'))
|
||
{
|
||
sHeight += xsText[idx];
|
||
}
|
||
|
||
while(xsText[++idx] != _T('$'))
|
||
{
|
||
sUnderline += xsText[idx];
|
||
}
|
||
|
||
cf = _tstof(sColor);
|
||
dHeight = _tstof(sHeight);
|
||
if (_tstof(sUnderline) > 0)
|
||
{
|
||
bUnderline = true;
|
||
}
|
||
else
|
||
{
|
||
bUnderline = false;
|
||
}
|
||
|
||
continue;
|
||
}
|
||
|
||
sTextShow += c;
|
||
if (c < 0)// 汉字
|
||
{
|
||
idx++;
|
||
sTextShow += xsText[idx];
|
||
}
|
||
|
||
if (c == _T('\n'))
|
||
{
|
||
continue;
|
||
}
|
||
m_vecCol.push_back(cf);
|
||
m_vecHeight.push_back(dHeight);
|
||
m_vecUnderLine.push_back(bUnderline);
|
||
}
|
||
sText = sTextShow;
|
||
}
|
||
|
||
void CMutiRowTextDlg::SetDlgTextProp()
|
||
{
|
||
CString csText;
|
||
m_ctrlInputText->GetWindowText(csText);
|
||
SetTextProp(csText);
|
||
if (m_vecCol.size() == 0)
|
||
{
|
||
return;
|
||
}
|
||
m_strInputText = csText;
|
||
UpdateData(FALSE);
|
||
XString xsText;
|
||
xsText=csText;
|
||
int nCount = (int)_tcslen(xsText);
|
||
int iLow=0, iUp=0, nIndex = 0;
|
||
acedSetStatusBarProgressMeter(_T("打开中..."), 0, nCount);
|
||
for(int idx = 0; idx < nCount; idx++)
|
||
{
|
||
acedSetStatusBarProgressMeterPos(idx + 1);
|
||
iUp = iLow + 1;
|
||
TCHAR c=xsText[idx];
|
||
CString sWord = c;
|
||
if (c < 0)// 汉字
|
||
{
|
||
idx++;
|
||
sWord += xsText[idx];
|
||
if (!IsGreeceChar(sWord))// 希腊字符在richedit控件中占一个存储单元,而在字符串中占2个存储单元
|
||
{
|
||
iUp++;
|
||
}
|
||
|
||
}
|
||
else if (c > 127 && !IsGreeceChar(c))//高平台汉字
|
||
{
|
||
iUp++;
|
||
}
|
||
|
||
int nSpare = idx - 1;
|
||
while (c == 13 && xsText[nSpare--] == _T(' '))
|
||
{
|
||
nIndex--;
|
||
}
|
||
|
||
m_ctrlInputText->SetSel(iLow, iUp);
|
||
CString s = m_ctrlInputText->GetSelText();
|
||
if (s.IsEmpty() || c == _T('\n'))
|
||
{
|
||
iLow++;
|
||
continue;
|
||
}
|
||
|
||
CHARFORMAT cf;
|
||
ZeroMemory(&cf, sizeof(CHARFORMAT));
|
||
DWORD d = m_ctrlInputText->GetSelectionCharFormat(cf);
|
||
cf.cbSize = sizeof(CHARFORMAT);
|
||
cf.dwMask = CFM_COLOR | CFM_SIZE | CFM_STYLE | CFM_UNDERLINE;
|
||
cf.dwEffects = 0;
|
||
if (nIndex < m_vecCol.size())
|
||
{
|
||
cf.crTextColor = m_vecCol[nIndex];
|
||
}
|
||
|
||
if (nIndex < m_vecHeight.size())
|
||
{
|
||
cf.yHeight = 50.5 * m_vecHeight[nIndex];
|
||
}
|
||
|
||
if (nIndex < m_vecUnderLine.size())
|
||
{
|
||
if (m_vecUnderLine[nIndex])
|
||
{
|
||
cf.dwEffects = CFE_UNDERLINE;
|
||
}
|
||
}
|
||
|
||
m_ctrlInputText->SetSelectionCharFormat(cf);
|
||
nIndex++;
|
||
iLow = iUp;
|
||
}
|
||
acedRestoreStatusBar();
|
||
}
|
||
|
||
void CMutiRowTextDlg::GetDefaultTextProp()
|
||
{
|
||
UpdateData(TRUE);
|
||
CString csText;
|
||
m_ctrlInputText->GetWindowText(csText);
|
||
|
||
XString xsText;
|
||
xsText=csText;
|
||
int nCount = (int)_tcslen(xsText);
|
||
int iLow=0, iUp=0;
|
||
COLORREF cfBefor = 0;
|
||
double dHeightBefor = 0.0;
|
||
bool bUnderLineBefor = false;
|
||
CString sTextShow, sText;
|
||
long lLen = 0L;
|
||
for(int idx = 0; idx < nCount; idx++)
|
||
{
|
||
iUp = iLow + 1;
|
||
TCHAR c=xsText[idx];
|
||
CString sWord;
|
||
sWord +=c;
|
||
if (c < 0 )// 汉字
|
||
{
|
||
idx++;
|
||
sWord += xsText[idx];
|
||
if (!IsGreeceChar(sWord))
|
||
{
|
||
iUp++;
|
||
}
|
||
}
|
||
else if (c > 127 && !IsGreeceChar(c))
|
||
{
|
||
iUp++;
|
||
}
|
||
m_ctrlInputText->SetSel(iLow, iUp);
|
||
LPSTR pst = new CHAR[2];
|
||
lLen = m_ctrlInputText->GetSelText(pst);
|
||
delete []pst;
|
||
if (lLen > 2L && iUp > iLow + 1) // 增加对word中拷贝的特殊格式的字符处理
|
||
{
|
||
--iUp;
|
||
m_ctrlInputText->SetSel(iLow, iUp);
|
||
}
|
||
sText = m_ctrlInputText->GetSelText();
|
||
if (sText.IsEmpty())
|
||
{
|
||
++iLow;
|
||
if (c == _T('\n'))
|
||
{
|
||
sTextShow += c;
|
||
}
|
||
continue;
|
||
}
|
||
CHARFORMAT cf;
|
||
m_ctrlInputText->GetSelectionCharFormat(cf);
|
||
// 16进制转化为10进制
|
||
CString sOx;
|
||
sOx.Format(_T("%d"), cf.yHeight);
|
||
double dDec = _tstof(sOx);
|
||
double dHeight = dDec / 50.5;
|
||
if (fabs(dHeight - 3.5) < 0.1)
|
||
{
|
||
dHeight = 3.5;
|
||
}
|
||
|
||
bool bUnderLine = false;
|
||
int nBool = 0;
|
||
if (cf.dwEffects & CFE_UNDERLINE)
|
||
{
|
||
bUnderLine = true;
|
||
nBool = 1;
|
||
}
|
||
|
||
if (cf.crTextColor != cfBefor || dHeight != dHeightBefor || bUnderLine != bUnderLineBefor)
|
||
{
|
||
CString sProp;
|
||
sProp.Format(_T("$%.0d|%.1f|%d$"), cf.crTextColor, dHeight, nBool);
|
||
sTextShow += sProp;
|
||
}
|
||
sTextShow += sWord;
|
||
|
||
cfBefor = cf.crTextColor;
|
||
dHeightBefor = dHeight;
|
||
bUnderLineBefor = bUnderLine;
|
||
iLow = iUp;
|
||
}
|
||
m_strInputText = sTextShow;
|
||
}
|
||
|
||
// zxl 2013.02.22 add 增加设定文字颜色功能
|
||
COLORREF CMutiRowTextDlg::GetCurColor(const int nPosCur)
|
||
{
|
||
int nPos = nPosCur;
|
||
COLORREF col = RGB(0, 0, 0);
|
||
#if (ADS >= 17)
|
||
nPos /= 2;
|
||
#endif
|
||
|
||
CString csText;
|
||
m_ctrlInputText->GetWindowText(csText);
|
||
XString xsText;
|
||
xsText=csText;
|
||
int nCount = (int)_tcslen(xsText);
|
||
int nIndex = 0;
|
||
for(int idx = 0; idx < nCount; idx++)
|
||
{
|
||
TCHAR c=xsText[idx];
|
||
if (c < 0 || c == _T('\n'))// 汉字
|
||
{
|
||
if (idx != nPos)
|
||
{
|
||
idx++;
|
||
}
|
||
else
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (idx == nPos)
|
||
{
|
||
break;
|
||
}
|
||
nIndex++;
|
||
}
|
||
|
||
if (nIndex < m_vecCol.size())
|
||
{
|
||
col = m_vecCol[nIndex];
|
||
m_dCurTextHeight = m_vecHeight[nIndex];
|
||
}
|
||
return col;
|
||
}
|