home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / DEMO / RIM22 / MACROS / SLIDE.RM < prev    next >
Text File  |  1993-11-01  |  3KB  |  130 lines

  1. /*
  2. ** Macro module: slide.rm - indent/unindent marked text
  3. **
  4. ** Copyright (C) 1993 Brian L. Smith
  5. ** Copyright (C) 1993 RimStar Technology, Inc.
  6. ** All rights reserved internationally.
  7. ** Unlicensed use is a violation of applicable laws.
  8. **
  9. ** This source code is provided to licensed users of RimStar's products
  10. ** for the purpose of allowing the user to customize and/or enhance RimStar's
  11. ** products. The source code remains the property of the copyright holders
  12. ** with all rights reserved internationally.
  13. ** Any modifications to the source code are considered derivative works and
  14. ** all rights thereto are reserved to the copyright holders except
  15. ** that the purchaser may use the derivitive work in the same manner
  16. ** as permitted by the license governing the unmodified product.
  17. ** Distribution in any manner of any part of the original source code,
  18. ** whether in source or object form, is expressly prohibited without the
  19. ** express written permission of the copyright holders.
  20. **
  21. */
  22.  
  23. #include "macro.h"
  24.  
  25. int    IndentSize = 3;
  26.  
  27.  
  28. int
  29. DistanceToNextIndent(long col) {
  30.     if ( IndentSize )
  31.         return IndentSize - ( (col-1L) % IndentSize );
  32.     else
  33.         return (int)(BufQueryNextTab(col) - col);
  34. } /* end DistanceToIndent() */
  35.  
  36.  
  37. int
  38. DistanceToPrevIndent(long col) {
  39.     int distance;
  40.  
  41.     if ( col == 1 )
  42.         return 0;
  43.     if ( IndentSize )    {
  44.         distance = (int)( (col-1L) % IndentSize );
  45.         if ( !distance )
  46.             return -IndentSize;
  47.         else
  48.             return -distance;
  49.     } else
  50.         return (int)(BufQueryPrevTab(col) - col);
  51. } /* end DistanceToPrevIndent() */
  52.  
  53.  
  54. void
  55. slide_in(void) {
  56.     SELECTION    saveSel, s;
  57.     ULONG            savedInsert;
  58.     SHORT            type;
  59.     LONG            indent_to;
  60.  
  61.     if ( type = MarkQuerySel(&s) ) {
  62.         /*
  63.         ** get non adjusted coords of selection
  64.         ** so it can be recreated correctly.
  65.         */
  66.         MarkQuerySel(&saveSel, 0);
  67.         MarkRemoveSel();
  68.  
  69.         if ( type != SELECT_COLUMN )
  70.             s.s_column = 1L;
  71.         indent_to = s.s_column +(long)DistanceToNextIndent(s.s_column);
  72.  
  73.         savedInsert = SysQueryFlags();
  74.         SysSetFlags(SYSTEM_INSERT, SYSTEM_INSERT);
  75.  
  76.         PosAbs(s.s_line, s.s_column);
  77.  
  78.         while ( s.s_line <= s.e_line ) {
  79.             BufIndentColumn(0, indent_to);
  80.             PosAbs(++s.s_line, s.s_column);
  81.         }
  82.  
  83.         SysSetFlags(SYSTEM_INSERT, savedInsert);
  84.  
  85.         MarkCreateSel(&saveSel);    /* restore the selection */
  86.     } else
  87.         BufInsertChar('\t');
  88. } /* end slide_in()    */
  89.  
  90.  
  91. void
  92. slide_out(void) {
  93.     SELECTION    s;
  94.     SHORT            type;
  95.     LONG            atCol, pos, size;
  96.  
  97.     if ( type = MarkQuerySel(&s) ) {
  98.         MarkPushPos();
  99.         if ( type != SELECT_COLUMN )
  100.             s.s_column = 1L;
  101.  
  102.         PosAbs(s.s_line, s.s_column);
  103.         while ( s.s_line <= s.e_line ) {
  104.             PosSOT();
  105.             atCol = BufQueryColumn();
  106.             if ( atCol < s.s_column && type == SELECT_COLUMN )    {
  107.                 PosAbs(0, s.s_column);
  108.                 SrchFwd("[^ \\t]");
  109.                 atCol = BufQueryColumn();
  110.             }
  111.             if ( atCol > s.s_column ) {
  112.                 size = BufQueryOffset();
  113.                 atCol += (LONG)DistanceToPrevIndent(atCol);
  114.                 if ( atCol < s.s_column )
  115.                     atCol = s.s_column;
  116.                 size -= PosAbs(0, atCol);
  117.                 BufDeleteChar(size);
  118.             }
  119.             PosAbs(++s.s_line, 0L);
  120.         }
  121.         MarkPopPos();
  122.     } else
  123.         MovPrevTabPos();
  124. } /* end slide_out() */
  125.  
  126.  
  127. /*
  128. ** End macro: slide.rm
  129. */
  130.