home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d534 / term.lha / Term / Source.LZH / StringHook.c < prev    next >
C/C++ Source or Header  |  1991-07-06  |  4KB  |  178 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
  4.  *
  5.  *    Name .....: StringHook.c
  6.  *    Created ..: Wednesday 06-Feb-91 12:35
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    06-Feb-91       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15. #include "TermGlobal.h"
  16.  
  17.     /* HookEntry():
  18.      *
  19.      *    Call a hook function.
  20.      */
  21.  
  22. ULONG __saveds __asm
  23. HookEntry(register __a0 struct Hook *HookPtr,register __a2 APTR Object,register __a1 APTR Message)
  24. {
  25.     return(HookPtr -> h_SubEntry(HookPtr,Object,Message));
  26. }
  27.  
  28.     /* InitHook(struct Hook *Hook,APTR HookCode):
  29.      *
  30.      *    Set up a call back routine (hook).
  31.      */
  32.  
  33. VOID
  34. InitHook(struct Hook *Hook,APTR HookCode)
  35. {
  36.     Hook -> h_Entry        = HookEntry;
  37.     Hook -> h_SubEntry    = HookCode;
  38.     Hook -> h_Data        = 0;
  39. }
  40.  
  41.     /* CommandKey(struct Hook *Hook,struct SGWork *Work,ULONG *Msg):
  42.      *
  43.      *    This routine is called whenever input passes through
  44.      *    a `term' string gadget. It releases the currently
  45.      *    active string gadget as soon as the Right-Amiga-key is
  46.      *    pressed (user is about to select a menu item).
  47.      */
  48.  
  49. VOID
  50. CommandKey(struct Hook *Hook,struct SGWork *Work,ULONG *Msg)
  51. {
  52.     if(Msg[0] == SGH_KEY)
  53.     {
  54.         if(Work -> Actions & SGA_END)
  55.             Work -> Actions |= SGA_NEXTACTIVE;
  56.  
  57.         if((Work -> IEvent -> ie_Qualifier & AMIGARIGHT) && Work -> IEvent -> ie_Code < 96)
  58.         {
  59.             if(!(Work -> IEvent -> ie_Qualifier & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT)) && (Work -> IEvent -> ie_Code == KEYCODE_X || Work -> IEvent -> ie_Code == KEYCODE_Q))
  60.                 return;
  61.             else
  62.             {
  63.                 Work -> Actions |= (SGA_END|SGA_REUSE);
  64.                 Work -> Actions &= ~(SGA_USE|SGA_BEEP);
  65.  
  66.                 CommandWindow = Work -> GadgetInfo -> gi_Window;
  67.                 CommandGadget = Work -> Gadget;
  68.             }
  69.         }
  70.  
  71.             /* The user pressed the cursor-right key to
  72.              * move the cursor to the next word in the buffer.
  73.              */
  74.  
  75.         if(Work -> IEvent -> ie_Code == CURSORRIGHT && (Work -> IEvent -> ie_Qualifier & IEQUALIFIER_CONTROL))
  76.         {
  77.             if(Work -> BufferPos != Work -> NumChars)
  78.             {
  79.                 SHORT i,Position = -1;
  80.  
  81.                 for(i = Work -> BufferPos ; i < Work -> NumChars ; i++)
  82.                 {
  83.                     if(Work -> WorkBuffer[i] == ' ')
  84.                     {
  85.                         for( ; i < Work -> NumChars ; i++)
  86.                         {
  87.                             if(Work -> WorkBuffer[i] != ' ')
  88.                             {
  89.                                 Position = i;
  90.                                 break;
  91.                             }
  92.                         }
  93.  
  94.                         break;
  95.                     }
  96.                 }
  97.  
  98.                 if(Position != -1)
  99.                     Work -> BufferPos = Position;
  100.                 else
  101.                     Work -> BufferPos = Work -> NumChars;
  102.  
  103.                 Work -> EditOp = EO_MOVECURSOR;
  104.             }
  105.         }
  106.  
  107.             /* The user pressed the cursor-right key to
  108.              * move the cursor to the previous word in the buffer.
  109.              */
  110.  
  111.         if(Work -> IEvent -> ie_Code == CURSORLEFT && (Work -> IEvent -> ie_Qualifier & IEQUALIFIER_CONTROL))
  112.         {
  113.             if(Work -> BufferPos)
  114.             {
  115.                 SHORT i,Position = -1;
  116.  
  117.                 for(i = Work -> BufferPos ; i >= 0 ; i--)
  118.                 {
  119.                     if(Work -> WorkBuffer[i] != ' ')
  120.                     {
  121.                         Position = i;
  122.                         break;
  123.                     }
  124.                 }
  125.  
  126.                 if(Position == -1)
  127.                     Position = 0;
  128.  
  129.                 if(Position)
  130.                 {
  131.                     i = Position;
  132.  
  133.                     Position = -1;
  134.  
  135.                     for( ; i >= 0 ; i--)
  136.                     {
  137.                         if(Work -> WorkBuffer[i] == ' ')
  138.                         {
  139.                             Position = i + 1;
  140.                             break;
  141.                         }
  142.                     }
  143.                 }
  144.  
  145.                 if(Position != -1)
  146.                     Work -> BufferPos = Position;
  147.                 else
  148.                     Work -> BufferPos = 0;
  149.  
  150.                 Work -> EditOp = EO_MOVECURSOR;
  151.             }
  152.         }
  153.     }
  154. }
  155.  
  156.     /* DubGadList(struct Gadget *Gadget):
  157.      *
  158.      *    Walk through a linked list of gadgets and modify
  159.      *    the string gadgets to use the private string gadget
  160.      *    editing hook.
  161.      */
  162.  
  163. VOID
  164. DubGadList(struct Gadget *Gadget)
  165. {
  166.     while(Gadget)
  167.     {
  168.         if((Gadget -> GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
  169.         {
  170.             SGEXT(Gadget,&CommandExtend);
  171.  
  172.             Gadget -> Activation |= GACT_IMMEDIATE;
  173.         }
  174.  
  175.         Gadget = Gadget -> NextGadget;
  176.     }
  177. }
  178.