home *** CD-ROM | disk | FTP | other *** search
/ Shareware Supreme Volume 6 #1 / swsii.zip / swsii / 484 / NPED.ZIP / NPEDITOR.PRG < prev    next >
Text File  |  1992-09-13  |  11KB  |  332 lines

  1. /*
  2.  
  3. Program Name  npeditor.prg
  4.  
  5. Purpose       Editor for Funck(y) II's notepad()
  6.  
  7. Author        Stephen L. Woolstenhulme    CIS 73060,1302
  8.               3805 Indigo Drive
  9.               Plano, Texas 75075
  10.  
  11. Notice        Copyright (c) 1992
  12.               Stephen L. Woolstenhulme
  13.               All Rights Reserved
  14.  
  15. Function 1    cText := npEditor( cText, nTop, nLeft, nBottom, nRight, ;
  16.                                  nAttr, nSize, nLines, nLineLen, nTab )
  17.         
  18. Parameters    Name, Default Value, & Description
  19.               ---------------------------------------------------------
  20.               cFile     File to edit -- fileman() Text file to edit.
  21.               nTop      3                         Top row of edit box.
  22.               nLeft     6                         Left column of box.
  23.               nBottom   maxrow()-4                Bottom row of box.
  24.               nRight    maxcol()-5                Right column of box.
  25.               nAttr     23                        Funck(y) color.
  26.               nSize     16000                     Maximum buffer size.
  27.               nLines    nSize/20                  Maximum buffer lines.
  28.               nLineLen  nRight - ( nLeft + 4 )    Line length to wrap.
  29.               nTab      4                         Tab expansion spaces.
  30.  
  31. */
  32.  
  33. #include "inkey.ch"
  34. #include "FUNCky.ch"
  35. #define K_ALT_BS 270
  36.  
  37. #xcommand ifNil <xVar> is <xVal> => ;
  38.                 <xVar> := iif( <xVar> == Nil, <xVal>, <xVar> )
  39.  
  40. FUNCTION npEditor( cFile, nTop, nLeft, nBottom, nRight, ;
  41.                    nAttr, nSize, nLines, nLineLen, nTab )
  42.  
  43.    local np, cText, cScrn := savescreen( 0, 0, maxrow(), maxcol() )
  44.    local nRow := row(), nCol := col(), nChoice 
  45.    local cDelim := chr(9) + chr(10) + chr(12) + chr(13) + chr(32) + ;
  46.                    chr(38) + '~`$%^@.,-_!?/\|;:(){}[]<>#+=*"0123456789'
  47.    
  48.    ifNil nTop     is 3
  49.    ifNil nLeft    is 6
  50.    ifNil nBottom  is maxrow()-4
  51.    ifNil nRight   is maxcol()-5
  52.    ifNil nAttr    is 23
  53.    ifNil nSize    is 16000
  54.    ifNil nLines   is 800
  55.    ifNil nLineLen is maxcol()-15
  56.    ifNil nTab     is 4
  57.    
  58.    nTop     := iif( ! valtype( ntop )     == 'N', val( nTop ),     nTop )
  59.    nleft    := iif( ! valtype( nleft )    == 'N', val( nleft ),    nleft )
  60.    nbottom  := iif( ! valtype( nbottom )  == 'N', val( nbottom ),  nbottom )
  61.    nright   := iif( ! valtype( nright )   == 'N', val( nright ),   nright )
  62.    nattr    := iif( ! valtype( nattr )    == 'N', val( nattr ),    nattr )
  63.    nsize    := iif( ! valtype( nsize )    == 'N', val( nsize ),    nsize )
  64.    nlines   := iif( ! valtype( nlines )   == 'N', val( nlines ),   nlines )
  65.    nlinelen := iif( ! valtype( nlinelen ) == 'N', val( nlinelen ), nlinelen )
  66.    ntab     := iif( ! valtype( ntab )     == 'N', val( ntab ),     ntab )
  67.  
  68.    np := npCreate( nTop + 1, nLeft + 2, nBottom - 1, nRight - 2, ;
  69.                    nAttr, nSize, nLines, nLineLen, nTab )
  70.    
  71.    setcolor( 'w+/b' )
  72.    cls
  73.    
  74.    if ! cFile == Nil
  75.       if file( cFile )
  76.          cText := memoread( cFile )
  77.       else
  78.          cText := ''                    // started with new file name.
  79.       endif
  80.    endif
  81.  
  82.    if cText == Nil
  83.         cFile := fileman( 5, 5, MAXROW() - 1, "W+/B, B/W ,,, W/N" )
  84.         cText := iif( empty( cFile ), '', memoread( cFile ) )
  85.    endif
  86.  
  87.    npColor( np, nAttr )
  88.    npBlockColor( np, 79 )
  89.    cls( 23, chr( 177 ) )
  90.    settitle( " Editing Notepad ", 1, 31 )
  91.    
  92.    box( npWinTop( np )-1,               ;
  93.         npWinLeft( np )-2,              ;
  94.         npWinBottom( np )+1,            ;
  95.         npWinRight( np )+2, '', 23 )          
  96.    @ npWinBottom( np ) + 1, npWinLeft( np ) say 'F1:Help' 
  97.    @ npWinBottom( np ) + 1, npWinLeft( np ) + 10 say 'F2:Spell' 
  98.    @ npWinBottom( np ) + 1, npWinRight( np ) - 19 say  'F10:Exit' 
  99.    @ npWinBottom( np ) + 1, npWinRight( np ) - 8 say 'Esc:Abort' 
  100.    
  101.    npStore( np, NP_WRAP, cText)
  102.    
  103.    do while .t.
  104.        NotePad( np, cDelim )
  105.        nChoice := 2
  106.  
  107.        if lastkey() == K_ESC
  108.            nChoice := alert( 'You pressed Escape!', ;
  109.                            { ' Abort ', ' Save ', ' Continue ' } )
  110.        endif
  111.  
  112.        if ! nChoice == 3
  113.            exit
  114.        endif
  115.    enddo
  116.  
  117.    if nChoice == 2                 // write the edited file.
  118.         set printer to ( cFile )
  119.         set print on
  120.         set console off
  121.         ?? npRetrieve( np, NP_VERBATIM )
  122.         set console on
  123.         set print off
  124.         set printer to
  125.    endif
  126.  
  127.    restscreen( 0, 0, maxrow(), maxcol(), cScrn )
  128.    setPos( nRow - 1, nCol )
  129. return npSave( np )
  130.  
  131. FUNCTION NotePad( np, cDelim )
  132.    LOCAL nKey, i, nMargin, nLines
  133.    LOCAL InsertMode := FALSE
  134.    LOCAL cLine, cScrn, cBookMark
  135.    
  136.    if cDelim == Nil
  137.        cDelim := chr(9) + chr(10) + chr(12) + chr(13) + chr(32) + ;
  138.                  chr(38) + '~`$%^@.,-_!?/\|;:(){}[]<>#+=*"0123456789'
  139.    endif
  140.  
  141.    csrtype( 0 )
  142.    
  143.    DO WHILE ( TRUE )
  144.        npDisplay( np )
  145.        csrput( npScrRow( np ), npScrCol( np ))
  146.        nKey := inkey(0)
  147.     
  148.        DO CASE
  149.        
  150.        CASE( nKey EQ K_F1 )
  151.              showHelp()
  152.  
  153.        CASE( nKey EQ K_F2 )
  154.              npSpell( np, cDelim )
  155.  
  156.        CASE( nKey EQ ENTER .or. nKey EQ K_TAB )
  157.              npInsert( np, nKey )
  158.                
  159.        CASE( nKey EQ BACKSPACE )
  160.              npBackSpace( np )
  161.                
  162.        CASE( nKey EQ K_DEL )
  163.              npDelete( np )
  164.                
  165.        CASE( nKey EQ K_CTRL_BS .or. nKey EQ K_CTRL_T )
  166.              npDeleteWord( np )
  167.                
  168.        CASE( nKey EQ K_ALT_BS )
  169.              npDeleteToken( np, cDelim )
  170.        
  171.        CASE( nKey EQ K_CTRL_Y .or. nKey EQ K_ALT_K )
  172.              npBeginMark( np )
  173.              npCsrEnd( np )
  174.              npDeleteBlock( np )
  175.  
  176.        CASE( nKey == K_ALT_L )
  177.              npDeleteLine( np )
  178.  
  179.        CASE( nKey >= 376 .AND. nKey <= 384 )  // K_ALT_1 to K_ALT_9
  180.              npSetBookMark( np, nKey - 375 )
  181.              npMarkToken( np, cDelim )        // quick light show
  182.              npDisplay( np )
  183.              nap( 4 )
  184.              npUnMark( np )
  185.              npDisplay( np )
  186.  
  187.        CASE( nKey == K_ALT_J )                // Jump to bookmark 1 to 9
  188.              cBookMark := ''
  189.              
  190.              for i := 1 to 9
  191.                 if npGetBookMark( np, i ) > 0
  192.                     cBookMark += transform( i, ' 9 ' )
  193.                 endif
  194.              next 
  195.              
  196.              if ! empty( cBookMark )
  197.                  cScrn := savescreen( maxrow() - 3, 0, maxrow(), maxcol() )
  198.                  @ maxrow() - 2, 0 say padc( ' Select a bookmark ', maxcol() + 1 ) color 'n/w'
  199.                  @ maxrow() - 1, 0 say padc( cBookMark, maxcol() + 1 ) color 'n/w'
  200.                  @ maxrow() - 3, 0 to maxrow(), maxcol() 
  201.                  inkey(0)
  202.                  restscreen( maxrow() - 3, 0, maxrow(), maxcol(), cScrn )
  203.                  
  204.                  if chr( lastkey() ) $ cBookMark
  205.                       npGoBookMark(np, val( chr( lastkey() ) ) )  
  206.                  endif
  207.              endif
  208.  
  209.        CASE( nKey EQ INS )
  210.              InsertMode := (! InsertMode)
  211.              csrtype( IIF(InsertMode, 1, 0) )
  212.                
  213.        CASE( nKey EQ LEFTARROW )
  214.              npCsrLeft(np, 1)
  215.                
  216.        CASE( nKey EQ RIGHTARROW )
  217.              npCsrRight(np, 1)
  218.                
  219.        CASE( nKey EQ UPARROW )
  220.              npCsrUp(np, 1)
  221.                
  222.        CASE( nKey EQ DOWNARROW )
  223.              npCsrDown(np, 1)
  224.                
  225.        CASE( nKey EQ PGUP )
  226.              npPageUp( np )
  227.                
  228.        CASE( nKey EQ PGDN )
  229.              npPageDown( np )
  230.                
  231.        CASE( nKey EQ K_END )
  232.              npCsrEnd( np )
  233.                
  234.        CASE( nKey EQ K_HOME )
  235.              npCsrHome( np )
  236.                
  237.        CASE( nKey EQ K_CTRL_RIGHT )
  238.              npWordRight( np )
  239.                
  240.        CASE( nKey EQ K_CTRL_LEFT )
  241.              npWordLeft( np )
  242.                
  243.        CASE( nKey EQ K_CTRL_HOME )
  244.              npCsrTop( np )
  245.                
  246.        CASE( nKey EQ K_CTRL_END )
  247.              npCsrBottom( np )
  248.                
  249.        CASE( nKey EQ K_CTRL_PGUP )
  250.              npHome( np )
  251.                
  252.        CASE( nKey EQ K_CTRL_PGDN )
  253.              npEnd( np )
  254.                
  255.        CASE( nKey EQ K_F10 .or. nKey EQ K_ESC )
  256.              npSave( np )
  257.              return NIL
  258.        
  259.        CASE( nKey EQ K_CTRL_RET )  // Hard Page Break
  260.              npInsert( np, 12 )
  261.              npInsert( np, 13 )
  262.        
  263.        CASE( nKey EQ K_ALT_P )     // Print
  264.              if prnstatus() == 0
  265.                 nMargin := max( ( 79 - npLineLength( np, 0 ) ) / 2, 0 )
  266.                 npSetBookMark( np, 10 )
  267.                 npHome( np )
  268.                 nLines := npLineCount( np )
  269.                 
  270.                 for i := 1 to nLines
  271.                    npMarkLine( np )
  272.                    npDisplay( np )
  273.                    cLine := space( nMargin ) + ;
  274.                             strtran( npGetLine( np ), ;
  275.                                      chr( K_TAB ),    ;
  276.                                      space( npTabSize( np ) ) )
  277.                    lPrintLine( cLine )
  278.                    npUnMark( np )
  279.                    npCsrDown( np )
  280.                 next
  281.  
  282.                 npGoBookMark( np, 10 )
  283.              else
  284.                 cScrn := savescreen( maxrow(), 0, maxrow(), maxcol() )
  285.                 @ maxrow(), 0 say padc( 'Printer not ready!  Press any key ... ', maxcol() + 1 )
  286.                 tone( 200, 1 )
  287.                 inkey(0)
  288.                 restscreen( maxrow(), 0, maxrow(), maxcol(), cScrn )
  289.              endif   
  290.  
  291.        CASE( nKey EQ K_ALT_R )     // Right Justify
  292.              npJustify( np )
  293.        
  294.        OTHERWISE
  295.              IF( InsertMode .or. ;
  296.                  chr( npGetChar( np ) ) $ chr( K_TAB ) + chr( K_ENTER ) )
  297.                  npInsert( np, nKey )
  298.              ELSE
  299.                  npOverWrite( np, nKey )
  300.              ENDIF
  301.        ENDCASE
  302.    ENDDO
  303.  
  304. return NIL
  305.  
  306. static function showHelp
  307.     local cText, cScrn := savescreen( 0, 0, maxrow(), maxcol() ), hp
  308.     local nTop := iif( row() > maxrow() / 2, 2, ( maxrow() / 2 + 1 ) )
  309.     local cTitleBuffer := '', nTitlePos := 0, nTitleAttr := 0
  310.  
  311.     if ! file( 'nphelp.txt' )
  312.        @ maxrow(), 0 say padc( 'Cannot locate NPHELP.TXT!  Press any key ...', maxcol() + 1 ) 
  313.        inkey(0)
  314.     else
  315.       cText := memoread( 'nphelp.txt' )
  316.       hp := npCreate( nTop, 5, nTop + ( maxrow() / 2 ) - 4, maxcol() - 5, ;
  317.                       atoAttr( 'w+/bg' ), 4000, 200, 66, 4 )
  318.       npColor( hp, atoAttr( 'w+/bg' ) )
  319.       gettitle( @cTitleBuffer, @nTitlePos, @nTitleAttr )
  320.       settitle( " Help Text Notepad ", 1, atoAttr( 'w+/rb' ) )
  321.       box( npWinTop( hp )-1,               ;
  322.            npWinLeft( hp )-2,              ;
  323.            npWinBottom( hp )+1,            ;
  324.            npWinRight( hp )+2, '', atoAttr( 'w+/bg' ) )          
  325.       npStore( hp, NP_WRAP, cText)
  326.       NotePad( hp )
  327.       settitle( cTitleBuffer, nTitlePos, nTitleAttr )
  328.       restscreen( 0, 0, maxrow(), maxcol(), cScrn )
  329.     endif
  330.  
  331. return Nil
  332.