?? newmtext.cpp
字號:
HideSelection(FALSE, FALSE);
return TRUE;
}
CMTextDlg* CMTextRichEditCtrl::GetMTextDlg()
{
return (CMTextDlg*)GetParent();
}
BOOL CMTextRichEditCtrl::init2(SDS_mTextData *pMTextData)
{
HideSelection(TRUE,FALSE);
SetOptions(ECOOP_XOR, ECO_AUTOVSCROLL | ECO_AUTOHSCROLL|ECO_NOHIDESEL);
LimitText(1048576);
SetEventMask(GetEventMask() | ENM_SELCHANGE);
SetWindowText(pMTextData->text);
GetMTextDlg()->SetStackAlign(FALSE);
CHARFORMAT cf;
SetSel(0,-1);
GetSelectionCharFormat(cf);
cf.dwMask = CFM_SIZE|CFM_COLOR;
cf.crTextColor=CMTextStyleBar::BOUND_SDS_RGBFromACADColor(pMTextData->nColor);
CMTextDlg::ConvertTextHeightToTwips(pMTextData->rTextHeight, cf.yHeight);
/*
if(cf.yHeight<=Mid_FontTwips)
//GetMTextDlg()->m_wndStyleBar.m_FontSizeScale=1.0;
GetMTextDlg()->m_wndStyleBar.m_FontSizeScale=double(cf.yHeight)/double(Mid_FontTwips);
else
GetMTextDlg()->m_wndStyleBar.m_FontSizeScale=double(cf.yHeight)/double(Mid_FontTwips);*/
cf.yHeight/=GetMTextDlg()->m_wndStyleBar.m_FontSizeScale;
SetSelectionCharFormat(cf);
GetSelectionCharFormat(cf);
CString height;
height.Format("%.4f", pMTextData->rTextHeight);
LONG yHeight;
yHeight=cf.yHeight*GetMTextDlg()->m_wndStyleBar.m_FontSizeScale;
if (GetMTextDlg()->m_wndStyleBar.m_wndFontSizes.FindStringExact(0, height) == -1)
{
int index =GetMTextDlg()->m_wndStyleBar.m_wndFontSizes.AddString(height);
GetMTextDlg()->m_wndStyleBar.m_wndFontSizes.SetItemData(index,yHeight);
GetMTextDlg()->m_wndStyleBar.m_wndFontSizes.SetCurSel(index);
GetMTextDlg()->m_wndStyleBar.m_BoxTwipToEditTwip[yHeight]=cf.yHeight;
}
/////////////////////////////////////////////////////////////////////////////////////////////
FINDTEXTEX ftS;
FINDTEXTEX ftE;
FINDTEXTEX ftT;
LONG SIndex;
LONG EIndex;
LONG TIndex;
CString strSelectString;
ftS.chrg.cpMin = 0;
ftS.chrg.cpMax = -1;
ftT.chrg.cpMin = 0;
ftT.chrg.cpMax = -1;
ftE.chrg.cpMin = 0;
ftE.chrg.cpMax = -1;
DWORD dwFlags = NULL;
dwFlags |= FR_DOWN;
// dwFlags |= FR_MATCHCASE;
CHARRANGE cr;
////////////////////////////////////////////////////////////////////////////////////////////////
ftS.lpstrText = (LPSTR)_T("\\P");
SIndex = FindText(dwFlags, &ftS);
while (SIndex != -1)
{
SetSel(ftS.chrgText);
ReplaceSel("\r");
GetSel(cr);
ftS.chrg.cpMin=cr.cpMax;
SIndex = FindText(dwFlags, &ftS);
}
///////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
ftS.chrg.cpMin = 0;
ftS.chrg.cpMax = -1;
ftS.lpstrText = (LPSTR)_T("{");
SIndex = FindText(dwFlags, &ftS);
while (SIndex != -1)
{
if(ftS.chrgText.cpMin==0)
SetSel(ftS.chrgText);
else
SetSel(ftS.chrgText.cpMin-1,ftS.chrgText.cpMax);
strSelectString=GetSelText();
if(strSelectString.Compare(_T("\\{"))==0)
ReplaceSel(_T("{"),FALSE);
else
{
SetSel(ftS.chrgText);
ReplaceSel(_T(""),FALSE);
}
GetSel(cr);
ftS.chrg.cpMin=cr.cpMax;
SIndex = FindText(dwFlags, &ftS);
}
ftS.chrg.cpMin = 0;
ftS.chrg.cpMax = -1;
ftS.lpstrText = (LPSTR)_T("}");
SIndex = FindText(dwFlags, &ftS);
while (SIndex != -1)
{
if(ftS.chrgText.cpMin==0)
SetSel(ftS.chrgText);
else
SetSel(ftS.chrgText.cpMin-1,ftS.chrgText.cpMax);
strSelectString=GetSelText();
if(strSelectString.Compare(_T("\\}"))==0)
ReplaceSel(_T("}"),FALSE);
else
{
SetSel(ftS.chrgText);
ReplaceSel(_T(""),FALSE);
}
GetSel(cr);
ftS.chrg.cpMin=cr.cpMax;
SIndex = FindText(dwFlags, &ftS);
}
///////////////////////////////////////////////////////////////////////////////////////////////
BOOL bBlob;
BOOL bIntalic;
int findIndex;
int icharSet;
int iPitch;
CString strFontName;
ftS.chrg.cpMin = 0;
ftS.chrg.cpMax = -1;
ftS.lpstrText = (LPSTR)_T("\\f");
ftE.lpstrText = (LPSTR)_T(";");
SIndex = FindText(dwFlags, &ftS);
if(SIndex!=-1)
ftE.chrg.cpMin=ftS.chrgText.cpMax;
EIndex = FindText(dwFlags, &ftE);
while(SIndex!=-1&&EIndex!=-1&&SIndex<EIndex)
{
SetSel(ftS.chrgText.cpMax,ftE.chrgText.cpMin);
strSelectString=GetSelText();
findIndex=strSelectString.Find(_T("|"));
if(findIndex!=-1&&strSelectString.GetLength()>0)
{
strFontName=strSelectString.Mid(0,findIndex);
}
else
{
strFontName=strSelectString.Mid(0);
}
bBlob=FALSE;
bIntalic=FALSE;
if(strSelectString.Find(_T("|b1|"))!=-1)
bBlob=TRUE;
if(strSelectString.Find(_T("|i1|"))!=-1)
bIntalic=TRUE;
if((findIndex=strSelectString.Find(_T("|c")))!=-1)
{
icharSet=atoi(strSelectString.GetBuffer(0)+2);
strSelectString.ReleaseBuffer(-1);
}
else
{
icharSet = ANSI_CHARSET;
}
if((findIndex=strSelectString.Find(_T("|p")))!=-1)
{
iPitch=atoi(strSelectString.GetBuffer(0)+2);
strSelectString.ReleaseBuffer(-1);
}
else
{
iPitch = DEFAULT_PITCH | FF_DONTCARE;;
}
ftT.chrg.cpMin=ftE.chrgText.cpMax;
ftT.lpstrText = (LPSTR)_T("\\f");
TIndex = FindText(dwFlags, &ftT);
SetSel(ftE.chrgText.cpMax,TIndex);
GetSelectionCharFormat(cf);
cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_CHARSET | CFM_FACE;
if (cf.dwEffects & CFE_BOLD)
{
if (!bBlob)
cf.dwEffects ^= CFE_BOLD;
}
else
{
if (bBlob)
cf.dwEffects ^= CFE_BOLD;
}
if (cf.dwEffects & CFE_ITALIC)
{
if (!bIntalic)
cf.dwEffects ^= CFE_ITALIC;
}
else
{
if (bIntalic)
cf.dwEffects ^= CFE_ITALIC;
}
/////////////////////////////////////////////////////////////
CString strFontCAD;
CString strFontTTF;
strFontCAD=strFontName;
if(GetMTextDlg()->m_wndStyleBar.IsInFontMap(strFontCAD,strFontTTF,TRUE))
{
strFontName=strFontTTF;
cf.dwMask^=CFM_CHARSET;
cf.dwEffects &= ~CFE_BOLD;
cf.dwEffects &= ~CFE_ITALIC;
}
////////////////////////////////////////////////////////////
_tcscpy (cf.szFaceName, strFontName);
cf.bCharSet = (BYTE)icharSet;
cf.bPitchAndFamily = (BYTE)iPitch;
SetSelectionCharFormat(cf);
SetSel(ftS.chrgText.cpMin,ftE.chrgText.cpMax);
ReplaceSel(_T(""));
GetSel(cr);
ftS.chrg.cpMin=cr.cpMax;
ftE.chrg.cpMin=cr.cpMax;
SIndex = FindText(dwFlags, &ftS);
if(SIndex!=-1)
{
ftE.chrg.cpMin=ftS.chrgText.cpMax;
EIndex = FindText(dwFlags, &ftE);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
ftS.chrg.cpMin = 0;
ftS.chrg.cpMax = -1;
ftE.chrg.cpMin = 0;
ftE.chrg.cpMax = -1;
ftS.lpstrText = (LPSTR)_T("\\H");
ftE.lpstrText = (LPSTR)_T(";");
SIndex = FindText(dwFlags, &ftS);
if(SIndex!=-1)
ftE.chrg.cpMin=ftS.chrgText.cpMax;
EIndex = FindText(dwFlags, &ftE);
double dHeight;
LONG lTwips;
while(SIndex!=-1&&EIndex!=-1&&SIndex<EIndex)
{
SetSel(ftS.chrgText.cpMax,ftE.chrgText.cpMin);
strSelectString=GetSelText();
if(strSelectString.GetLength()>0)
{
dHeight=atof(strSelectString);
SetSel(ftE.chrgText.cpMin-1,ftE.chrgText.cpMin);
strSelectString=GetSelText();
if(strSelectString.CompareNoCase(_T("x"))==0)
dHeight*=pMTextData->rTextHeight;
CMTextDlg::ConvertTextHeightToTwips(dHeight,lTwips);
height.Format("%.4f", dHeight);
yHeight=lTwips/GetMTextDlg()->m_wndStyleBar.m_FontSizeScale;
if (GetMTextDlg()->m_wndStyleBar.m_wndFontSizes.FindStringExact(0, height) == -1)
{
int index = GetMTextDlg()->m_wndStyleBar.m_wndFontSizes.AddString(height);
GetMTextDlg()->m_wndStyleBar.m_wndFontSizes.SetItemData(index,lTwips);
GetMTextDlg()->m_wndStyleBar.m_BoxTwipToEditTwip[lTwips]=yHeight;
}
lTwips=yHeight;
ftT.chrg.cpMin=ftE.chrgText.cpMax;
ftT.lpstrText = (LPSTR)_T("\\H");
TIndex = FindText(dwFlags, &ftT);
SetSel(ftS.chrgText.cpMax,TIndex);
GetSelectionCharFormat(cf);
cf.dwMask = CFM_SIZE;
cf.yHeight=lTwips;
SetSelectionCharFormat(cf);
SetSel(ftS.chrgText.cpMin,ftE.chrgText.cpMax);
ReplaceSel(_T(""),FALSE);
GetSel(cr);
ftS.chrg.cpMin=cr.cpMax;
ftE.chrg.cpMin=cr.cpMax;
SIndex = FindText(dwFlags, &ftS);
if(SIndex!=-1)
ftE.chrg.cpMin=ftS.chrgText.cpMax;
EIndex = FindText(dwFlags, &ftE);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
ftS.chrg.cpMin = 0;
ftS.chrg.cpMax = -1;
ftE.chrg.cpMin = 0;
ftE.chrg.cpMax = -1;
ftS.lpstrText = (LPSTR)_T("\\L");
ftE.lpstrText = (LPSTR)_T("\\l");
SIndex = FindText(dwFlags, &ftS);
// CString strS;
while(SIndex!=-1)
{
// GetWindowText(strS);
ftE.chrg.cpMin=ftS.chrgText.cpMax;
EIndex = FindText(dwFlags, &ftE);
SetSel(ftS.chrgText.cpMax,EIndex);
GetSelectionCharFormat(cf);
cf.dwMask = CFM_UNDERLINE;
cf.dwEffects = CFE_UNDERLINE;
SetSelectionCharFormat(cf);
SetSel(ftE.chrgText);
ReplaceSel(_T(""),FALSE);
SetSel(ftS.chrgText);
ReplaceSel(_T(""),FALSE);
GetSel(cr);
ftS.chrg.cpMin=cr.cpMax;
ftE.chrg.cpMin=cr.cpMax;
SIndex = FindText(dwFlags, &ftS);
}
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
ftS.chrg.cpMin = 0;
ftS.chrg.cpMax = -1;
ftE.chrg.cpMin = 0;
ftE.chrg.cpMax = -1;
ftS.lpstrText = (LPSTR)_T("\\C");
ftE.lpstrText = (LPSTR)_T(";");
SIndex = FindText(dwFlags, &ftS);
if(SIndex!=-1)
ftE.chrg.cpMin=ftS.chrgText.cpMax;
EIndex = FindText(dwFlags, &ftE);
int cadcolor;
COLORREF RGBcolor;
while(SIndex!=-1&&EIndex!=-1&&SIndex<EIndex)
{
SetSel(ftS.chrgText.cpMax,ftE.chrgText.cpMin);
strSelectString=GetSelText();
if(strSelectString.GetLength()>0)
{
cadcolor=atof(strSelectString);
RGBcolor=SDS_RGBFromACADColor(cadcolor);
if(cadcolor==256)
RGBcolor=COLOR_FOR_LAYER_PLUS;
else
if(cadcolor==0)
RGBcolor=COLOR_FOR_BLOCK_PLUS;
ftT.chrg.cpMin=ftE.chrgText.cpMax;
ftT.lpstrText = (LPSTR)_T("\\H");
TIndex = FindText(dwFlags, &ftT);
SetSel(ftS.chrgText.cpMax,TIndex);
GetSelectionCharFormat(cf);
cf.dwMask = CFM_COLOR;
cf.crTextColor=RGBcolor;
SetSelectionCharFormat(cf);
SetSel(ftS.chrgText.cpMin,ftE.chrgText.cpMax);
ReplaceSel(_T(""),FALSE);
GetSel(cr);
ftS.chrg.cpMin=cr.cpMax;
ftE.chrg.cpMin=cr.cpMax;
SIndex = FindText(dwFlags, &ftS);
if(SIndex!=-1)
ftE.chrg.cpMin=ftS.chrgText.cpMax;
EIndex = FindText(dwFlags, &ftE);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
switch(pMTextData->nAlignment)
{
case 0:
case 3:
case 6:
SetLeft();
break;
case 1:
case 4:
case 7:
SetCenter();
break;
case 2:
case 5:
case 8:
SetRight();
}
SetSel(0,0);
HideSelection(FALSE,FALSE);
SetOptions(ECOOP_OR, ECO_AUTOVSCROLL | ECO_AUTOHSCROLL|ECO_NOHIDESEL);
return TRUE;
}
BOOL CMTextRichEditCtrl::GetRTF(CString &strText)
{
EDITSTREAM es;
es.dwError = 0;
es.pfnCallback = RTFStreamOut;
es.dwCookie = (DWORD) &strText;
StreamOut(SF_RTF, es);
return TRUE;
}
BOOL CMTextRichEditCtrl::SetRTF(CString strText)
{
EDITSTREAM es;
es.dwError = 0;
es.pfnCallback = RTFStreamIn;
es.dwCookie = (DWORD) &strText;
StreamIn(SF_RTF, es);
return TRUE;
}
DWORD CALLBACK CMTextRichEditCtrl::RTFStreamOut(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CString *psEntry = (CString*) dwCookie;
CString tmpEntry = "";
tmpEntry = (CString) pbBuff;
*psEntry += tmpEntry.Left(cb);
return 0;
}
DWORD CALLBACK CMTextRichEditCtrl::RTFStreamIn(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CString *pstr = (CString *) dwCookie;
if (pstr->GetLength() < cb)
{
*pcb = pstr->GetLength();
memcpy(pbBuff, (LPCSTR) *pstr, *pcb);
pstr->Empty();
}
else
{
*pcb = cb;
memcpy(pbBuff, (LPCSTR) *pstr, *pcb);
*pstr = pstr->Right(pstr->GetLength() - cb);
}
return 0;
}
void CMTextRichEditCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// CN_COMMAND, (WORD)id, (WORD)id,
// GetMTextDlg()->SendDlgItemMessage(ID_StackStyle,CN_COMMAND);
GetMTextDlg()->PostMessage(WM_COMMAND,ID_StackStyle,0);
//CMTextRichEditCtrl::OnLButtonDblClk(nFlags, point);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -