home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _3af380209b7ea29e0c25c0b7fbf674dc < prev    next >
Encoding:
Text File  |  2004-06-01  |  15.3 KB  |  418 lines

  1. #  Copyright (c) 1996 Sun Microsystems, Inc.
  2. #  See the file "license.terms" for information on usage and redistribution
  3. #  of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  4. #
  5. #
  6.  
  7. =head1 NAME
  8.  
  9. Tk::event - Miscellaneous event facilities: define virtual events and generate events
  10.  
  11. =for category Binding Events and Callbacks
  12.  
  13. =head1 SYNOPSIS
  14.  
  15. I<$widget>-E<gt>B<event>I<Action>(?I<arg, arg, ...>?);
  16.  
  17. =head1 DESCRIPTION
  18.  
  19. The B<event>I<Action> methods provides several facilities for dealing with
  20. window system events, such as defining virtual events and synthesizing
  21. events.  Virtual events are shared by all widgets of the same
  22. B<MainWindow>.  Different L<MainWindow|Tk::MainWindow>s can have different
  23. virtual event.
  24.  
  25. The following methods are currently supported:
  26.  
  27. =over 4
  28.  
  29. =item I<$widget>-E<gt>B<eventAdd>(B<'E<lt>E<lt>>I<virtual>B<E<gt>E<gt>'>I<, sequence >?,I<sequence, ...>?)
  30.  
  31. Associates the virtual event I<virtual> with the physical
  32. event sequence(s) given by the I<sequence> arguments, so that
  33. the virtual event will trigger whenever any one of the I<sequence>s
  34. occurs.
  35. I<Virtual> may be any string value and I<sequence> may have
  36. any of the values allowed for the I<sequence> argument to the
  37. L<bind|Tk::bind> method.
  38. If I<virtual> is already defined, the new physical event sequences
  39. add to the existing sequences for the event.
  40.  
  41. =item I<$widget>-E<gt>B<eventDelete>(B<'E<lt>E<lt>>I<virtual>B<E<gt>E<gt>'> ?,I<sequence,> I<sequence, ...>?)
  42.  
  43. Deletes each of the I<sequence>s from those associated with
  44. the virtual event given by I<virtual>.
  45. I<Virtual> may be any string value and I<sequence> may have
  46. any of the values allowed for the I<sequence> argument to the
  47. L<bind|Tk::bind> method.
  48. Any I<sequence>s not currently associated with I<virtual>
  49. are ignored.
  50. If no I<sequence> argument is provided, all physical event sequences
  51. are removed for I<virtual>, so that the virtual event will not
  52. trigger anymore.
  53.  
  54. =item I<$widget>-E<gt>B<eventGenerate>(I<event> ?,I<option =E<gt> value, option =E<gt> value, ...>?)
  55.  
  56. Generates a window event and arranges for it to be processed just as if
  57. it had come from the window system.
  58. I<$window> is a reference to the window for which the event
  59. will be generated.
  60. I<Event> provides a basic description of
  61. the event, such as B<E<lt>Shift-Button-2E<gt>> or B<E<lt>E<lt>PasteE<gt>E<gt>>.
  62. If I<Window> is empty the whole screen is meant, and coordinates
  63. are relative to the screen.
  64. I<Event> may have any of the forms allowed for the I<sequence>
  65. argument of the L<bind|Tk::bind> method except that it must consist
  66. of a single event pattern, not a sequence.
  67. I<Option-value> pairs may be used to specify additional
  68. attributes of the event, such as the x and y mouse position;
  69. see L<"EVENT FIELDS"> below.  If the B<-when> option is not specified, the
  70. event is processed immediately:  all of the handlers for the event
  71. will complete before the B<eventGenerate> method returns.
  72. If the B<-when> option is specified then it determines when the
  73. event is processed.
  74.  
  75. =item I<$widget>-E<gt>B<eventInfo>(?'B<E<lt>E<lt>>I<virtual>B<E<gt>E<gt>'>?)
  76.  
  77. Returns information about virtual events.
  78. If the B<E<lt>E<lt>>I<virtual>B<E<gt>E<gt>> argument is omitted, the return value
  79. is a list of all the virtual events that are currently defined.
  80. If B<E<lt>E<lt>>I<virtual>B<E<gt>E<gt>> is specified then the return value is
  81. a list whose elements are the physical event sequences currently
  82. defined for the given virtual event;  if the virtual event is
  83. not defined then B<undef> is returned.
  84.  
  85. =back
  86.  
  87. =head1 EVENT FIELDS
  88.  
  89. The following options are supported for the B<eventGenerate>
  90. method.  These correspond to the ``%'' expansions
  91. allowed in binding callback for the L<bind|Tk::bind> method.
  92.  
  93. =over 4
  94.  
  95. =item B<-above> => I<window>
  96.  
  97. I<Window> specifies the I<above> field for the event,
  98. either as a window path name or as an integer window id.
  99. Valid for B<Configure> events.
  100. Corresponds to the L<%a|Tk::bind/'a'> substitution for binding scripts.
  101.  
  102. =item B<-borderwidth> => I<size>
  103.  
  104. I<Size> must be a screen distance;  it specifies the
  105. I<border_width> field for the event.
  106. Valid for B<Configure> events.
  107. Corresponds to the L<%B|Tk::bind/'B'> substitution for binding scripts.
  108.  
  109. =item B<-button> => I<number>
  110.  
  111. I<Number> must be an integer;  it specifies the I<detail> field
  112. for a B<ButtonPress> or B<ButtonRelease> event, overriding
  113. any button  number provided in the base I<event> argument.
  114. Corresponds to the L<%b|Tk::bind/'b'> substitution for binding scripts.
  115.  
  116. =item B<-count> => I<number>
  117.  
  118. I<Number> must be an integer;  it specifies the I<count> field
  119. for the event.  Valid for B<Expose> events.
  120. Corresponds to the L<%c|Tk::bind/'c'> substitution for binding scripts.
  121.  
  122. =item B<-delta> =E<gt> I<number>
  123.  
  124. B<number> must be an integer; it specifies the B<delta> field for the
  125. B<MouseWheel> event.  The delta refers to the direction and magnitude the
  126. mouse wheel was rotated.  Note the value is not a screen distance but
  127. are units of motion in the mouse wheel.  Typically these values are
  128. multiples of 120.  For example, 120 should scroll the text widget up 4
  129. lines and -240 would scroll the text widget down 8 lines.  Of course,
  130. other widgets may define different behaviors for mouse wheel motion.
  131. This field corresponds to the %D substitution for binding scripts.
  132.  
  133. =item B<-detail> => I<detail>
  134.  
  135. I<Detail> specifies the I<detail> field for the event
  136. and must be one of the following:
  137.  
  138. =over 8
  139.  
  140.  NotifyAncestor            NotifyNonlinearVirtual
  141.  NotifyDetailNone       NotifyPointer
  142.  NotifyInferior            NotifyPointerRoot
  143.  NotifyNonlinear        NotifyVirtual
  144.  
  145. =back
  146.  
  147. Valid for B<Enter>, B<Leave>, B<FocusIn> and
  148. B<FocusOut> events.
  149. Corresponds to the L<%d|Tk::bind/'d'> substitution for binding scripts.
  150.  
  151. =item B<-focus>I< boolean>
  152.  
  153. I<Boolean> must be a boolean value;  it specifies the I<focus>
  154. field for the event.
  155. Valid for B<Enter> and B<Leave> events.
  156. Corresponds to the L<%f|Tk::bind/'f'> substitution for binding scripts.
  157.  
  158. =item B<-height>I< size>
  159.  
  160. I<Size> must be a screen distance;  it specifies the I<height>
  161. field for the event.  Valid for B<Configure> events.
  162. Corresponds to the L<%h|Tk::bind/'h'> substitution for binding scripts.
  163.  
  164. =item B<-keycode>I< number>
  165.  
  166. I<Number>  must be an integer;  it specifies the I<keycode>
  167. field for the event.
  168. Valid for B<KeyPress> and B<KeyRelease> events.
  169. Corresponds to the L<%k|Tk::bind/'k'> substitution for binding scripts.
  170.  
  171. =item B<-keysym>I< name>
  172.  
  173. I<Name> must be the name of a valid keysym, such as B<g>,
  174. B<space>, or B<Return>;  its corresponding
  175. keycode value is used as the I<keycode> field for event, overriding
  176. any detail specified in the base I<event> argument.
  177. Valid for B<KeyPress> and B<KeyRelease> events.
  178. Corresponds to the L<%K|Tk::bind/'K'> substitution for binding scripts.
  179.  
  180. =item B<-mode>I< notify>
  181.  
  182. I<Notify> specifies the I<mode> field for the event and must be
  183. one of B<NotifyNormal>, B<NotifyGrab>, B<NotifyUngrab>, or
  184. B<NotifyWhileGrabbed>.
  185. Valid for B<Enter>, B<Leave>, B<FocusIn>, and
  186. B<FocusOut> events.
  187. Corresponds to the L<%m|Tk::bind/'m'> substitution for binding scripts.
  188.  
  189. =item B<-override>I< boolean>
  190.  
  191. I<Boolean> must be a boolean value;  it specifies the
  192. I<override_redirect> field for the event.
  193. Valid for B<Map>, B<Reparent>, and B<Configure> events.
  194. Corresponds to the L<%o|Tk::bind/'o'> substitution for binding scripts.
  195.  
  196. =item B<-place>I< where>
  197.  
  198. I<Where> specifies the I<place> field for the event;  it must be
  199. either B<PlaceOnTop> or B<PlaceOnBottom>.
  200. Valid for B<Circulate> events.
  201. Corresponds to the L<%p|Tk::bind/'p'> substitution for binding scripts.
  202.  
  203. =item B<-root>I< window>
  204.  
  205. I<Window> must be either a window path name or an integer window
  206. identifier;  it specifies the I<root> field for the event.
  207. Valid for B<KeyPress>, B<KeyRelease>, B<ButtonPress>,
  208. B<ButtonRelease>, B<Enter>, B<Leave>, and B<Motion>
  209. events.
  210. Corresponds to the L<%R|Tk::bind/'R'> substitution for binding scripts.
  211.  
  212. =item B<-rootx>I< coord>
  213.  
  214. I<Coord> must be a screen distance;  it specifies the I<x_root>
  215. field for the event.
  216. Valid for B<KeyPress>, B<KeyRelease>, B<ButtonPress>,
  217. B<ButtonRelease>, B<Enter>, B<Leave>, and B<Motion>
  218. events.  Corresponds to the L<%X|Tk::bind/'X'> substitution for binding scripts.
  219.  
  220. =item B<-rooty>I< coord>
  221.  
  222. I<Coord> must be a screen distance;  it specifies the I<y_root>
  223. field for the event.
  224. Valid for B<KeyPress>, B<KeyRelease>, B<ButtonPress>,
  225. B<ButtonRelease>, B<Enter>, B<Leave>, and B<Motion>
  226. events.
  227. Corresponds to the L<%Y|Tk::bind/'Y'> substitution for binding scripts.
  228.  
  229. =item B<-sendevent>I< boolean>
  230.  
  231. B<Boolean> must be a boolean value;  it specifies the I<send_event>
  232. field for the event.  Valid for all events.  Corresponds to the
  233. L<%E|Tk::bind/'E'> substitution for binding scripts.
  234.  
  235. =item B<-serial>I< number>
  236.  
  237. I<Number> must be an integer;  it specifies the I<serial> field
  238. for the event.  Valid for all events.
  239. Corresponds to the L<%#|Tk::bind/'#'> substitution for binding scripts.
  240.  
  241. =item B<-state>I< state>
  242.  
  243. I<State> specifies the I<state> field for the event.
  244. For B<KeyPress>, B<KeyRelease>, B<ButtonPress>,
  245. B<ButtonRelease>, B<Enter>, B<Leave>, and B<Motion> events
  246. it must be an integer value.
  247. For B<Visibility> events it must be one of B<VisibilityUnobscured>,
  248. B<VisibilityPartiallyObscured>, or B<VisibilityFullyObscured>.
  249. This option overrides any modifiers such as B<Meta> or B<Control>
  250. specified in the base I<event>.
  251. Corresponds to the L<%s|Tk::bind/'s'> substitution for binding scripts.
  252.  
  253. =item B<-subwindow>I< window>
  254.  
  255. I<Window> specifies the I<subwindow> field for the event, either
  256. as a path name for a Tk widget or as an integer window identifier.
  257. Valid for B<KeyPress>, B<KeyRelease>, B<ButtonPress>,
  258. B<ButtonRelease>, B<Enter>, B<Leave>, and B<Motion> events.
  259. Similar to L<%S|Tk::bind/'S'> substitution for binding scripts.
  260.  
  261. =item B<-time>I< integer>
  262.  
  263. I<Integer> must be an integer value;  it specifies the I<time> field
  264. for the event.
  265. Valid for B<KeyPress>, B<KeyRelease>, B<ButtonPress>,
  266. B<ButtonRelease>, B<Enter>, B<Leave>, B<Motion>,
  267. and B<Property> events.
  268. Corresponds to the L<%t|Tk::bind/'t'> substitution for binding scripts.
  269.  
  270.  
  271. =item B<-warp>I< boolean>
  272.  
  273. I<boolean> must be a boolean value;  it specifies whether
  274. the screen pointer should be warped as well.
  275. Valid for B<KeyPress>, B<KeyRelease>, B<ButtonPress>,
  276. B<ButtonRelease>, and B<Motion> events.
  277.  
  278. =item B<-width>I< size>
  279.  
  280. I<Size> must be a screen distance;  it specifies the I<width> field
  281. for the event.
  282. Valid for B<Configure> events.
  283. Corresponds to the L<%w|Tk::bind/'w'> substitution for binding scripts.
  284.  
  285. =item B<-when>I< when>
  286.  
  287. I<When> determines when the event will be processed;  it must have one
  288. of the following values:
  289.  
  290. =over 8
  291.  
  292. =item B<now>
  293.  
  294. Process the event immediately, before the command returns.
  295. This also happens if the B<-when> option is omitted.
  296.  
  297. =item B<tail>
  298.  
  299. Place the event on perl/Tk's event queue behind any events already
  300. queued for this application.
  301.  
  302. =item B<head>
  303.  
  304. Place the event at the front of perl/Tk's event queue, so that it
  305. will be handled before any other events already queued.
  306.  
  307. =item B<mark>
  308.  
  309. Place the event at the front of perl/Tk's event queue but behind any
  310. other events already queued with B<-when mark>.
  311. This option is useful when generating a series of events that should
  312. be processed in order but at the front of the queue.
  313.  
  314. =back
  315.  
  316. =item B<-x>I< coord>
  317.  
  318. I<Coord> must be a screen distance;  it specifies the I<x> field
  319. for the event.
  320. Valid for B<KeyPress>, B<KeyRelease>, B<ButtonPress>,
  321. B<ButtonRelease>, B<Motion>, B<Enter>, B<Leave>,
  322. B<Expose>, B<Configure>, B<Gravity>, and B<Reparent>
  323. events.
  324. Corresponds to the the L<%x|Tk::bind/'x'> substitution for binding scripts.
  325. If I<Window> is empty the coordinate is relative to the
  326. screen, and this option corresponds to the L<%X|Tk::bind/'X'> substitution
  327. for binding scripts.
  328.  
  329. =item B<-y>I< coord>
  330.  
  331. I<Coord> must be a screen distance;  it specifies the I<y>
  332. field for the event.
  333. Valid for B<KeyPress>, B<KeyRelease>, B<ButtonPress>,
  334. B<ButtonRelease>, B<Motion>, B<Enter>, B<Leave>,
  335. B<Expose>, B<Configure>, B<Gravity>, and B<Reparent>
  336. events.
  337. Corresponds to the the L<%y|Tk::bind/'y'> substitution for binding scripts.
  338. If I<Window> is empty the coordinate is relative to the
  339. screen, and this option corresponds to the L<%Y|Tk::bind/'Y'> substitution
  340. for binding scripts.
  341.  
  342. Any options that are not specified when generating an event are filled
  343. with the value 0, except for I<serial>, which is filled with the
  344. next X event serial number.
  345.  
  346. =back
  347.  
  348. =head1 VIRTUAL EVENT EXAMPLES
  349.  
  350. In order for a virtual event binding to trigger, two things must
  351. happen.  First, the virtual event must be defined with the
  352. B<eventAdd> method.  Second, a binding must be created for
  353. the virtual event with the B<bind> method.
  354. Consider the following virtual event definitions:
  355.  
  356.  $widget->eventAdd('<<Paste>>' => '<Control-y>');
  357.  $widget->eventAdd('<<Paste>>' => '<Button-2>');
  358.  $widget->eventAdd('<<Save>>' => '<Control-X><Control-S>');
  359.  $widget->eventAdd('<<Save>>' => '<Shift-F12>');
  360.  
  361. In the B<bind> method, a virtual event can be bound like any other
  362. builtin event type as follows:
  363.  
  364.  $entry->bind('Tk::Entry', '<<Paste>>' => sub {
  365.          $entry->Insert($entry->selectionGet) });
  366.  
  367. The double angle brackets are used to specify that a virtual event is being
  368. bound.  If the user types Control-y or presses button 2, or if
  369. a B<E<lt>E<lt>PasteE<gt>E<gt>> virtual event is synthesized with B<eventGenerate>,
  370. then the B<E<lt>E<lt>PasteE<gt>E<gt>> binding will be invoked.
  371.  
  372. If a virtual binding has the exact same sequence as a separate
  373. physical binding, then the physical binding will take precedence.
  374. Consider the following example:
  375.  
  376.  $mw->eventAdd('<<Paste>>' => '<Control-y>','<Meta-Control-y>');
  377.  $mw->bind('Tk::Entry', '<Control-y>' => sub{print 'Control-y'});
  378.  $mw->bind('Tk::Entry', '<<Paste>>'   => sub{print 'Paste'});
  379.  
  380. When the user types Control-y the B<E<lt>Control-yE<gt>> binding
  381. will be invoked, because a physical event is considered
  382. more specific than a virtual event, all other things being equal.
  383. However, when the user types Meta-Control-y the
  384. B<E<lt>E<lt>PasteE<gt>E<gt>> binding will be invoked, because the
  385. B<Meta> modifier in the physical pattern associated with the
  386. virtual binding is more specific than the B<E<lt>Control-y>E<gt> sequence for
  387. the physical event.
  388.  
  389. Bindings on a virtual event may be created before the virtual event exists.
  390. Indeed, the virtual event never actually needs to be defined, for instance,
  391. on platforms where the specific virtual event would meaningless or
  392. ungeneratable.
  393.  
  394. When a definition of a virtual event changes at run time, all windows
  395. will respond immediately to the new definition.
  396. Starting from the preceding example, if the following code is executed:
  397.  
  398.  $entry->bind(ref($entry), '<Control-y>' => undef);
  399.  $entry->eventAdd('<<Paste>>' => '<Key-F6>');
  400.  
  401. the behavior will change such in two ways.  First, the shadowed
  402. B<E<lt>E<lt>PasteE<gt>E<gt>> binding will emerge.
  403. Typing Control-y will no longer invoke the B<E<lt>Control-yE<gt>> binding,
  404. but instead invoke the virtual event B<E<lt>E<lt>PasteE<gt>E<gt>>.  Second,
  405. pressing the F6 key will now also invoke the B<E<lt>E<lt>PasteE<gt>E<gt>> binding.
  406.  
  407. =head1 SEE ALSO
  408.  
  409. L<Tk::bind|Tk::bind>
  410. L<Tk::callbacks|Tk::callbacks>
  411.  
  412. =head1 KEYWORDS
  413.  
  414. event, binding, define, handle, virtual event
  415.  
  416. =cut
  417.  
  418.