home *** CD-ROM | disk | FTP | other *** search
/ CLIX - Fazer Clix Custa Nix / CLIX-CD.cdr / mac / lib / Mac / Events.xs < prev    next >
Text File  |  1998-04-05  |  4KB  |  241 lines

  1. /* $Header: /home/neeri/MacCVS/MacPerl/perl/ext/Mac/Events/Events.xs,v 1.2 1997/11/18 00:52:17 neeri Exp $
  2.  *
  3.  *    Copyright (c) 1996 Matthias Neeracher
  4.  *
  5.  *    You may distribute under the terms of the Perl Artistic License,
  6.  *    as specified in the README file.
  7.  *
  8.  * $Log: Events.xs,v $
  9.  * Revision 1.2  1997/11/18 00:52:17  neeri
  10.  * MacPerl 5.1.5
  11.  *
  12.  * Revision 1.1  1997/04/07 20:49:28  neeri
  13.  * Synchronized with MacPerl 5.1.4a1
  14.  *
  15.  */
  16.  
  17. #define MAC_CONTEXT
  18.  
  19. #include "EXTERN.h"
  20. #include "perl.h"
  21. #include "XSUB.h"
  22. #include <Types.h>
  23. #include <Memory.h>
  24. #include <Events.h>
  25.  
  26. typedef EventRecord * ToolboxEvent;
  27.  
  28. static void WipeFilter(void)
  29. {
  30.     gFilterEvent= nil;
  31.     gFilterMenu = nil;
  32. }
  33.  
  34. static void FilterEvent(ToolboxEvent ev)
  35. {
  36.     AV *  events = perl_get_av("Mac::Events::Event", 2);
  37.     SV ** handler= av_fetch(events, ev->what, 0);
  38.     
  39.     if (handler && SvTRUE(*handler)) {
  40.         int count ;
  41.         SV *result;
  42.         dSP ;
  43.  
  44.         ENTER ;
  45.         SAVETMPS;
  46.  
  47.         PUSHMARK(sp) ;
  48.         XPUSHs(sv_setref_pv(sv_newmortal(), "ToolboxEvent", (void*)ev));
  49.         PUTBACK ;
  50.  
  51.         count = perl_call_pv("Mac::Events::DispatchEvent", G_SCALAR);
  52.  
  53.         SPAGAIN ;
  54.  
  55.         result = POPs;
  56.         if (SvTRUE(result))
  57.             ev->what = nullEvent;
  58.  
  59.         PUTBACK ;
  60.         FREETMPS ;
  61.         LEAVE ;
  62.     }
  63. }
  64.  
  65. MODULE = Mac::Events    PACKAGE = ToolboxEvent
  66.  
  67. BOOT:
  68. gFilterEvent= FilterEvent;
  69. atexit(WipeFilter);
  70.  
  71. =head2 Structures
  72.  
  73. =over 4
  74.  
  75. =item ToolboxEvent
  76.  
  77. This type represents an Event record with the following fields:
  78.  
  79. =over 4
  80.  
  81. =item what
  82.     
  83. Event type.
  84.  
  85. =item message
  86.  
  87. Event message.
  88.  
  89. =item when
  90.  
  91. Event time.
  92.  
  93. =item where
  94.  
  95. Mouse position in global coordinates.
  96.  
  97. =item modifiers
  98.  
  99. Global flags.
  100.  
  101. =back
  102.  
  103. Additionally, a few read only accessors are provided to conveniently access the 
  104. event specific meaning of the C<message> field:
  105.  
  106. =over 4
  107.  
  108. =item window
  109.  
  110. The affected window for activate and update events.
  111.  
  112. =item character
  113.  
  114. The character code for C<keyDown>, C<keyUp>, and C<autoKey> events.
  115.  
  116. =item key
  117.  
  118. The key code for C<keyDown>, C<keyUp>, and C<autoKey> events.
  119.  
  120. =item osMessage
  121.  
  122. The subevent for suspend, resume, and mouse-moved events.
  123.  
  124. =back
  125.  
  126. =back
  127.  
  128. =cut
  129. STRUCT * ToolboxEvent
  130.     short           what;
  131.     U32             message;
  132.     U32             when;
  133.     Point           where;
  134.     U16             modifiers;
  135.     GrafPtr         window;
  136.         READ_ONLY
  137.         OUTPUT:
  138.         XS_OUTPUT(GrafPtr, (GrafPtr)STRUCT->message, $arg);
  139.     U8              character;
  140.         READ_ONLY
  141.         OUTPUT:
  142.         XS_OUTPUT(U8, STRUCT->message & 0xFF, $arg);
  143.     U8              key;
  144.         READ_ONLY
  145.         OUTPUT:
  146.         XS_OUTPUT(U8, (STRUCT->message>>8) & 0xFF, $arg);
  147.     U8              osMessage;
  148.         READ_ONLY
  149.         OUTPUT:
  150.         XS_OUTPUT(U8, (STRUCT->message>>24) & 0xFF, $arg);
  151.  
  152. MODULE = Mac::Events    PACKAGE = Mac::Events
  153.  
  154. =head2 Functions
  155.  
  156. =over 4
  157.  
  158. =item GetCaretTime()
  159.  
  160. Returns interval for caret blinking.
  161.  
  162. =cut
  163. long
  164. GetCaretTime()
  165.  
  166. =item GetDblTime()
  167.  
  168. Returns double-click interval.
  169.  
  170. =cut
  171. long
  172. GetDblTime()
  173.     
  174. =item GetMouse()
  175.  
  176. Returns the current mouse position.
  177.  
  178. =cut
  179. Point
  180. GetMouse()
  181.     CODE:
  182.     GetMouse(&RETVAL);
  183.     OUTPUT:
  184.     RETVAL
  185.  
  186. =item Button()
  187.  
  188. Returns the current state of the mouse button.
  189.  
  190. =cut
  191. Boolean
  192. Button()
  193.  
  194. =item DOWN = StillDown()
  195.  
  196. Returns whether the button is still down after the last C<mouseDown> event 
  197. processed.
  198.  
  199. =cut
  200. Boolean
  201. StillDown()
  202.         
  203. =item UP = WaitMouseUp()
  204.  
  205. Wait until the mouse button is released.
  206.  
  207. =cut
  208. Boolean
  209. WaitMouseUp()
  210.         
  211. =item TICKS = TickCount()
  212.  
  213. Returns the current time in 60th of a second since startup.
  214.  
  215. =cut
  216. long
  217. TickCount()
  218.         
  219. =item FlushEvents WHICHMASK, STOPMASK
  220.  
  221. Discard events matching WHICHMASK until an event matching STOPMASK is found.
  222.  
  223. =cut
  224. void
  225. FlushEvents(whichMask, stopMask)
  226.     short   whichMask
  227.     short   stopMask
  228.  
  229. =item WaitNextEvent [SLEEP [, RGN] ]
  230.  
  231. Waits for the next event but doesn't return anything. Event processing is purely
  232. implicit.
  233.  
  234. =cut
  235. void
  236. WaitNextEvent(sleep=-1, rgn=nil)
  237.     long        sleep
  238.     RgnHandle   rgn
  239.     CODE:
  240.     (*gWaitEvent)(false, sleep, rgn);
  241.