home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / imap-3.0 / MailManager / XTextPkg.h < prev    next >
Encoding:
Text File  |  1992-05-01  |  8.5 KB  |  292 lines

  1. /*    This file is part of the XText package (version 0.8)
  2.     Mike Dixon, April 1992
  3.     
  4.     Copyright (c) 1992 Xerox Corporation.  All rights reserved.
  5.  
  6.     Use and copying of this software and preparation of derivative works based
  7.     upon this software are permitted.  This software is made available AS IS,
  8.     and Xerox Corporation makes no warranty about the software or its
  9.     performance.
  10. */
  11.  
  12. // (beginning of ErrorStream.h)
  13. #import <objc/Object.h>
  14.  
  15. /*  The ErrorStream class allows clients of XText to customize its error
  16.     handling.  All errors are reported by invoking the report: method on
  17.     a client-supplied ErrorStream.  The default implementation simply puts
  18.     the message up in a modal panel, but you can create subclasses that do
  19.     more interesting things if you like.
  20.  
  21.     By default, all instances of XText share a single instance of ErrorStream,
  22.     which can be obtained by calling [ErrorStream default].
  23. */
  24.  
  25. @interface ErrorStream:Object
  26. {
  27. }
  28. + default;
  29. - report: (const STR) msg;
  30. @end
  31.  
  32. // (end of ErrorStream.h)
  33. // (beginning of XTAction.h)
  34. #import <dpsclient/event.h>
  35.  
  36. /*    An XTAction specifies the action to be taken in response to a key event.
  37.     When a key event occurs, the applyTo:event: method is invoked; this is
  38.     the key method that must be implemented by the subclasses of XTAction.
  39.  
  40.     Actions normally return self from the applyTo:event: method, but by
  41.     returning nil they can cause the event to be handled normally by XText0's
  42.     superclass (i.e. Text).
  43.  
  44.     The class method undefinedAction returns a default action that invokes
  45.     the text object's unboundKey method.
  46. */
  47.  
  48. @interface XTAction:Object
  49. {
  50. }
  51. + undefinedAction;
  52. - applyTo:xtext event:(NXEvent *)event;
  53. @end
  54.  
  55. #define MAPPED_KEYS      81                //    table size for a dispatch action
  56. #define KEY_CODES  (MAPPED_KEYS * 16)    //    4 modifiers = 16 combinations/key
  57.  
  58. /* keyCodes are 16 * event->data.key.keyCode,
  59.         + 1 if control,
  60.         + 2 if shift,
  61.         + 4 if alt,
  62.         + 8 if command
  63. */
  64.  
  65. typedef int keyCode;
  66. typedef XTAction *actionTbl[KEY_CODES];
  67.  
  68. /*    XTMsg0Action, XTMsg1Action, and XTMsg2Action are subclasses of XTAction
  69.     that send a specified message to the text object with 0, 1, or 2 args.
  70. */
  71.  
  72. @interface XTMsg0Action:XTAction
  73. {
  74.     SEL    action_sel;
  75. }
  76. - initSel:(SEL)sel;
  77. @end
  78.  
  79. @interface XTMsg1Action:XTAction
  80. {
  81.     SEL    action_sel;
  82.     int action_arg;
  83. }
  84. - initSel:(SEL)sel arg:(int)arg;
  85. @end
  86.  
  87. @interface XTMsg2Action:XTAction
  88. {
  89.     SEL    action_sel;
  90.     int action_arg1;
  91.     int action_arg2;
  92. }
  93. - initSel:(SEL)sel arg:(int)arg1 arg:(int)arg2;
  94. @end
  95.  
  96. /*    XTDispatchAction is a subclass of XTAction that maintains a dispatch
  97.     table of other actions and selects one based on the key pressed.  The
  98.     methods are
  99.         initBase:estream:    the first argument is a string naming a 'base'
  100.                             set of initial bindings; the only values currently
  101.                             supported are "emacs" and "none"
  102.         bindKey:toAction:estream:
  103.                             bind a key to a specified action; an action of nil
  104.                             will cause the key to be handled normally by the
  105.                             Text class
  106.         addBindings:estream:
  107.                             parse and install the bindings specified by a
  108.                             string
  109.  
  110.     The estream argument is used to report any errors; if it is nil, the
  111.     default error stream (which simply pops up an alert panel) is used.
  112. */
  113.  
  114. @interface XTDispatchAction:XTAction
  115. {
  116.     actionTbl actions;
  117. }
  118. - initBase:(const char *)base estream:errs;
  119. - bindKey:(keyCode)key toAction:action estream:errs;
  120. @end
  121.  
  122. @interface XTDispatchAction(parsing)
  123. - addBindings:(const char *)bindings estream:errs;
  124. @end
  125.  
  126. /*    XTEventMsgAction is a subclass of XTAction that sends a specified
  127.     message to the text object, passing the event as an argument.
  128.     This is useful for implementing some special-purpose prefix commands
  129.     like 'quote next character'
  130. */
  131.  
  132. @interface XTEventMsgAction:XTAction
  133. {
  134.     SEL action_sel;
  135. }
  136. - initSel:(SEL)sel;
  137. @end
  138.  
  139. /*    XTSeqAction is a subclass of XTAction that invokes a sequence of
  140.     subactions.
  141. */
  142.  
  143. @interface XTSeqAction:XTAction
  144. {
  145.     int length;
  146.     XTAction **actions;
  147. }
  148. - initLength:(int)len actions:(XTAction **)acts;
  149. @end
  150. // (end of XTAction.h)
  151. // (beginning of XText0.h)
  152. #import <appkit/Text.h>
  153.  
  154. /*    XText0 is the 'bare' extensible Text class; it provides the support for
  155.     key bindings, but doesn't provide any of the useful methods you're likely
  156.     to want to bind them to.
  157.  
  158.     The instance variables are
  159.         nextAction        the action that will interpret the next key
  160.         initialAction    the basic action used to interpret keys (generally
  161.                         an XTDispatchAction)
  162.         errorStream        used to report errors
  163.  
  164.     In normal operation nextAction == initialAction, but an action may
  165.     change nextAction to cause the next key to be interpreted specially.
  166.     For example, this is used to implement ctrl-q (quote next char), and
  167.     could also be used to implement emacs-style prefix maps.
  168.  
  169.     Most of the methods are all self-explanatory;  the ones that might not
  170.     be are
  171.         newFieldEditorFor:initialAction:estream:
  172.                                 should be called from a window's delegate's
  173.                                 getFieldEditor:for: method; returns an XText
  174.                                 for editing the window's fields
  175.         unboundKey                just beeps
  176.         disableAutodisplay        like setAutodisplay:NO, except that it does
  177.                                 nothing if this is a field editor (to work
  178.                                 around a bug in text fields)
  179.  
  180.     The default initialAction is nil, which just causes all key events to
  181.     be handled by the superclass (i.e. Text).
  182. */
  183.  
  184. @interface XText0:Text
  185. {
  186.     id nextAction;
  187.     id initialAction;
  188.     id errorStream;
  189. }
  190. + newFieldEditorFor:win initialAction:action estream:errs;
  191. - initFrame:(const NXRect *)frameRect text:(const STR)theText
  192.     alignment:(int)mode;
  193. - setErrorStream:errs;
  194. - errorStream;
  195. - setInitialAction:action;
  196. - initialAction;
  197. - setNextAction:action;
  198. - unboundKey;
  199. - disableAutodisplay;
  200. @end
  201. // (end of XText0.h)
  202. // (beginning of XText.h)
  203.  
  204. /*    XText augments XText0 with a bunch of useful methods for emacs-like
  205.     key bindings.
  206.  
  207.     All of the cursor-movement methods take a 'mode' argument, which may
  208.     be
  209.         0        just move the point to new location
  210.         1        delete to new location
  211.         2        cut to new location
  212.         3        extend selection to new location
  213.     
  214.     The methods are
  215.         goto:end:mode:        implements all movement; second argument specifies
  216.                             the other end of the selection when mode != 0
  217.         moveWord:mode:        move n words forward from point (back if n<0)
  218.         moveChar:mode:        move n chars forward from point (back if n<0)
  219.         moveLine:mode:        move n lines down from point (up if n<0)
  220.         lineBegin:            move to beginning of current line
  221.         lineEnd:            move to end of current line
  222.         docBegin:            move to beginning of document
  223.         docEnd:                move to end of document
  224.         collapseSel:        move to beginning of selection (dir<0), end of
  225.                             selection (dir>0), or active end of sel (dir=0)
  226.         transChars            transpose characters around point
  227.         openLine            insert new line after point
  228.         scroll::            scroll window n pages + m lines
  229.         scrollIfRO::        scroll window n pages + m lines if doc is
  230.                             read-only; returns nil if doc is editable
  231.         insertChar:            inserts the character associated with a key event
  232.         insertNextChar        sets nextAction so that the next key event will be
  233.                             interpreted as a character
  234.  
  235.     When there is a non-empty selection, we keep track of which end is active
  236.     (further movement commands will be relative to that end).  When we move
  237.     up or down lines, we keep track of which column we started in and try to
  238.     stick to it.  XText's instance variables are used to implement this
  239.     behavior:
  240.         posHint        the cp of the point; if this doesn't correspond to either
  241.                     end of the selection, we put the point after the selection
  242.         xHint        the column we're trying to keep the point in during
  243.                     vertical movement
  244.         xHintPos    xHint is only valid if this is the cp of the point
  245.     ("cp" == character position)
  246.  
  247.     This file also includes initbase_emacs, called by XTDispatchAction's
  248.     initBase:estream: method when base == "emacs" to set up the default
  249.     key bindings.
  250. */
  251.  
  252. @interface XText:XText0
  253. {
  254.     int posHint;
  255.     int xHint;        // note that this is in characters, not pixels
  256.     int xHintPos;
  257. }
  258. - goto:(int)pos end:(int)end mode:(int)mode;
  259. - moveWord:(int)cnt mode:(int)mode;
  260. - moveChar:(int)cnt mode:(int)mode;
  261. - moveLine:(int)cnt mode:(int)mode;
  262. - lineBegin:(int)mode;
  263. - lineEnd:(int)mode;
  264. - docBegin:(int)mode;
  265. - docEnd:(int)mode;
  266. - collapseSel:(int)dir;
  267. - transChars;
  268. - openLine;
  269. - scroll:(int)pages :(int)lines;
  270. - scrollIfRO:(int)pages :(int)lines;
  271. - insertChar:(NXEvent *)event;
  272. - insertNextChar;
  273. @end
  274.  
  275. void initbase_emacs(actionTbl actions, NXZone *zone);
  276. // (end of XText.h)
  277. // (beginning of XTScroller.h)
  278. #import <appkit/ScrollView.h>
  279.  
  280. /*    An XTScroller is a ScrollView that automatically installs an XText as
  281.     its subview and does all the appropriate setup.
  282. */
  283.  
  284. @interface XTScroller:ScrollView
  285. {
  286. }
  287.  
  288. - initFrame:(const NXRect *)frameRect;
  289.  
  290. @end
  291. // (end of XTScroller.h)
  292.