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

📄 mtextdlg.cpp

📁 mtext,编辑器,支持潜入对象
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				strFormat+=strColor;
			}
		
		}
	    if(strFormat.GetLength()>0)
		{
			m_ctlRichText.SetSel(index,index);
			m_ctlRichText.ReplaceSel(strFormat,FALSE);
			m_ctlRichText.GetSel(cr);
			index=cr.cpMax;
		}
		index++;
		oldfonttype = fonttype;
		oldbold = bold;
		olditalic = italic;
		oldunderline = underline;
		oldfontsize = fontsize;
		oldcolor=newcolor;
	}

////////////////////////////////////////////////////////////////////////////////////////////////
	FINDTEXTEX ftS;
	LONG SIndex;
	DWORD dwFlags = NULL;
	dwFlags |= FR_DOWN;
	dwFlags |= FR_MATCHCASE;

	ftS.chrg.cpMin = 0;
	ftS.chrg.cpMax = -1;

	ftS.lpstrText = (LPSTR)_T("{");
    SIndex=m_ctlRichText.FindText(dwFlags, &ftS);
	while (SIndex != -1)
	{
		m_ctlRichText.SetSel(ftS.chrgText);
		m_ctlRichText.ReplaceSel(_T("\\{"),FALSE);
		m_ctlRichText.GetSel(cr);
		ftS.chrg.cpMin=cr.cpMax;
		SIndex = m_ctlRichText.FindText(dwFlags, &ftS);
	}

	ftS.chrg.cpMin = 0;
	ftS.chrg.cpMax = -1;
	
	ftS.lpstrText = (LPSTR)_T("}");
    SIndex=m_ctlRichText.FindText(dwFlags, &ftS);
	while (SIndex != -1)
	{
		m_ctlRichText.SetSel(ftS.chrgText);
		m_ctlRichText.ReplaceSel(_T("\\}"),FALSE);
		m_ctlRichText.GetSel(cr);
		ftS.chrg.cpMin=cr.cpMax;
		SIndex = m_ctlRichText.FindText(dwFlags, &ftS);
	}
//////////////////////////////////////////////////////////////////////////////////////////	
	SetStackAlign(TRUE); //
	m_ctlRichText.GetWindowText(m_text);
//	m_text+=m_strLineIdent;
	return TRUE;
}
void CMTextDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	if(!m_bIsOK)
		return;
	ConvertMTextStrToCADStr();
	// TODO: Add your message handler code here
	
}
void CMTextDlg::OnTransparent() 
{
	// TODO: Add your command handler code here
	SetTransparent(!m_bIsTransparent,80);
	m_bIsTransparent=!m_bIsTransparent;
}

void CMTextDlg::SetWindowPlace()
{
	/* //由于文本框和实际显示并不一致,所以以下代码意义不大,故放弃使用
	sds_point pt1;
		int PX;
		int PY;
		//take the lesser of the X's
		if(m_pMTextData->ptInsertion[0]>m_pMTextData->ptOppCorner[0])
			pt1[0]=m_pMTextData->ptOppCorner[0];
		else
			pt1[0]=m_pMTextData->ptInsertion[0];
		//take the greater of the Y's
		if(m_pMTextData->ptInsertion[1]>m_pMTextData->ptOppCorner[1])
			pt1[1]=m_pMTextData->ptInsertion[1];
		else
			pt1[1]=m_pMTextData->ptOppCorner[1];
		
		sds_rp2pix(pt1[0],pt1[1],&PX,&PY);
		
		CRect dlgRect;
		CRect richRect;
		CRect rectWindow;
		CPoint ptP(PX,PY);
		
		GetWindowRect(&dlgRect);
	
		m_ctlRichText.GetClientRect(&richRect);
		m_ctlRichText.ClientToScreen(&richRect);
		CWnd::GetDesktopWindow()->GetWindowRect(&rectWindow);
		if(SDS_CMainWindow->m_pCurView)
			SDS_CMainWindow->m_pCurView->ClientToScreen(&ptP);
		ptP.x=ptP.x+dlgRect.left-richRect.left;
		ptP.y=ptP.y+dlgRect.top-richRect.top;
	
		if( (ptP.x>0&&ptP.y>0)&&	
			(rectWindow.Width()-ptP.x-dlgRect.Width())>0&&
			(rectWindow.Height()-ptP.y-dlgRect.Height()/2)>0	
		  )
		MoveWindow(ptP.x,ptP.y,dlgRect.Width(),dlgRect.Height(),TRUE);*/
	
	

	SetLineLength(m_pMTextData->rBoxWidth); //由于没有找到将rBoxWith转化为合适的Twips宽度的方法
											//并没有正确得到宽度,建议放弃调用;
	
}

