1 /*	SCCS Id: @(#)winmenu.c	3.2	96/02/17	*/
2 /* Copyright (c) Gregg Wonderly, Naperville, Illinois,  1991,1992,1993,1996. */
3 /* NetHack may be freely redistributed.  See license for details. */
4 
5 #include "NH:sys/amiga/windefs.h"
6 #include "NH:sys/amiga/winext.h"
7 #include "NH:sys/amiga/winproto.h"
8 
9 /* Start building the text for a menu */
10 void
amii_start_menu(window)11 amii_start_menu(window)
12     register winid window;
13 {
14     register int i;
15     register struct amii_WinDesc *cw;
16     register amii_menu_item *mip;
17 
18     if(window == WIN_ERR || (cw = amii_wins[window]) == NULL || cw->type != NHW_MENU)
19 	panic(winpanicstr,window, "start_menu");
20 
21     amii_clear_nhwindow(window);
22 
23     if( cw->data && ( cw->type == NHW_MESSAGE ||
24 	    cw->type == NHW_MENU || cw->type == NHW_TEXT ) )
25     {
26 	for( i = 0; i < cw->maxrow; ++i )
27 	{
28 	    if( cw->data[ i ] )
29 		free( cw->data[ i ] );
30 	}
31 	free( cw->data );
32 	cw->data = NULL;
33     }
34 
35     for( mip = cw->menu.items, i = 0; (mip = cw->menu.items) && i < cw->menu.count; ++i )
36     {
37 	cw->menu.items = mip->next;
38     	free( mip );
39     }
40 
41     cw->menu.items = 0;
42     cw->menu.count = 0;
43     cw->menu.chr = 'a';
44 
45     if( cw->morestr ) free( cw->morestr );
46     cw->morestr = NULL;
47 
48     if( window == WIN_INVEN && cw->win != NULL )
49     {
50 	if( alwaysinvent )
51 	    cw->wasup = 1;
52     }
53     cw->cury = cw->rows = cw->maxrow = cw->maxcol = 0;
54     return;
55 }
56 
57 /* Add a string to a menu */
58 void
amii_add_menu(window,glyph,id,ch,gch,attr,str,preselected)59 amii_add_menu(window,glyph, id, ch, gch, attr, str, preselected)
60     register winid window;
61     register int glyph;
62     register const anything *id;
63     register char ch;
64     register char gch;
65     register int attr;
66     register const char *str;
67     register BOOLEAN_P preselected;
68 {
69     register struct amii_WinDesc *cw;
70     amii_menu_item *mip;
71     char buf[ 4+BUFSZ ];
72 
73     if(str == NULL)return;
74 
75     if(window == WIN_ERR || (cw = amii_wins[window]) == NULL || cw->type != NHW_MENU)
76 	panic(winpanicstr,window, "add_menu");
77 
78     mip = (amii_menu_item *)alloc( sizeof( *mip ) );
79     mip->identifier = *id;
80     mip->selected = preselected;
81     mip->attr = attr;
82     mip->glyph = Is_rogue_level(&u.uz) ? NO_GLYPH : glyph;
83     mip->selector = 0;
84     mip->gselector = gch;
85     mip->count = -1;
86 
87     if (id->a_void && !ch && cw->menu.chr != 0)
88     {
89 	ch = cw->menu.chr++;
90 	if( ch == 'z' )
91 	    cw->menu.chr = 'A';
92 	if( ch == 'Z' )
93 	    cw->menu.chr = 0;
94     }
95 
96     mip->canselect = ( id->a_void != 0 );
97 
98     if( id->a_void && ch != '\0')
99     {
100 	Sprintf( buf, "%c - %s", ch, str );
101 	str = buf;
102 	mip->canselect = 1;
103     }
104 
105     mip->selector = ch;
106 
107     amii_putstr( window, attr, str );
108 
109     mip->str = cw->data[ cw->cury - 1 ];
110     cw->menu.count++;
111 
112     mip->next = NULL;
113 
114     if( cw->menu.items == 0 )
115     	cw->menu.last = cw->menu.items = mip;
116     else
117     {
118 	cw->menu.last->next = mip;
119 	cw->menu.last = mip;
120     }
121 }
122 
123 /* Done building a menu. */
124 
125 void
amii_end_menu(window,morestr)126 amii_end_menu(window,morestr)
127     register winid window;
128     register const char *morestr;
129 {
130     register struct amii_WinDesc *cw;
131 
132     if(window == WIN_ERR || (cw=amii_wins[window]) == NULL
133        || cw->type != NHW_MENU )
134 	panic(winpanicstr,window, "end_menu");
135 
136     if( morestr && *morestr )
137     {
138 	anything any;
139 #define PROMPTFIRST /* Define this to have prompt first */
140 #ifdef PROMPTFIRST
141 	amii_menu_item *mip;
142 	int i;
143 	char *t;
144 	mip = cw->menu.last;
145 #endif
146 	any.a_void = 0;
147 	amii_add_menu( window, NO_GLYPH, &any, 0, 0, ATR_NONE, morestr,
148 	   MENU_UNSELECTED);
149 #ifdef PROMPTFIRST /* Do some shuffling. Last first, push others one forward */
150 	mip->next = NULL;
151 	cw->menu.last->next = cw->menu.items;
152 	cw->menu.items = cw->menu.last;
153 	cw->menu.last = mip;
154 	t = cw->data[cw->cury-1];
155 	for (i=cw->cury-1; i>0; i--) {
156 	    cw->data[i] = cw->data[i-1];
157 	}
158 	cw->data[0] = t;
159 #endif
160     }
161 
162     /* If prompt first, don't put same string in title where in most cases
163        it's not entirely visible anyway */
164 #ifndef PROMPTFIRST
165     if( morestr )
166 	cw->morestr = strdup( morestr );
167 #endif
168 }
169 
170 /* Select something from the menu. */
171 
172 int
amii_select_menu(window,how,mip)173 amii_select_menu(window, how, mip )
174     register winid window;
175     register int how;
176     register menu_item **mip;
177 {
178     int cnt;
179     register struct amii_WinDesc *cw;
180 
181     if( window == WIN_ERR || ( cw=amii_wins[window] ) == NULL ||
182 	  cw->type != NHW_MENU )
183 	panic(winpanicstr,window, "select_menu");
184 
185     cnt = DoMenuScroll( window, 1, how, mip );
186 
187     /* This would allow the inventory window to stay open. */
188     if( !alwaysinvent || window != WIN_INVEN )
189 	dismiss_nhwindow(window);       /* Now tear it down */
190     return cnt;
191 }
192 
193 amii_menu_item *
find_menu_item(register struct amii_WinDesc * cw,int idx)194 find_menu_item( register struct amii_WinDesc *cw, int idx )
195 {
196     amii_menu_item *mip;
197     for( mip = cw->menu.items; idx > 0 && mip; mip = mip->next )
198 	--idx;
199 
200     return( mip );
201 }
202 
203 int
make_menu_items(register struct amii_WinDesc * cw,register menu_item ** rmip)204 make_menu_items( register struct amii_WinDesc *cw, register menu_item **rmip )
205 {
206     register int idx = 0;
207     register amii_menu_item *mip;
208     register menu_item *mmip;
209 
210     for( mip = cw->menu.items; mip; mip = mip->next )
211     {
212 	if( mip->selected )
213 	    ++idx;
214     }
215 
216     if( idx )
217     {
218 	mmip = *rmip = (menu_item *)alloc( idx * sizeof( *mip ) );
219 	for( mip = cw->menu.items; mip; mip = mip->next )
220 	{
221 	    if( mip->selected )
222 	    {
223 		mmip->item = mip->identifier;
224 		mmip->count = mip->count;
225 		mmip++;
226 	    }
227 	}
228 
229 	cw->mi = *rmip;
230     }
231     return( idx );
232 }
233 
234 int
DoMenuScroll(win,blocking,how,retmip)235 DoMenuScroll( win, blocking, how, retmip )
236     int win, blocking, how;
237     menu_item **retmip;
238 {
239     amii_menu_item *amip;
240     register struct Window *w;
241     register struct NewWindow *nw;
242     struct PropInfo *pip;
243     register struct amii_WinDesc *cw;
244     struct IntuiMessage *imsg;
245     struct Gadget *gd;
246     register int wheight, xsize, ysize, aredone = 0;
247     register int txwd, txh;
248     long mics, secs, class, code;
249     long oldmics = 0, oldsecs = 0;
250     int aidx, oidx, topidx, hidden;
251     int totalvis;
252     SHORT mx, my;
253     static char title[ 100 ];
254     int dosize = 1;
255     struct Screen *scrn = HackScreen;
256     int x1,x2,y1,y2;
257     long counting = FALSE, count = 0, reset_counting = FALSE;
258     char countString[32];
259 
260     if( win == WIN_ERR || ( cw = amii_wins[ win ] ) == NULL )
261 	panic(winpanicstr,win,"DoMenuScroll");
262 
263     /*  Initial guess at window sizing values */
264     txwd = txwidth;
265     if( WINVERS_AMIV )
266     {
267 	if( win == WIN_INVEN )
268 	    txh = max( txheight, pictdata.ysize + 3 ); /* interline space */
269 	else
270 	    txh = txheight; /* interline space */
271     }
272     else
273 	txh = txheight; /* interline space */
274 
275     /* Check to see if we should open the window, should need to for
276      * TEXT and MENU but not MESSAGE.
277      */
278 
279     w = cw->win;
280     topidx = 0;
281 
282     if( w == NULL )
283     {
284 
285 #ifdef  INTUI_NEW_LOOK
286 	if( IntuitionBase->LibNode.lib_Version >= 37 )
287 	{
288 	    PropScroll.Flags |= PROPNEWLOOK;
289 	}
290 #endif
291 	nw = (void *)DupNewWindow( (void *)(&new_wins[ cw->type ].newwin) );
292 	if( !alwaysinvent || win != WIN_INVEN )
293 	{
294 	    xsize = scrn->WBorLeft + scrn->WBorRight + MenuScroll.Width + 1 +
295 				(txwd * cw->maxcol);
296 	    if( WINVERS_AMIV )
297 	    {
298 		if( win == WIN_INVEN )
299 		    xsize += pictdata.xsize + 4;
300 	    }
301 	    if( xsize > amiIDisplay->xpix )
302 		xsize = amiIDisplay->xpix;
303 
304 	    /* If next row not off window, use it, else use the bottom */
305 
306 	    ysize = ( txh * cw->maxrow ) +          	  /* The text space */
307 		    HackScreen->WBorTop + txheight + 1 +  /* Top border */
308 		    HackScreen->WBorBottom + 3;     	  /* The bottom border */
309 	    if( ysize > amiIDisplay->ypix )
310 		ysize = amiIDisplay->ypix;
311 
312 	    /* Adjust the size of the menu scroll gadget */
313 
314 	    nw->TopEdge = 0;
315 	    if( cw->type == NHW_TEXT && ysize < amiIDisplay->ypix )
316 		nw->TopEdge += ( amiIDisplay->ypix - ysize ) / 2;
317 	    nw->LeftEdge = amiIDisplay->xpix - xsize;
318 	    if( cw->type == NHW_MENU )
319 	    {
320 		if( nw->LeftEdge > 10 )
321 		    nw->LeftEdge -= 10;
322 		else
323 		    nw->LeftEdge = 0;
324 		if( amiIDisplay->ypix - nw->Height > 10 )
325 		    nw->TopEdge += 10;
326 		else
327 		    nw->TopEdge = amiIDisplay->ypix - nw->Height - 1;
328 	    }
329 	    if( cw->type == NHW_TEXT && xsize < amiIDisplay->xpix )
330 		nw->LeftEdge -= ( amiIDisplay->xpix - xsize ) / 2;
331 	}
332 	else if( win == WIN_INVEN )
333 	{
334 	    struct Window *mw = amii_wins[ WIN_MAP ]->win;
335 	    struct Window *sw = amii_wins[ WIN_STATUS ]->win;
336 
337 	    xsize = scrn->WBorLeft + scrn->WBorRight + MenuScroll.Width + 1 +
338 				(txwd * cw->maxcol);
339 
340 	    /* Make space for the glyph to appear at the left of the description */
341 	    if( WINVERS_AMIV )
342 		xsize += pictdata.xsize + 4;
343 
344 	    if( xsize > amiIDisplay->xpix )
345 		xsize = amiIDisplay->xpix;
346 
347 	    /* If next row not off window, use it, else use the bottom */
348 
349 	    ysize = sw->TopEdge - (mw->TopEdge + mw->Height) - 1;
350 	    if( ysize > amiIDisplay->ypix )
351 		ysize = amiIDisplay->ypix;
352 
353 	    /* Adjust the size of the menu scroll gadget */
354 
355 	    nw->TopEdge = mw->TopEdge + mw->Height;
356 	    nw->LeftEdge = 0;
357 	}
358 	cw->newwin = (void *)nw;
359 	if( nw == NULL )
360 	    panic("No NewWindow Allocated" );
361 
362 	nw->Screen = HackScreen;
363 
364 	if( win == WIN_INVEN )
365 	{
366 	    sprintf( title, "%s the %s's Inventory", plname, pl_character );
367 	    nw->Title = title;
368 	    if( lastinvent.MaxX != 0 )
369 	    {
370 		nw->LeftEdge = lastinvent.MinX;
371 		nw->TopEdge = lastinvent.MinY;
372 		nw->Width = lastinvent.MaxX;
373 		nw->Height = lastinvent.MaxY;
374 	    }
375 	}
376 	else if( cw->morestr )
377 	    nw->Title = cw->morestr;
378 
379 	/* Adjust the window coordinates and size now that we know
380 	 * how many items are to be displayed.
381 	 */
382 
383 	if( ( xsize > amiIDisplay->xpix - nw->LeftEdge ) &&
384 	    ( xsize < amiIDisplay->xpix ) )
385 	{
386 	    nw->LeftEdge = amiIDisplay->xpix - xsize;
387 	    nw->Width = xsize;
388 	}
389 	else
390 	{
391 	    nw->Width = min( xsize, amiIDisplay->xpix - nw->LeftEdge );
392 	}
393 	nw->Height = min( ysize, amiIDisplay->ypix - nw->TopEdge );
394 
395 	if( WINVERS_AMIV )
396 	{
397 	    /* Make sure we are using the correct hook structure */
398 	    nw->Extension = cw->wintags;
399 	}
400 
401 	/* Now, open the window */
402 	w = cw->win = OpenShWindow( (void *)nw );
403 
404 	if( w == NULL )
405 	{
406 	    char buf[ 130 ];
407 
408 	    sprintf( buf, "No Window Opened For Menu (%d,%d,%d-%d,%d-%d)",
409 		nw->LeftEdge, nw->TopEdge, nw->Width, amiIDisplay->xpix,
410 		nw->Height, amiIDisplay->ypix );
411 	    panic( buf );
412 	}
413 
414 #ifdef HACKFONT
415 	if( TextsFont )
416 	    SetFont(w->RPort, TextsFont );
417 	else if( HackFont )
418 	    SetFont(w->RPort, HackFont );
419 #endif
420 	txwd = w->RPort->TxWidth;
421 	if( WINVERS_AMIV )
422 	{
423 	    if( win == WIN_INVEN )
424 		txh = max( w->RPort->TxHeight, pictdata.ysize + 3 ); /* interline space */
425 	    else
426 		txh = w->RPort->TxHeight; /* interline space */
427 	}
428 	else
429 	    txh = w->RPort->TxHeight; /* interline space */
430 
431 	/* subtract 2 to account for spacing away from border (1 on each side) */
432 	wheight = ( w->Height - w->BorderTop - w->BorderBottom - 2 ) / txh;
433 	if( WINVERS_AMIV )
434 	{
435 	    if( win == WIN_INVEN )
436 	    {
437 		cw->cols = ( w->Width - w->BorderLeft -
438 			    w->BorderRight - 4 - pictdata.xsize - 3 ) / txwd;
439 	    }
440 	    else
441 	    {
442 		cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd;
443 	    }
444    	}
445 	else
446 	{
447 	    cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd;
448 	}
449 	totalvis = CountLines( win );
450     }
451     else
452     {
453 	txwd = w->RPort->TxWidth;
454 	if( WINVERS_AMIV )
455 	{
456 	    if( win == WIN_INVEN )
457 		txh = max( w->RPort->TxHeight, pictdata.ysize + 3 ); /* interline space */
458 	    else
459 		txh = w->RPort->TxHeight; /* interline space */
460 	}
461 	else
462 	{
463 	    txh = w->RPort->TxHeight; /* interline space */
464 	}
465 
466 	/* subtract 2 to account for spacing away from border (1 on each side) */
467 	wheight = ( w->Height - w->BorderTop - w->BorderBottom - 2 ) / txh;
468 	if( WINVERS_AMIV )
469 	{
470 	    if( win == WIN_INVEN )
471 	    {
472 		cw->cols = ( w->Width - w->BorderLeft -
473 			    w->BorderRight - 4 - pictdata.xsize - 3) / txwd;
474 	    }
475 	    else
476 		cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd;
477 	}
478 	else
479 	{
480 	    cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd;
481 	}
482 
483 	totalvis = CountLines( win );
484 
485 	for( gd = w->FirstGadget; gd && gd->GadgetID != 1; )
486 	    gd = gd->NextGadget;
487 
488 	if( gd )
489 	{
490 	    pip = (struct PropInfo *)gd->SpecialInfo;
491 	    hidden = max( totalvis - wheight, 0 );
492 	    topidx = (((ULONG)hidden * pip->VertPot) + (MAXPOT/2)) >> 16;
493 	}
494     }
495 
496     for( gd = w->FirstGadget; gd && gd->GadgetID != 1; )
497 	gd = gd->NextGadget;
498 
499     if( !gd ) panic("Can't find scroll gadget" );
500 
501     morc = 0;
502     oidx = -1;
503 
504 #if 0
505     /* Make sure there are no selections left over from last time. */
506 /* XXX potential problem for preselection if this is really needed */
507   for( amip = cw->menu.items; amip; amip = amip->next )
508 	amip->selected = 0;
509 #endif
510 
511     DisplayData( win, topidx );
512 
513     /* Make the prop gadget the right size and place */
514 
515     SetPropInfo( w, gd, wheight, totalvis, topidx );
516     oldsecs = oldmics = 0;
517 
518     /* If window already up, don't stop to process events */
519     if( cw->wasup )
520     {
521     	aredone = 1;
522     	cw->wasup = 0;
523     }
524 
525     while( !aredone )
526     {
527 	/* Process window messages */
528 
529 	WaitPort( w->UserPort );
530 	while( imsg = (struct IntuiMessage * ) GetMsg( w->UserPort ) )
531 	{
532 	    class = imsg->Class;
533 	    code = imsg->Code;
534 	    mics = imsg->Micros;
535 	    secs = imsg->Seconds;
536 	    gd = (struct Gadget *) imsg->IAddress;
537 	    mx = imsg->MouseX;
538 	    my = imsg->MouseY;
539 
540 	    /* Only do our window or VANILLAKEY from other windows */
541 
542 	    if( imsg->IDCMPWindow != w && class != VANILLAKEY &&
543 							class != RAWKEY )
544 	    {
545 		ReplyMsg( (struct Message *) imsg );
546 		continue;
547 	    }
548 
549 	    /* Do DeadKeyConvert() stuff if RAWKEY... */
550 	    if( class == RAWKEY )
551 	    {
552 		class = VANILLAKEY;
553 		code = ConvertKey( imsg );
554 	    }
555 	    ReplyMsg( (struct Message *) imsg );
556 
557 	    switch( class )
558 	    {
559 		case NEWSIZE:
560 
561 		    /*
562 		     * Ignore every other newsize, no action needed,
563 		     * except RefreshWindowFrame() in case borders got overwritten
564 		     * for some reason. It should not happen, but ...
565 		     */
566 
567 		    if( !dosize )
568 		    {
569 			RefreshWindowFrame(w);
570 			dosize = 1;
571 			break;
572 		    }
573 
574 		    if( win == WIN_INVEN )
575 		    {
576 			lastinvent.MinX = w->LeftEdge;
577 			lastinvent.MinY = w->TopEdge;
578 			lastinvent.MaxX = w->Width;
579 			lastinvent.MaxY = w->Height;
580 		    }
581 		    else if( win == WIN_MESSAGE )
582 		    {
583 			lastmsg.MinX = w->LeftEdge;
584 			lastmsg.MinY = w->TopEdge;
585 			lastmsg.MaxX = w->Width;
586 			lastmsg.MaxY = w->Height;
587 		    }
588 
589 		    /* Find the gadget */
590 
591 		    for( gd = w->FirstGadget; gd && gd->GadgetID != 1; )
592 			gd = gd->NextGadget;
593 
594 		    if( !gd )
595 			panic("Can't find scroll gadget" );
596 
597 		    totalvis = CountLines( win );
598 		    wheight = ( w->Height - w->BorderTop -
599 						w->BorderBottom - 2) / txh;
600 		    if( WINVERS_AMIV )
601 		    {
602 			if( win == WIN_INVEN )
603 			{
604 			    cw->cols = ( w->Width - w->BorderLeft -
605 					w->BorderRight - 4 - pictdata.xsize - 3) / txwd;
606 			}
607 			else
608 			    cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd;
609 		    }
610 		    else
611 		    {
612 			cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd;
613 		    }
614 
615 		    if( wheight < 2 )
616 			wheight = 2;
617 
618 		    /*
619 		     * Clear the right side & bottom. Parts of letters are not erased by
620 		     * amii_cl_end if window shrinks and columns decrease.
621 		     */
622 
623 		    if ( WINVERS_AMII || WINVERS_AMIV ) {
624 			amii_setfillpens(w, cw->type);
625 			SetDrMd(w->RPort, JAM2);
626 			x2 = w->Width - w->BorderRight;
627 			y2 = w->Height - w->BorderBottom;
628 			x1 = x2 - w->IFont->tf_XSize - w->IFont->tf_XSize;
629 			y1 = w->BorderTop;
630 			if (x1 < w->BorderLeft)
631 			    x1 = w->BorderLeft;
632 			RectFill(w->RPort, x1, y1, x2, y2);
633 			x1 = w->BorderLeft;
634 			y1 = y1 - w->IFont->tf_YSize;
635 			RectFill(w->RPort, x1, y1, x2, y2);
636 			RefreshWindowFrame(w);
637 		    }
638 
639 		    /* Make the prop gadget the right size and place */
640 
641 		    DisplayData( win, topidx );
642 		    SetPropInfo( w, gd, wheight, totalvis, topidx );
643 
644 		    /* Force the window to a text line boundary <= to
645 		     * what the user dragged it to.  This eliminates
646 		     * having to clean things up on the bottom edge.
647 		     */
648 
649 		    SizeWindow( w, 0, ( wheight * txh) +
650 			    w->BorderTop + w->BorderBottom + 2 - w->Height );
651 
652 		    /* Don't do next NEWSIZE, we caused it */
653 		    dosize = 0;
654 		    oldsecs = oldmics = 0;
655 		    break;
656 
657 		case VANILLAKEY:
658 #define CTRL(x)     ((x)-'@')
659 		    morc = code = map_menu_cmd(code);
660 		    if (code == MENU_SELECT_ALL) {
661 			if (how == PICK_ANY) {
662 			    amip = cw->menu.items;
663 			    while (amip) {
664 				if (amip->canselect) {
665 				/*
666 				 * Select those yet unselected
667 				 * and apply count if necessary
668 				 */
669 				    if (!amip->selected) {
670 					amip->selected = TRUE;
671 					if (counting) {
672 					    amip->count = count;
673 					    reset_counting = TRUE;
674 					/*
675 					 * This makes the assumption that
676 					 * the string is in format "X - foo"
677 					 * with additional selecting and formatting
678 					 * data in front (size SOFF)
679 					 */
680 					    amip->str[SOFF+2] = '#';
681 					} else {
682 					    amip->count = -1;
683 					    amip->str[SOFF+2] = '-';
684 					}
685 				    }
686 				}
687 				amip=amip->next;
688 			    }
689 			    DisplayData(win, topidx);
690 			}
691 		    } else if (code == MENU_UNSELECT_ALL) {
692 			if (how == PICK_ANY) {
693 			    amip = cw->menu.items;
694 			    while (amip) {
695 				if (amip->canselect) {
696 				    amip->selected = FALSE;
697 				    amip->count = -1;
698 				    amip->str[SOFF+2] = '-';
699 				}
700 				amip=amip->next;
701 			    }
702 			    DisplayData(win, topidx);
703 			}
704 		    } else if (code == MENU_INVERT_ALL) {
705 			if (how == PICK_ANY) {
706 			    amip = cw->menu.items;
707 			    while (amip) {
708 				if (amip->canselect) {
709 				    amip->selected = !amip->selected;
710 				    if (counting && amip->selected) {
711 					amip->count = count;
712 					amip->str[SOFF+2] = '#';
713 					reset_counting = TRUE;
714 				    } else {
715 					amip->count = -1;
716 					amip->str[SOFF+2] = '-';
717 				    }
718 				}
719 				amip=amip->next;
720 			    }
721 			    DisplayData(win, topidx);
722 			}
723 		    } else if (code == MENU_SELECT_PAGE) {
724 			if (how == PICK_ANY) {
725 			    int i = 0;
726 			    amip = cw->menu.items;
727 			    while (amip && i++ < topidx)
728 				amip = amip->next;
729 			    for (i=0;i < wheight && amip; i++, amip=amip->next) {
730 				if (amip->canselect) {
731 				    if (!amip->selected) {
732 					if (counting) {
733 					    amip->count = count;
734 					    reset_counting = TRUE;
735 					    amip->str[SOFF+2] = '#';
736 					} else {
737 					    amip->count = -1;
738 					    amip->str[SOFF+2] = '-';
739 					}
740 				    }
741 	 			    amip->selected = TRUE;
742 				}
743 			    }
744 			    DisplayData(win, topidx);
745 			}
746 		    } else if (code == MENU_UNSELECT_PAGE) {
747 			if (how == PICK_ANY) {
748 			    int i = 0;
749 			    amip = cw->menu.items;
750 			    while (amip && i++ < topidx)
751 				amip = amip->next;
752 			    for (i=0;i < wheight && amip; i++, amip=amip->next) {
753 				if (amip->canselect) {
754 				    amip->selected = FALSE;
755 				    amip->count = -1;
756 				    amip->str[SOFF+2] = '-';
757 				}
758 			    }
759 			    DisplayData(win, topidx);
760 			}
761 		    } else if (code == MENU_INVERT_PAGE) {
762 			if (how == PICK_ANY) {
763 			    int i = 0;
764 			    amip = cw->menu.items;
765 			    while (amip && i++ < topidx)
766 				amip = amip->next;
767 			    for (i=0;i < wheight && amip; i++, amip=amip->next) {
768 				if (amip->canselect) {
769 				    amip->selected = !amip->selected;
770 				    if (counting && amip->selected) {
771 					amip->count = count;
772 					amip->str[SOFF+2] = '#';
773 					reset_counting = TRUE;
774 				    } else {
775 					amip->count = -1;
776 					amip->str[SOFF+2] = '-';
777 				    }
778 				}
779 			    }
780 			    DisplayData(win, topidx);
781 			}
782 		    } else if (code == MENU_SEARCH && cw->type == NHW_MENU) {
783 			if (how == PICK_ONE || how == PICK_ANY) {
784 			    char buf[BUFSZ];
785 			    amip = cw->menu.items;
786 			    amii_getlin("Search for:", buf);
787 			    if (!*buf || *buf == '\033')
788 				break;
789 			    while (amip) {
790 				if (amip->canselect && amip->str &&
791 				    strstri(&amip->str[SOFF], buf)) {
792 				    if (how == PICK_ONE) {
793 					amip->selected = TRUE;
794 					aredone = 1;
795 					break;
796 				    }
797 				    amip->selected = !amip->selected;
798 				    if (counting && amip->selected) {
799 					amip->count = count;
800 					reset_counting = TRUE;
801 					amip->str[SOFF+2] = '#';
802 				    } else {
803 					amip->count = -1;
804 					reset_counting = TRUE;
805 					amip->str[SOFF+2] = '-';
806 				    }
807 				}
808 				amip = amip->next;
809 			    }
810 			}
811 			DisplayData(win, topidx);
812 		    } else if (how == PICK_ANY && isdigit(code) &&
813 			       (counting || (!counting && code !='0'))) {
814 			if (count < LARGEST_INT) {
815 			    count = count*10 + (long)(code-'0');
816 			    if (count > LARGEST_INT)
817 				count = LARGEST_INT;
818 			    if (count > 0) {
819 				counting = TRUE;
820 				reset_counting = FALSE;
821 			    } else {
822 				reset_counting = TRUE;
823 			    }
824 			    sprintf(countString, "Count: %d", count);
825 			    pline(countString);
826 			}
827 		    } else if( code == CTRL('D') || code == CTRL('U') ||
828 			       code == MENU_NEXT_PAGE || code == MENU_PREVIOUS_PAGE ||
829 			       code == MENU_FIRST_PAGE || code == MENU_LAST_PAGE )
830 		    {
831 			int endcnt, i;
832 
833 			for( gd = w->FirstGadget; gd && gd->GadgetID != 1; )
834 			    gd = gd->NextGadget;
835 
836 			if( !gd )
837 			    panic("Can't find scroll gadget" );
838 
839 			endcnt = wheight; /* /2; */
840 			if( endcnt == 0 )
841 			    endcnt = 1;
842 
843 			if (code == MENU_FIRST_PAGE) {
844 			    topidx = 0;
845 			} else if (code == MENU_LAST_PAGE) {
846 			    topidx = cw->maxrow - wheight;
847 			} else for( i = 0; i < endcnt; ++i )
848 			{
849 			    if (code == CTRL('D') || code == MENU_NEXT_PAGE)
850 			    {
851 				if( topidx + wheight < cw->maxrow )
852 				    ++topidx;
853 				else
854 				    break;
855 			    }
856 			    else if (code = CTRL('U') || code == MENU_PREVIOUS_PAGE)
857 			    {
858 				if( topidx > 0 )
859 				    --topidx;
860 				else
861 				    break;
862 			    }
863 			}
864 			/* Make prop gadget the right size and place */
865 
866 			DisplayData( win, topidx );
867 			SetPropInfo( w,gd, wheight, totalvis, topidx );
868 			oldsecs = oldmics = 0;
869 		    }
870 		    else if( code == '\b' )
871 		    {
872 			for( gd = w->FirstGadget; gd && gd->GadgetID != 1; )
873 			    gd = gd->NextGadget;
874 
875 			if( !gd )
876 			    panic("Can't find scroll gadget" );
877 
878 			if( topidx - wheight - 2 < 0 )
879 			{
880 			    topidx = 0;
881 			}
882 			else
883 			{
884 			    topidx -= wheight - 2;
885 			}
886 			DisplayData( win, topidx );
887 			SetPropInfo( w, gd, wheight, totalvis, topidx );
888 			oldsecs = oldmics = 0;
889 		    }
890 		    else if( code == ' ' )
891 		    {
892 			for( gd = w->FirstGadget; gd && gd->GadgetID != 1; )
893 			    gd = gd->NextGadget;
894 
895 			if( !gd )
896 			    panic("Can't find scroll gadget" );
897 
898 			if( topidx + wheight >= cw->maxrow )
899 			{
900 			    morc = 0;
901 			    aredone = 1;
902 			}
903 			else
904 			{
905 			    /*  If there are still lines to be seen */
906 
907 			    if( cw->maxrow > topidx + wheight )
908 			    {
909 				if( wheight > 2 )
910 				    topidx += wheight - 2;
911 				else
912 				    ++topidx;
913 				DisplayData( win, topidx );
914 				SetPropInfo( w, gd, wheight,
915 						    totalvis, topidx );
916 			    }
917 			    oldsecs = oldmics = 0;
918 			}
919 		    }
920 		    else if( code == '\n' || code == '\r' )
921 		    {
922 			for( gd = w->FirstGadget; gd && gd->GadgetID != 1; )
923 			    gd = gd->NextGadget;
924 
925 			if( !gd )
926 			    panic("Can't find scroll gadget" );
927 
928 			/* If all line displayed, we are done */
929 
930 			if( topidx + wheight >= cw->maxrow )
931 			{
932 			    morc = 0;
933 			    aredone = 1;
934 			}
935 			else
936 			{
937 			    /*  If there are still lines to be seen */
938 
939 			    if( cw->maxrow > topidx + 1 )
940 			    {
941 				++topidx;
942 				DisplayData( win, topidx );
943 				SetPropInfo( w, gd, wheight,
944 						    totalvis, topidx );
945 			    }
946 			    oldsecs = oldmics = 0;
947 			}
948 		    }
949 		    else if( code == '\33' )
950 		    {
951 			if (counting) {
952 			    reset_counting = TRUE;
953 			} else {
954 			    aredone = 1;
955 			}
956 		    }
957 		    else
958 		    {
959 			int selected = FALSE;
960 			for( amip = cw->menu.items; amip; amip = amip->next )
961 			{
962 			    if( amip->selector == code )
963 			    {
964 				if( how == PICK_ONE )
965 				    aredone = 1;
966 				amip->selected = !amip->selected;
967 				if (counting && amip->selected) {
968 				    amip->count = count;
969 				    reset_counting = TRUE;
970 				    amip->str[SOFF+2] = '#';
971 				} else {
972 				    amip->count = -1;
973 				    reset_counting = TRUE;
974 				    amip->str[SOFF+2] = '-';
975 				}
976 				selected = TRUE;
977 			    } else if (amip->gselector == code )
978 			    {
979 				amip->selected = !amip->selected;
980 				if (counting) {
981 				    amip->count = count;
982 				    reset_counting = TRUE;
983 				    amip->str[SOFF+2] = '#';
984 				} else {
985 				    amip->count = -1;
986 				    reset_counting = TRUE;
987 				    amip->str[SOFF+2] = '-';
988 				}
989 				selected = TRUE;
990 			    }
991 			}
992 			if (selected)
993 			    DisplayData( win, topidx );
994 		    }
995 		    break;
996 
997 		case CLOSEWINDOW:
998 		    if( win == WIN_INVEN )
999 		    {
1000 			lastinvent.MinX = w->LeftEdge;
1001 			lastinvent.MinY = w->TopEdge;
1002 			lastinvent.MaxX = w->Width;
1003 			lastinvent.MaxY = w->Height;
1004 		    }
1005 		    else if( win == WIN_MESSAGE )
1006 		    {
1007 			lastmsg.MinX = w->LeftEdge;
1008 			lastmsg.MinY = w->TopEdge;
1009 			lastmsg.MaxX = w->Width;
1010 			lastmsg.MaxY = w->Height;
1011 		    }
1012 		    aredone = 1;
1013 		    morc = '\33';
1014 		    break;
1015 
1016 		case GADGETUP:
1017 		    if( win == WIN_MESSAGE )
1018 			aredone = 1;
1019 		    for( gd = w->FirstGadget; gd && gd->GadgetID != 1; )
1020 			gd = gd->NextGadget;
1021 
1022 		    pip = (struct PropInfo *)gd->SpecialInfo;
1023 		    totalvis = CountLines( win );
1024 		    hidden = max( totalvis - wheight, 0 );
1025 		    aidx = (((ULONG)hidden * pip->VertPot) + (MAXPOT/2)) >> 16;
1026 		    if( aidx != topidx )
1027 			DisplayData( win, topidx = aidx );
1028 		    break;
1029 
1030 		case MOUSEMOVE:
1031 		    for( gd = w->FirstGadget; gd && gd->GadgetID != 1; )
1032 			gd = gd->NextGadget;
1033 
1034 		    pip = (struct PropInfo *)gd->SpecialInfo;
1035 		    totalvis = CountLines( win );
1036 		    hidden = max( totalvis - wheight, 0 );
1037 		    aidx = (((ULONG)hidden * pip->VertPot) + (MAXPOT/2)) >> 16;
1038 		    if( aidx != topidx )
1039 			DisplayData( win, topidx = aidx );
1040 		    break;
1041 
1042 		case INACTIVEWINDOW:
1043 		    if( win == WIN_MESSAGE || ( win == WIN_INVEN && alwaysinvent ) )
1044 			aredone = 1;
1045 		    break;
1046 
1047 		case MOUSEBUTTONS:
1048 		    if( ( code == SELECTUP || code == SELECTDOWN ) &&
1049 					cw->type == NHW_MENU && how != PICK_NONE )
1050 		    {
1051 			/* Which one is the mouse pointing at? */
1052 
1053 			aidx = ( ( my - w->BorderTop - 1 ) / txh ) + topidx;
1054 
1055 			/* If different lines, don't select double click */
1056 
1057 			if( aidx != oidx )
1058 			{
1059 			    oldsecs = 0;
1060 			    oldmics = 0;
1061 			}
1062 
1063 			/* If releasing, check for double click */
1064 
1065 			if( code == SELECTUP )
1066 			{
1067 			    amip = find_menu_item( cw, aidx );
1068 			    if( aidx == oidx )
1069 			    {
1070 				if( DoubleClick( oldsecs,
1071 						    oldmics, secs, mics ) )
1072 				{
1073 				    aredone = 1;
1074 				}
1075 				oldsecs = secs;
1076 				oldmics = mics;
1077 			    }
1078 			    else
1079 			    {
1080 				amip = find_menu_item( cw, oidx );
1081 				amip->selected = 0;
1082 				amip->count = -1;
1083 				reset_counting = TRUE;
1084 				if (amip->canselect)
1085 				    amip->str[SOFF+2] = '-';
1086 			    }
1087 			    if (counting && amip->selected && amip->canselect) {
1088 				amip->count = count;
1089 				reset_counting = TRUE;
1090 				amip->str[SOFF+2] = '#';
1091 			    }
1092 			    DisplayData( win, topidx );
1093 			}
1094 			else if( aidx - topidx < wheight &&
1095 				aidx < cw->maxrow && code == SELECTDOWN )
1096 			{
1097 			    /* Remove old highlighting if visible */
1098 
1099 			    amip = find_menu_item( cw, oidx );
1100 			    if( amip && oidx != aidx &&
1101 				    ( oidx > topidx && oidx - topidx < wheight ) )
1102 			    {
1103 				if( how != PICK_ANY ) {
1104 				    amip->selected = 0;
1105 				    amip->count = -1;
1106 				    reset_counting = TRUE;
1107 				    if (amip->canselect)
1108 					amip->str[SOFF+2] = '-';
1109 				}
1110 				oidx = -1;
1111 			    }
1112 			    amip = find_menu_item( cw, aidx );
1113 
1114 			    if( amip && amip->canselect && how != PICK_NONE )
1115 			    {
1116 				oidx = aidx;
1117 				if( !DoubleClick( oldsecs,
1118 						    oldmics, secs, mics ) )
1119 				{
1120 				    amip->selected = !amip->selected;
1121 				    if (counting && amip->selected) {
1122 					amip->count = count;
1123 					reset_counting = TRUE;
1124 					amip->str[SOFF+2] = '#';
1125 				    } else {
1126 					amip->count = -1;
1127 					reset_counting = TRUE;
1128 					if (amip->canselect)
1129 					    amip->str[SOFF+2] = '-';
1130 				    }
1131 				}
1132 			    }
1133 			    else
1134 			    {
1135 				DisplayBeep( NULL );
1136 				oldsecs = 0;
1137 				oldmics = 0;
1138 			    }
1139 			    DisplayData( win, topidx );
1140 			}
1141 		    }
1142 		    else
1143 		    {
1144 			DisplayBeep( NULL );
1145 		    }
1146 		    break;
1147 	    }
1148 	    if (reset_counting) {
1149 		count = 0;
1150 		if (counting)
1151 		    pline("Count: 0");
1152 		counting = FALSE;
1153 	    }
1154 	}
1155     }
1156     /* Force a cursor reposition before next message output */
1157     if( win == WIN_MESSAGE )
1158 	cw->curx = -1;
1159     return( make_menu_items( cw, retmip ) );
1160 }
1161 
1162 void
ReDisplayData(win)1163 ReDisplayData( win )
1164     winid win;
1165 {
1166     int totalvis;
1167     register struct amii_WinDesc *cw;
1168     register struct Window *w;
1169     register struct Gadget *gd;
1170     unsigned long hidden, aidx, wheight;
1171     struct PropInfo *pip;
1172 
1173     if( win == WIN_ERR || !(cw = amii_wins[win]) || !( w = cw->win ) )
1174 	return;
1175 
1176     for( gd = w->FirstGadget; gd && gd->GadgetID != 1; )
1177 	gd = gd->NextGadget;
1178 
1179     if( !gd )
1180 	return;
1181 
1182     wheight = (w->Height - w->BorderTop - w->BorderBottom-2)/w->RPort->TxHeight;
1183 
1184     pip = (struct PropInfo *)gd->SpecialInfo;
1185     totalvis = CountLines( win );
1186     hidden = max( totalvis - wheight, 0 );
1187     aidx = (((ULONG)hidden * pip->VertPot) + (MAXPOT/2)) >> 16;
1188     clear_nhwindow( win );
1189     DisplayData( win, aidx );
1190 }
1191 
1192 long
FindLine(win,line)1193 FindLine( win, line )
1194     winid win;
1195     int line;
1196 {
1197     int txwd;
1198     register char *t;
1199     register struct amii_WinDesc *cw;
1200     register struct Window *w;
1201     register int i, disprow, len;
1202     int col = -1;
1203 
1204     if( win == WIN_ERR || !(cw = amii_wins[win]) || !( w = cw->win ) )
1205     {
1206 	panic( winpanicstr, win, "No Window in FindLine" );
1207     }
1208     txwd = w->RPort->TxWidth;
1209     if( WINVERS_AMIV )
1210     {
1211 	if( win == WIN_INVEN )
1212 	{
1213 	    cw->cols = ( w->Width - w->BorderLeft -
1214 			w->BorderRight - 4 - pictdata.xsize - 3) / txwd;
1215 	}
1216 	else
1217 	    cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd;
1218     }
1219     else
1220     {
1221 	cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd;
1222     }
1223 
1224     disprow = 0;
1225     for( col = i = 0; line > disprow && i < cw->maxrow; ++i )
1226     {
1227 	t = cw->data[ i ] + SOFF;
1228 	if( cw->data[i][1] >= 0 )
1229 	{
1230 	    ++disprow;
1231 	    col = 0;
1232 	}
1233 
1234 	while( *t )
1235 	{
1236 	    len = strlen( t );
1237 	    if( col + len > cw->cols )
1238 		len = cw->cols - col;
1239 	    while( len > 0 )
1240 	    {
1241 	    	if( !t[len] || t[len] == ' ' )
1242 		    break;
1243 	    	--len;
1244 	    }
1245 	    if( len == 0 ) {
1246 		while ( *t && *t != ' ') {
1247 		    t++; col++;
1248 		}
1249 	    } else {
1250 		t += len;
1251 		col += len;
1252 	    }
1253 	    if( *t )
1254 	    {
1255 		while( *t == ' ' )
1256 		    ++t;
1257 		col = 0;
1258 		++disprow;
1259 	    }
1260 	}
1261     }
1262     return( i );
1263 }
1264 
1265 long
CountLines(win)1266 CountLines( win )
1267     winid win;
1268 {
1269     int txwd;
1270     amii_menu_item *mip;
1271     register char *t;
1272     register struct amii_WinDesc *cw;
1273     register struct Window *w;
1274     register int i, disprow, len;
1275     int col = -1;
1276 
1277     if( win == WIN_ERR || !(cw = amii_wins[win]) || !( w = cw->win ) )
1278     {
1279 	panic( winpanicstr, win, "No Window in CountLines" );
1280     }
1281 
1282     txwd = w->RPort->TxWidth;
1283     if( WINVERS_AMIV )
1284     {
1285 	if( win == WIN_INVEN )
1286 	{
1287 	    cw->cols = ( w->Width - w->BorderLeft -
1288 			w->BorderRight - 4 - pictdata.xsize - 3) / txwd;
1289 	}
1290 	else
1291 	    cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd;
1292     }
1293     else
1294     {
1295 	cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd;
1296     }
1297 
1298     disprow = cw->maxrow;
1299     mip = cw->menu.items;
1300     for( col = i = 0; i < cw->maxrow; ++i )
1301     {
1302 	t = cw->data[ i ] + SOFF;
1303 	if( cw->type == NHW_MESSAGE && cw->data[ i ][ SEL_ITEM ] < 0 )
1304 	    --disprow;
1305 	else
1306 	    col = 0;
1307 	while( *t )
1308 	{
1309 	    len = strlen( t );
1310 	    if( col + len > cw->cols )
1311 		len = cw->cols - col;
1312 	    while( len > 0 )
1313 	    {
1314 	    	if( !t[len] || t[len] == ' ' )
1315 		    break;
1316 	    	--len;
1317 	    }
1318 	    if( len == 0 ) {
1319 		while ( *t && *t != ' ') {
1320 		    t++; col++;
1321 		}
1322 	    } else {
1323 		t += len;
1324 		col += len;
1325 	    }
1326 	    if( *t )
1327 	    {
1328 		while( *t == ' ' )
1329 		    ++t;
1330 		col = 0;
1331 		++disprow;
1332 	    }
1333 	}
1334     }
1335     return( disprow );
1336 }
1337 
1338 void
DisplayData(win,start)1339 DisplayData( win, start )
1340     winid win;
1341     int start;
1342 {
1343     int txwd;
1344     amii_menu_item *mip;
1345     register char *t;
1346     register struct amii_WinDesc *cw;
1347     register struct Window *w;
1348     register struct RastPort *rp;
1349     register int i, disprow, len, wheight;
1350     int whichcolor = -1;
1351     int col;
1352 
1353     if( win == WIN_ERR || !(cw = amii_wins[win]) || !( w = cw->win ) )
1354     {
1355 	panic( winpanicstr, win, "No Window in DisplayData" );
1356     }
1357 
1358     rp = w->RPort;
1359     SetDrMd( rp, JAM2 );
1360     if( WINVERS_AMIV && win == WIN_INVEN )
1361     {
1362 	wheight = ( w->Height - w->BorderTop - w->BorderBottom - 2 ) /
1363 		    max( rp->TxHeight, pictdata.ysize + 3 );
1364     }
1365     else
1366     {
1367 	wheight = ( w->Height - w->BorderTop - w->BorderBottom - 2 ) /
1368 		    rp->TxHeight;
1369     }
1370 
1371     cw->rows = wheight;
1372     txwd = rp->TxWidth;
1373     if( WINVERS_AMIV )
1374     {
1375 	if( win == WIN_INVEN )
1376 	{
1377 	    cw->cols = ( w->Width - w->BorderLeft -
1378 			w->BorderRight - 4 - pictdata.xsize - 3) / txwd;
1379 	}
1380 	else
1381 	    cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd;
1382     }
1383     else
1384     {
1385 	cw->cols = ( w->Width - w->BorderLeft - w->BorderRight - 4 ) / txwd;
1386     }
1387 
1388     /* Get the real line to display at */
1389     start = FindLine( win, start );
1390 
1391     mip = cw->menu.items;
1392     for( i = 0; mip && i < start; ++i )
1393     {
1394 	mip = mip->next;
1395     }
1396 
1397     /* Skip any initial response to a previous line */
1398     if( cw->type == NHW_MESSAGE && mip && mip->selected < 0 )
1399 	++start;
1400     if( WINVERS_AMIV && cw->type == NHW_MESSAGE )
1401 	SetAPen( rp, amii_msgAPen );
1402 
1403     for( disprow = i = start; disprow < wheight + start; i++ )
1404     {
1405 	/* Just erase unused lines in the window */
1406     	if( i >= cw->maxrow )
1407     	{
1408 	    if (WINVERS_AMIV && win == WIN_INVEN) {
1409 		amii_curs( win, 0, disprow - start );
1410 		amiga_print_glyph( win, 0, NO_GLYPH);
1411 	    }
1412 	    amii_curs( win, 1, disprow - start );
1413 	    amii_cl_end( cw, 0 );
1414 	    ++disprow;
1415 	    continue;
1416     	}
1417 
1418 	/* Any string with a highlighted attribute goes
1419 	 * onto the end of the current line in the message window.
1420 	 */
1421 	if( cw->type == NHW_MESSAGE )
1422 	    SetAPen( rp, cw->data[ i ][ SEL_ITEM ] < 0 ? C_RED : amii_msgAPen );
1423 
1424 	/* Selected text in the message window goes onto the end of the current line */
1425 	if( cw->type != NHW_MESSAGE || cw->data[ i ][ SEL_ITEM ] >= 0 )
1426 	{
1427 	    amii_curs( win, 1, disprow - start );
1428 	    if( WINVERS_AMIV && win == WIN_INVEN )
1429 	    {
1430 		if( mip )
1431 		    amiga_print_glyph( win, 0, mip->glyph );
1432 		amii_curs( win, 1, disprow - start );
1433 	    }
1434 	    col = 0;
1435 	}
1436 
1437 	/* If this entry is to be highlighted, do so */
1438 	if( mip && mip->selected != 0 )
1439 	{
1440 	    if( whichcolor != 1 )
1441 	    {
1442 		SetDrMd( rp, JAM2 );
1443 		if( WINVERS_AMIV )
1444 		{
1445 		    SetAPen( rp, amii_menuBPen );
1446 		    SetBPen( rp, C_BLUE );
1447 		}
1448 		else
1449 		{
1450 		    SetAPen( rp, C_BLUE );
1451 		    SetBPen( rp, amii_menuAPen );
1452 		}
1453 		whichcolor = 1;
1454 	    }
1455 	}
1456 	else if( whichcolor != 2 )
1457 	{
1458 	    SetDrMd( rp, JAM2 );
1459 	    if( cw->type == NHW_MESSAGE )
1460 	    {
1461 		SetAPen( rp, amii_msgAPen );
1462 		SetBPen( rp, amii_msgBPen );
1463 	    }
1464 	    else if( cw->type == NHW_MENU )
1465 	    {
1466 		SetAPen( rp, amii_menuAPen );
1467 		SetBPen( rp, amii_menuBPen );
1468 	    }
1469 	    else if( cw->type == NHW_TEXT )
1470 	    {
1471 		SetAPen( rp, amii_textAPen );
1472 		SetBPen( rp, amii_textBPen );
1473 	    }
1474 	    whichcolor = 2;
1475 	}
1476 
1477 	/* Next line out, wrap if too long */
1478 
1479 	t = cw->data[ i ] + SOFF;
1480 	++disprow;
1481 	col = 0;
1482 	while( *t )
1483 	{
1484 	    len = strlen( t );
1485 	    if( len > (cw->cols - col) )
1486 		len = cw->cols - col;
1487 	    while( len > 0 )
1488 	    {
1489 	    	if( !t[len] || t[len] == ' ' )
1490 		    break;
1491 	    	--len;
1492 	    }
1493 	    if( len == 0 ) {
1494 		Text( rp, t, cw->cols - col );
1495 		while ( *t && *t != ' ') {
1496 		    t++; col++;
1497 		}
1498 	    } else {
1499 		Text( rp, t, len );
1500 		t += len;
1501 		col += len;
1502 	    }
1503 	    amii_cl_end( cw, col );
1504 	    if( *t )
1505 	    {
1506 		++disprow;
1507 		/* Stop at the bottom of the window */
1508 		if( disprow > wheight + start )
1509 		    break;
1510 		while( *t == ' ' )
1511 		    ++t;
1512 		amii_curs( win, 1, disprow - start - 1 );
1513 		if( mip && win == WIN_INVEN && WINVERS_AMIV )
1514 		{
1515 		    /* Erase any previous glyph drawn here. */
1516 		    amiga_print_glyph( win, 0, NO_GLYPH );
1517 		    amii_curs( win, 1, disprow - start - 1 );
1518 		}
1519 		Text( rp, "+", 1 );
1520 		col = 1;
1521 	    }
1522 	}
1523 
1524 	if( cw->type == NHW_MESSAGE )
1525 	{
1526 	    SetAPen( rp, amii_msgBPen );
1527 	    SetBPen( rp, amii_msgBPen );
1528 	}
1529 	else if( cw->type == NHW_MENU )
1530 	{
1531 	    SetAPen( rp, amii_menuBPen );
1532 	    SetBPen( rp, amii_menuBPen );
1533 	}
1534 	else if( cw->type == NHW_TEXT )
1535 	{
1536 	    SetAPen( rp, amii_textBPen );
1537 	    SetBPen( rp, amii_textBPen );
1538 	}
1539  	amii_cl_end( cw, col );
1540 	whichcolor = -1;
1541 	if( mip ) mip = mip->next;
1542     }
1543     RefreshWindowFrame(w);
1544     return;
1545 }
1546 
SetPropInfo(win,gad,vis,total,top)1547 void SetPropInfo( win, gad, vis, total, top )
1548     register struct Window *win;
1549     register struct Gadget *gad;
1550     register long vis, total, top;
1551 {
1552     long mflags;
1553     register long hidden;
1554     register int body, pot;
1555 
1556     hidden = max( total-vis, 0 );
1557 
1558     /* Force the last section to be just to the bottom */
1559 
1560     if( top > hidden )
1561 	top = hidden;
1562 
1563     /* Scale the body position. */
1564     /* 2 lines overlap */
1565 
1566     if( hidden > 0 && total > 2)
1567 	body = (ULONG) ((vis - 2) * MAXBODY) / (total - 2);
1568     else
1569 	body = MAXBODY;
1570 
1571     if( hidden > 0 )
1572 	pot = (ULONG) (top * MAXPOT) / hidden;
1573     else
1574 	pot = 0;
1575 
1576     mflags = AUTOKNOB|FREEVERT;
1577 #ifdef  INTUI_NEW_LOOK
1578     if( IntuitionBase->LibNode.lib_Version >= 37 )
1579     {
1580 	mflags |= PROPNEWLOOK;
1581     }
1582 #endif
1583 
1584     NewModifyProp( gad, win, NULL,
1585 			    mflags, 0, pot, MAXBODY, body, 1 );
1586 }
1587