home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / dev / e / amigae / rkrmsrc / intuition / intuition_gui / easyintuition37.e < prev   
Text File  |  1995-03-26  |  4KB  |  104 lines

  1. -> easyintuition37.e -- Simple Intuition program for V37 (Release 2) and later
  2. -> versions of the operating system
  3.  
  4. -> Use lowest non-obsolete version that supplies the functions needed
  5. OPT OSVERSION=37
  6.  
  7. -> E-Note: you need to be more specific about modules than C does about includes
  8. MODULE 'intuition/intuition',  -> Intuition and window data structures and tags
  9.        'intuition/screens',    -> Screen data structures and tags
  10.        'graphics/modeid',      -> Release 2 Amiga display mode ID's
  11.        'dos/dos'               -> Official return codes defined here
  12.  
  13. -> Position and sizes for our window
  14. CONST WIN_LEFTEDGE=20, WIN_TOPEDGE=20,
  15.       WIN_WIDTH=400,   WIN_MINWIDTH=80,
  16.       WIN_HEIGHT=150,  WIN_MINHEIGHT=20
  17.  
  18. -> Exception values
  19. -> E-Note: exceptions are a much better way of handling errors
  20. ENUM ERR_NONE, ERR_SCRN, ERR_WIN
  21.  
  22. -> Automatically raise exceptions
  23. -> E-Note: these take care of a lot of error cases
  24. RAISE ERR_SCRN IF OpenScreenTagList()=NIL,
  25.       ERR_WIN  IF OpenWindowTagList()=NIL
  26.  
  27. PROC main() HANDLE
  28.   -> Declare variables here
  29.   -> E-Note: the signals stuff is handled directly by WaitIMessage
  30.   DEF screen1=NIL:PTR TO screen, window1=NIL:PTR TO window
  31.  
  32.   -> E-Note: E automatically opens the Intuition library
  33.  
  34.   -> Open the screen
  35.   -> E-Note: automatically error-checked (automatic exception)
  36.   -> E-Note: pens is just a INT-typed list
  37.   screen1:=OpenScreenTagList(NIL,
  38.                              [SA_PENS, [-1]:INT,
  39.                               SA_DISPLAYID, HIRES_KEY,
  40.                               SA_DEPTH, 2,
  41.                               SA_TITLE, 'Our Screen',
  42.                               NIL])
  43.  
  44.   -> ... and open the window
  45.   -> E-Note: automatically error-checked (automatic exception)
  46.   window1:=OpenWindowTagList(NIL,
  47.                              -> Specify window dimensions and limits
  48.                             [WA_LEFT,      WIN_LEFTEDGE,
  49.                              WA_TOP,       WIN_TOPEDGE,
  50.                              WA_WIDTH,     WIN_WIDTH,
  51.                              WA_HEIGHT,    WIN_HEIGHT,
  52.                              WA_MINWIDTH,  WIN_MINWIDTH,
  53.                              WA_MINHEIGHT, WIN_MINHEIGHT,
  54.                              WA_MAXWIDTH,  -1,
  55.                              WA_MAXHEIGHT, -1,
  56.                              -> Specify the system gadgets we want
  57.                              WA_CLOSEGADGET, TRUE,
  58.                              WA_SIZEGADGET,  TRUE,
  59.                              WA_DEPTHGADGET, TRUE,
  60.                              WA_DRAGBAR,     TRUE,
  61.                              -> Specify other attributes
  62.                              WA_ACTIVATE,      TRUE,
  63.                              WA_NOCAREREFRESH, TRUE,
  64.  
  65.                              -> Specify the events we want to know about
  66.                              WA_IDCMP, IDCMP_CLOSEWINDOW,
  67.  
  68.                              -> Attach the window to the open screen ...
  69.                              WA_CUSTOMSCREEN, screen1,
  70.                              WA_TITLE,      'EasyWindow',
  71.                              WA_SCREENTITLE,'Our Screen - EasyWindow is Active',
  72.                              NIL])
  73.  
  74.   -> Here's the main input event loop
  75.   -> E-Note: the signals and stuff is handled by WaitIMessage
  76.   REPEAT
  77.   UNTIL handleIDCMP(window1)
  78.  
  79.   -> E-Note: exit and clean up via handler
  80. EXCEPT DO
  81.   IF window1 THEN CloseWindow(window1)
  82.   IF screen1 THEN CloseScreen(screen1)
  83.   -> E-Note: we can print a minimal error message
  84.   SELECT exception
  85.   CASE ERR_SCRN; WriteF('Error: Failed to open custom screen\n')
  86.   CASE ERR_WIN;  WriteF('Error: Failed to open window\n')
  87.   ENDSELECT
  88. -> E-Note: select return code according to exception
  89. ENDPROC IF exception THEN RETURN_WARN ELSE RETURN_OK
  90.  
  91. PROC handleIDCMP(win:PTR TO window)
  92.   DEF class, done=FALSE
  93.   -> E-Note: WaitIMessage replaces a lot of C code concerned with signals
  94.   class:=WaitIMessage(win)
  95.   -> E-Note: other parts of the message are available via MsgXXX() functions
  96.  
  97.   -> See what events occurred
  98.   SELECT class
  99.   CASE IDCMP_CLOSEWINDOW
  100.     done:=TRUE
  101.   ENDSELECT
  102. ENDPROC done
  103.  
  104.