home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
d
/
dir_nm20.zip
/
Dir_NM_2.0
/
NM-Button.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-16
|
16KB
|
485 lines
/* === NM-Button.c ===
*
* void SetUpCoordSystem(width,height)
* void DoMotionEvent(report,mouse_x,mouse_y,dx,dy)
* int DoButtonEvent(report,button,Mx,My,Mdy_Id,nx,ny)
* void DoButtonReleaseEvent(report,button,mouse_x,mouse_y,dx,dy)
* void ProcessKeyModifiers(report,modifier_state,button_state)
* void RemoveKeyModifiers(report,modifier_state,button_state)
* void DoKeyPressEvent(report)
* void DoKeyReleaseEvent(report)
* void draw_modifier_state(modifier_state)
* void print_mouse_coords(mouse_x,mouse_y,button)
* void draw_mouse_coords(win,gc,font_info,mouse_x,mouse_y,button,state)
*
*/
#include "NM.h"
GC saveGC; /* Use this to save context.
* See Menu.c */
Colormap theCmap,cmap;
XColor mycolor,exactcolor,mine;
int FirstTime=True;
extern int lit,IN;
void SetUpCoordSystem(width,height)
int width,height;
{
saveGC=XCreateGC(display,win,0,0);sleep(1);XSync(display,False);Init();
RefreshMenu(); /* Add the color allocation; should be the same as theCmap
cmap=DefaultColormap(display,screen); */
}
void DoMotionEvent(report,mouse_x,mouse_y,dx,dy)
XEvent report;
int mouse_x,mouse_y,dx,dy;
{
int state,button,n;
state=report.xbutton.state;button=state&(Button1Mask|Button2Mask|Button3Mask);
if (Motion==Piano_On) n=Piano_Note(Piano_X,Piano_Y,mouse_x,mouse_y);
switch(state)
{
case False:if (On_Text==1) Hi_light_Text(mouse_x,mouse_y);
else
{
HighlightMenu(mouse_x,mouse_y);
Hi_light_Map(mouse_x,mouse_y);
if (Motion==List_On || (Motion<0 && Action==List_On))
Hi_light_Table(mouse_x,mouse_y);
if (Host==1) Hi_light_host(mouse_x,mouse_y);
}
break;
/* Put a SWITCH here to select among different command modes,
* do the same in the button press/release processing.
*/
case Button1Mask:
break;
case Button2Mask:if (In_Map(mouse_x,mouse_y)==1)
{ Map_Dx+=dx;Map_Dy+=dy; }
break;
case (Button3Mask|ControlMask): break;
default:/* print_mouse_coords(button,mouse_x,mouse_y); */ break;
} /* end switch(state) */
switch(IN)
{
case 2:break;
case 7:break;
}
}
int DoButtonEvent(report,button,Mx,My,Mdy_Id,nx,ny)
XEvent report;
int button,Mx,My,Mdy_Id,nx,ny;
{
int state,Pos;
state=report.xbutton.state;Pos=0;
/* printf("\n press IN=%i\n",IN); */
switch (button)
{ /* Process Menu Selection if Button Pressed */
case Button1:if (Motion==Input_On)
{
if (five && now>0)
{
if (922<Mx && Mx<962 && 781<My && My<818)
{
Adjust_Text(166,737,1);Pos=-2;
if (On_Text==1)
{
Show_Text_Table(Map_SX,Text_SY);
High_Light_Char(Word_X,Word_Y);
}
else
{
High_Light_Char(Word_X,Word_Y);
Showup(166,737,five);
}
}
else if (On_Text==0)
{
if (922<Mx && Mx<962 && 742<My && My<779)
{
SetColor("cyan");
XSetLineAttributes(display,gc,2,0,0,0);
Use_Font("7x14");
DrawRectangle(922,743,38,35);
SetColor("magenta");
DrawRectangle(924,745,34,31);
Rub(927,749,28,23,"NavyBlue");
SetColor("cyan");
Adjust_High_Low(166,737,1);Pos=-1;
}
else if (40<Mx&&Mx<1120&&32<My&&My<732)
Pos=MS_Input(button,Mx,My,Mdy_Id,
nx,ny,On_High);
}
else if (On_Text==1) Edit_Word(button,Mx,My);
}
}
else if (Motion==Output_On)
{
if (548<Mx && Mx<585 && 2<My && My<28)
{
Display_Array(Mdy_Id,Print_pt,Print_pt+50,now);
Print_pt+=50;Pos=1;
if (Print_pt>906 || now==0) Print_pt=0;
}
else if (Tour_On==0 && 738<My && My<738+122 &&
((2<Mx&&Mx<2+160) || (969<Mx&&Mx<969+160)))
See_Tempo_Set(Mdy_Id);
else if (Tour_On==1)
{
now=next=Now_Bank;Tour_On=0;
Output(Back_Id);
}
else ch='*';
}
else if (Motion==Piano_On)
Show_Piano(Piano_X,Piano_Y,button);
else if (NewMenuSelection())
{
if ((2<IN && IN<9) || IN==12 || IN==22)
Action=IN+1;
else { Old_Motion=Motion;Motion=IN+1; }
Renew_Notice();
switch (IN)
{
case 0:Show_host(IN);break;
case 1:if (total>0)
{
Column_Pointer=1;Host=0;
Row_Pointer=0;List();
}
break;
case 2:Show_host(IN);break;
case 3: /* Re_Name */
case 4: /* Move_To */
case 5: /* Delete */
case 6: /* Value */
case 7: /* Check_Tmp */
case 8: /* Switch */
if (total>0 && Motion!=List_On)
{
Host=0;List();
Motion=List_On;
}
break;
case 9:Show_host(IN);break;
case 12: /* Load Text Files*/
if (total>0&&Motion!=List_On)
{
Host=0;List();
Motion=List_On;
}
break;
case 13:Show_host(IN);break;
case 15:In_Menu=0;Timbre();
RefreshMenu();
break;
case 16:In_Menu=0;Word_I_O('I');
RefreshMenu();
break;
case 17: /* In_Menu=0;Dance(); */
RefreshMenu();
break;
case 18:In_Menu=0;Sound('I');
RefreshMenu();
break;
case 19:In_Menu=0;Voice('P');
RefreshMenu();
break;
case 20:Show_Piano(Piano_X,Piano_Y,
button);
break;
case 21:Show_host(IN);break;
case 23:Quit();break;
}
}
else if (Host==1 && (Column_Id>0 || (-1<Host_X
&& Host_X<6 && -1<Host_Y&&Host_Y<6)))
Finish_host();
else if (Motion==List_On)
{
if (In_Table(Mx,My)==1)
Edit_Table(Mx,My);
else if (In_Map(Mx,My)==1)
Do_Re_Name(Mx,My,button);
}
break;
case Button2:if (Motion==Input_On)
{
if (On_Text==1) Edit_Word(button,Mx,My);
else if (five&&now>0&&40<Mx&&Mx<1120&&32<My&&My<732)
Pos=MS_Input(button,Mx,My,Mdy_Id,nx,ny,On_High);
}
else if (Motion==Output_On) ch='!';
else if (Motion==List_On && In_Map(Mx,My)==1)
Do_Re_Name(Mx,My,button);
else if (Motion==Piano_On)
Show_Piano(Piano_X,Piano_Y,button);
else if (NewMenuSelection())
{
switch (IN)
{
case 2:Update_Text_Tar();break;
case 3:break;
}
}
break;
case Button3:if (In_Menu==1) RefreshMenu();
else if (Motion==Input_On)
{
if (On_Text==1) Edit_Word(button,Mx,My);
else if (five && now>0 && 40<Mx && Mx<1120 &&
33<My && My<732)
Pos=MS_Input(button,Mx,My,Mdy_Id,nx,ny,
On_High);
else if (548<Mx && Mx<585 && 2<My && My<34)
{ /* Save & Exit */
if (now==0) tmp[M_Id][0].note+=1;
else St[M_Id][0][On_High].nt[0]+=1;
head=M_Id+1;Save(M_Id+1,tail);ch='&';
}
}
else if (Motion==Output_On)
{
if (548<Mx && Mx<585 && 2<My && My<28) ch='&';
else if (Tour_On==0) ch='/';
}
break;
} /* end switch(button) */
fflush(stdout);return Pos; /* This makes the screen printing happen... */
}
void DoButtonReleaseEvent(report,button,mouse_x,mouse_y,dx,dy)
XEvent report;
int button,mouse_x,mouse_y,dx,dy;
{
int state,Wwidth,Wheight;
state=report.xbutton.state; /* printf("\n release"); */
switch (button)
{
case Button1:switch (IN)
{
case 3:if (FirstTime==False )
{
XSetFunction(display,gc,GXxor);
XSetFunction(display,gc,GXcopy);
}
else FirstTime=False;
break;
default:break;
}
break;
case Button2:if (In_Map(mouse_x,mouse_y)==1 && (Map_Dx!=0 || Map_Dy!=0))
Move_Table(mouse_x,mouse_y,Map_Dx/6,Map_Dy/3);
Map_Dx=0;Map_Dy=0;
if (Motion==-Input_On || Motion==-Output_On)
Show_Preface(139);
break;
case Button3: break;
}
fflush(stdout);
}
/* Process key modifiers to make new mask
* construct a state with only modifier keys */
void ProcessKeyModifiers(report,modifier_state,button_state)
XEvent *report;
unsigned int *modifier_state, *button_state;
{
int state;
KeySym ks,sym;
XComposeStatus status;
state=report->xkey.state;
*modifier_state=state & (ShiftMask | ControlMask | Mod1Mask);
/* construct a state with only button presses */
*button_state= state &( Button1Mask | Button2Mask | Button3Mask);
sym = XLookupKeysym(report,0); /* 0 = lower case, 1 = upper case */
/* keycode=report->xkey.keycode;KeycodeToKeysm(display,code,index);
printf("\n1. code %d, sym %d, state %x, mod-mask %x,\n
Cs %d %d : %d %d ; %d %d \n",report->xkey.keycode,sym,state,*modifier_state,
XK_Shift_L,XK_Shift_R,XK_Control_L,XK_Control_R, XK_Meta_L, XK_Meta_R );
*/
switch (sym)
{
case XK_Shift_L:
case XK_Shift_R:/* printf("--bare ShiftMask");Force addition of shift
mask */
*modifier_state = *modifier_state | ShiftMask;
break;
case XK_Control_L:
case XK_Control_R:/* printf("-- bare ControlMask");Force addition of
control mask */
*modifier_state=*modifier_state | ControlMask;
break;
case XK_Meta_L:
case XK_Meta_R:/* printf("-- bare Mod1Mask");Force addition of Meta mask*/
*modifier_state=*modifier_state | Mod1Mask;
break;
/* Process non-modifier keypresses */
default:XLookupString(report,tmpstr,128,&ks,&status);
if (tmpstr[0]=='q' || tmpstr[0]=='Q') Quit();
/* here is where other letter keys hit */
if (tmpstr[0]=='a' || tmpstr[0]=='A') Quit();
break;
}
}
/* Remove inserted key modifiers from mask */
void RemoveKeyModifiers(report,modifier_state,button_state)
XEvent *report;
unsigned int *modifier_state, *button_state;
{
int state;
KeySym ks,sym;
XComposeStatus status;
state=report->xkey.state;
*modifier_state= state & ( ShiftMask | ControlMask | Mod1Mask);
/* construct a state with only button presses */
*button_state= state & ( Button1Mask | Button2Mask | Button3Mask);
sym=XLookupKeysym(report,0); /* 0 = lower case, 1 = upper case */
switch (sym)
{
case XK_Shift_L:
case XK_Shift_R:/* printf("--bare ShiftMask");Force deletion of shift
mask by XOR operator if it is present */
*modifier_state=*modifier_state ^ ShiftMask;
break;
case XK_Control_L:
case XK_Control_R:/* printf("-- bare ControlMask");Force addition of
control mask */
*modifier_state=*modifier_state ^ ControlMask;
break;
case XK_Meta_L:
case XK_Meta_R:/* printf("-- bare Mod1Mask");Force addition of Meta mask*/
*modifier_state=*modifier_state ^ Mod1Mask;
break;
/* Process non-modifier keypresses */
default:XLookupString(report,tmpstr,128,&ks,&status);
if (tmpstr[0]=='q' || tmpstr[0]=='Q') Quit();
break;
}
}
void DoKeyPressEvent(report)
XEvent report;
{
unsigned int state,modifier_state,button_state;
ProcessKeyModifiers(&report,&modifier_state,&button_state);
/* draw_modifier_state(modifier_state);
switch (modifier_state)
{
case ShiftMask: printf("-- Shift");break;
case ControlMask: printf("-- Control");break;
case Mod1Mask: printf("-- Mod1");break;
case ShiftMask|ControlMask: printf("-- Shift Control");break;
case ShiftMask|Mod1Mask: printf("-- Shift Mod1");break;
case Mod1Mask|ControlMask: printf("-- Control Mod1");break;
case ShiftMask|Mod1Mask|ControlMask: printf("-- Shift Control Mod1");
break;
default:printf("-- no modifiers");break;
}
switch(button_state)
{
case Button1Mask:printf("-- Button1Mask");break;
case (Button1Mask|ShiftMask):printf("-- Button1Mask | ShiftMask");break;
}
*/ /* end switch(state) */
fflush(stdout);
}
void DoKeyReleaseEvent(report)
XEvent report;
{
unsigned int state,new_modifier_state,old_modifier_state,new_button_state,
old_button_state;
/* printf("\n keyrelease");*/
ProcessKeyModifiers(&report,&old_modifier_state,&old_button_state);
RemoveKeyModifiers(&report,&new_modifier_state,&new_button_state);
/* The idea here is that if SHIFT WAS down, the things that
ran when shift was down need to know it was down in the old state.
But things that depend on the CURRENT state, need to have the modifier
deleted so the new state appears immediately updated. */
/*draw_modifier_state(new_modifier_state);
switch (old_modifier_state)
{
case ShiftMask: printf("-- Shift");break;
case ControlMask: printf("-- Control"); break;
case Mod1Mask: printf("-- Mod1"); break;
case ShiftMask|ControlMask: printf("-- Shift Control"); break;
case ShiftMask|Mod1Mask: printf("-- Shift Mod1"); break;
case Mod1Mask|ControlMask: printf("-- Control Mod1"); break;
case ShiftMask|Mod1Mask|ControlMask:printf("-- Shift Control Mod1");break;
default:printf("-- no modifiers");break;
}
switch(old_button_state)
{
case Button1Mask:printf("-- Button1Mask");break;
case (Button1Mask|ShiftMask):printf("-- Button1Mask | ShiftMask");break;
}
*/ /* end switch(state) */
fflush(stdout);
}
/* Announce Modifier State so you know what Mouse Button will do */
/* Mouse position drawn to window stdio */
void draw_modifier_state(modifier_state)
unsigned int modifier_state;
{
static char MsgText[255];
switch (modifier_state)
{
case ShiftMask:(void) sprintf(MsgText," Shift ");break;
case ControlMask:(void) sprintf(MsgText," Control ");break;
case Mod1Mask:(void) sprintf(MsgText," Mod1 ");break;
case (ShiftMask|ControlMask):(void) sprintf(MsgText, " Shift Control ");
break;
case ShiftMask|Mod1Mask:(void) sprintf(MsgText," Shift Mod1 ");break;
case Mod1Mask|ControlMask:(void) sprintf(MsgText," Control Mod1 ");break;
case ShiftMask|Mod1Mask|ControlMask:(void) sprintf(MsgText,
"Shift Control Mod1 ");
break;
default:(void) sprintf(MsgText,"-- no modifiers");break;
}
PrintMsgText(win,gc,font_info,MsgText);
}
/* Mouse position printed to stdio */
void print_mouse_coords(mouse_x,mouse_y,button)
int button,mouse_x,mouse_y;
{
printf("(%d, %d: %d) ", mouse_x, mouse_y, button);
}
/* Mouse position drawn to window stdio */
void draw_mouse_coords(win,gc,font_info,mouse_x,mouse_y,button,state)
Window win;
GC gc;
XFontStruct *font_info;
int button,state,mouse_x,mouse_y;
{
static char MsgText[255];
(void) sprintf(MsgText,"(x,y:State:Button)=(%d,%d: %d:%d).",mouse_x,mouse_y,
state, button);
PrintMsgText(win,gc,font_info,MsgText);
}