home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 106 / EnigmaAmiga106CD.iso / www / afc / afc-dir / winmanager_examples.lha / Examples / WinManager_Example.e < prev   
Text File  |  1999-01-10  |  7KB  |  196 lines

  1. /*
  2.   WinManager Example - by Andrea Galimberti - (C)Brighting Brain Brothers
  3.  
  4.   This example exploits the winmanager object to open two windows, the
  5. first of which is a superbitmap window: the winmanager object takes care to
  6. add two proportional gadgets to the superbitmap window and allows the user
  7. to scroll the superbitmap using the two gadgets. Besides, three idcmp
  8. handling procedures are added to both windows: when the user clicks inside
  9. a window or presses a key then the procedure linked to that event is called
  10. producing a small output that tells the user what happened.
  11.  
  12. */
  13.  
  14. MODULE 'afc/winmanager',
  15.        'afc/resourceTracker',
  16.        'afc/bitmapper',
  17.        'afc/explain_exception',
  18.        'intuition/intuition'
  19.  
  20.  
  21. /* There follows three idcmp handling procedure that will be linked to the
  22. two windows opened in the main() procedure (see the addProc() calls in
  23. main()). They take only a parameter: a taglist containing the fields of
  24. the IntuiMessage arrived at the winmanager userport */
  25.  
  26. /* This procedure is called when an IDCMP_CLOSEWINDOW message arrives */
  27. PROC clickclose(tags=NIL:PTR TO LONG)
  28.   DEF t,v,wm=NIL:PTR TO winmanager
  29.  
  30.   -> cycle to read all the tags
  31.   IF tags
  32.     WHILE (t:=Long(tags++))
  33.       v:=Long(tags++)
  34.       SELECT t
  35.         CASE WINM_MSG_WINMGR  ->get the pointer to the winmanager object
  36.           wm:=v               ->that called the procedure
  37.       ENDSELECT
  38.     ENDWHILE
  39.   ENDIF
  40.  
  41.   ->get (and print) the name of the window being closed
  42.   /* Note that the winmanager's list of windows is already positioned on
  43. the window that generated the IntuiMessage (and thus indirectly called
  44. this procedure), so the getattr() method returns the name of the correct
  45. window */
  46.   WriteF('Closing window:\s\n',wm.getattr(WINM_WTAG_NAME))
  47.  
  48.   /* Note the exit value: if the procedure is called by the parseSignals()
  49. method, then a value of TRUE tells the winmanager object to close the
  50. window */
  51. ENDPROC TRUE
  52.  
  53. /* This procedure is called when an IDCMP_MOUSEBUTTONS message arrives */
  54. PROC clickmouse(tags=NIL:PTR TO LONG)
  55.   DEF t=0,v,x,y, wm:PTR TO winmanager
  56.  
  57.   IF tags
  58.     WHILE (t:=Long(tags++))
  59.       v:=Long(tags++)
  60.       SELECT t
  61.         CASE WINM_MSG_MOUSEX  -> get mouse x coordinate
  62.           x:=v
  63.         CASE WINM_MSG_MOUSEY  -> get mouse y coordinate
  64.           y:=v
  65.         CASE WINM_MSG_WINMGR  -> get the pointer to the calling winmanager
  66.           wm:=v
  67.       ENDSELECT
  68.     ENDWHILE
  69.   ENDIF
  70.  
  71.   -> Write the mouse coordinates and the name of the window
  72.   /* Note that the coordinates returned are relative to the top-left
  73. corner of the bitmap (and not of the window: the winmanager object
  74. automatically takes into account the scrolling offset of a superbitmap
  75. window)*/
  76.   WriteF('Mousebuttons at x:\d, y:\d OF window:\s\n',x,y,wm.getattr(WINM_WTAG_NAME))
  77.  
  78.   /* Return FALSE: parseSignals() doesn't close the window */
  79. ENDPROC FALSE
  80.  
  81. /* This procedure is called when an IDCMP_VANILLAKEY message arrives */
  82. PROC gotkey(tags=NIL:PTR TO LONG)
  83.   DEF t=0,v,k, wm=NIL:PTR TO winmanager
  84.  
  85.   IF tags
  86.     WHILE (t:=Long(tags++))
  87.       v:=Long(tags++)
  88.       SELECT t
  89.         CASE WINM_MSG_CODE     -> get the ascii code of key pressed
  90.           k:=v
  91.         CASE WINM_MSG_WINMGR   -> get the pointer to the calling winmanager
  92.           wm:=v
  93.       ENDSELECT
  94.     ENDWHILE
  95.   ENDIF
  96.  
  97.   -> output key and window name
  98.   WriteF('Vanillakey:\d OF window:\s\n',k,wm.getattr(WINM_WTAG_NAME))
  99. ENDPROC FALSE
  100.  
  101.  
  102. /**** main procedure *****/
  103.  
  104. PROC main() HANDLE
  105.   DEF wm:PTR TO winmanager, rt:PTR TO resourceTracker
  106.   DEF bm:PTR TO bitmapper, rp
  107.  
  108. /* Initialisation of three objects: resourceTracker to keep track of our
  109.    resources; the main winmanager object; a bitmapper object used to
  110.    allocate a bitmap */
  111.  
  112.   NEW rt.resourceTracker()
  113.   NEW wm.winmanager(rt)
  114.   NEW bm.bitmapper(rt)
  115.  
  116. /* Here we add some _default_ idcmp handling procedures: they will be linked
  117. to all subsequently opened windows (idcmp handling procedures are added as
  118. default procedures if the first parameter of addProc() is set to NIL;
  119. otherwise you can specify a particular window to add the procedure to).*/
  120.  
  121. -> when an IDCMP_CLOSEWINDOW message arrives then call the "clickclose"
  122. -> procedure
  123.   wm.addProc(NIL,[WINM_PROC_IDCMP,IDCMP_CLOSEWINDOW,
  124.                   WINM_PROC_CODE, {clickclose}, NIL,NIL])
  125.  
  126. -> when an IDCMP_MOUSEBUTTONS message arrives then call the "clickmouse"
  127. -> procedure
  128.   wm.addProc(NIL,[WINM_PROC_IDCMP,IDCMP_MOUSEBUTTONS,
  129.                   WINM_PROC_CODE, {clickmouse}, NIL,NIL])
  130.  
  131. -> when an IDCMP_VANILLAKEY message arrives then call the "gotkey"
  132. -> procedure
  133.   wm.addProc(NIL,[WINM_PROC_IDCMP,IDCMP_VANILLAKEY,
  134.                   WINM_PROC_CODE, {gotkey}, NIL,NIL])
  135.  
  136. /* These are the window default attributes: they will be applied to every
  137.    subsequently opened window */
  138.   wm.setattrs([WINM_WDEF_TOP,10,
  139.                WINM_WDEF_LEFT,10,
  140.                WINM_WDEF_WIDTH,300,
  141.                WINM_WDEF_HEIGHT,200,
  142.                WINM_WDEF_MAXWIDTH,800,
  143.                WINM_WDEF_MAXHEIGHT,300,
  144.                WINM_WDEF_MINWIDTH,50,
  145.                WINM_WDEF_MINHEIGHT,50,
  146.                NIL,NIL])
  147.  
  148. /* We allocate the bitmap to be used in the first (superbitmap) window */
  149.   bm.allocbitmap(550,200,4)
  150.  
  151. /* Add the first window (named "foo"): the (super)bitmap will be taken
  152. from the bitmapper object. Besides, two proportional gadgets must be added
  153. to the window borders, one horizontal (WINM_PROPG_HORIZ) and the other
  154. vertical (WINM_PROPG_VERT), and their movements must be automatically used
  155. to scroll the superbitmap (WINM_PROPG_BITMAP).
  156. Note that if you resize the window, then the knobs of the two proportional
  157. gadgets will be resized to account for the new dimension of the visible
  158. part of the superbitmap */
  159.   wm.add('foo',[WINM_WTAG_BITMAPPER,bm,
  160.                 WINM_WTAG_PROPGADS, WINM_PROPG_HORIZ OR WINM_PROPG_VERT OR WINM_PROPG_BITMAP,
  161.                 NIL,NIL])
  162.  
  163. /* Add the second window (named "bar") overriding the default
  164. WINM_WTAG_LEFT attribute */
  165.   wm.add('bar',[WINM_WTAG_LEFT,320,
  166.                 NIL,NIL])
  167.  
  168. /* Open all added windows */
  169.   wm.open(NIL,WINM_MODE_ALL)
  170.  
  171. /* Search for the window named "foo" */
  172.   wm.search('foo',WINM_SEARCH_NAME)
  173. /* Get its rastport... */
  174.   rp:=wm.getattr(WINM_WTAG_RASTPORT)
  175. /* ... to draw a line in its bitmap */
  176.   Move(rp,250,50)
  177.   Draw(rp,350,100)
  178.  
  179. /* Just wait for all signals coming from the two windows: if a procedure
  180. is linked to the class of the arriving message (see the addProc() methods
  181. above) then call that procedure passing it a taglist containing the fields
  182. of the Intuimessage just arrived. Exit only when all windows have been
  183. closed */
  184.   wm.parseSignals()
  185.  
  186. EXCEPT DO
  187. /* Remember to END all allocated objects */
  188.   IF wm THEN END wm
  189.   IF bm THEN END bm
  190.   IF rt THEN END rt  ->this MUST be the last OBJECT TO be ENDed
  191.  
  192. /* If something went wrong, tell me what it was */
  193.   explain_exception()
  194. ENDPROC
  195.  
  196.