📄 mweditctl.cpp
字号:
while(l<b)
{
Try=m_bufferStr.Mid(l,1);
//str=str.Right(str.GetLength()-1);
if((Try[0]>=0x1800)&&(Try[0]<=0x1900))
{
t++;
l++;
}
else
break;
}
return t;
}
void CMWEditCtrl::OnInitialsizecxChanged()
{
// TODO: Add notification handler code
SetModifiedFlag();
}
void CMWEditCtrl::OnInitialsizecyChanged()
{
// TODO: Add notification handler code
SetModifiedFlag();
}
void CMWEditCtrl::OnFontWeightChanged()
{
// TODO: Add notification handler code
SetModifiedFlag();
}
void CMWEditCtrl::OnFontHeightChanged()
{
// TODO: Add notification handler code
SetModifiedFlag();
}
void CMWEditCtrl::mytextout(CMWEditCtrl::Caret tempCaret,CString Sub)
{
CClientDC dc(this);
//CPaintDC dc(this);
// dc.SetBkColor(0x00ffffff);
dc.SetBkMode(TRANSPARENT);
Font(2700,_T("Times New Roman"));
CFont* pOldFont=dc.SelectObject(&MyFont);
CString tempstrE,tempstrH,Try;
Try=Sub.Left(1);
CString s=Enter.Left(1);
if(!Try.Compare(s))//回车
{
curGeneral.ColumnCount[tempCaret.GeneralLine]+=1;
tempCaret.CaretPos.x+=m_fontHeight;
tempCaret.CaretPos.y=0;
//if(curCaret.SCreenLine<10)不超过
tempCaret.SCreenLine++;
if(tempCaret.SCreenLine>maxscreenline)
{
tempCaret.SCreenLine=maxscreenline;
SFLisGL++;
Move(SFLisGL);
tempCaret.CaretPos.x-=m_fontHeight;
}
tempCaret.GeneralLine++;
tempCaret.CharCount=0;
tempCaret.GeneralBufPos+=1;
}
//**********************************
else//非回车
{
if(((Try[0]>20)&&(Try[0]<128))||((Try[0]>=0x1800)&&(Try[0]<=0x1900)))//字符
{
tempstrE=Sub.Left(1);
long Len=tempCaret.CaretPos.y+dc.GetTextExtent(tempstrE,1).cx;
if(Len<((m_bottom-m_top)-26))
{ int charlen=dc.GetTextExtent(tempstrE,1).cx;//传入字符宽
//dc.TextOut(0+m_fontHeight,0,tempstrE);
dc.TextOut(tempCaret.CaretPos.x+m_fontHeight,tempCaret.CaretPos.y,tempstrE);
tempCaret.CaretPos.y+=charlen;
tempCaret.GeneralBufPos+=1;
tempCaret.CharCount+=1;
curGeneral.ColumnPosit[tempCaret.GeneralLine]+=charlen;
curGeneral.ColumnCount[tempCaret.GeneralLine]+=1;
}
else//换行
{ tempCaret.CaretPos.x+=m_fontHeight;
tempCaret.CaretPos.y=0;
tempCaret.CharCount=0;
//judge
tempCaret.SCreenLine++;
if(tempCaret.SCreenLine>maxscreenline)
{
tempCaret.SCreenLine=maxscreenline;
SFLisGL++;
Move(SFLisGL);
tempCaret.CaretPos.x-=m_fontHeight;
}
tempCaret.GeneralLine++;
tempCaret.GeneralBufPos+=tempstrE.GetLength();
if((tempstrE[0]!=32))//是字母
{
int forward=0;
CString forwardstr=m_bufferStr.Mid(tempCaret.GeneralBufPos-1-
curGeneral.ColumnCount[tempCaret.GeneralLine-1],
curGeneral.ColumnCount[tempCaret.GeneralLine-1]);//截
if((tempstrE[0]>=0x1800)&&(tempstrE[0]<=0x1900))
forward=ForwardM(forwardstr);
else
forward=Forward(forwardstr);//数
CString tempstr2=forwardstr.Right(forward);//砍
long forwardwid=GetStrWid(tempstr2);//计宽
forwardwid+=dc.GetTextExtent(tempstrE,1).cx;
if(forwardwid<((m_bottom-m_top)-26))
{
int num=curGeneral.ColumnCount[tempCaret.GeneralLine-1]-
tempstr2.GetLength();
curGeneral.ColumnCount[tempCaret.GeneralLine-1]-=forward;
//**************8
CString tempstr3=forwardstr.Left(num);
// MessageBox(tempstr2);
curGeneral.ColumnPosit[tempCaret.GeneralLine-1]=
GetStrWid(tempstr3);
//**************8
//curGeneral.ColumnPosit[tempCaret.GeneralLine-1]-=
//GetStrWid(tempstr2);
curGeneral.ColumnCount[tempCaret.GeneralLine]+=forward;
curGeneral.ColumnPosit[tempCaret.GeneralLine]=GetStrWid(tempstr2);
COLORREF col=dc.GetBkColor();
POINT p1,p2;
p1.x=tempCaret.CaretPos.x-m_fontHeight;
p1.y=curGeneral.ColumnPosit[tempCaret.GeneralLine-1];
p2.x=tempCaret.CaretPos.x-m_fontHeight;
p2.y=m_bottom;
BackColor(p1,p2,col);
while(forward)
{
//刷
CString tempstr21;
tempstr21=tempstr2.Left(1);
dc.TextOut(tempCaret.CaretPos.x+m_fontHeight,tempCaret.
CaretPos.y,tempstr21);
tempCaret.CaretPos.y+=dc.GetTextExtent
(tempstr21,tempstr21.GetLength()).cx;
tempCaret.CharCount+=1;
forward--;
tempstr2=tempstr2.Right(forward);
}
}
dc.TextOut(tempCaret.CaretPos.x+m_fontHeight,tempCaret.CaretPos.y,tempstrE);
curGeneral.ColumnCount[tempCaret.GeneralLine]+=1;
// TestInt(curGeneral.ColumnCount[tempCaret.GeneralLine],"huan");
tempCaret.CaretPos.y+=dc.GetTextExtent
(tempstrE,tempstrE.GetLength()).cx;
curGeneral.ColumnPosit[tempCaret.GeneralLine]=tempCaret.CaretPos.y;
dc.GetTextExtent(tempstrE,tempstrE.GetLength()).cx;
tempCaret.CharCount+=1;
//tempCaret.GeneralBufPos+=1;
}//if
//88888888888888888888888888888888888
/* if((tempstrE[0]>=0x1800)&&(tempstrE[0]<=0x1900))//是字母
{
int forward=0;
CString forwardstr=m_bufferStr.Mid(tempCaret.GeneralBufPos-1-
curGeneral.ColumnCount[tempCaret.GeneralLine-1],
curGeneral.ColumnCount[tempCaret.GeneralLine-1]);//截
forward=ForwardM(forwardstr);//数
CString tempstr2=forwardstr.Right(forward);//砍
long forwardwid=GetStrWid(tempstr2);//计宽
forwardwid+=dc.GetTextExtent(tempstrE,1).cx;
if(forwardwid<((m_bottom-m_top)-26))
{
int num=curGeneral.ColumnCount[tempCaret.GeneralLine-1]-
tempstr2.GetLength();
curGeneral.ColumnCount[tempCaret.GeneralLine-1]-=forward;
//**************8
CString tempstr3=forwardstr.Left(num);
// MessageBox(tempstr2);
curGeneral.ColumnPosit[tempCaret.GeneralLine-1]=
GetStrWid(tempstr3);
//**************8
//curGeneral.ColumnPosit[tempCaret.GeneralLine-1]-=
//GetStrWid(tempstr2);
curGeneral.ColumnCount[tempCaret.GeneralLine]+=forward;
curGeneral.ColumnPosit[tempCaret.GeneralLine]=GetStrWid(tempstr2);
COLORREF col=dc.GetBkColor();
POINT p1,p2;
p1.x=tempCaret.CaretPos.x-m_fontHeight;
p1.y=curGeneral.ColumnPosit[tempCaret.GeneralLine-1];
p2.x=tempCaret.CaretPos.x-m_fontHeight;
p2.y=m_bottom;
BackColor(p1,p2,col);
while(forward)
{
//刷
CString tempstr21;
tempstr21=tempstr2.Left(1);
dc.TextOut(tempCaret.CaretPos.x+m_fontHeight,tempCaret.
CaretPos.y,tempstr21);
tempCaret.CaretPos.y+=dc.GetTextExtent
(tempstr21,tempstr21.GetLength()).cx;
tempCaret.CharCount+=1;
forward--;
tempstr2=tempstr2.Right(forward);
}
}
dc.TextOut(tempCaret.CaretPos.x+m_fontHeight,tempCaret.CaretPos.y,tempstrE);
curGeneral.ColumnCount[tempCaret.GeneralLine]+=1;
// TestInt(curGeneral.ColumnCount[tempCaret.GeneralLine],"huan");
tempCaret.CaretPos.y+=dc.GetTextExtent
(tempstrE,tempstrE.GetLength()).cx;
curGeneral.ColumnPosit[tempCaret.GeneralLine]=tempCaret.CaretPos.y;
dc.GetTextExtent(tempstrE,tempstrE.GetLength()).cx;
tempCaret.CharCount+=1;
//tempCaret.GeneralBufPos+=1;
}//if*/
else//空格
{
dc.TextOut(tempCaret.CaretPos.x+m_fontHeight,tempCaret.CaretPos.y,
tempstrE);
tempCaret.CaretPos.y+=dc.GetTextExtent(tempstrE,1).cx;
tempCaret.CharCount+=1;
//tempCaret.GeneralBufPos+=1;
curGeneral.ColumnCount[tempCaret.GeneralLine]+=1;
curGeneral.ColumnPosit[tempCaret.GeneralLine]=tempCaret.CaretPos.y;
}
}
}//end else3shihuanhang
else//hanzi
{
int length=Sub.GetLength();
Font(0,_T("Times New Roman"));
pOldFont=dc.SelectObject(&MyFont);
while(length)
{
//MessageBox(Sub);
tempstrH=Sub.Left(1);
if((tempCaret.CaretPos.y+dc.GetTextExtent(tempstrH,1).cy)<((m_bottom-m_top)-26))
{
dc.TextOut(tempCaret.CaretPos.x,tempCaret.CaretPos.y,
tempstrH);
tempCaret.CaretPos.y+=dc.GetTextExtent(tempstrH,1).cy;
tempCaret.CharCount+=1;
curGeneral.ColumnCount[tempCaret.GeneralLine]+=1;
curGeneral.ColumnPosit[tempCaret.GeneralLine]=tempCaret.CaretPos.y;
tempCaret.GeneralBufPos+=1;
}
else
{
tempCaret.CaretPos.x+=m_fontHeight;
tempCaret.CaretPos.y=0;
tempCaret.SCreenLine++;
if(tempCaret.SCreenLine>maxscreenline)
{
tempCaret.SCreenLine=maxscreenline;
SFLisGL++;
Move(SFLisGL);
tempCaret.CaretPos.x-=m_fontHeight;
}
tempCaret.GeneralLine++;
tempCaret.GeneralBufPos+=1;
dc.TextOut(tempCaret.CaretPos.x,tempCaret.CaretPos.y,
tempstrH);
tempCaret.CaretPos.y+=dc.GetTextExtent(tempstrH,1).cy;
tempCaret.CharCount=1;
curGeneral.ColumnCount[tempCaret.GeneralLine]+=1;
curGeneral.ColumnPosit[tempCaret.GeneralLine]=tempCaret.CaretPos.y;
}
length--;
Sub=Sub.Right(length);
}//while
Font(2700,_T("Times New Roman"));
pOldFont=dc.SelectObject(&MyFont);
}//hanzi
}//huiche
// }
curCaret.CaretPos.x=tempCaret.CaretPos.x;
curCaret.CaretPos.y=tempCaret.CaretPos.y;
curCaret.CharCount=tempCaret.CharCount;
curCaret.GeneralBufPos=tempCaret.GeneralBufPos;
curCaret.GeneralLine=tempCaret.GeneralLine;
curCaret.SCreenLine=tempCaret.SCreenLine;
}
void CMWEditCtrl::OnPaint()
{
CPaintDC dc(this); // devce context for painting
long cc=curCaret.GeneralBufPos;
allflag=0;
// dc.GetFontUnicodeRanges(NULL);
if(WindowChangFlag)
{
HideCaret();
for(int i=0;i<100;i++)
{
curGeneral.ColumnCount[i]=curGeneral.ColumnPosit[i]=0;
}
CRect BrushWin;
BrushWin.left=m_left;
BrushWin.right=m_right;
BrushWin.top=m_top;
BrushWin.bottom=m_bottom;
dc.FillRect(BrushWin, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
if(!m_bufferStr.IsEmpty())
SubRePaint(zero,m_bufferStr);
GetCharPosFromCount(cc);
curCaret=GetCharPositFromCount;
WindowChangFlag=0;
SFLisGL=1;
if(curCaret.GeneralLine<=maxscreenline)
{
curCaret.SCreenLine=curCaret.GeneralLine;
curCaret.CaretPos.x=(curCaret.SCreenLine-1)*m_fontHeight;
CreateSolidCaret(m_fontHeight-2,1);
SetCaretPos(curCaret.CaretPos);
ShowCaret();
}
}
else
{
if(!SubStr.IsEmpty())
{
if((m_bufferStr.GetLength()==curCaret.GeneralBufPos))//&&(!SubStr.Compare(m_bufferStr)))//正常输入
{
// curCaretCopy=curCaret;
// MessageBox(_T("dsffdds"));
mytextout(curCaret,SubStr);
// m_bufferStrCopy=m_bufferStr.Left(m_bufferStr.GetLength());
m_bufferStr+=SubStr;
}
else
{
if(Insert)//Insert)//插入
{
// curCaretCopy=curCaret;
// m_bufferStrCopy=m_bufferStr.Left(m_bufferStr.GetLength());
m_bufferStr.Insert(curCaret.GeneralBufPos,SubStr);
CString rightstr=m_bufferStr.Right(m_bufferStr.GetLength()-curCaret.GeneralBufPos);
bool all=Judge2(curCaret);
storeCaret=GetCharPositFromCount;
if(all)
{
COLORREF col=dc.GetBkColor();
POINT p1,p2;
p1.x=storeCaret.CaretPos.x;
p1.y=storeCaret.CaretPos.y;
p2.x=m_right;
p2.y=m_bottom;
BackColor(p1,p2,col);
for(int i=storeCaret.GeneralLine;i<100;i++)
{
curGeneral.ColumnCount[i]=0;
curGeneral.ColumnPosit[i]=0;
}
int Fir2=0;
for(i=1;i<storeCaret.GeneralLine;i++)
Fir2+=curGeneral.ColumnCount[i];
CString str2=m_bufferStr.Mid(Fir2,storeCaret.CharCount);
curGeneral.ColumnCount[storeCaret.GeneralLine]=storeCaret.CharCount;
curGeneral.ColumnPosit[storeCaret.GeneralLine]=GetStrWid(str2);
SubRePaint(storeCaret,storeStr);
}//if all
else
{
COLORREF col=dc.GetBkColor();
POINT p1,p2;
p1.x=storeCaret.CaretPos.x;
p1.y=storeCaret.CaretPos.y;
p2.x=(allLine-1)*m_fontHeight;
p2.y=m_bottom;
BackColor(p1,p2,col);
for(int i=storeCaret.GeneralLine;i<allLine;i++)
{
curGeneral.ColumnCount[i]=0;
curGeneral.ColumnPosit[i]=0;
}
int Fir2=0;
for(i=1;i<storeCaret.GeneralLine;i++)
Fir2+=curGeneral.ColumnCount[i];
CString str2=m_bufferStr.Mid(Fir2,storeCaret.CharCount);
curGeneral.ColumnCount[storeCaret.GeneralLine]=storeCaret.CharCount;
curGeneral.ColumnPosit[storeCaret.GeneralLine]=GetStrWid(str2);
int Fir3=0;
for(i=(allLine+1);i<100;i++)
Fir3+=curGeneral.ColumnCount[i];
CString storeStr2=storeStr.Left(storeStr.GetLength()-Fir3);
SubRePaint(storeCaret,storeStr2);
}//部分刷新
curCaret.GeneralBufPos+=SubStr.GetLength();
GetCharPosFromCount(curCaret.GeneralBufPos);
curCaret=GetCharPositFromCount;
if(curCaret.SCreenLine>maxscreenline)
{
curCaret.SCreenLine=maxscreenline;
SFLisGL=curCaret.GeneralLine-curCaret.SCreenLine+1;
Move(SFLisGL);
curCaret.CaretPos.x=(maxscreenline-1)*m_fontHeight;
}
else
{
if(SFLisGL>1)
{
Move(SFLisGL);
curCaret.SCreenLine=curCaret.GeneralLine-SFLisGL+1;
curCaret.CaretPos.x=(curCaret.SCreenLine-1)*m_fontHeight;
}
}
}//插入
else//改写
{
CString s1=SubStr.Left(1);
CString Enter1=Enter.Left(1);
bool change=false;
if(SubStr[0]==0x0d)//是回车
{
curCaret.CaretPos.y=0;
curCaret.CaretPos.x+=m_fontHeight;
curCaret.CharCount=0;
curCaret.GeneralLine++;
curCaret.SCreenLine++;
if(curCaret.GeneralLine>SFLisGL+maxscreenline-1)
{
curCaret.CaretPos.x=(maxscreenline-1)*m_fontHeight;
curCaret.SCreenLine=maxscreenline;
SFLisGL=curCaret.GeneralLine-curCaret.SCreenLine+1;
Move(SFLisGL);
}
long count=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -