home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / code / p_popupm.sit < prev    next >
Encoding:
Text File  |  1988-06-20  |  3.0 KB  |  135 lines

  1. 18-Jun-88 14:37:50-MDT,3191;000000000000
  2. Return-Path: <u-lchoqu%sunset@cs.utah.edu>
  3. Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:37:44 MDT
  4. Received: by cs.utah.edu (5.54/utah-2.0-cs)
  5.     id AA22530; Sat, 18 Jun 88 14:37:45 MDT
  6. Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
  7.     id AA24715; Sat, 18 Jun 88 14:37:42 MDT
  8. Date: Sat, 18 Jun 88 14:37:42 MDT
  9. From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
  10. Message-Id: <8806182037.AA24715@sunset.utah.edu>
  11. To: rthum@simtel20.arpa
  12. Subject: PopupMenu-XCMD.p
  13.  
  14. {$R-          }
  15. {$S PopUpMenu }
  16.  
  17.  
  18. { PopUpMenu( MenuItems, CheckedItem, Top, Left );
  19.  
  20.     This HyperCard external function returns the selection from a popup
  21.     menu created from a hypercard item list (the first parameter).  The
  22.     menu is placed on the screen so that the checked item is at the 
  23.     position (global) top,left.
  24.  
  25.     To compile and link using Macintosh Programmer's Workshop    2.0 execute
  26.     the following:
  27.     
  28.         pascal -w PopUp.p
  29.         link -o HyperCommands -rt XFCN=0 -sn Main=PopUpMenu PopUp.p.o
  30.  
  31.     I wish to thank Dewi Williams and Larry Rosenstein for thier initial
  32.     information and example.
  33.  
  34.     Andrew Gilmartin
  35.     Brown University
  36. }
  37.  
  38.  
  39. unit PopUpUnit;
  40.  
  41.     interface
  42.     
  43.         uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
  44.         
  45.         procedure EntryPoint( paramPtr: XCmdPtr );
  46.         
  47.     implementation
  48.     
  49.         procedure PopUpMenu( paramPtr: XCmdPtr ); forward;
  50.     
  51.         
  52.         procedure EntryPoint( paramPtr: XCmdPtr );
  53.         begin
  54.             PopUpMenu( paramPtr )
  55.         end{ entrypoint };
  56.         
  57.         
  58.         procedure PopUpMenu;
  59.         
  60.             const MenuID = 128;
  61.             
  62.             var    Menu                : MenuHandle;
  63.                     MenuItems        : Str255;
  64.                     CheckedItem    ,
  65.                     SelectedItem,
  66.                     Top                    ,
  67.                     Left                : LongInt;
  68.  
  69.  
  70.             {$I XCmdGlue.inc}
  71.  
  72.  
  73.             procedure ParamToMenuItems( Param: Handle; var MenuItems: Str255 );
  74.                 var Index: integer;
  75.             begin
  76.                         
  77.                 ZeroToPas( Param^, MenuItems );
  78.                     
  79.                 for Index := 1 to length( MenuItems )
  80.                     do
  81.                         if MenuItems[ Index ] = ',' then
  82.                             MenuItems[ Index ] := ';';
  83.  
  84.             end{ ParamToMenuItems };
  85.             
  86.             
  87.             function ParamToNum( Param: Handle ): LongInt;
  88.                 var Str: Str255;
  89.             begin
  90.                 ZeroToPas( Param^, Str );
  91.                 ParamToNum := StrToNum( Str );
  92.             end{ ParamToNum };
  93.             
  94.             
  95.             function NumToParam( Num: LongInt ): Handle;
  96.                 var Str: Str31;
  97.             begin
  98.                     Str                 := NumToStr( Num );
  99.                     NumToParam    := PasToZero( Str )
  100.             end{ NumToParam };
  101.             
  102.             
  103.         begin
  104.         
  105.             with paramPtr^ do
  106.                 begin
  107.  
  108.                     { Create the PopUp menu }
  109.                     ParamToMenuItems( Params[1], MenuItems ); 
  110.                     CheckedItem := ParamToNum( Params[2] );
  111.                     Menu := NewMenu( MenuID, '' );
  112.                     AppendMenu( Menu, MenuItems );
  113.                     CheckItem( Menu, CheckedItem, true );
  114.                     InsertMenu( Menu, -1 );
  115.                     
  116.                     { Get Menu Position }
  117.                     Top  := ParamToNum( Params[3] );
  118.                     Left := ParamToNum( Params[4] );
  119.  
  120.                     { Get Menu Selection }
  121.                     SelectedItem := PopUpMenuSelect( Menu, Top, Left, CheckedItem );
  122.                     
  123.                     { Tidy up }
  124.                     DeleteMenu( MenuID );
  125.                     DisposeMenu( Menu );
  126.                     
  127.                     { Return the selection }
  128.                     returnValue := NumToParam( LoWord( SelectedItem ) )
  129.                     
  130.                 end    
  131.                 
  132.         end{ PopUpMenu };
  133.         
  134. end.{ PopUp Unit }
  135.