BOOL CMTextDlg::ParseLineIdentToCADStr()
{
	// TODO: Add your command handler code here
//	return FALSE;
	PARAFORMAT pf;
	CHARFORMAT2 cf;
	LONG lRight;
	LONG lFirst;
	LONG lLeft;
/*
	sds_real rRight;
	sds_real rFirst;
	sds_real rLeft;*/

	int	 nEnd;
	int  nBegin;
	CClientDC clientDC(&m_ctlRichText);
	CSize size;
	CFont font;
	LOGFONT lf;
	CFont*pOldFont;
	int    iFirstSpace;
// 	int	   iLeftSpace;
/*
	for(int i=0;i<m_ctlRichText.GetLineCount()-1;i++)
	{
	
		if ((nBegin=m_ctlRichText.LineIndex(i)) != -1)
		{
			nEnd = nBegin + m_ctlRichText.LineLength(i);
			m_ctlRichText.SetSel(nEnd, nEnd);
			m_ctlRichText.ReplaceSel(_T("\\P"));
		}
	}*/


	for(int i=0;i<m_ctlRichText.GetLineCount();i++)
	{
		
		if ((nBegin=m_ctlRichText.LineIndex(i)) != -1)
		{
			nEnd = nBegin + m_ctlRichText.LineLength(i);
			m_ctlRichText.SetSel(nBegin, nEnd);
		}
		m_ctlRichText.GetParaFormat(pf);
		m_ctlRichText.GetSelectionCharFormat(cf);
		
		lRight =(pf.dwMask & PFM_RIGHTINDENT) ? pf.dxRightIndent : DDXM_BLANK;
		if (pf.dwMask & PFM_OFFSET)
		{
			lFirst = -pf.dxOffset;
			lLeft = (pf.dwMask & PFM_STARTINDENT) ?
				pf.dxStartIndent + pf.dxOffset : DDXM_BLANK;
		}
		else
			lLeft = lFirst =DDXM_BLANK;
	
		font.CreatePointFont(10,cf.szFaceName);
		font.GetLogFont(&lf);
		lf.lfHeight=cf.yHeight/15;
		font.DeleteObject();
		font.CreateFontIndirect(&lf);
		pOldFont=clientDC.SelectObject(&font);
		size=clientDC.GetTextExtent(_T(" "));
		clientDC.SelectObject(pOldFont);
		font.DeleteObject();
		size.cx*=15;
		iFirstSpace=lFirst/size.cx;
		m_ctlRichText.SetSel(nBegin, nBegin);
		while(iFirstSpace)
		{
			iFirstSpace--;
			m_ctlRichText.ReplaceSel(_T(" "));
		}
		/*
		CMTextDlg::ConvertTwipsToTextHeight(rFirst,lFirst);
				CMTextDlg::ConvertTwipsToTextHeight(rLeft,lLeft);
				CMTextDlg::ConvertTwipsToTextHeight(rRight,lRight);*/
		
		
	}

	return TRUE;
}

