?? newmtext.cpp
字號:
cf.dwMask&=~CFM_COLOR;
SetSelectionCharFormat(cf);
lCurPos++;
}
}
SetSel(crSelect);
}
SetOptions(ECOOP_OR, ECO_AUTOVSCROLL | ECO_AUTOHSCROLL|ECO_NOHIDESEL);
HideSelection(FALSE, FALSE);
}
void CMTextRichEditCtrl::DelectSelectFormat()
{
CHARFORMAT cf;
// GetSelectionCharFormat(cf);
cf.dwEffects=0;
cf.dwMask=CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE;
SetSelectionCharFormat(cf);
}
void CMTextRichEditCtrl::CombineSelectParagraph()
{
ASSERT_VALID(this);
FINDTEXTEX ft;
CHARRANGE crSelect;
CString strFind;
LONG m_FindIndex;
strFind=_T("\r");
GetSel( crSelect);
ft.chrg.cpMin = crSelect.cpMin;
ft.chrg.cpMax = crSelect.cpMax;
ft.lpstrText =LPSTR(LPCTSTR(strFind));
DWORD dwFlags = NULL;
dwFlags |= FR_DOWN;
m_FindIndex = FindText(dwFlags, &ft);
CHARRANGE cr;
HideSelection(TRUE, FALSE);
while(m_FindIndex!=-1)
{
SetSel(ft.chrgText);
GetSel( cr );
//Send_keybd_event(VK_DELETE);
ReplaceSel(_T(" "),TRUE);
GetSel( cr );
ft.chrg.cpMin=cr.cpMax;
m_FindIndex = FindText(dwFlags, &ft);
}
HideSelection(FALSE, FALSE);
ASSERT_VALID(this);
}
void CMTextRichEditCtrl::Send_keybd_event(BYTE bVk)
{
keybd_event( bVk,
0x45,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
// Simulate a key release
keybd_event( bVk,
0x45,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
}
void CMTextRichEditCtrl::ReadFromFile()
{
CHARRANGE crSelect;
GetSel( crSelect);
TCHAR szFilters[]=_T("Text Files(*.txt)|*.txt|All files(*.*)|*.*||");
CString strFileName;
if(dlg.DoModal()==IDOK)
{
strFileName=dlg.GetPathName();
CFile fFile;
if(!fFile.Open(strFileName,CFile::modeRead))
{
AfxMessageBox(_T("Can not Open ")+strFileName);
return ;
}
SetSel(crSelect);
SetFocus();
TCHAR *pChar;
DWORD dCharRead;
TCHAR end;
dCharRead=fFile.GetLength();
pChar=new TCHAR[dCharRead];
dCharRead=fFile.ReadHuge(pChar,dCharRead);
if(dCharRead>0)
{
end=pChar[dCharRead];
pChar[dCharRead]='\0';
ReplaceSel(pChar,TRUE);
}
pChar[dCharRead]=end;
delete[]pChar;
pChar=NULL;
}
else
{
SetFocus();
SetSel(crSelect);
}
}
BOOL CMTextRichEditCtrl::GetObjectInfo(COleDataObject* pDataObject,
CSize* pSize, CSize* pOffset)
{
ASSERT(pSize != NULL);
// get object descriptor data
HGLOBAL hObjDesc = pDataObject->GetGlobalData(m_cfObjectDescriptor);
if (hObjDesc == NULL)
{
if (pOffset != NULL)
*pOffset = CSize(0, 0); // fill in defaults instead
*pSize = CSize(0, 0);
return FALSE;
}
ASSERT(hObjDesc != NULL);
// otherwise, got CF_OBJECTDESCRIPTOR ok. Lock it down and extract size.
LPOBJECTDESCRIPTOR pObjDesc = (LPOBJECTDESCRIPTOR)GlobalLock(hObjDesc);
ASSERT(pObjDesc != NULL);
pSize->cx = (int)pObjDesc->sizel.cx;
pSize->cy = (int)pObjDesc->sizel.cy;
if (pOffset != NULL)
{
pOffset->cx = (int)pObjDesc->pointl.x;
pOffset->cy = (int)pObjDesc->pointl.y;
}
GlobalUnlock(hObjDesc);
GlobalFree(hObjDesc);
// successfully retrieved pSize & pOffset info
return TRUE;
}
BOOL CMTextRichEditCtrl::GetStackStatus(int& itype)
{
CString strSelectString;
itype=-1;
strSelectString=GetSelText();
if(strSelectString.GetLength()<3)
{
itype=-1;
}
else
if(strSelectString.Find('/')!=-1)
{
itype=StackS_Horizontal;//選中了可堆疊的字符串
}
else
if(strSelectString.Find('#')!=-1)
{
itype=StackS_Lean;
}
else
if(strSelectString.Find('^')!=-1)
{
itype=StackS_Tolerance;
}
else
{
itype=-1;
}
return TRUE;
}
BOOL CMTextRichEditCtrl::IsSelectStack()
{
return FALSE;
}
BOOL CMTextRichEditCtrl::init(SDS_mTextData *pMTextData)
{
// Increase bytes allowed from 32K default
// Increase bytes allowed from 32K default
LimitText(1048576);
// Bugzilla No. 78437; 30-01-2003
SetEventMask(GetEventMask() | ENM_SELCHANGE);
SetWindowText(pMTextData->text);
CString tmptext, tmpfont;
bool tmpbold = false, tmpitalic = false;
double tmpheight;
short tmpcharset = DEFAULT_CHARSET; // EBATECH(CNBR)
short tmppitch = 0; // EBATECH(CNBR)
CHARFORMAT cf;
GetWindowText(tmptext);
//I edit the text in the richeditctrl by the following: I insert the text into a string,
//find the location of what I'm looking for, then store the appropriate information in
//variables. I then select the formatting information and delete it from the richeditctrl.
//I then set the charformat as indicated by the variables. I use GetWindowText occasionally
//to make sure the two match up.
SetSel(0, GetTextLength());
cf.dwMask = CFM_SIZE ;
//DP: old realization commented
//cf.yHeight = (long) (m_pMTextData->rTextHeight * 1000);
CMTextDlg::ConvertTextHeightToTwips(pMTextData->rTextHeight, cf.yHeight);
if(cf.yHeight<=Mid_FontTwips)
GetMTextDlg()->m_wndStyleBar.m_FontSizeScale=1.0;
else
GetMTextDlg()->m_wndStyleBar.m_FontSizeScale=cf.yHeight/Mid_FontTwips;
cf.yHeight/=GetMTextDlg()->m_wndStyleBar.m_FontSizeScale;
SetSelectionCharFormat(cf);
CString height;
height.Format("%.4f", pMTextData->rTextHeight);
// Bugzilla No. 78034; 23-12-2002 [
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,cf.yHeight*GetMTextDlg()->m_wndStyleBar.m_FontSizeScale);
GetMTextDlg()->m_wndStyleBar.m_wndFontSizes.SetCurSel(index);
}
// Bugzilla No. 78034; 23-12-2002 ]
//
int erase, eraseend;
int index = tmptext.Find("\\P", 0);
while (index != -1)
{
SetSel(index, index + 2);
ReplaceSel("\r\n");
GetWindowText(tmptext);
index = tmptext.Find("\\P", 0);
}
static int kk=0;
kk++;
TRACE(" (%d",kk);
TRACE(tmptext+") ");
//find all formatting information for fontname, bold, and italics.
index = tmptext.Find("\\f", 0);
while (index != -1)
{
//store, and delete, the first set of formatting information from the string.
tmptext.Delete(index, 2);
int end = tmptext.Find("|", index);
if (end != -1)
{
tmpfont = tmptext.Mid(index, end - index);
// EBATECH(CNBR) -[ 23/06/2001
// \fFontname|b0|i0|c128|p34;
//Modified Cybage AW 30/04/2001[
//Reason : To avoid the crash when different fonts are used
//if(tmpfont.Find("TXT.shx") != -1)
//{
// end = tmptext.Find(";", index);
//}
//tmpfont = tmptext.Mid(index, end - index);
//Modified Cybage AW 30/04/2001]
tmptext.Delete(index, end - index + 2);
tmpbold = true;
tmpitalic = true;
if (tmptext.GetAt(index) == '0')
tmpbold = false;
if (tmptext.GetAt(index + 3) == '0')
tmpitalic = false;
// EBATECH(CNBR) get charset
end = tmptext.Find("|c",index);
if( end != -1 )
tmpcharset = atoi(tmptext.GetBuffer(0)+(index+end+2));
else
tmpcharset = ANSI_CHARSET;
// EBATECH(CNBR) get pitchandfamily
end = tmptext.Find("|p",index);
if( end != -1 )
tmppitch = atoi(tmptext.GetBuffer(0)+(index+end+2));
else
tmppitch = DEFAULT_PITCH | FF_DONTCARE;
// EBATECH(CNBR) okay to get charset and pitchandfamily
end = tmptext.Find(";", index);
}
else
{
end = tmptext.Find(";", index);
tmpfont = tmptext.Mid(index, end - index);
}
if (end == -1)
break; // error
tmptext.Delete(index, end - index + 1);
end = tmptext.Find("\\f", index);
if (end < index)
//end = tmptext.GetLength() + 1;
end = tmptext.GetLength();
//here we erase that which has been erased in tmptext.
GetWindowText(tmptext);
kk++;
TRACE(" (%d",kk);
TRACE(tmptext+") ");
erase = tmptext.Find("\\f", 0);
eraseend = tmptext.Find(";", erase);
//this condition is for the extra inserted space before // in most formatting info.
//when it is there, I must modify the counters appropriately.
//Modified Cybage AW 30/04/2001[
//Reason : Bug : The spaces between the words are deleted in the text editor.
/*
if (erase != 0 && tmptext.GetAt(erase - 1) == ' ')
{
erase--;
index--;
end--;
}
*/
//Modified Cybage AW 30/04/2001]
SetSel(erase, eraseend + 1);
ReplaceSel("");
//find the length of text the previous formatting info affected, then insert the
//appropriate charformatting.
//SetSel(index, end - 1);
SetSel(index, end);
GetSelectionCharFormat(cf);
cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_CHARSET | CFM_FACE; // EBATECH(CNBR)
if (cf.dwEffects & CFE_BOLD)
{
if (!tmpbold)
cf.dwEffects ^= CFE_BOLD;
}
else
{
if (tmpbold)
cf.dwEffects ^= CFE_BOLD;
}
if (cf.dwEffects & CFE_ITALIC)
{
if (!tmpitalic)
cf.dwEffects ^= CFE_ITALIC;
}
else
{
if (tmpitalic)
cf.dwEffects ^= CFE_ITALIC;
}
_tcscpy (cf.szFaceName, tmpfont);
cf.bCharSet = (BYTE)tmpcharset; // EBATECH(CNBR)
cf.bPitchAndFamily = (BYTE)tmppitch; // EBATECH(CNBR)
SetSelectionCharFormat(cf);
GetWindowText(tmptext);
kk++;
TRACE(" (%d",kk);
TRACE(tmptext+") ");
//find the next set of formatting information
index = tmptext.Find("\\f", 0);
}
//return TRUE;
//find all formatting information for text height.
index = tmptext.Find("\\H", 0);
{
tmptext.Delete(index, 2);
int end = tmptext.Find(";", index);
if (end == -1)
break; // error
tmpheight = atof(tmptext.Mid(index, end - index));
// Bugzilla No. 78034; 23-12-2002 [
long tempHeight;
CMTextDlg::ConvertTextHeightToTwips(tmpheight,tempHeight);
tempHeight/=GetMTextDlg()->m_wndStyleBar.m_FontSizeScale;
height.Format("%.4f", tmpheight);
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,tempHeight);
}
// Bugzilla No. 78034; 23-12-2002 ]
tmptext.Delete(index, end - index + 1);
end = tmptext.Find("\\H", index);
if (end < index)
//end = tmptext.GetLength() + 1;
end = tmptext.GetLength();
GetWindowText(tmptext);
erase = tmptext.Find("\\H", 0);
eraseend = tmptext.Find(";", erase);
//Modified Cybage AW 30/04/2001[
//Reason : Bug : The spaces between the words are deleted in the text editor.
/*
if (erase != 0 && tmptext.GetAt(erase - 1) == ' ')
{
erase--;
index--;
end--;
}
*/
//Modified Cybage AW 30/04/2001]
SetSel(erase, eraseend + 1);
ReplaceSel("");
//SetSel(index, end - 1);
SetSel(index, end);
GetSelectionCharFormat(cf);
cf.dwMask = CFM_SIZE;
//DP: old realization commented
//cf.yHeight = (int) ((tmpheight / 0.2) * 200 + 0.5);
CMTextDlg::ConvertTextHeightToTwips(tmpheight, cf.yHeight);
cf.yHeight/=GetMTextDlg()->m_wndStyleBar.m_FontSizeScale;
SetSelectionCharFormat(cf);
GetWindowText(tmptext);
index = tmptext.Find("\\H", 0);
}
//find all formatting information for underlining.
index = tmptext.Find("\\L", 0);
while (index != -1)
{
tmptext.Delete(index, 2);
int end = tmptext.Find("\\l", index);
if (end < index)
end = tmptext.GetLength() + 1;
GetWindowText(tmptext);
erase = tmptext.Find("\\L", 0);
eraseend = tmptext.Find("\\l", 0);
SetSel(erase, erase + 2);
ReplaceSel("");
SetSel(eraseend - 2, eraseend);
ReplaceSel("");
//SetSel(index, end - 1);
SetSel(index, end);
GetSelectionCharFormat(cf);
cf.dwMask = CFM_UNDERLINE;
cf.dwEffects = CFE_UNDERLINE;
SetSelectionCharFormat(cf);
GetWindowText(tmptext);
index = tmptext.Find("\\L", 0);
}
//SetSel(0, 0);
//UpdateData(true);
// ((CMTextPropSheet*)GetParent())->UpdateChar();
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();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -