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

📄 medit.cpp

📁 飞虹 vision仿windows开发
💻 CPP
字号:
#include"\sunshine\include\medit.h"
#include"\sunshine\include\app.h"
#include"\sunshine\include\define.h"
#include<string.h>
#include<bios.h>
#define CURCOUNT 30
MEdit::MEdit(int x1,int y1,int num,EDITTYPE edittype,char *defedit,char *idname)
 : MObj(x1,y1,(num+1)*textwidth("A")+3,22,idname)
 {
  number=num;
  type=edittype;
  editbuffer=new char[num+1]; //the last is NULL
  strcpy(editbuffer,defedit);
  firstrun=1;
  curcount=0;
  cx=x()+Length(editbuffer)+3;idex=strlen(editbuffer);
  curflag=0;
  TransMes(NOEDIT);
 }
MEdit::~MEdit()
 {
  delete editbuffer;
 }
void MEdit::UnFocus()
 {
  Mouse am(1);
  setcolor(BLACK);
  rectangle(x(),y(),x()+w()-1,y()+h()-1);
  setfillstyle(SOLID_FILL,WHITE);
  bar(x()+1,y()+1,x()+w()-2,y()+h()-2);
  Write(editbuffer,x()+3,y(),BLACK);
 }
void MEdit::GetFocus()
 {
  int c;
  int i;
  char c1[2];
  int mf=0;
  Mouse am;
  c1[1]='\0';
  if(!bioskey(1)){ //Cursor blinks while No Message received
	 if(curcount++<=CURCOUNT) {return;}
	 curcount=0;
	 if(curflag) curflag=0;
	 else curflag=1;
	 ShowCursor();
	 return;
  }

  if(!curflag) {ShowCursor();curflag=1;}

  switch(c=bioskey(0)){
	case LA: ShowCursor();
				idex--;
				if(idex>=0){c1[0]=editbuffer[idex],
								cx=cx-Length(c1);}
				idex=(idex<0?0:idex);
				ShowCursor();
				return;
	case RA: ShowCursor();
				idex++;
				if(idex<=strlen(editbuffer)){c1[0]=editbuffer[idex-1];
					 cx=cx+Length(c1);}
				idex=(idex>strlen(editbuffer)?strlen(editbuffer):idex);
				ShowCursor();
				return;
	case HOME:
				ShowCursor();
				idex=0;
				cx=x()+3;
				ShowCursor();
				return;
	case END:
				ShowCursor();
				idex=strlen(editbuffer);
				cx=x()+3+Length(editbuffer);
				ShowCursor();
				return;
	case BS:
				if(idex==0){if(mf) am.MouseOn();return;}
				c1[0]=editbuffer[idex-1];
				for(i=idex;i<=strlen(editbuffer);i++)
					editbuffer[i-1]=editbuffer[i];
				ShowCursor();
				idex--;
				cx=cx-Length(c1);
				setfillstyle(SOLID_FILL,WHITE);
				bar(x()+1,y()+1,x()+w()-2,y()+h()-2);
				Write(editbuffer,x()+3,y(),BLACK);
				ShowCursor();
				return;
	case RETURN:
				TransMes(NOEDIT);
				return;
  }

  if(!Condition(c)) return ;
  if((strlen(editbuffer))==number) return;
  for(i=strlen(editbuffer);i>=idex;i--)
	editbuffer[i+1]=editbuffer[i];

  editbuffer[idex]=(char)c;
  ShowCursor();
  setfillstyle(SOLID_FILL,WHITE);
  bar(x()+1,y()+1,x()+w()-2,y()+h()-2);
  if(am.x()>x()&&am.y()>y()&&am.x()<(x()+w()-1)&&am.y()
	  <(x()+w()-1)) {am.MouseOff();mf=1;}
  Write(editbuffer,x()+3,y(),BLACK);
  if(mf) am.MouseOn();
  idex++;
  c1[0]=(char )c;
  cx=cx+Length(c1);
  ShowCursor();
 }
int MEdit::Condition(int c)
 {
  if((char)c==0) return 0;
  return 1;
 }
void MEdit::ShowCursor()
 {
  Mouse am;
  int mf=0;
  if(am.x()>(cx-30)&&am.y()>(y()-30)&&am.x()<(cx+30)&&am.y()<
	  (y()+50)) {am.MouseOff();mf=1;}
  setcolor(WHITE);
  setwritemode(XOR_PUT);
  line(cx,y()+2,cx,y()+18);
  line(cx-1,y()+2,cx-1,y()+18);
  setwritemode(COPY_PUT);
  if(mf){am.MouseOn();}
 }
int MEdit::Process()
 {
  Mouse am;
  if(firstrun){firstrun=0;UnFocus();return 1;}
  if(!am.lp()&&Mes==NOEDIT) return 1;
  if(am.x()>x()&&am.y()>y()&&am.x()<(x()+w()-1)
	  && am.y()<(y()+h()-1) && am.lp() && Mes==NOEDIT)
	{
	 TransMes(EDIT);UnFocus();return 1;
	}
  if((am.x()<x() || am.y()<y() || am.x()>(x()+w()-1) ||
	  am.y()>(y()+h()-1))&& am.lp() && Mes==EDIT)
	{
	 TransMes(NOEDIT);UnFocus();return 1;
	}
  if(Mes==NOEDIT) return 1;
  GetFocus();
  return 1;
 }

⌨️ 快捷键说明

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