📄 yyxwin.cpp
字号:
// if (pwin_handled->type == DIALOG_WIN ) return 0;
setport(win_living_viewport);
if (pcurrent_selected_win == this ) {
draw_win_frame_rect_and_others( bounds,
title,WIN_TITLEBAR_SELECTED_COLOR,
WIN_TITLE_SELECTED_COLOR );
} else {
draw_win_frame_rect_and_others( bounds,
title,WIN_TITLEBAR_UNSELECTED_COLOR,
WIN_TITLE_UNSELECTED_COLOR );
}
}
void win_class::draw_win_control ()
{ struct Rect bound_rect;
Tcontrol *ptemp_control;
int i;
setport(viewport);
// SetRect (&bound_rect,1,1,viewport.right-viewport.left-LINE_WIDTH-1,
// viewport.bottom-viewport.top-bar_height-LINE_WIDTH-1);
SetRect (&bound_rect,1,1,viewport.right-viewport.left-1,
viewport.bottom-viewport.top-bar_height-1);
FillRect (bound_rect,WHITE);
win_group_control ->draw ();
}
int win_class::draw_win_contents ()
{
getviewsettings (¤t_viewport );
setport(viewport);
return 0;
setport (current_viewport );
}
win_class::win_class
(int ID,char *title,byte type,byte hotkey,
int left,int top,int width,int height
) :object_class (ID,title,NORMAL, type ,left,top,width,height )
{ Twin /* *ptemp_win, */ *temp1;
canclose =TRUE;
// this->title =title;
this->hotkey =hotkey;
this->visible =VISIBLE ;
// insert_control later !! OK !!
this->punder_bitmap =NULL;
this->pself_bitmap =NULL;
this->viewport.clip =CLIP_ON ;
this->win_group_control =new Tgroup(0,"",viewport.left,viewport.top,
viewport.right-viewport.left,viewport.bottom-viewport.top);
//======================================================================
this->pnext_win=NULL;
this->pfirst_above =NULL;
this->pfirst_under =NULL;
this->pother_info = NULL ;
/* now draw win frames & build needed links */
// open_one_win (this ); used in the call func
setup_window();
}
win_class::~win_class ()
{
delete (win_group_control);
close_one_win ();
if (pcurrent_selected_win!=NULL ) setport (pcurrent_selected_win->viewport);
thequeue.SendMessage(ID,WinSysClosedMSG,this);
}
void win_class::draw_size_rect()
{
// disable();
getviewsettings (¤t_viewport );
setwritemode (XOR_PUT);
setcolor (GREEN);
setport (win_living_viewport);
setlinestyle ( DASHED_LINE,1,THICK_WIDTH );
FrameRect(newbounds);
/*
#ifdef rectangle //(left,top,right,bottom)
#undef rectangle
// FrameRect(newbounds);
mouse_off;
disable();
rectangle(newbounds.left,newbounds.top,newbounds.right,newbounds.bottom);
mouse_on;
#define rectangle(left,top,right,bottom) mouse_off;rectangle((left),(top),(right),(bottom));mouse_on
#endif
disable();
*/ setlinestyle ( SOLID_LINE,1,NORM_WIDTH );
setwritemode (COPY_PUT);
setport (current_viewport );
// enable();
}
int win_class::move_size_window (int key_scan_num )
{
draw_size_rect();
switch (key_scan_num ) {
// move
case LEFTKEY :
if (newbounds.left > 0) {newbounds.left--;newbounds.right--;}
break;
case RIGHTKEY :
if (newbounds.right< win_living_viewport.right-win_living_viewport.left){newbounds.left++;newbounds.right++;}
break;
case UPKEY :
if (newbounds.top > 0) {newbounds.top--;newbounds.bottom--;}
break;
case DOWNKEY :
if (newbounds.bottom < win_living_viewport.bottom-win_living_viewport.top) {newbounds.top++;newbounds.bottom++;}
break;
// size
case SHIFT_LEFT :
if (newbounds.right>newbounds.left +100) {newbounds.right--;}//min_width
break;
case SHIFT_RIGHT:
if (newbounds.right< win_living_viewport.right-win_living_viewport.left){newbounds.right++;}
break;
case SHIFT_UP :
if (newbounds.bottom>newbounds.top +100) {newbounds.bottom--;}
break;
case SHIFT_DOWN :
if (newbounds.bottom < win_living_viewport.bottom-win_living_viewport.top) {newbounds.bottom++;}
break;
// move
case HOMEKEY :
if (newbounds.left > 10) {newbounds.left -=10;newbounds.right-=10;}
if (newbounds.top > 10) {newbounds.top-=10;newbounds.bottom-=10;}
break;
case PGUPKEY :
if (newbounds.right< win_living_viewport.right-win_living_viewport.left-10){newbounds.left+=10;newbounds.right+=10;}
if (newbounds.top > 10) {newbounds.top-=10;newbounds.bottom-=10;}
break;
case ENDKEY :
if (newbounds.left > 10) {newbounds.left -=10;newbounds.right-=10;}
if (newbounds.bottom < win_living_viewport.bottom-win_living_viewport.top-10) {newbounds.top+=10;newbounds.bottom+=10;}
break;
case PGDNKEY :
if (newbounds.right< win_living_viewport.right-win_living_viewport.left-10){newbounds.left+=10;newbounds.right+=10;}
if (newbounds.bottom < win_living_viewport.bottom-win_living_viewport.top-10) {newbounds.top+=10;newbounds.bottom+=10;}
break;
// size
case SHIFT_HOME :
if (newbounds.right>newbounds.left +100 +10) {newbounds.right-=10;}//min_width
if (newbounds.bottom>newbounds.top +100 +10) {newbounds.bottom-=10;}
break;
case SHIFT_PGUP:
if (newbounds.right< win_living_viewport.right-win_living_viewport.left-10){newbounds.right+=10;}
if (newbounds.bottom>newbounds.top +100 +10) {newbounds.bottom-=10;}
break;
case SHIFT_END:
if (newbounds.right>newbounds.left +100 +10) {newbounds.right-=10;}//min_width
if (newbounds.bottom < win_living_viewport.bottom-win_living_viewport.top-10) {newbounds.bottom+=10;}
break;
case SHIFT_PGDN:
if (newbounds.right< win_living_viewport.right-win_living_viewport.left-10){newbounds.right+=10;}
if (newbounds.bottom < win_living_viewport.bottom-win_living_viewport.top-10) {newbounds.bottom+=10;}
break;
case ENTERKEY:
thequeue.SendMessage(pcurrent_selected_win->ID
,WinMovedSizedMSG,pcurrent_selected_win );
draw_size_rect();
in_win_moving =FALSE;
return TRUE;
case ESCKEY:
in_win_moving =FALSE;
getviewsettings (¤t_viewport );
setport (menu_viewport);
FillRect ( on_line_help_rect,HELP_RECT_COLOR );
setcolor (HELP_TEXT_COLOR);
outtextxy( on_line_help_rect.left+10,on_line_help_rect.top,pcurrent_menu->help);
setport (current_viewport );
return TRUE;
};
draw_size_rect();
return TRUE;
}
Twin* win_class::pnext=NULL;
int win_class::key_pressed_handler ( int key_scan_num )
{ Twin *ptemp_win;
// pnext ! // used as CTRL_F6's link procedure
if (pfirst_win_of_all == NULL ) return FALSE;
if (pcurrent_selected_win->visible == IN_VISIBLE ) return FALSE;
if (in_win_moving) {
move_size_window(key_scan_num);
return TRUE;
}
if (!(pcurrent_selected_win->type & DIALOG_WIN )) //not dialog
switch (key_scan_num ) {
case CTRL_F4 :
thequeue.SendMessage(pcurrent_selected_win->ID
,WinSysCloseMSG,pcurrent_selected_win );
pnext=NULL;
return TRUE;
case CTRL_F6 :
if (pnext==NULL ) pnext =pfirst_win_of_all;
if ( (pnext != NULL)&& (pnext !=pcurrent_selected_win)){
pnext->select ();
pnext =pnext->pnext_win;
return TRUE;
}
return FALSE;
case CTRL_F5 :
newbounds=bounds;
in_win_moving =TRUE;
getviewsettings (¤t_viewport );
setport (menu_viewport);
FillRect ( on_line_help_rect,HELP_RECT_COLOR );
setcolor (HELP_TEXT_COLOR);
outtextxy( on_line_help_rect.left+10,on_line_help_rect.top,"MOVING WIN");
setport (current_viewport );
draw_size_rect();
old_mouse_x=mouse_x;
old_mouse_y=mouse_y;
return TRUE;
};
if (pcurrent_selected_win->win_group_control != NULL)
return pcurrent_selected_win->win_group_control->key_pressed_handler
(key_scan_num );
else return FALSE;
}
int win_class::msg_handler ( MSG& message )
{ int x,y;
int ret_val;
switch (message.Action){
case KeyPressedMSG:
return key_pressed_handler( key_code );
case WinOpenedMSG:
return TRUE;
case WinSelectedMSG:
// if ((win_sysmenu != NULL ) && ( ((Twin*)message.fptr)->visible !=INVISIBLE ) ) {
if ((win_sysmenu != NULL ) && ( ((Twin*)message.fptr)->visible !=2 ) ) {
// x=((Twin*)message.fptr)->bounds.left+win_living_viewport.left-menu_viewport.left+LINE_WIDTH;
// y=((Twin*)message.fptr)->bounds.top+win_living_viewport.top -menu_viewport.top+LINE_WIDTH;
x=((Twin*)message.fptr)->bounds.left+win_living_viewport.left-menu_viewport.left+LINE_WIDTH-win_sysmenu->bounds.left+1;
y=((Twin*)message.fptr)->bounds.top+win_living_viewport.top -menu_viewport.top+LINE_WIDTH-win_sysmenu->bounds.top+1;
win_sysmenu->offsetmenu(x,y);
win_sysmenu->status =NORMAL;
}
return TRUE;
/* case WinMovingSizingMSG: //for speed
pcurrent_selected_win-> draw_size_rect();
OffsetRect (&pcurrent_selected_win->newbounds,
mouse_x-old_mouse_x,mouse_y-old_mouse_y );
if (pcurrent_selected_win->newbounds.right>
win_living_viewport.right-win_living_viewport.left-1)
pcurrent_selected_win->newbounds.right
=win_living_viewport.right-win_living_viewport.left-1;
if (pcurrent_selected_win->newbounds.bottom>
win_living_viewport.bottom-win_living_viewport.top-1)
pcurrent_selected_win->newbounds.bottom
=win_living_viewport.bottom-win_living_viewport.top-1;
if (pcurrent_selected_win->newbounds.left<1)
pcurrent_selected_win->newbounds.left=1;
if (pcurrent_selected_win->newbounds.top<1)
pcurrent_selected_win->newbounds.top=1;
old_mouse_x=mouse_x;
old_mouse_y=mouse_y;
pcurrent_selected_win-> draw_size_rect();
return TRUE;
*/
case WinMovedSizedMSG:
in_win_moving =FALSE;
pcurrent_selected_win-> draw_size_rect();
getviewsettings (¤t_viewport );
setport (menu_viewport);
FillRect ( on_line_help_rect,HELP_RECT_COLOR );
setcolor (HELP_TEXT_COLOR);
outtextxy( on_line_help_rect.left+10,on_line_help_rect.top,pcurrent_menu->help);
setport (current_viewport );
case WinRedrawboundsMSG:
((Twin*)message.fptr)->close_one_win();
bounds=newbounds;
((Twin*)message.fptr)->setup_window();
((Twin*)message.fptr)->open_one_win ();
printf ("\007");
return TRUE;
/* case WinSysCloseMSG:
if (! (canclose|| ( func_canclose()) )) return FALSE;
x=((Twin*)message.fptr)->bounds.left+win_living_viewport.left-menu_viewport.left+LINE_WIDTH;
y=((Twin*)message.fptr)->bounds.top+win_living_viewport.top -menu_viewport.top+LINE_WIDTH;
win_sysmenu->offsetmenu(-x,-y);
win_sysmenu->menu_status |=INVISIBLE;
delete ((Twin*)message.fptr );
return TRUE ;
*/// case ControlSelectedMSG: --->ListBoxControlSelectedMSG
// return TRUE; //NOW IT IN APPLICATION
case MouseLButtonDownMSG:
// int win_mouse_x,win_mouse_y;
sysmouse->get_posn();
win_mouse_x=mouse_x; win_mouse_y=mouse_y;
if (!Global2LocalPort(win_mouse_x,win_mouse_y,win_living_viewport)) return FALSE;
if (!(pcurrent_selected_win->type & DIALOG_WIN )) { //not dialog
if (!Global2Local(win_mouse_x,win_mouse_y,bounds)) {
// see if in other windows's bounds;
if (pfirst_win_of_all == NULL) return FALSE;
Twin *ptmp;
ptmp =pfirst_win_of_all;
while ((ptmp!=NULL) && !(PtInRect(win_mouse_x,win_mouse_y,ptmp->bounds)) ) ptmp=ptmp->pnext_win;
if (ptmp==NULL) return FALSE;
ptmp->select();
return TRUE;
} else { // in title_box;
if((PtInRect(win_mouse_x,win_mouse_y,title_box)) ||
(PtInRect(win_mouse_x,win_mouse_y,size_box))
) {
//MOVE win//MOVE win//MOVE win//MOVE win//MOVE win//MOVE win//MOVE win//MOVE win
newbounds=bounds;
if (PtInRect(win_mouse_x,win_mouse_y,size_box))
in_win_moving =SIZING;
else in_win_moving =TRUE;
getviewsettings (¤t_viewport );
setport (menu_viewport);
FillRect ( on_line_help_rect,HELP_RECT_COLOR );
setcolor (HELP_TEXT_COLOR);
outtextxy( on_line_help_rect.left+10,on_line_help_rect.top,"MOVING WIN");
setport (current_viewport );
draw_size_rect();
sysmouse->get_release_count(LEFT_BUTTON);
old_mouse_x=mouse_x;
old_mouse_y=mouse_y;
return TRUE;
//MOVE win//MOVE win//MOVE win//MOVE win//MOVE win//MOVE win//MOVE win//MOVE win
return TRUE;
} else
if (PtInRect(win_mouse_x,win_mouse_y,close_box)) {
thequeue.SendMessage(pcurrent_selected_win->ID
,WinSysCloseMSG,pcurrent_selected_win );
pnext=NULL;
return TRUE;
} else
if (PtInRect(win_mouse_x,win_mouse_y,zoom_out_box)) {
SetRect (&newbounds,
10,10,
win_living_viewport.right-win_living_viewport.left-10,
win_living_viewport.bottom-win_living_viewport.top-10);
thequeue.SendMessage(this->ID
,WinRedrawboundsMSG, this );
oldbounds=bounds;
return TRUE;
} else
if (PtInRect(win_mouse_x,win_mouse_y,zoom_in_box)) {
newbounds=oldbounds;
thequeue.SendMessage(this->ID
,WinRedrawboundsMSG, this );
return TRUE;
}
} //in this && other bounds
} else { //is a dialog
win_mouse_x=mouse_x; win_mouse_y=mouse_y;
if (!Global2LocalPort(win_mouse_x,win_mouse_y,viewport)) {
putch('\007');
return FALSE;
} else break;
}
return FALSE; // unreachable
// default:; //; // return FALSE;
}
if (win_group_control != NULL) //Always true
return win_group_control ->msg_handler(message);
}
BOOL win_class::func_canclose ()
{
return TRUE;
}
void win_class::insert_control (Tcontrol *pcontrol_handled)
{
win_group_control ->insert_control (pcontrol_handled);
}
void win_class::setup_window ()
{
if (bounds.right>win_living_viewport.right-win_living_viewport.left-2)
bounds.right=win_living_viewport.right-win_living_viewport.left-2;
if (bounds.bottom>win_living_viewport.bottom-win_living_viewport.top-2)
bounds.bottom=win_living_viewport.bottom-win_living_viewport.top-2;
if (bounds.left<2)bounds.left=2;
if (bounds.top<2) bounds.top=2;
if (bounds.right <=bounds.left ) bounds.right =bounds.left +1;
if (bounds.bottom<=bounds.top ) bounds.right =bounds.top +1;
viewport.left =bounds.left+win_living_viewport.left+LINE_WIDTH;
viewport.top =bounds.top +win_living_viewport.top +bar_height+LINE_WIDTH;
viewport.right =bounds.right-bounds.left+viewport.left-2*LINE_WIDTH;
viewport.bottom =bounds.bottom-bounds.top+viewport.top-2*LINE_WIDTH;
SetRect (&title_box,LINE_WIDTH+bar_height,LINE_WIDTH,
bounds.right-bounds.left-2*LINE_WIDTH-2*bar_height,LINE_WIDTH+bar_height);
SetRect (&close_box,LINE_WIDTH,LINE_WIDTH,
LINE_WIDTH+bar_height,LINE_WIDTH+bar_height);
//zoom_out_box;
SetRect (&zoom_out_box,bounds.right-bounds.left-2*LINE_WIDTH-2*bar_height,
LINE_WIDTH,
bounds.right-bounds.left- 2*LINE_WIDTH- bar_height,
LINE_WIDTH+bar_height);
//zoom_in_box
SetRect (&zoom_in_box,bounds.right-bounds.left-2*LINE_WIDTH-bar_height,
LINE_WIDTH,
bounds.right-bounds.left- 2*LINE_WIDTH,
LINE_WIDTH+bar_height);
SetRect (&size_box,bounds.right-bounds.left-2*LINE_WIDTH,
bounds.bottom-bounds.top-2*LINE_WIDTH,
bounds.right-bounds.left ,
bounds.bottom-bounds.top );
if (pcurrent_selected_win !=NULL)
SetRect (&oldbounds,
pcurrent_selected_win->bounds.left+20,
pcurrent_selected_win->bounds.top +20,
pcurrent_selected_win->bounds.left+310,
pcurrent_selected_win->bounds.top +200);
else SetRect (&oldbounds,20,20,310,210);
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -