Some applications require notification of changes to data on the
clipboard. Typically, these applications will need to do some processing
when this occurs. You can set up such an environment through the
cbd_changehook command. cbd_changehook allows you to specify a hook to be
called when the data on the clipboard changes.
For example, a show clipboard utility would need to know when the data on
the clipboard is changed so that it can display the new data. The hook it
would specify would read the new clipboard data and display it for the
user.
You specify a hook for the clipboard device by initializing a Hook
structure and then passing an IOClipReq to the device with cbd_changehook
set in io_Command, 1 set in io_Length, and the address of the Hook
structure set in io_Data.
ULONG HookEntry (); /* Declare the hook assembly function */
struct IOClipReq *ClipIO; /* Declare the IOClipReq */
struct Hook *ClipHook; /* Declare the Hook */
/* Prepare the hook */
ClipHook->h_Entry = HookEntry; /* C intrfce in asmbly rout. HookEntry*/
ClipHook->h_SubEntry = HookFunc;/* Call function when Hook activated */
ClipHook->h_Data = FindTask(NULL);/* Set pointer to current task */
ClipIO->io_Data = (char *) ClipHook;/* Point to hook struct */
ClipIO->io_Length = 1; /* Add hook to clipboard */
ClipIO->io_Command = CBD_CHANGEHOOK;
DoIO(clipIO);
The above code fragment assumes that an assembly language routine
HookEntry() has been coded:
; entry interface for C code
_HookEntry:
move.l a1,-(sp) ; push message packet pointer
move.l a2,-(sp) ; push object pointer
move.l a0,-(sp) ; push hook pointer
move.l h_SubEntry(a0),a0 ; fetch C entry point ...
jsr (a0) ; ... and call it
lea 12(sp),sp ; fix stack
rts
It also assumes that the function HookFunc() has been coded. One of the
example programs at the end of this chapter has hook processing in it.
See the include file utility/hooks.h and the amiga rom kernel reference
Manual: libraries for further information on hooks.
You remove a hook by passing an ioclipreq to the device with the address
of the Hook structure set in io_Data, 0 set in io_Length and
cbd_changehook set in io_command.
ClipIO->io_Data = (char *) ClipHook; /* point to hook struct */
ClipIO->io_Length = 0; /* Remove hook from clipboard */
ClipIO->io_Command = CBD_CHANGEHOOK;
(DoIO (clipIO))
You must remove the hook or it will continue indefinitely.
caveats for cbd_changehook