1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
/*
* *********************************************************************
* * Copyright (C) 1988, 1990 Stanford University. *
* * Permission to use, copy, modify, and distribute this *
* * software and its documentation for any purpose and without *
* * fee is hereby granted, provided that the above copyright *
* * notice appear in all copies. Stanford University *
* * makes no representations about the suitability of this *
* * software for any purpose. It is provided "as is" without *
* * express or implied warranty. Export of this software outside *
* * of the United States of America may require an export license. *
* *********************************************************************
*/
#include <stdio.h>
#include <string.h>
#include "ana.h"
#include "ana_glob.h"
#include "graphics.h"
#define PDMENU_TOP ( bannerBox.bot + 1 )
private MenuItem zoom_menu[] =
{
{ "in", MENU_NOMARK, Zoom },
{ "out", MENU_NOMARK, Zoom },
{ NULL }
};
private MenuItem base_menu[] =
{
{ "bin", MENU_NOMARK, ChangeBase },
{ "oct", MENU_NOMARK, ChangeBase },
{ "hex", MENU_NOMARK, ChangeBase },
{ NULL }
};
private MenuItem window_menu[] =
{
{ "delta T", MENU_NOMARK, DeltaT },
{ "move to", MENU_NOMARK, MoveToTime },
{ "set width", MENU_NOMARK, SetWidth },
{ "name length", MENU_NOMARK, SetNameLen },
{ "scroll", MENU_MARK, ScrollUpdate },
{ NULL }
};
private MenuItem print_menu[] =
{
{ "file", MENU_NOMARK, printPS },
{ "banner", MENU_MARK, SetPSParms },
{ "legend", MENU_UNMARK, SetPSParms },
{ "times", MENU_MARK, SetPSParms },
{ "outline", MENU_MARK, SetPSParms },
{ NULL }
};
public Menu menu[] =
{
{ "zoom", zoom_menu },
{ "base", base_menu },
{ "window", window_menu },
{ "print", print_menu },
{ NULL, NULL }
};
private int inMenu; /* TRUE if mouse is in menu window */
#define PTinBOX( px, py, BOX ) \
( ( (py > (BOX).bot) || (py < (BOX).top ) || \
(px > (BOX).right) || (px < (BOX).left ) ) ? 0 : 1 )
#define ITEMHGT( ITM ) ( (ITM)->bot - (ITM)->top + 1 )
public void InitMenus()
{
Menu *mp;
MenuItem *item;
int len, maxlen;
Coord ypos;
for( mp = menu; mp->str != NULL; mp++ )
{
mp->len = strlen( mp->str );
maxlen = 0;
ypos = 0;
for( item = mp->items; item->str != NULL; item++ )
{
len = strlen( item->str );
if( len > maxlen )
maxlen = len;
item->len = len;
item->top = ypos;
item->bot = ypos + CHARHEIGHT + 1;
ypos += CHARHEIGHT + 2;
}
mp->width = CHARWIDTH * (maxlen + 2);
mp->height = ypos;
if( mp->w == 0 )
{
XSetWindowAttributes att;
unsigned long mask;
att.background_pixel = colors.white;
att.border_pixel = colors.black;
att.save_under = True;
att.override_redirect = True;
mask = CWBackPixel|CWBorderPixel|CWOverrideRedirect|CWSaveUnder;
mp->w = XCreateWindow( display, RootWindowOfScreen( screen ),
0, 0, mp->width, mp->height, 1, DefaultDepthOfScreen( screen ),
InputOutput, (Visual *) CopyFromParent, mask, &att );
XSelectInput( display, mp->w, ExposureMask | EnterWindowMask |
LeaveWindowMask | ButtonMotionMask | ButtonPressMask |
ButtonReleaseMask );
}
}
}
private void PutUpMenu( m )
Menu *m;
{
Coord x, y, sx, sy;
Window w;
sy = PDMENU_TOP;
sx = (m->box.right + m->box.left - m->width) / 2 + 1;
XTranslateCoordinates( display, window, RootWindowOfScreen( screen ),
sx, sy, &x, &y, &w );
if( x < 0 )
x = 0;
else if( x + m->width > WidthOfScreen( screen ) )
x = WidthOfScreen( screen ) - m->width;
if( x < 0 )
y = 0;
else if( y + m->height > HeightOfScreen( screen ) )
y = HeightOfScreen( screen ) - m->height;
XMoveWindow( display, m->w, x, y );
XMapRaised( display, m->w );
GrabMouse( m->w, EnterWindowMask | LeaveWindowMask | ButtonMotionMask |
ButtonPressMask | ButtonReleaseMask, cursors.deflt );
XFlush( display );
}
private void DrawMenu( m )
Menu *m;
{
MenuItem *item;
char *s;
int len;
for( item = m->items; item->str != NULL; item++ )
{
s = item->str;
len = item->len;
if (item->mark == MENU_MARK)
{
XCopyArea( display, pix.chk, m->w, gcs.black, 0, 0, 6, 8, 1,
(item->top + item->bot - 8)/2 );
}
StrCenter( m->w, s, len, 0, m->width - 1, item->bot - 1, gcs.black );
}
}
private MenuItem *MouseMoved( m, sel, y )
Menu *m;
MenuItem *sel;
Coord y;
{
MenuItem *new;
if( not inMenu or y < 0 or y > m->height )
new = NULL;
else
for( new = m->items; y > new->bot; new++ );
if( new != sel )
{
if( sel != NULL )
InvAREA( m->w, 0, sel->top, m->width, ITEMHGT( sel ) );
if( new != NULL )
InvAREA( m->w, 0, new->top, m->width, ITEMHGT( new ) );
}
return( new );
}
public void DoMenu( x, y )
Coord x, y;
{
XEvent ev;
Menu *m;
MenuItem *select;
int button_down;
for( m = menu; m->str != NULL; m++ )
{
if( PTinBOX( x, y, m->box ) )
break;
}
if( m->str == NULL ) /* should never happen */
return;
InvBox( window, m->box );
PutUpMenu( m );
inMenu = FALSE;
select = NULL;
button_down = TRUE;
while( button_down )
{
XNextEvent( display, &ev );
switch( ev.type )
{
case Expose :
if( ev.xexpose.window == m->w )
DrawMenu( m );
break;
case EnterNotify :
if( ev.xcrossing.window == m->w )
inMenu = TRUE;
x = ev.xcrossing.x;
y = (x < 0 or x > m->width) ? -1 : ev.xcrossing.y;
select = MouseMoved( m, select, y );
break;
case LeaveNotify :
if( ev.xcrossing.window == m->w )
inMenu = FALSE;
select = MouseMoved( m, select, ev.xcrossing.y );
break;
case MotionNotify :
if( ev.xmotion.window == m->w )
select = MouseMoved( m, select, ev.xmotion.y );
break;
case ButtonRelease :
button_down = FALSE;
break;
default : ;
}
}
if( select != NULL )
InvAREA( m->w, 0, select->top, m->width, ITEMHGT(select) );
XUngrabPointer( display, CurrentTime );
XUnmapWindow( display, m->w );
XFlush( display );
InvBox( window, m->box );
if( select != NULL )
{
if (select->mark == MENU_NOMARK)
(*select->func)( select->str );
else
(*select->func)( select );
}
}
|