home *** CD-ROM | disk | FTP | other *** search
/ C/C++ User's Journal & Wi…eveloper's Journal Tools / C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso / windbase / windbase.exe / MEMSLC.3 / EDITOR / KEYFUNCT.C < prev    next >
C/C++ Source or Header  |  1995-10-19  |  34KB  |  1,291 lines

  1. /*****************************************************************************\
  2. **                                                                           **
  3. **  WW     WW IIIIIIII NNN   NN DDDDDDD  BBBBBBB     AA     SSSSSS EEEEEEEE  **
  4. **  WW  W  WW    II    NNNN  NN DD    DD BB    BB  AA  AA  SS      EE        **
  5. **  WW  W  WW    II    NN NN NN DD    DD BBBBBBB  AAAAAAAA  SSSSSS EEEEEE    **
  6. **   WW W WW     II    NN  NNNN DD    DD BB    BB AA    AA      SS EE        **
  7. **    WWWWW   IIIIIIII NN   NNN DDDDDDD  BBBBBBB  AA    AA SSSSSS  EEEEEEEE  **
  8. **                                                                           **
  9. **   SSSSSS  OOOOOO  FFFFFFFF TTTTTTTT WW     WW    AA    RRRRRRR  EEEEEEEE  **
  10. **  SS      OO    OO FF          TT    WW  W  WW  AA  AA  RR    RR EE        **
  11. **   SSSSS  OO    OO FFFFF       TT    WW  W  WW AAAAAAAA RRRRRRR  EEEEEE    **
  12. **       SS OO    OO FF          TT     WW W WW  AA    AA RR   RR  EE        **
  13. **  SSSSSS   OOOOOO  FF          TT      WWWWW   AA    AA RR    RR EEEEEEEE  **
  14. **                                                                           **
  15. *********** NOTICE ************************************************************
  16. **        This file contains valuable trade secrets and proprietary          **
  17. **        assets of Windbase Software Inc.  Embodying substantial            **
  18. **        creative efforts and confidential information.  Unauthorized       **
  19. **        use, copying, decompiling, translating, disclosure or              **
  20. **        transfer, of any kind, is strictly prohibited.                     **
  21. **                                                                           **
  22. **        COPYRIGHT (C) 1992, 1993, 1994.  Windbase Software Inc.            **
  23. **        ALL RIGHTS RESERVED.                                               **
  24. \*****************************************************************************/
  25.  
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <malloc.h>
  30. #include <conio.h>
  31.  
  32. #include "../../memsl.h"
  33. #include "port.h"
  34. #include "vedt.h"
  35. #include "getkey.h"
  36.  
  37. int GetIndent(EDITOR *editor, int current)
  38.   {
  39.     WBDLIST *dlistptr;
  40.     int indent = 0, done = 0;
  41.     char *strptr;
  42.  
  43.     if (editor->indent)
  44.       if (current)
  45.     {
  46.       strptr = editor->str;
  47.       while (indent < editor->pos+editor->offset
  48.         && *(strptr+indent+1) && *(strptr+indent+1) == ' ')
  49.           indent++;
  50.     }
  51.       else
  52.     {
  53.       if ((dlistptr = WBDListPointer(editor->dlist)) != NULL)
  54.         {
  55.           while (done == 0)
  56.         {
  57.           indent = 0;
  58.           if ((strptr = (char *) WBDListGet(dlistptr,WB_PREV)) != NULL)
  59.             {
  60.               while (*(strptr+indent+1) && *(strptr+indent+1) == ' ')
  61.             indent++;
  62.               if (*(strptr+indent+1) != 0
  63.             && indent < editor->pos+editor->offset)
  64.               done = 1;
  65.             }
  66.           else done = 1;
  67.         }
  68.           WBDListClose(dlistptr);
  69.         }
  70.     }
  71.     return(indent);
  72.   }
  73.  
  74. int SpacesToLeft(EDITOR *editor, int pos)
  75.   {
  76.     char *strptr;
  77.  
  78.     strptr = editor->str;
  79.     while (*(strptr+pos) && *(strptr+pos) == ' ' && pos-1)
  80.       pos--;
  81.     return(pos-1 ? 0 : 1);
  82.   }
  83.  
  84. /***************************************************************************\
  85. **
  86. \***************************************************************************/
  87. void KeyEnter(EDITOR *editor)
  88.   {
  89.     int indent = 0, setp1 = 0, setp2 = 0;
  90.     char *newstr;
  91.  
  92.     if (editor->insert || (WBDListIs(editor->dlist)&WB_LAST) == WB_LAST)
  93.       {
  94.     if (editor->insert == 0
  95.       && (WBDListIs(editor->dlist)&WB_LAST) == WB_LAST)
  96.         editor->pos = strlen(editor->str+1);
  97.  
  98.     if (editor->indent)
  99.       indent = GetIndent(editor,1);
  100.     newstr = malloc(strlen(editor->str+1+editor->offset+editor->pos)+indent+2);
  101.     if (editor->p1
  102.       && WBDListIsPtrEqual(editor->p1,editor->dlist)
  103.       && editor->offset+editor->pos < editor->p1pos)
  104.       {
  105.         setp1 = 1;
  106.         editor->p1pos-=(editor->offset+editor->pos)+indent;
  107.       }
  108.     if (editor->p2
  109.       && WBDListIsPtrEqual(editor->p2,editor->dlist))
  110.       {
  111.         if (editor->offset+editor->pos < editor->p2pos)
  112.           {
  113.         setp2 = 1;
  114.         editor->p2pos-=(editor->offset+editor->pos)+indent;
  115.           }
  116.       }
  117.     memset(newstr+1,' ',indent);
  118.     strcpy(newstr+indent+1,editor->str+1+editor->offset+editor->pos);
  119.     *(editor->str+1+editor->offset+editor->pos) = '\0';
  120.     editor->changed = editor->realloc = 1;
  121.     UpdateCurrent(editor);
  122.     WBDListAdd(editor->dlist,newstr,WB_NEXT);
  123.     if (setp1)
  124.       WBDListSetPtrEqual(editor->p1,editor->dlist);
  125.     if (setp2)
  126.       WBDListSetPtrEqual(editor->p2,editor->dlist);
  127.       }
  128.     else
  129.       {
  130.     if (editor->changed)
  131.       UpdateCurrent(editor);
  132.     WBDListGet(editor->dlist,WB_NEXT);
  133.       }
  134.     if (editor->p1)
  135.       if (setp1 || editor->linenum < editor->p1line)
  136.     editor->p1line++;
  137.     if (editor->p2)
  138.       if (setp2 || editor->linenum < editor->p2line)
  139.       editor->p2line++;
  140.     editor->linenum++;
  141.     if (editor->row < MAXROW-1)
  142.       editor->row++;
  143.     else
  144.       {
  145.     WBDListGet(editor->dltopscr,WB_NEXT);
  146.     editor->deltop = 1;
  147.       }
  148.     editor->pos = indent;
  149.     if (editor->offset)
  150.       {
  151.     editor->offset = 0;
  152.     UpdateCoordinates(editor,0,MAXROW-1);
  153.       }
  154.     else if (editor->insert)
  155.       UpdateCoordinates(editor,editor->row-1,MAXROW-1);
  156.     LineMove(editor);
  157.   }
  158.  
  159. /***************************************************************************\
  160. **
  161. \***************************************************************************/
  162. int KeyUp(EDITOR *editor, int shift)
  163.   {
  164.     unsigned int ptrbits = 0;
  165.  
  166.     if ((WBDListIs(editor->dlist)&WB_FIRST) != WB_FIRST)
  167.       {
  168.     if (shift)
  169.       if ((ptrbits = ChkBlkPtrs(editor)) == NOPTRS
  170.         || (ptrbits&PTR1) == 0 && (ptrbits&PTR2) == 0)
  171.         {
  172.           ptrbits = PTR1;
  173.           SetBlock(editor);
  174.         }
  175.  
  176.     if (editor->changed)
  177.       UpdateCurrent(editor);
  178.  
  179.     editor->linenum--;
  180.     WBDListGet(editor->dlist,WB_PREV);
  181.  
  182.     if (editor->row > 0)
  183.       editor->row--;
  184.     else
  185.       {
  186.         WBDListGet(editor->dltopscr,WB_PREV);
  187.         editor->instop = 1;
  188.         UpdateCoordinates(editor,editor->row,editor->row);
  189.       }
  190.  
  191.     if (shift && ((ptrbits&PTR1) || (ptrbits&PTR2)))
  192.       SetBlkPtrs(editor,ptrbits);
  193.  
  194.     LineMove(editor);
  195.  
  196.     return(1);
  197.       }
  198.     return(0);
  199.   }
  200.  
  201. /***************************************************************************\
  202. **
  203. \***************************************************************************/
  204. int KeyPageUp(EDITOR *editor, int shift)
  205.   {
  206.     unsigned int ptrbits = 0;
  207.     int i;
  208.  
  209.     if ((WBDListIs(editor->dlist)&WB_FIRST) != WB_FIRST)
  210.       {
  211.     if (shift)
  212.       if ((ptrbits = ChkBlkPtrs(editor)) == NOPTRS
  213.         || (ptrbits&PTR1) == 0 && (ptrbits&PTR2) == 0)
  214.         {
  215.           ptrbits = PTR1;
  216.           SetBlock(editor);
  217.         }
  218.  
  219.     if (editor->changed)
  220.       UpdateCurrent(editor);
  221.  
  222.     i = MAXROW;
  223.     while (i && (WBDListIs(editor->dlist)&WB_FIRST) != WB_FIRST)
  224.       {
  225.         editor->linenum--;
  226.         WBDListGet(editor->dlist,WB_PREV);
  227.         if ((WBDListIs(editor->dltopscr)&WB_FIRST) != WB_FIRST)
  228.           WBDListGet(editor->dltopscr,WB_PREV);
  229.         else editor->row--;
  230.         i--;
  231.       }
  232.  
  233.     if (shift && ((ptrbits&PTR1) || (ptrbits&PTR2)))
  234.       SetBlkPtrs(editor,ptrbits);
  235.  
  236.     UpdateCoordinates(editor,0,MAXROW-1);
  237.     LineMove(editor);
  238.  
  239.     return(1);
  240.       }
  241.     return(0);
  242.   }
  243.  
  244. /***************************************************************************\
  245. **
  246. \***************************************************************************/
  247. int KeyControlPageUp(EDITOR *editor, int shift)
  248.   {
  249.     unsigned int ptrbits = 0;
  250.  
  251.     if ((WBDListIs(editor->dlist)&WB_FIRST) != WB_FIRST)
  252.       {
  253.     if (shift)
  254.       if ((ptrbits = ChkBlkPtrs(editor)) == NOPTRS
  255.         || (ptrbits&PTR1) == 0 && (ptrbits&PTR2) == 0)
  256.         {
  257.           ptrbits = PTR1;
  258.           SetBlock(editor);
  259.         }
  260.  
  261.     if (editor->changed)
  262.       UpdateCurrent(editor);
  263.     while ((WBDListIs(editor->dlist)&WB_FIRST) != WB_FIRST)
  264.       WBDListGet(editor->dlist,WB_PREV);
  265.     WBDListGet(editor->dltopscr,WB_FIRST);
  266.     editor->row = 0;
  267.     editor->linenum = 0;
  268.  
  269.     if (shift && ((ptrbits&PTR1) || (ptrbits&PTR2)))
  270.       SetBlkPtrs(editor,ptrbits);
  271.  
  272.     UpdateCoordinates(editor,0,MAXROW-1);
  273.     LineMove(editor);
  274.  
  275.     retu