|
|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 4319 (0x10df)
Types: TextFile
Notes: UNIX file
Names: »dmenu2.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
└─⟦2d53db1df⟧ UNIX Filesystem
└─⟦this⟧ »hr/src/desk/dmenu2.c«
#include <stdio.h>
#include "desk.h"
/************************************************************************
int MU_New(id, n, s): Define a menu
int MU_Start(id): Pop a menu to the screen
int MU_End(): Close popup and return choice
void MU_Close(): Close popup without flashing
int MU_Point(pt): Feed the menu system a point
************************************************************************/
MENU mu_menu[NMENU];
AMENU mu_am;
IMENU mu_imenu[MAXIMENU];
int mu_enable;
int mu_im; /* index to next free IMENU elt */
int mu_flash = 5; /* number of times to flash item*/
/*
** int MU_New(id, n, s)
**
** Entry: id, = menu identifier [0..NMENU-1]
** n, = number of menu items [1..NIMENU]
** s = ^ to 'n' number of C-string pointers
**
** Exit: 0, if OK
** -1, if couldn't do it
*/
MU_New(id, n, s)
unsigned id;
unsigned n;
char *s[];
{
MENU *m;
IMENU *mi;
int i;
if ( id >= NMENU || n - 1 >= NIMENU || s == NULL )
return -1;
m = &mu_menu[id];
if ( m->mn_n || mu_im + n > MAXIMENU )
return -2;
/*
* Do menu definition header
*/
m->mn_n = n;
m->mn_item = mi = &mu_imenu[mu_im];
m->mn_height = n * dskFntH;
m->mn_width = 0;
mu_im += n;
/*
* Do menu item initialization
*/
for ( i = n ; i ; i-- )
{
int l;
mi->mi_clen = ((l=strlen(*s)) > 255 ? 255 : l);
mi->mi_str = *s;
mi->mi_flag = 01;
mi->mi_next = -1;
mi->mi_len = ( mi->mi_clen ? D_StrW(*s, mi->mi_clen) : 0 );
mi->mi_len += 2*MHFILL;
if ( mi->mi_len > m->mn_width )
m->mn_width = mi->mi_len;
mi++;
s++;
}
return 0;
}
/*
** int MU_Start(id, pt)
**
** Entry: id, menu id of menu to open as the root
** pt, physical coordinate to use to open the window
**
** Exit: -1, if couldn't do it
**
** Notes: The upper left corner of the menu shall be located as
** close to 'pt' as possible. A tree of menus, according
** to what menus are linked to the menu items is started.
*/
int MU_Start(id, pt)
unsigned id;
POINT pt;
{
RECT rect;
int i;
#ifdef DEBUG
printf("\nIn MU_Start:\t%d, (%d,%d)\n", id, pt.x, pt.y);
#endif
ioctl(myfd, CIOMOUSE, MNU_MOUSE);
if ( (i = mu_OpenMenu(id, pt)) < 0 )
{
ioctl(myfd, CIOMOUSE, MNU_MOUSE);
return i;
}
MU_Point(pt);
return 0;
}
/*
** int MU_End() - Close all popups and return choice
*/
int MU_End()
{
unsigned n;
int i;
int j;
#ifdef DEBUG
printf("In MU_End\n");
#endif
if ( !mu_am.ma_menu )
return -1;
if ( (n = mu_am.ma_elt) == -1 )
{
MU_Close();
ioctl( myfd, CIOMOUSE, DSK_MOUSE );
return -1;
}
n += (mu_am.ma_menu - mu_menu) << 8;
for ( i = mu_flash ; i ; i-- )
{
mu_InvertItem();
for (j=5000; j ; j--)
;
mu_InvertItem();
for (j=5000; j ; j--)
;
}
MU_Close();
#ifdef DEBUG
printf("\t\treturning 0x%x\n", n);
#endif
ioctl( myfd, CIOMOUSE, DSK_MOUSE );
return n;
}
/*
** MU_Close() - Close the open menu.
*/
MU_Close()
{
register int n;
register IMENU *mi;
if ( !mu_am.ma_menu )
return;
#ifdef DEBUG
printf("\tClosing mid=%d\n", mu_am.ma_menu - mu_menu);
#endif
D_Close(&mu_am.ma_rect, mu_am.ma_heap);
n = mu_am.ma_menu->mn_n;
mi = mu_am.ma_menu->mn_item;
mu_am.ma_menu = NULL;
while ( n )
{
mi->mi_flag &= 0xfffd; /* turn off on bit */
mi++;
n--;
}
}
/*
** MU_Point(pt) - Feed the active menu group a point
**
** Entry: pt, physical point
*/
MU_Point(pt)
POINT pt;
{
register int newitem;
#ifdef DEBUG2
printf("\tIn MU_Point:\t(%d,%d)\n", pt.x, pt.y);
#endif
if ( !mu_am.ma_menu )
return;
newitem = mu_FindItem(pt, &pt);
if ( newitem != mu_am.ma_elt )
{
#ifdef DEBUG
printf("\t\titem %d, olditem %d\n", newitem, mu_am.ma_elt);
#endif
/* Turn off menu item.
Turn on menu item newitem (if not -1).
*/
mu_InvertItem();
if ( (mu_am.ma_elt = newitem) != -1 )
mu_InvertItem();
}
}
mu_Panic()
{
fprintf(stderr, "Menu Panic\n");
exit(-1);
}
#ifdef DEBUG
dumpamenu(ma)
register AMENU *ma;
{
printf("\tDUMPA:");
printf("\tma=0x%lx, mid=%d\n", ma, ma->ma_menu - mu_menu);
printf("\t\telt=%d, pt=(%d,%d)\n", ma->ma_elt, ma->ma_point.x, ma->ma_point.y);
printf("\t\trect=(%d,%d),(%d,%d), crect=(%d,%d),(%d,%d)\n",
ma->ma_rect.origin.x, ma->ma_rect.origin.y,
ma->ma_rect.corner.x, ma->ma_rect.corner.y,
ma->ma_crect.origin.x, ma->ma_crect.origin.y,
ma->ma_crect.corner.x, ma->ma_crect.corner.y);
}
#endif