📄 mlistite.cpp
字号:
#include"\sunshine\include\mlistite.h"
#include"\sunshine\include\app.h"
#include"\sunshine\include\mapp.h"
#include"\sunshine\include\define.h"
#include<alloc.h>
#include<string.h>
MListItem::MListItem(int x,int y,int h,char *text1,char *idname)
: MObj(x,y,Length(text1)+16,h,idname)
{
text=new char[strlen(text1)+1];
strcpy(text,text1);
tcolor=BLACK;bkcolor=WHITE;
htcolor=WHITE;hbkcolor=BLUE;
flag=0;
mflag=0;
firstrun=1;
if(text[0]=='~') SetAc(0);
else SetAc(1);
}
void MListItem::SetColor(int m1,int m2,int m3,int m4)
{
tcolor=m1;bkcolor=m2;
htcolor=m3;hbkcolor=m4;
}
MListItem::~MListItem()
{
delete text;
}
void MListItem::UnFocus()
{
Mouse am(1);
if(text[0]=='~')
{
setfillstyle(SOLID_FILL,bkcolor);
bar(x(),y(),x()+w()-1,y()+h()-1);
setcolor(BLACK);
line(x(),y()+h()/2,x()+w()-1,y()+h()/2);
return ;
}
setfillstyle(SOLID_FILL,bkcolor);
bar(x(),y(),x()+w()-1,y()+h()-1);
if(IsAc())
Write(text,x()+8,y()+1,tcolor);
else
Write(text,x()+8,y()+1,LIGHTGRAY);
}
void MListItem::GetFocus()
{
Mouse am(1);
setfillstyle(SOLID_FILL,hbkcolor);
bar(x(),y(),x()+w()-1,y()+h()-1);
Write(text,x()+8,y()+1,htcolor);
}
int MListItem::Process()
{
Mouse am;
START_RUN;
if(!IsAc()) return 1;
if(am.x()<x()||am.y()<y()||am.x()>(x()+w()-1)||
am.y()>(y()+h()-1))
{
if(flag){flag=0; UnFocus();}
return 1;
}
if(!flag) {GetFocus();flag=1;}
if(am.lp())
{
mflag=1;
return 1;
}
else
{
if(mflag){mflag=0;return F();}
}
return 1;
}
//MBarMenuitem class information process function
int MBarMenuItem::Process()
{
Mouse am;
START_RUN;
if(am.x()<x()||am.y()<y()||am.x()>(x()+w()-1)||
am.y()>(y()+h()-1))
{
if(flag) {UnFocus();flag=0;}
return 1;
}
if(!flag) {GetFocus();flag=1;return 1;}
if(as) return F();
if(am.lp())
{
while(am.lp()) am.Reset();
if(am.x()<x()||am.y()<y()||am.x()>(x()+w()-1)||
am.y()>(y()+h()-1)) return 1;
return F();
}
return 1;
}
///////////for MKey class ////////////////
//////////////////////////////////////////
MKey::MKey(int x,int y,int w1,int h,char *idname)
: MBarMenuItem(x,y,h,"NOT",idname),MBmp("key.bmp")
{
w(w1);
M=MApp::Application;
}
MKey::MKey(int x,int y,int w1,int h,MWindowObj& awin,char *idname)
: MBarMenuItem(x,y,h,"NOT",idname),MBmp("key.bmp")
{
w(w1);
M=&awin;
}
void MKey::UnFocus()
{
Mouse am(1);
BitBlt(x(),y());
}
void MKey::GetFocus()
{
Mouse am(1);
setcolor(BLACK);
rectangle(x()+1,y()+1,x()+w()-2,y()+h()-2);
rectangle(x()+2,y()+2,x()+w()-3,y()+h()-3);
}
int MKey::F()
{
char *s1="还原(R)";
char *s2="移动";
char *s3="~";
char *s4="关闭 ALT+F4";
char *s5="~";
char *s6="系统设置...";
int sy=y()+h()+1;
int sx=x()+1;
int W=18;
MPopMenu &apop=*new MPopMenu(sx,y()+h(),"PDESK",*M);
MKeyItem *ak;
ak=new MKeyItem(sx+1,sy,W,s1);
if(!strcmp(M->Nameof(),"mapp")||!strcmp(M->Nameof(),"mdialog"))
ak->SetAc(0);
apop.Add(*ak);
ak=new MKeyItem(sx+1,sy=sy+W,W,s2);
if(!strcmp(M->Nameof(),"mapp")||!strcmp(M->Nameof(),"mdialog"))
ak->SetAc(0);
apop.Add(*ak);
apop.Add(*new MKeyItem(sx+1,sy=sy+W,W,s3));
apop.Add(*new MKeyItem(sx+1,sy=sy+W,W,s4));
apop.Add(*new MKeyItem(sx+1,sy=sy+W,W,s5));
ak=new MKeyItem(sx+1,sy=sy+W,W,s6);
if(!strcmp(M->Nameof(),"mdialog")||!strcmp(M->Nameof(),"mwindow"))
ak->SetAc(0);
apop.Add(*ak);
M->Add(apop);
return 1;
}
int MKeyItem::F3()
{
return CLOSE;
}
int MKeyItem::F()
{
if(!strcmp(GetName(),"还原(R)")) return F1();
if(!strcmp(GetName(),"移动")) return F2();
if(!strcmp(GetName(),"关闭 ALT+F4")) return F3();
if(!strcmp(GetName(),"系统设置...")) return F4();
return 1;
}
/////////for popmenu function///////////
/////////mainly used in main menu//////
///////////////////////////////////////
MPopMenu::MPopMenu(int x1,int y1,char *idname)
: MWindowObj(x1,y1,0,0,idname)
{
H=0;W=0;
firstrun=1;
M=MApp::Application;
}
MPopMenu::MPopMenu(int x1,int y1,char *idname,MWindowObj &awin)
: MWindowObj(x1,y1,0,0,idname)
{
H=0;W=0;
firstrun=1;
M=&awin;
}
MPopMenu::~MPopMenu()
{
Restore();
}
void MPopMenu::Add(MListItem &alist)
{
W=(W>alist.w()?W:alist.w());
H=H+alist.h();
h(H+2);
w(W+2);
MWindowObj::Add(alist);
}
void MPopMenu::SetW()
{
int num=GetNumber();
for(int i=0;i<num;i++)
GetObj(i).w(W);
}
void MPopMenu::UnFocus()
{
char fs[8]={0x55,0xaa,0x55,0xaa,
0x55,0xaa,0x55,0xaa};
Mouse am(1);
setcolor(BLACK);
rectangle(x(),y(),x()+w()-1,y()+h()-1);
setfillpattern(fs,DARKGRAY);
bar(x()+w(),y()+4,x()+w()-1+8,y()+h()-1+8);
bar(x()+4,y()+h(),x()+w()-1,y()+h()-1+8);
}
void MPopMenu::GetFocus()
{ } //usually do nothing
STATE MPopMenu::Save()
{
Mouse am(1);
rscreen=farmalloc(imagesize(x(),y(),x()+w()-1+8,y()+h()-1+8));
if(!rscreen) return FAIL;
getimage(x(),y(),x()+w()-1+8,y()+h()-1+8,rscreen);
return SUCC;
}
void MPopMenu::Restore()
{
Mouse am(1);
putimage(x(),y(),rscreen,COPY_PUT);
if(!rscreen) farfree(rscreen);
}
int MPopMenu::Process()
{
int i=0;
int value;
if(firstrun)
{
firstrun=0;Save();SetW();
UnFocus();
}
while(1)
{
Mouse am;
if(am.x()<x()||am.y()<y()||am.x()>(x()+w()-1)||
am.y()>(y()+h()-1))
{
if(am.lp())
if(!strcmp(M->Nameof(),"mdialog")||
!strcmp(M->Nameof(),"mwindow")) return DIALOG_DEL;
else return DEL;
}
value=GetObj(i).Process();
switch(value)
{
case DEL: return DEL; //for main menu
case CLOSE:
M->TransMes(CLOSE);
if(!strcmp(M->Nameof(),"mapp"))
return DEL;
else
return DIALOG_DEL;
}
i++;if(i>=GetNumber()) i=0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -