home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / amigae / e_v3.2a / rkrmsrc / clipboard / changehook_test.e < prev    next >
Text File  |  1977-12-31  |  2KB  |  102 lines

  1. -> Changehook_Test.e
  2. ->
  3. -> Demonstrate the use of CBD_CHANGEHOOK command.  The program will set a hook
  4. -> and wait for the clipboard data to change.  You must put something in the
  5. -> clipboard in order for it to return.
  6. ->
  7. -> Requires Kickstart 36 or greater.
  8.  
  9. ->>> Header (globals)
  10. MODULE '*cbio',
  11.        'tools/inithook',
  12.        'devices/clipboard',
  13.        'dos/dos',
  14.        'utility/hooks'
  15.  
  16. DEF version=1
  17.  
  18. -> Data to pass around with the clipHook
  19. OBJECT chData
  20.   task
  21.   clipID
  22. ENDOBJECT
  23.  
  24. -> E-Note: clip_port is not actually used...
  25. DEF hook:hook, ch:chData
  26. ->>>
  27.  
  28. ->>> PROC clipHook(h:PTR TO hook, o, msg:PTR TO cliphookmsg)
  29. PROC clipHook(h:PTR TO hook, o, msg:PTR TO cliphookmsg)
  30.   DEF ch:PTR TO chData
  31.   ch:=h.data
  32.   IF ch
  33.     -> Remember the ID of clip
  34.     ch.clipID:=msg.clipid
  35.  
  36.     -> Signal the task that started the hook
  37.     Signal(ch.task, SIGBREAKF_CTRL_E)
  38.   ENDIF
  39. ENDPROC
  40. ->>>
  41.  
  42. ->>> PROC openCB(unit)
  43. PROC openCB(unit)
  44.   DEF clipIO:PTR TO ioclipreq
  45.   -> Open clipboard
  46.   -> E-Note: the C version opens 0 instead of using the parameter!
  47.   clipIO:=cbOpen(unit)
  48.   -> Fill out the IORequest
  49.   clipIO.data:=hook
  50.   clipIO.length:=1
  51.   clipIO.command:=CBD_CHANGEHOOK
  52.  
  53.   -> Set up the hook data
  54.   ch.task:=FindTask(NIL)
  55.  
  56.   -> Prepare the hook
  57.   inithook(hook, {clipHook}, ch)
  58.  
  59.   -> Start the hook
  60.   WriteF(IF DoIO(clipIO) THEN 'Unable to set hook\n' ELSE 'Hook set\n')
  61. ENDPROC clipIO
  62. ->>>
  63.  
  64. ->>> PROC closeCB(clipIO:PTR TO ioclipreq)
  65. PROC closeCB(clipIO:PTR TO ioclipreq)
  66.   -> Fill out the IO request
  67.   clipIO.data:=hook
  68.   clipIO.length:=0
  69.   clipIO.command:=CBD_CHANGEHOOK
  70.  
  71.   -> Stop the hook
  72.   WriteF(IF DoIO(clipIO) THEN 'Unable to stop hook\n' ELSE 'Hook is stopped\n')
  73.  
  74.   cbClose(clipIO)
  75. ENDPROC
  76. ->>>
  77.  
  78. ->>> PROC main()
  79. PROC main() HANDLE
  80.   DEF clipIO=NIL, sig_rcvd
  81.   WriteF('Test v\d\n', version)
  82.  
  83.   clipIO:=openCB(0)
  84.   
  85.   sig_rcvd:=Wait(SIGBREAKF_CTRL_C OR SIGBREAKF_CTRL_E)
  86.  
  87.   IF sig_rcvd AND SIGBREAKF_CTRL_C
  88.     WriteF('^C received\n')
  89.   ENDIF
  90.  
  91.   IF sig_rcvd AND SIGBREAKF_CTRL_E
  92.     WriteF('Clipboard change, current ID is \d\n', ch.clipID)
  93.   ENDIF
  94. EXCEPT DO
  95.   IF clipIO THEN closeCB(clipIO)
  96.   SELECT exception
  97.   CASE "CBOP";  WriteF('Error: could not open clipboard device\n')
  98.   ENDSELECT
  99. ENDPROC
  100. ->>>
  101.  
  102.