BOOL CMTextDlg::SetLineLength(double length)
{
	
	m_dBoxWidth=length;
	LONG lineLength;
	if(m_dcTarget.m_hDC==NULL)
		m_dcTarget.CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
	
		
	
/*
			sds_point pt1;
				pt1[0]=length;
				pt1[1]=0;
				pt1[2]=0;
				sds_point pt2;
				pt2[0]=0;
				pt2[1]=0;
				pt2[2]=0;
				int PX1;
				int PY1;
				int PX2;
				int PY2;
				
				  sds_rp2pix(pt1[0],pt1[1],&PX1,&PY1);
				  sds_rp2pix(pt2[0],pt2[1],&PX2,&PY2);
		/ *		  CPoint pOne(PX1, PY1);
				  CPoint pTwo(PX2, PY2);
				//  HDC hdc = ::GetDC(NULL);
				  int mapmode=GetMapMode(m_dcTarget.m_hDC);
				  SetMapMode(m_dcTarget.m_hDC, MM_TWIPS);
				  DPtoLP(m_dcTarget.m_hDC, &pOne, 1);
				  DPtoLP(m_dcTarget.m_hDC, &pTwo, 1);
				  SetMapMode(m_dcTarget.m_hDC,mapmode);
				  float xx = abs(  pOne.x-pTwo.x ) /m_wndStyleBar.m_FontSizeScale/2;// *6015.0/6613.0;* /
		
				
		//::ReleaseDC(NULL,hdc);*/
		
	
	
	if(length>1E-11)
	{
		if(length>0.0159)
		{
			length=length*0.865/m_wndStyleBar.m_FontSizeScale;
			CMTextDlg::ConvertTextHeightToTwips(length,lineLength);
			m_ctlRichText.SetTargetDevice(m_dcTarget,lineLength);
		}
		else
		{
			m_ctlRichText.SetTargetDevice(m_dcTarget,1);
		}
	}
	else
	{
		m_ctlRichText.SetTargetDevice(m_dcTarget,MAXLONG);
	}
	return TRUE;
}
BOOL CMTextDlg::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
{
    ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);
	
    // if there is a top level routing frame then let it handle the message
  //  if (GetRoutingFrame() != NULL) return FALSE;
	
    // to be thorough we will need to handle UNICODE versions of the message also !!
    TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
    TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
    TCHAR szFullText[512];
    CString strTipText;
    UINT nID = pNMHDR->idFrom;
	
    if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
        pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
    {
        // idFrom is actually the HWND of the tool 
        nID = ::GetDlgCtrlID((HWND)nID);
    }
	
    if (nID != 0) // will be zero on a separator
    {
        AfxLoadString(nID, szFullText);
        strTipText=szFullText;
		
#ifndef _UNICODE
        if (pNMHDR->code == TTN_NEEDTEXTA)
        {
            lstrcpyn(pTTTA->szText, strTipText, sizeof(pTTTA->szText));
        }
        else
        {
            _mbstowcsz(pTTTW->szText, strTipText, sizeof(pTTTW->szText));
        }
#else
        if (pNMHDR->code == TTN_NEEDTEXTA)
        {
            _wcstombsz(pTTTA->szText, strTipText,sizeof(pTTTA->szText));
        }
        else
        {
            lstrcpyn(pTTTW->szText, strTipText, sizeof(pTTTW->szText));
        }
#endif
		
        *pResult = 0;
		
        // bring the tooltip window above other popup windows
        ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,
            SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER);
        
        return TRUE;
    }
	
    return FALSE;
}

void CMTextDlg::SetStackAlign(BOOL forCAD)
{
	CString strAling;
	if(forCAD)
	{
		m_iStackAlign=2-m_iStackAlign;
		if(m_iStackAlign!=0)
		{
			strAling.Format("\\A%d;",m_iStackAlign);
			m_ctlRichText.SetSel(0,0);
			m_ctlRichText.ReplaceSel(strAling,FALSE);
		}
	}
	else
	{
		m_ctlRichText.SetSel(0,4);
		strAling=m_ctlRichText.GetSelText();
		if(strAling.CompareNoCase(_T("\\A2;"))==0)
		{
			m_iStackAlign=2;
			m_ctlRichText.ReplaceSel(_T(""));
		}
		else
			if(strAling.CompareNoCase(_T("\\A1;"))==0)
			{
				m_iStackAlign=1;
				m_ctlRichText.ReplaceSel(_T(""));
			}
			else
				if(strAling.CompareNoCase(_T("\\A0;"))==0)
				{
					m_iStackAlign=0;
					m_ctlRichText.ReplaceSel(_T(""));
				}
				else
				m_iStackAlign=0;
	m_iStackAlign=2-m_iStackAlign;
	}

}
void CMTextDlg::OnMTextWithSet() 
{
	// TODO: Add your command handler code here
	CMTextWidthSetDlg widthDlg;
	widthDlg.m_dWidth=m_dBoxWidth;
	widthDlg.m_dLineSpace=m_dLineSpace;
	widthDlg.m_iLineSpaceStyle=m_iLineSpaceStyle;
	if(widthDlg.DoModal()==IDOK)
	{
		m_dBoxWidth=widthDlg.m_dWidth;
		
		if(widthDlg.m_bIsNoWrap)
			SetLineLength(0.0);
		else
			SetLineLength(m_dBoxWidth);
		m_dLineSpace=widthDlg.m_dLineSpace;
		m_iLineSpaceStyle=widthDlg.m_iLineSpaceStyle;
		
	}
}

