home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / dev / e / amigae / rkrmsrc / intuition / gadgets / simplegad.e next >
Text File  |  1995-03-26  |  3KB  |  70 lines

  1. -> simplegad.e - show the use of a button gadget.
  2.  
  3. MODULE 'graphics/rastport',   -> RastPort and other structures
  4.        'intuition/intuition'  -> Intuition data structures and tags
  5.  
  6. CONST BUTTON_GAD_NUM=3, MYBUTTONGADWIDTH=100, MYBUTTONGADHEIGHT=50
  7.  
  8. -> NOTE that the use of constant size and positioning values are not
  9. -> recommended; it just makes it easy to show what is going on. The position
  10. -> of the gadget should be dynamically adjusted depending on the height of the
  11. -> font in the title bar of the window.
  12.  
  13. ENUM ERR_NONE, ERR_WIN, ERR_KICK
  14.  
  15. RAISE ERR_WIN IF OpenWindowTagList()=NIL
  16.  
  17. -> Routine to show the use of a button (boolean) gadget.
  18. PROC main() HANDLE
  19.   DEF win=NIL:PTR TO window, class, gad:PTR TO gadget
  20.   -> Make sure to get version 37, for OpenWindowTags() */
  21.   IF KickVersion(37)=FALSE THEN Raise(ERR_KICK)
  22.  
  23.   -> E-Note: E automatically opens the Intuition library
  24.   -> E-Note: automatically error-checked (automatic exception)
  25.   win:=OpenWindowTagList(NIL,
  26.                         [WA_WIDTH, 400,
  27.                          WA_HEIGHT, 100,
  28.                          WA_GADGETS,  -> E-Note: use typed lists for gadget
  29.                  [NIL, 20, 20, MYBUTTONGADWIDTH, MYBUTTONGADHEIGHT,
  30.                   GFLG_GADGHCOMP, GACT_RELVERIFY OR GACT_IMMEDIATE,
  31.                   GTYP_BOOLGADGET,
  32.                     [-1, -1, 1, 0, RP_JAM1, 5, -> E-Note: Border
  33.                    [0, 0,      -> E-Note: 5 co-ords (INTs)
  34.                     MYBUTTONGADWIDTH+1, 0,
  35.                     MYBUTTONGADWIDTH+1, MYBUTTONGADHEIGHT+1,
  36.                     0, MYBUTTONGADHEIGHT+1,
  37.                     0,0]:INT,
  38.                      NIL]:border,
  39.                   NIL, NIL, 0, NIL, BUTTON_GAD_NUM, NIL]:gadget,
  40.                          WA_ACTIVATE, TRUE,
  41.                          WA_CLOSEGADGET, TRUE,
  42.                          WA_IDCMP, IDCMP_GADGETDOWN OR IDCMP_GADGETUP OR
  43.                                    IDCMP_CLOSEWINDOW,
  44.                          NIL])
  45.   REPEAT
  46.     class:=WaitIMessage(win)
  47.     -> SELECT on the type of the event
  48.     SELECT class
  49.     CASE IDCMP_GADGETUP
  50.       -> Caused by GACT_RELVERIFY
  51.       gad:=MsgIaddr()
  52.       WriteF('Received an IDCMP_GADGETUP , gadget number \d\n', gad.gadgetid)
  53.     CASE IDCMP_GADGETDOWN
  54.       -> Caused by GACT_IMMEDIATE
  55.       gad:=MsgIaddr()
  56.       WriteF('Received an IDCMP_GADGETDOWN , gadget number \d\n', gad.gadgetid)
  57.     ENDSELECT
  58.   UNTIL class=IDCMP_CLOSEWINDOW
  59.   WriteF('Received an IDCMP_CLOSEWINDOW\n')
  60.  
  61.   -> E-Note: exit and clean up via handler
  62. EXCEPT DO
  63.   IF win THEN CloseWindow(win)
  64.   -> E-Note: we can print a minimal error message
  65.   SELECT exception
  66.   CASE ERR_WIN;  WriteF('Error: Failed to open window\n')
  67.   CASE ERR_KICK; WriteF('Error: Needs Kickstart V37+\n')
  68.   CASE "MEM";    WriteF('Error: Ran out of memory\n')
  69.   ENDSELECT
  70. ENDPROC