home *** CD-ROM | disk | FTP | other *** search
/ Kyūkyoku!! X68000 Emulator / X68000Book.dat / mac / OLS / X68000 / Ko-Window / kow142s.lzh / parts / popup.c < prev    next >
C/C++ Source or Header  |  1995-08-09  |  2KB  |  97 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #include "wlib.h"
  5. #include "winop.h"
  6.  
  7. /*
  8.     proto -s popup.c > temp
  9. */
  10. static    int        PopUpExec( WindowID, EventInfo* );
  11.  
  12. static    char    **PopUpItem ;
  13. static    int        PopUpItems ;
  14. static    int        PopUpFont ;
  15. static    int        ReturnCode ;
  16.  
  17. static    int        PopUpExec( wp, info )
  18. WindowID    wp ;
  19. EventInfo    *info ;
  20. {
  21.     if( info->option == EventRedraw ){
  22.             int        i,    h, v ;
  23.             DrawBuf    dbuf[44], *dp= dbuf;
  24.             WindowGetViewSize( wp, &h, &v );
  25.             DrawSetClear( dp++, 1 );
  26.             for( i = 0 ; i < PopUpItems ; ++i )
  27.                 DrawSetSymbol( dp++, 4, PopUpFont*i, PopUpItem[i], AttrDefault, PopUpFont );
  28.             i= PopUpFont * ReturnCode ;
  29.             DrawSetLine( dp++, 0, i, h-1, i+PopUpFont-1, 1+OptionXor, OptionFill );
  30.             WindowDraw( wp, dbuf, dp-dbuf );
  31.     }
  32.     return    TRUE;
  33. }
  34.  
  35. static
  36. X_strlen( ptr )
  37. char    *ptr;
  38. {
  39.     int    i= 0;
  40.     for(; *ptr++ ; i++ );
  41.     return    i;
  42. }
  43.  
  44. int        PopUpMenu( x, y, item, items, font )
  45. int        x, y ;
  46. char    **item ;
  47. int        items, font ;
  48. {
  49.     int            h, sx, sy;
  50.     WindowID    wp;
  51.     EventInfo    info;
  52.  
  53.     PopUpItem= item;
  54.     PopUpItems= items;
  55.     PopUpFont= font;
  56.  
  57.     {
  58.         int        n, i;
  59.         for( i= h= 0 ; i < items ; i++ ){
  60.             if( (n= X_strlen( *item++ )) >= h )
  61.                 h= n;
  62.         }
  63.         h= h*font/2+8;
  64.     }
  65.  
  66.     wp= WindowSimpleOpen( x, y, h, items*font, NULL, PopUpExec );
  67.     WindowGetScreenPosition( wp, &sx, &sy );
  68.  
  69.     WindowGetEventInfo( &info );
  70.     ReturnCode= (info.y-sy) / font;
  71.     if( info.y-sy < 0 || ReturnCode >= items )
  72.         ReturnCode= -2;
  73.  
  74.     WindowRedraw( wp );
  75.     info.LeftStat= info.RightStat= TRUE;
  76.  
  77.     do{
  78.         if( WindowGetEventInfo( &info ) ){
  79.             int        new= (info.y-= sy) / font;
  80.             if( info.y < 0 || new >= PopUpItems )
  81.                 new= -2;
  82.             if( ReturnCode != new ){
  83.                 DrawBuf        dbuf[2] ;
  84.                 DrawSetLine( dbuf, 0, PopUpFont*new, h-1,
  85.                     PopUpFont*new+PopUpFont-1, 1|OptionXor, OptionFill );
  86.                 DrawSetLine( dbuf+1, 0, PopUpFont*ReturnCode, h-1,
  87.                     PopUpFont*ReturnCode+PopUpFont-1, 1|OptionXor, OptionFill);
  88.                 WindowDraw( wp, dbuf, 2 );
  89.                 ReturnCode= new;
  90.             }
  91.         }
  92.     }while( info.LeftStat || info.RightStat );
  93.     WindowClose( wp );
  94.     return    ReturnCode;
  95. }
  96.  
  97.