BOOL CMTextDlg::UpdateStackOnChange(CHARFORMAT cf)
{
	
	LONG iStackNumber;
	CHARRANGE cr;
	m_ctlRichText.GetSel(cr);
	if(cr.cpMax==cr.cpMin)
		return FALSE;
	m_ctlRichText.GetSelectionCharFormat(cf);
	iStackNumber=m_pRichEditOle->GetObjectCount();
	while ((--iStackNumber)>=0) 
	{
		if(IsStackInSelectRange(iStackNumber,cr))
		UpdateStackCF(iStackNumber,cf);
	}
	m_ctlRichText.SetSel(cr);
	return TRUE;
}

BOOL CMTextDlg::IsStackInSelectRange(LONG index,CHARRANGE cr)
{
	
	REOBJECT reobject;
	BOOL reVal;
	
	reVal=FALSE;
	
	ZeroMemory(&reobject, sizeof(REOBJECT));
	reobject.cbStruct = sizeof(REOBJECT);
	m_pRichEditOle->GetObject(
		index,                   
		&reobject,  
		REO_GETOBJ_NO_INTERFACES               
		);
	if(reobject.cp>=cr.cpMin&&reobject.cp<=cr.cpMax)
		reVal=TRUE;
	return reVal;
}

BOOL CMTextDlg::UpdateStackCF(LONG index, CHARFORMAT cf)
{
	CMTextStack stackobj;
	GetStackObject(index,stackobj);
	if(cf.dwMask&CFM_FACE)
		strcpy(stackobj.m_lf.lfFaceName,cf.szFaceName);
	if(cf.dwMask&CFM_SIZE)
		stackobj.m_lf.lfHeight=cf.yHeight*-96/1440;
	SetStackObject(index,stackobj);
	return TRUE;
}

BOOL CMTextDlg::GetStackObject(LONG index, CMTextStack &stackobj)
{
	REOBJECT reobject;
	ZeroMemory(&reobject, sizeof(REOBJECT));
	reobject.cbStruct = sizeof(REOBJECT);
	m_pRichEditOle->GetObject(
		index,                   
		&reobject,  
		REO_GETOBJ_ALL_INTERFACES               
		);
/*
	if(!(reobject.dwFlags&REO_SELECTED))
	{
		return FALSE;
	}*/

	IStream *ppstm;
	HRESULT res;
	IEnumSTATSTG *ppenum;
	res=reobject.pstg->EnumElements(
		0,        //Reserved; must be zero
		NULL,        //Reserved; must be NULL
		0,        //Reserved; must be zero
		&ppenum   //Pointer to output variable that
		// receives the IEnumSTATSTG interface pointer
		);
	STATSTG statstg;
	memset( &statstg, 0, sizeof(statstg) );
	CHAR pv[1000];
	ULONG pcbRead;
	CString strReadString;
	int i=0;
	while (	ppenum->Next( 1, &statstg, 0 )==S_OK)
	{
		
		USES_CONVERSION;
		CString strName;
		strName=OLE2T(statstg.pwcsName);
		if(strName.Compare(_T("Contents"))!=0)
			continue;
		res = reobject.pstg->OpenStream( statstg.pwcsName,
			NULL,
			STGM_READ | STGM_SHARE_EXCLUSIVE,
			NULL,
			&ppstm );
		
		res=ppstm->Read((void*)pv,sizeof(pv),&pcbRead);
		
		CMemFile memFile;
		CArchive  ar(&memFile,CArchive::store);
		memFile.SeekToBegin();
		ar.Write(pv,sizeof(pv));
		ar.Flush();
		ar.Close();
		memFile.SeekToBegin();
		CArchive  ar2(&memFile,CArchive::load);
		stackobj.Serialize(ar2);
		ppstm->Release()

⌨️ 快捷键说明

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