home *** CD-ROM | disk | FTP | other *** search
- /*
- WinManager Example - by Andrea Galimberti - (C)Brighting Brain Brothers
-
- This example exploits the winmanager object to open two windows, the
- first of which is a superbitmap window: the winmanager object takes care to
- add two proportional gadgets to the superbitmap window and allows the user
- to scroll the superbitmap using the two gadgets. Besides, three idcmp
- handling procedures are added to both windows: when the user clicks inside
- a window or presses a key then the procedure linked to that event is called
- producing a small output that tells the user what happened.
-
- */
-
- MODULE 'afc/winmanager',
- 'afc/resourceTracker',
- 'afc/bitmapper',
- 'afc/explain_exception',
- 'intuition/intuition'
-
-
- /* There follows three idcmp handling procedure that will be linked to the
- two windows opened in the main() procedure (see the addProc() calls in
- main()). They take only a parameter: a taglist containing the fields of
- the IntuiMessage arrived at the winmanager userport */
-
- /* This procedure is called when an IDCMP_CLOSEWINDOW message arrives */
- PROC clickclose(tags=NIL:PTR TO LONG)
- DEF t,v,wm=NIL:PTR TO winmanager
-
- -> cycle to read all the tags
- IF tags
- WHILE (t:=Long(tags++))
- v:=Long(tags++)
- SELECT t
- CASE WINM_MSG_WINMGR ->get the pointer to the winmanager object
- wm:=v ->that called the procedure
- ENDSELECT
- ENDWHILE
- ENDIF
-
- ->get (and print) the name of the window being closed
- /* Note that the winmanager's list of windows is already positioned on
- the window that generated the IntuiMessage (and thus indirectly called
- this procedure), so the getattr() method returns the name of the correct
- window */
- WriteF('Closing window:\s\n',wm.getattr(WINM_WTAG_NAME))
-
- /* Note the exit value: if the procedure is called by the parseSignals()
- method, then a value of TRUE tells the winmanager object to close the
- window */
- ENDPROC TRUE
-
- /* This procedure is called when an IDCMP_MOUSEBUTTONS message arrives */
- PROC clickmouse(tags=NIL:PTR TO LONG)
- DEF t=0,v,x,y, wm:PTR TO winmanager
-
- IF tags
- WHILE (t:=Long(tags++))
- v:=Long(tags++)
- SELECT t
- CASE WINM_MSG_MOUSEX -> get mouse x coordinate
- x:=v
- CASE WINM_MSG_MOUSEY -> get mouse y coordinate
- y:=v
- CASE WINM_MSG_WINMGR -> get the pointer to the calling winmanager
- wm:=v
- ENDSELECT
- ENDWHILE
- ENDIF
-
- -> Write the mouse coordinates and the name of the window
- /* Note that the coordinates returned are relative to the top-left
- corner of the bitmap (and not of the window: the winmanager object
- automatically takes into account the scrolling offset of a superbitmap
- window)*/
- WriteF('Mousebuttons at x:\d, y:\d OF window:\s\n',x,y,wm.getattr(WINM_WTAG_NAME))
-
- /* Return FALSE: parseSignals() doesn't close the window */
- ENDPROC FALSE
-
- /* This procedure is called when an IDCMP_VANILLAKEY message arrives */
- PROC gotkey(tags=NIL:PTR TO LONG)
- DEF t=0,v,k, wm=NIL:PTR TO winmanager
-
- IF tags
- WHILE (t:=Long(tags++))
- v:=Long(tags++)
- SELECT t
- CASE WINM_MSG_CODE -> get the ascii code of key pressed
- k:=v
- CASE WINM_MSG_WINMGR -> get the pointer to the calling winmanager
- wm:=v
- ENDSELECT
- ENDWHILE
- ENDIF
-
- -> output key and window name
- WriteF('Vanillakey:\d OF window:\s\n',k,wm.getattr(WINM_WTAG_NAME))
- ENDPROC FALSE
-
-
- /**** main procedure *****/
-
- PROC main() HANDLE
- DEF wm:PTR TO winmanager, rt:PTR TO resourceTracker
- DEF bm:PTR TO bitmapper, rp
-
- /* Initialisation of three objects: resourceTracker to keep track of our
- resources; the main winmanager object; a bitmapper object used to
- allocate a bitmap */
-
- NEW rt.resourceTracker()
- NEW wm.winmanager(rt)
- NEW bm.bitmapper(rt)
-
- /* Here we add some _default_ idcmp handling procedures: they will be linked
- to all subsequently opened windows (idcmp handling procedures are added as
- default procedures if the first parameter of addProc() is set to NIL;
- otherwise you can specify a particular window to add the procedure to).*/
-
- -> when an IDCMP_CLOSEWINDOW message arrives then call the "clickclose"
- -> procedure
- wm.addProc(NIL,[WINM_PROC_IDCMP,IDCMP_CLOSEWINDOW,
- WINM_PROC_CODE, {clickclose}, NIL,NIL])
-
- -> when an IDCMP_MOUSEBUTTONS message arrives then call the "clickmouse"
- -> procedure
- wm.addProc(NIL,[WINM_PROC_IDCMP,IDCMP_MOUSEBUTTONS,
- WINM_PROC_CODE, {clickmouse}, NIL,NIL])
-
- -> when an IDCMP_VANILLAKEY message arrives then call the "gotkey"
- -> procedure
- wm.addProc(NIL,[WINM_PROC_IDCMP,IDCMP_VANILLAKEY,
- WINM_PROC_CODE, {gotkey}, NIL,NIL])
-
- /* These are the window default attributes: they will be applied to every
- subsequently opened window */
- wm.setattrs([WINM_WDEF_TOP,10,
- WINM_WDEF_LEFT,10,
- WINM_WDEF_WIDTH,300,
- WINM_WDEF_HEIGHT,200,
- WINM_WDEF_MAXWIDTH,800,
- WINM_WDEF_MAXHEIGHT,300,
- WINM_WDEF_MINWIDTH,50,
- WINM_WDEF_MINHEIGHT,50,
- NIL,NIL])
-
- /* We allocate the bitmap to be used in the first (superbitmap) window */
- bm.allocbitmap(550,200,4)
-
- /* Add the first window (named "foo"): the (super)bitmap will be taken
- from the bitmapper object. Besides, two proportional gadgets must be added
- to the window borders, one horizontal (WINM_PROPG_HORIZ) and the other
- vertical (WINM_PROPG_VERT), and their movements must be automatically used
- to scroll the superbitmap (WINM_PROPG_BITMAP).
- Note that if you resize the window, then the knobs of the two proportional
- gadgets will be resized to account for the new dimension of the visible
- part of the superbitmap */
- wm.add('foo',[WINM_WTAG_BITMAPPER,bm,
- WINM_WTAG_PROPGADS, WINM_PROPG_HORIZ OR WINM_PROPG_VERT OR WINM_PROPG_BITMAP,
- NIL,NIL])
-
- /* Add the second window (named "bar") overriding the default
- WINM_WTAG_LEFT attribute */
- wm.add('bar',[WINM_WTAG_LEFT,320,
- NIL,NIL])
-
- /* Open all added windows */
- wm.open(NIL,WINM_MODE_ALL)
-
- /* Search for the window named "foo" */
- wm.search('foo',WINM_SEARCH_NAME)
- /* Get its rastport... */
- rp:=wm.getattr(WINM_WTAG_RASTPORT)
- /* ... to draw a line in its bitmap */
- Move(rp,250,50)
- Draw(rp,350,100)
-
- /* Just wait for all signals coming from the two windows: if a procedure
- is linked to the class of the arriving message (see the addProc() methods
- above) then call that procedure passing it a taglist containing the fields
- of the Intuimessage just arrived. Exit only when all windows have been
- closed */
- wm.parseSignals()
-
- EXCEPT DO
- /* Remember to END all allocated objects */
- IF wm THEN END wm
- IF bm THEN END bm
- IF rt THEN END rt ->this MUST be the last OBJECT TO be ENDed
-
- /* If something went wrong, tell me what it was */
- explain_exception()
- ENDPROC
-
-