📄 mtextdlg.cpp
字号:
ASSERT(m_lpClientSite != NULL);
reobject.polesite = m_lpClientSite;
ASSERT(m_lpStorage != NULL);
reobject.pstg = m_lpStorage;
SIZEL sizel;
sizel.cx = sizel.cy = 0;
reobject.sizel = sizel;
////////////////////////////
HWND hWndRT = m_ctlRichText.m_hWnd;
// ::SendMessage(hWndRT, EM_SETSEL, 0, -1);
// DWORD dwStart, dwEnd;
// ::SendMessage(hWndRT, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
// ::SendMessage(hWndRT, EM_SETSEL, dwEnd+1, dwEnd+1);
//
// //////////////////////////////////////////////////////////////////////
// CString strCr = "\r\n";
// m_ctlRichText. ReplaceSel(strCr,TRUE);
////////////////////////////////////////////////////
m_pRichEditOle->InsertObject(&reobject);
//////////////////////////////////////////////////////
::SendMessage(hWndRT, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
/////////////////////////////////////////////////////////////////////
if(m_pDataObject)
{
m_pDataObject->Release();
m_pDataObject=NULL;
}
if (m_lpObject)
{
m_lpObject->Release();
m_lpObject = NULL;
}
if (m_lpStorage)
{
m_lpStorage->Release();
m_lpStorage = NULL;
}
if (m_lpClientSite)
{
m_lpClientSite->Release();
m_lpClientSite = NULL;
}
return TRUE;
}
CMTextDlg::~CMTextDlg()
{
m_pRichEditOle->Release();
}
BOOL CMTextDlg::CreateFromClipboard()
{
USES_CONVERSION;
ASSERT_VALID(this);
ASSERT(m_lpObject == NULL); // one time only
ASSERT(m_lpStorage == NULL);
ASSERT(m_lpClientSite == NULL);
LPLOCKBYTES lpLockBytes = NULL;
OLERENDER render = OLERENDER_DRAW;
CLIPFORMAT cfFormat = 0;
LPFORMATETC lpFormatEtc = NULL;
SCODE sc;
sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);
if (sc != S_OK)
AfxThrowOleException(sc);
ASSERT(lpLockBytes != NULL);
sc = ::StgCreateDocfileOnILockBytes(lpLockBytes,
STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &m_lpStorage);
if (sc != S_OK)
{
VERIFY(lpLockBytes->Release() == 0);
lpLockBytes = NULL;
AfxThrowOleException(sc);
}
ASSERT(m_lpStorage != NULL);
FORMATETC formatEtc;
lpFormatEtc = &formatEtc;
lpFormatEtc->cfFormat = cfFormat;
lpFormatEtc->ptd = NULL;
lpFormatEtc->dwAspect = DVASPECT_CONTENT;
lpFormatEtc->lindex = -1;
lpFormatEtc->tymed = TYMED_NULL;
m_pRichEditOle->GetClientSite(&m_lpClientSite);
::OleGetClipboard(&m_pDataObject);
sc=::OleCreateFromData(m_pDataObject,IID_IUnknown,OLERENDER_DRAW,lpFormatEtc,m_lpClientSite,m_lpStorage,
(void**)&m_lpObject);
////////////////////////////////////////////////
if (sc != S_OK)
AfxThrowOleException(sc);
if (m_lpObject != NULL)
{
LPUNKNOWN lpUnk = m_lpObject;
lpUnk->QueryInterface(IID_IOleObject, (void**)&m_lpObject);
lpUnk->Release();
if (m_lpObject == NULL)
AfxThrowOleException(E_OUTOFMEMORY);
}
// all items are "contained" -- this makes our reference to this object
// weak -- which is needed for links to embedding silent update.
OleSetContainedObject(m_lpObject, TRUE);
ASSERT_VALID(this);
return TRUE;
}
void CMTextDlg::OnStack()
{
// TODO: Add your command handler code here
if(IsSelectStack())
UnMakeStack();
else
MakeStack(0.5);
}
BOOL CMTextDlg::IsSelectStack()
{
LONG iStackNumber;
REOBJECT reobject;
BOOL reVal;
iStackNumber=m_pRichEditOle->GetObjectCount();
m_CurrentSelStackIndex=-1;
reVal=FALSE;
while ((--iStackNumber)>=0)
{
ZeroMemory(&reobject, sizeof(REOBJECT));
reobject.cbStruct = sizeof(REOBJECT);
m_pRichEditOle->GetObject(
iStackNumber,
&reobject,
REO_GETOBJ_NO_INTERFACES
);
if(reobject.dwFlags&REO_SELECTED)
{
reVal=TRUE;
m_CurrentSelStackIndex=iStackNumber;
break;
}
}
return reVal;
}
BOOL CMTextDlg::MakeStack(float fScale)
{
CString strSelectText;
CString strUpText;
CString strDownText;
int iStackStatus;
int index;
strSelectText=m_ctlRichText.GetSelText();
m_ctlRichText.GetStackStatus(iStackStatus);
switch(iStackStatus) {
case StackS_Horizontal:
index=strSelectText.Find(_T("/"));
break;
case StackS_Lean:
index=strSelectText.Find(_T("#"));
break;
case StackS_Tolerance:
index=strSelectText.Find(_T("^"));
break;
case -1:
return FALSE;
}
strUpText=strSelectText.Left(index);
strDownText=strSelectText.Right(strSelectText.GetLength()-strUpText.GetLength()-1);
IZWStack stack;
CComBSTR bstr;
BOOL bSussess=stack.CreateDispatch(_T("ZWStack.Document"));
if(bSussess==0)
{
CHARRANGE cr;
m_ctlRichText.GetSel(cr);
m_ctlRichText.SetSel(cr.cpMax,cr.cpMax);
m_ctlRichText.ReplaceSel(_T(";"));
m_ctlRichText.SetSel(cr.cpMin,cr.cpMin);
m_ctlRichText.ReplaceSel(_T("\\S"));
return FALSE;
}
bstr=strUpText.AllocSysString();
stack.SetUpString(&bstr);
bstr.Detach();
bstr=strDownText.AllocSysString();
stack.SetDownString(&bstr);
bstr.Detach();
int nTwips;
CString strSize;
CString strPost;
CHARFORMAT cf;
m_ctlRichText.GetSelectionCharFormat(cf);
nTwips=cf.yHeight*-90/1440;
strSize.Format("/%ld/%d",cf.crTextColor,nTwips);
strPost=cf.szFaceName;
strPost=strPost+strSize;
bstr=strPost.AllocSysString();
stack.SetOptionWithString(OP_SetFont,&bstr);
bstr.Detach();
strPost.Format("%lf",fScale);
bstr=strPost.AllocSysString();
stack.SetOptionWithString(OP_SetScale,&bstr);
bstr.Detach();
strPost.Format("%d",m_iStackAlign);
bstr=strPost.AllocSysString();
stack.SetOptionWithString(OP_SetAlign,&bstr);
bstr.Detach();
stack.SetStackStyle(iStackStatus);
stack.SetOption(0);
OnEditPast();
return TRUE;
}
BOOL CMTextDlg::UnMakeStack()
{
CMTextStack StackObj;
CString strReplaceStr;
strReplaceStr=_T("");
GetStackObject(StackObj);
StackObj.m_lf.lfHeight=StackObj.m_fSizeScale*StackObj.m_lf.lfHeight*1440*2/-90;
m_ctlRichText.ChangeFontSize(StackObj.m_lf.lfHeight);
m_ctlRichText.ChangeFont(StackObj.m_lf.lfFaceName);
// m_ctlRichText.ReplaceSel(StackObj.m_strUpString,TRUE);
strReplaceStr+=StackObj.m_strUpString;
switch(StackObj.m_StackStyle)
{
case StackS_Horizontal:
// m_ctlRichText.ReplaceSel(_T("/"),TRUE);
strReplaceStr+=_T("/");
break;
case StackS_Lean:
// m_ctlRichText.ReplaceSel(_T("#"),TRUE);
strReplaceStr+=_T("#");
break;
case StackS_Tolerance:
// m_ctlRichText.ReplaceSel(_T("^"),TRUE);
strReplaceStr+=_T("^");
}
// m_ctlRichText.ReplaceSel(StackObj.m_strDownString,TRUE);
strReplaceStr+=StackObj.m_strDownString;
m_ctlRichText.ReplaceSel(strReplaceStr,TRUE);
// memFile.Close();
return TRUE;
}
void CMTextDlg::OnStackStyle()
{
// TODO: Add your command handler code here
if(IsSelectStack())
{
CMTextStack StackObj;
CMTextStackStyleDlg dlg;
GetStackObject(StackObj);
dlg.m_strUpString=StackObj.m_strUpString;
dlg.m_strDownString=StackObj.m_strDownString;
dlg.m_iStackStyle=StackObj.m_StackStyle;
dlg.m_fSizeScale=StackObj.m_fSizeScale;
dlg.m_iAlign=m_iStackAlign;
if(dlg.DoModal()==IDOK)
{
StackObj.m_strUpString=dlg.m_strUpString;
StackObj.m_strDownString=dlg.m_strDownString;
StackObj.m_StackStyle=dlg.m_iStackStyle;
StackObj.m_fSizeScale=dlg.m_fSizeScale;
StackObj.m_iAlign=dlg.m_iAlign;
m_iStackAlign=dlg.m_iAlign;
SetStackObject(StackObj);
}
}
}
BOOL CMTextDlg::GetStackObject(CMTextStack &stackobj)
{
if(!IsSelectStack())
return FALSE;
return GetStackObject(m_CurrentSelStackIndex,stackobj);
}
BOOL CMTextDlg::SetStackObject(CMTextStack &stackobj)
{
if(!IsSelectStack())
return FALSE;
return SetStackObject(m_CurrentSelStackIndex,stackobj);
}
BOOL CMTextDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_KEYDOWN )
{
if(pMsg->wParam == VK_TAB)
{
CHARRANGE cr;
m_ctlRichText.GetSel(cr);
m_ctlRichText.SetSel(cr.cpMin,cr.cpMin);
m_ctlRichText.ReplaceSel("\t", TRUE);
return TRUE;
}
else
if ((pMsg->wParam == VK_INSERT && (GetKeyState(VK_SHIFT) < 0)) // To trap 'SHIFT + INSERT'
|| (pMsg->wParam == 'V' && (GetKeyState(VK_CONTROL) < 0))) // To trap 'CTRL + V'
{
OnEditPast();
return TRUE;
}
else
if((pMsg->wParam =='S') && (GetKeyState(VK_CONTROL)) < 0)
{
OnOkButton();
return TRUE;
}
else
if((pMsg->wParam =='F') && (GetKeyState(VK_CONTROL)) < 0)
{
OnEditFindR();
return TRUE;
}
else
if(pMsg->wParam ==VK_RETURN&&m_wndStyleBar.isFoucsInComBoxSize)
{
SetFocus();
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
void CMTextDlg::OnOkButton()
{
//m_ctlRichText.HideSelection(TRUE, FALSE);
// ConvertMTextStrToCADStr();
// return;
m_bIsOK=TRUE;
CDialog::OnOK();
/*
return;
AllStackToCADString();
TEXTRANGE range;
range.chrg.cpMin = 0;
range.chrg.cpMax = m_ctlRichText.GetTextLength();
range.lpstrText = m_text.GetBufferSetLength(range.chrg.cpMax);
m_ctlRichText.SendMessage(EM_GETTEXTRANGE, 0, (LPARAM)&range);
m_text.ReleaseBuffer(-1);
// return;
//////////////////////////////////////////////////////////////
CString text = "";
m_ctlRichText.SetSel(0, 0);
int index = 0, bold = 0, italic = 0, underline = 0;
LONG fontsize = 200;
int textindex = 0, oldbold = 0, olditalic = 0, oldunderline = 0, oldfontsize = -1;
CString fonttype = "Arial", oldfonttype = "", height = "";
bool isSHX = 0;
int pitch = 0, charset = 0; // EBATECH(CNBR)
double defaultsize;
struct resbuf rb;
SDS_getvar(NULL,DB_QTEXTSIZE,&rb,SDS_CURDWG,&SDS_CURCFG,&SDS_CURSES);
m_wndStyleBar.m_wndFontStyle.GetTextStyle();
defaultsize = m_wndStyleBar.m_wndFontStyle.m_tableInfo.GetHeight();
if (defaultsize <= 0.0009)
defaultsize = rb.resval.rreal; //Default fontheight
// Bugzilla No. 78394; 09-12-2002
//m_pMTextData->rTextHeight = defaultsize;
//DP: old realization commented
//oldfontsize = (int) (defaultsize * 1000);
ConvertTextHeightToPix(defaultsize, SDS_CURGRVW, oldfontsize);
fonttype = m_wndStyleBar.m_wndFontStyle.m_tableInfo.GetFontFilename(false);
if (fonttype.Right(4) == ".shx" || fonttype.Right(4) == ".SHX" ||
fonttype.Right(4) == ".shp" || fonttype.Right(4) == ".SHP")
isSHX = 1;
if (!isSHX)
oldfonttype = m_wndStyleBar.m_wndFontStyle.m_tableInfo.GetFontFamily();
else
oldfonttype = m_wndStyleBar.m_wndFontStyle.m_tableInfo.GetFontFilename(false);
while (index <= m_ctlRichText.GetTextLength())
{
CHARFORMAT cf;
m_ctlRichText.SetSel(index, index);
m_ctlRichText.GetSelectionCharFormat(cf);
/////////////////////////////////////////////////
cf.yHeight*=m_wndStyleBar.m_FontSizeScale;
/////////////////////////////////////////////////
bold = (cf.dwEffects & CFE_BOLD);
italic = (cf.dwEffects & CFE_ITALIC);
underline = (cf.dwEffects & CFE_UNDERLINE);
fontsize = cf.yHeight;
fonttype = cf.szFaceName;
isSHX = 0;
// EBATECH(CNBR) -[ Accept any language
pitch = ( cf.bPitchAndFamily & 0x00ff); // EBATECH(CNBR)
charset = ( cf.bCharSet & 0x00ff ); // EBATECH(CNBR)
int i = m_wndStyleBar.m_wndFontNames.FindStringExact(-1, fonttype);
if(i == -1)
{ // Not found set default
pitch = ( FF_SWISS | VARIABLE_PITCH );
charset = ANSI_CHARSET;
}
//if (i == -1)
// i = 34;
//FontItem* pFontItem = (FontItem*)m_wndStyleBar.m_wndFontNames.GetItemDataPtr(i);
//if(pFontItem)
// pitch.Format(_T ("%d"), pFontItem->logFont.lfPitchAndFamily);
double newsize;
// Bugzilla No. 78034; 23-12-2002
//m_wndStyleBar.GetTextHeightFromTwips(newsize, fontsize);
CMTextDlg::ConvertTwipsToTextHeight(newsize,fontsize);
height.Format(_T ("%.4lf"), newsize);
while(height.Right(1) == '0')
height.Delete(height.GetLength() - 1, 1);
// Bugzilla No. 78394; 09-12-2002
if(index == 0)
m_wndStyleBar.m_wndFontStyle.m_tableInfo.SetHeight(atof(height));
//m_pMTextData->rTextHeight = atof(height);
if (fonttype.Right(4) == ".shx" || fonttype.Right(4) == ".SHX" ||
fonttype.Right(4) == ".shp" || fonttype.Right(4) == ".SHP")
isSHX = 1;
//the formatting information for italic, bold, and fonttype are redisplayed if one is
//changed. The usage of the c value has not been determined yet.
if (bold != oldbold || italic != olditalic || fonttype.CompareNoCase(oldfonttype) != 0)
{
CString format = "\\f";
format.Insert(format.GetLength(), fonttype);
if (!isSHX)
{
/ * EBATECH(CNBR) Set various charaset and pitch.
if (bold == 0)
format.Insert(format.GetLength(), "|b0");
else
format.Insert(format.GetLength(), "|b1");
if (italic == 0)
format.Insert(format.GetLength(), "|i0|c0|p");
else
format.Insert(format.GetLength(), "|i1|c0|p");
format.Insert(format.GetLength(), pitch);* /
CString fontFormat;
fontFormat.Format(
"|b%d|i%d|c%d|p%d",
(bold == 0 ? 0 : 1),
(italic == 0 ? 0 : 1),
charset,
pitch);
format.Insert(format.GetLength(),fontFormat);
// EBATECH(CNBR) ]-
}
format.Insert(format.GetLength(), ";");
m_text.Insert(textindex, format);
textindex += format.GetLength();
}
if (fontsize != oldfontsize && index != 0)
{
CString format;
/ *
if (textindex >= 1)
{
if (m_text.GetAt(textindex-1) != ';')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -