home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / eText.subproj / XTAction.h < prev    next >
Encoding:
Text File  |  1995-08-01  |  4.1 KB  |  160 lines

  1. /* XText 0.9 7/20/95  beta 1
  2. Paul A. Griffin
  3.  
  4. pgriffin@tiac.net (home->NextMail/Mime/text welcome)
  5. */
  6. /*    This file is part of the XText package (version 0.8)
  7.     Mike Dixon, April 1992
  8.     
  9.     Copyright (c) 1992 Xerox Corporation.  All rights reserved.
  10.  
  11.     Use and copying of this software and preparation of derivative works based
  12.     upon this software are permitted.  This software is made available AS IS,
  13.     and Xerox Corporation makes no warranty about the software or its
  14.     performance.
  15. */
  16.  
  17. #import <objc/Object.h>
  18. #import <dpsclient/event.h>
  19.  
  20. /*    An XTAction specifies the action to be taken in response to a key event.
  21.     When a key event occurs, the applyTo:event: method is invoked; this is
  22.     the key method that must be implemented by the subclasses of XTAction.
  23.  
  24.     Actions normally return self from the applyTo:event: method, but by
  25.     returning nil they can cause the event to be handled normally by XText0's
  26.     superclass (i.e. Text).
  27.  
  28.     The class method undefinedAction returns a default action that invokes
  29.     the text object's unboundKey method.
  30. */
  31.  
  32. @interface XTAction:Object
  33. {
  34. }
  35. + undefinedAction;
  36. - applyTo:xtext event:(NXEvent *)event;
  37. @end
  38.  
  39. #define MAPPED_KEYS      256            //    table size for a dispatch action
  40. #define NUM_MASKS        7              // keyboard independent flags
  41. /* 
  42. NX_ALPHASHIFTMASK Shift lock
  43. NX_SHIFTMASK      Shift key
  44. NX_CONTROLMASK      Control key 
  45. NX_ALTERNATEMASK  Alt key
  46. NX_COMMANDMASK      Command key 
  47. NX_NUMERICPADMASK Number pad key
  48. NX_HELPMASK          Help key
  49.  
  50.  charCodes are 128 * event->data.key.charCode,
  51.         + 1 if shift lock,
  52.         + 2 if shift,
  53.         + 4 if control,
  54.         + 8 if alt
  55.         + 16 if command
  56.         + 32 if numeric keypad
  57.         + 64 if help key
  58. */
  59.  
  60. #define CHAR_CODES  (MAPPED_KEYS * (1 << NUM_MASKS) )//combinations/key
  61.  
  62. typedef int charCode;
  63. typedef XTAction *actionTbl[CHAR_CODES];
  64.  
  65. /*    XTMsg0Action, XTMsg1Action, and XTMsg2Action are subclasses of XTAction
  66.     that send a specified message to the text object with 0, 1, or 2 args.
  67. */
  68.  
  69. @interface XTMsg0Action:XTAction
  70. {
  71.     SEL    action_sel;
  72. }
  73. - initSel:(SEL)sel;
  74. @end
  75.  
  76. @interface XTMsg1Action:XTAction
  77. {
  78.     SEL    action_sel;
  79.     int action_arg;
  80. }
  81. - initSel:(SEL)sel arg:(int)arg;
  82. @end
  83.  
  84. @interface XTMsg2Action:XTAction
  85. {
  86.     SEL    action_sel;
  87.     int action_arg1;
  88.     int action_arg2;
  89. }
  90. - initSel:(SEL)sel arg:(int)arg1 arg:(int)arg2;
  91. @end
  92.  
  93. /*    XTDispatchAction is a subclass of XTAction that maintains a dispatch
  94.     table of other actions and selects one based on the key pressed.  The
  95.     methods are
  96.         init                initializes all actions to `nil'.  XText
  97.                             has default NeXT Text Class behavior 
  98.  
  99.         initBase:estream:    the first argument is a string naming a 'base'
  100.                             set of initial bindings; the only values currently
  101.                             supported are "none". 
  102.  
  103.         loadFromFile:fullName estream:errs
  104.                             loads keybindings from a file.  Comments are
  105.                             lines in the file beginning with `#'.  This 
  106.                             method enables developers to load keybinding
  107.                             files from their .app wrapper directories.
  108.  
  109.         bindKey:toAction:estream:
  110.                             bind a key to a specified action; an action of nil
  111.                             will cause the key to be handled normally by the
  112.                             Text class
  113.  
  114.         addBindings:estream:
  115.                             parse and install the bindings specified by a
  116.                             string
  117.  
  118.     The estream argument is used to report any errors; if it is nil, the
  119.     default error stream (which simply pops up an alert panel) is used.
  120. */
  121.  
  122. @interface XTDispatchAction:XTAction
  123. {
  124.     actionTbl actions;
  125. }
  126. - init;
  127. - initBase:(const char *)base estream:errs;
  128. - loadFromFile:(char *)fullName estream:errs;
  129. - bindKey:(charCode)key toAction:action estream:errs;
  130. @end
  131.  
  132. @interface XTDispatchAction(parsing)
  133. - addBindings:(const char *)bindings estream:errs;
  134. @end
  135.  
  136. /*    XTEventMsgAction is a subclass of XTAction that sends a specified
  137.     message to the text object, passing the event as an argument.
  138.     This is useful for implementing some special-purpose prefix commands
  139.     like 'quote next character'
  140. */
  141.  
  142. @interface XTEventMsgAction:XTAction
  143. {
  144.     SEL action_sel;
  145. }
  146. - initSel:(SEL)sel;
  147. @end
  148.  
  149. /*    XTSeqAction is a subclass of XTAction that invokes a sequence of
  150.     subactions.
  151. */
  152.  
  153. @interface XTSeqAction:XTAction
  154. {
  155.     int length;
  156.     XTAction **actions;
  157. }
  158. - initLength:(int)len actions:(XTAction **)acts;
  159. @end
  160.