home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / FOXPRO / VEDIT060 / SOURCE / VEDIT9.PRG < prev   
Text File  |  1992-04-01  |  14KB  |  463 lines

  1. *******************************************************************************
  2. *                                                                             *
  3. *VEDIT_MEMO_EDITOR()
  4. *                                                                             *
  5. *                        (c) 1992  -  Jayson R. Minard                        *
  6. *                                                                             *
  7. * This FUNCTION loads a VLIST with lines of text from a MEMO, then calls      *
  8. * the internal editor routine.  The editor routine is also written in         *
  9. * FORCE.                                                                      *
  10. *                                                                             *
  11. *******************************************************************************
  12.  
  13. #INCLUDE KEYS.HDR
  14. #INCLUDE vlist.hdr
  15. #INCLUDE vmouse.hdr
  16. #INCLUDE vedit.hdr
  17. #INCLUDE STRING.HDR
  18. #INCLUDE combined.hdr
  19. #INCLUDE SYSTEM.HDR
  20. #INCLUDE IO.HDR
  21.  
  22. VARDEF EXTERN
  23.   BYTE __color_std, __color_enhcd
  24. ENDDEF
  25.  
  26. *******************************************************************************
  27. * return codes                                                                *
  28. *   0 - no errors                                                             *
  29. *   2 - memo doesn't exist                                                    *
  30. *   3 - error reading memo                                                    *
  31. *   4 - error editting memo                                                   *
  32. *   5 - error allocating memory                                               *
  33. *   6 - cannot open memo to save                                              *
  34. *******************************************************************************
  35.  
  36. FUNCTION UINT VEdit_Memo_Editor
  37.   PARAMETERS  MEMO      memoname,;
  38.               VALUE INT upper_row,;
  39.               VALUE INT upper_col,;
  40.               VALUE INT lower_row,;
  41.               VALUE INT lower_col,;
  42.              VALUE UINT start_line,;
  43.              VALUE UINT start_col,;
  44.              VALUE UINT right_margin,;
  45.              VALUE UINT hard_margin,;
  46.              VALUE BYTE m_text_color,;
  47.           VALUE LOGICAL word_wrap,;
  48.           VALUE LOGICAL disp_only,;
  49.           VALUE LOGICAL scroll_bar,;
  50.           VALUE LOGICAL stat_line,;
  51.              VALUE UINT stat_row,;
  52.              VALUE UINT stat_col,;
  53.           VALUE LOGICAL is_mouse,;
  54.           VALUE LOGICAL a_embedded,;
  55.              VALUE UINT tab_width,;
  56.              VALUE UINT undelete_lines,;
  57.                 UNTYPED key_handler
  58.  
  59.   VARDEF
  60.     LONG    handle,;
  61.             scrap,;
  62.             undelete
  63.     CHAR    temp_str
  64.     CHAR( 128 )  temp_filename
  65.     UINT    ret_val
  66.     UINT    top_element,;
  67.             left_col,;
  68.             temp_loc
  69.     LOGICAL going
  70.     LOGICAL need_wrap
  71.     LOGICAL go_ahead
  72.     UINT    dum
  73.     BYTE    old_std
  74.     FILE    input_file
  75.     INT     open_type
  76.   ENDDEF
  77.  
  78.   need_wrap = .F.
  79.   go_ahead  = .F.
  80.   temp_filename = "MEMOTEMP.TXT" + SPACE( 110 )
  81.  
  82.   *- initialize main text file list, use 200 width so that there is work
  83.   *  room for word wrap.  If word wrap is never used, or the right margin
  84.   *  is limited to a lower number, then this can be lowered.
  85.   *
  86.   dum = hard_margin + ( hard_margin/2 )
  87.   IF dum > 245
  88.     dum = 245
  89.   ENDIF
  90.  
  91.   handle = Vlist_Init( dum )
  92.   IF handle = 0
  93.     RETURN 5
  94.   ENDIF
  95.  
  96.   *- initialize scrap text buffers
  97.   scrap = Vlist_Init( dum )
  98.   IF scrap = 0
  99.     VList_Clear( handle )
  100.     RETURN 5
  101.   ENDIF
  102.  
  103.   *- initialize undelete text buffers
  104.   undelete = Vlist_Init( dum )
  105.   IF undelete = 0
  106.     Vlist_Clear( handle )
  107.     vlist_clear( scrap )
  108.     RETURN 5
  109.   ENDIF
  110.  
  111.   *- open file
  112.   IF .NOT. M_EXIST( memoname )
  113.   ELSE
  114.  
  115.     M_OPEN( memoname, &mo_read )
  116.  
  117.     SAVE_AREA( upper_row, upper_col, upper_row+3, upper_col+14 )
  118.     FILL( upper_row, upper_col, upper_row+3, upper_col+14,;
  119.           &double_box, " ", __color_bar, __color_tab, 6 )
  120.     old_std     = __color_std
  121.     __color_std = __color_tab
  122.     CURSOR_ON()
  123.     @upper_row+1, upper_col+2 SAY "Reading..."
  124.  
  125.     *- read file
  126.     DO WHILE .NOT. M_EOF( memoname )
  127.       M_GETLN( memoname, temp_str )
  128.  
  129.       temp_str = LEFT( RTRIM( temp_str ), hard_margin )
  130.  
  131.       temp_loc = AT( CHR( 9 ), temp_str )
  132.       DO WHILE temp_loc > 0
  133.         temp_str = LEFT( temp_str, temp_loc - 1 ) + SPACE( tab_width ) +;
  134.                    SUBSTR( temp_str, temp_loc + 1, 250 )
  135.         temp_loc = AT( CHR( 9 ), temp_str )
  136.       ENDDO
  137.  
  138.       IF LEN( temp_str ) > right_margin
  139.         need_wrap = .T.
  140.       ENDIF
  141.  
  142.       *- pad the string out to the far right margin
  143.       temp_str = temp_str + SPACE( hard_margin - LEN( temp_str ) )
  144.  
  145.       *- add one line of text to VLIST
  146.       IF .NOT. Vlist_Add( handle, temp_str )
  147.         __color_std = old_std
  148.         RESTORE_AREA()
  149.         Vlist_Clear( handle )
  150.         Vlist_Clear( scrap )
  151.         vlist_clear( undelete )
  152.         M_CLOSE( memoname )
  153.         RETURN 5
  154.       ENDIF
  155.  
  156.     ENDDO
  157.  
  158.     *- close file
  159.     M_CLOSE( memoname )
  160.     __color_std = old_std
  161.     RESTORE_AREA()
  162.   ENDIF
  163.  
  164.   *- lets check the parameters to make sure they are valid
  165.   IF start_line > Vlist_Max( handle )
  166.     start_line = Vlist_Max( handle )
  167.   ENDIF
  168.  
  169.   IF start_col = 0
  170.     start_col = 1
  171.   ENDIF
  172.  
  173.   IF start_col > hard_margin
  174.     start_col = hard_margin
  175.   ENDIF
  176.  
  177.   IF start_line = 0
  178.     start_line = 1
  179.   ENDIF
  180.  
  181.   IF right_margin < 10
  182.     right_margin = 10
  183.   ENDIF
  184.  
  185.   IF right_margin > hard_margin
  186.     right_margin = hard_margin
  187.   ENDIF
  188.  
  189.   top_element = 0
  190.   left_col    = 0
  191.   going       = .T.
  192.  
  193.   *- if word wrap on, and at least one line in the file was longer than
  194.   *  the right margin, then word wrap the whole file.
  195.   IF need_wrap
  196.     IF word_wrap
  197.       VEdit_Word_Wrap( handle, 1, .F., right_margin, hard_margin,;
  198.          dum, dum )
  199.     ENDIF
  200.  
  201.   ENDIF
  202.  
  203.   DO WHILE going
  204.  
  205.     *- call internal editor, NOTE:  this is the same thing the MEMO editor
  206.     *  calls since it just edits text in a VLIST, it does not care where
  207.     *  it came from.
  208.  
  209.     ret_val = VEdit_Internal_Editor( handle, scrap, undelete,;
  210.                upper_row, upper_col,;
  211.                lower_row, lower_col,;
  212.                top_element, start_line, left_col, start_col,;
  213.                right_margin, hard_margin, m_text_color, word_wrap,;
  214.                disp_only, .F., scroll_bar, stat_line, stat_row, stat_col,;
  215.                is_mouse, a_embedded,;
  216.                tab_width, undelete_lines,;
  217.                key_handler )
  218.  
  219.     *- check our return cases
  220.     DO CASE
  221.       CASE ret_val = &edit_continue && continue with edit, I guess we must
  222.         && have resized or something!
  223.         LOOP
  224.       CASE ret_val = &edit_none     && exit after doing NOTHING
  225.         ret_val = 0
  226.         going = .F.
  227.  
  228.       CASE ret_val = &edit_save_scrap .OR.;
  229.              ret_val = &edit_read_scrap
  230.         IF ret_val = &edit_save_scrap .AND. Vlist_Max( scrap ) = 0
  231.           LOOP
  232.         ENDIF
  233.  
  234.         SAVE_AREA( upper_row, upper_col, upper_row+3, upper_col+38 )
  235.         FILL( upper_row, upper_col, upper_row+3, upper_col+38,;
  236.               &double_box, " ", __color_bar, __color_tab, 6 )
  237.         old_std = __color_std
  238.         __color_std = __color_tab
  239.         CURSOR_ON()
  240.         temp_filename = LEFT( TRIM( temp_filename ), 128 )
  241.         temp_filename = temp_filename + SPACE( 128 - LEN( temp_filename ) )
  242.         @upper_row+1, upper_col+2 SAY "Enter SCRAP filename:";
  243.                                   GET temp_filename PICTURE "@K@S12"
  244.         READ
  245.         __color_std = old_std
  246.         RESTORE_AREA()
  247.         IF LASTKEY() = 27
  248.           LOOP
  249.         ELSE
  250.           temp_filename = TRIM( temp_filename )
  251.         ENDIF
  252.  
  253.         SAVE_AREA( upper_row, upper_col, upper_row+3, upper_col+14 )
  254.         FILL( upper_row, upper_col, upper_row+3, upper_col+14,;
  255.               &double_box, " ", __color_bar, __color_tab, 6 )
  256.         old_std = __color_std
  257.         __color_std = __color_tab
  258.         CURSOR_ON()
  259.         IF ret_val = &edit_save_scrap
  260.           @upper_row+1, upper_col+2 SAY "Saving..."
  261.           open_type = &f_create
  262.         ELSE
  263.           @upper_row+1, upper_col+2 SAY "Reading..."
  264.           open_type = &f_read
  265.         ENDIF
  266.  
  267.         IF .NOT. F_OPEN( input_file, temp_filename, open_type )
  268.           ret_val = 6
  269.           going = .F.
  270.         ELSE
  271.           IF ret_val = &edit_save_scrap
  272.             VLIST_Top( scrap )
  273.             DO WHILE .NOT. VLIST_BOL( scrap )
  274.               temp_str = RTRIM( Vlist_Cstr( scrap ) )
  275.               F_PUT( input_file, temp_str + CHR( 13 ) + CHR( 10 ) )
  276.               Vlist_Skip( scrap, &jl_forward )
  277.             ENDDO
  278.  
  279.           ELSE
  280.           * read scrap
  281.             DO WHILE .NOT. F_EOF( input_file )
  282.               IF .NOT. F_GETLN( input_file, temp_str )
  283.                 __color_std = old_std
  284.                 RESTORE_AREA()
  285.                 F_CLOSE( input_file )
  286.                 ret_val = 3
  287.                 going = .F.
  288.                 LOOP
  289.               ENDIF
  290.  
  291.               temp_str = LEFT( RTRIM( temp_str ), hard_margin )
  292.  
  293.               temp_loc = AT( CHR( 9 ), temp_str )
  294.               DO WHILE temp_loc > 0
  295.                 temp_str = LEFT( temp_str, temp_loc - 1 ) + SPACE( tab_width ) +;
  296.                            SUBSTR( temp_str, temp_loc + 1, 250 )
  297.                 temp_loc = AT( CHR( 9 ), temp_str )
  298.               ENDDO
  299.  
  300.               *- pad the string out to the far right margin
  301.               temp_str = temp_str + SPACE( hard_margin - LEN( temp_str ) )
  302.  
  303.               IF .NOT. Vlist_Add( scrap, temp_str )
  304.                 __color_std = old_std
  305.                 RESTORE_AREA()
  306.                 F_CLOSE( input_file )
  307.                 ret_val = 5
  308.                 going = .F.
  309.                 LOOP
  310.               ENDIF
  311.  
  312.             ENDDO
  313.  
  314.           ENDIF
  315.  
  316.           F_CLOSE( input_file )
  317.         ENDIF
  318.  
  319.         __color_std = old_std
  320.         RESTORE_AREA()
  321.  
  322.       CASE  ret_val = &edit_save_as_new .OR.;
  323.               ret_val = &edit_save_rename
  324.  
  325.         SAVE_AREA( upper_row, upper_col, upper_row+3, upper_col+38 )
  326.         FILL( upper_row, upper_col, upper_row+3, upper_col+38,;
  327.               &double_box, " ", __color_bar, __color_tab, 6 )
  328.         old_std = __color_std
  329.         __color_std = __color_tab
  330.         CURSOR_ON()
  331.         temp_filename = LEFT( TRIM( temp_filename ), 128 )
  332.         temp_filename = temp_filename + SPACE( 128 - LEN( temp_filename ) )
  333.         @upper_row+1, upper_col+2 SAY "Enter TEXT filename:";
  334.                                   GET temp_filename PICTURE "@K@S12"
  335.         READ
  336.         __color_std = old_std
  337.         RESTORE_AREA()
  338.         IF LASTKEY() = 27
  339.           LOOP
  340.         ENDIF
  341.  
  342.         temp_filename = TRIM( temp_filename )
  343.  
  344.         SAVE_AREA( upper_row, upper_col, upper_row+3, upper_col+13 )
  345.         FILL( upper_row, upper_col, upper_row+3, upper_col+13,;
  346.               &double_box, " ", __color_bar, __color_tab, 6 )
  347.         old_std = __color_std
  348.         __color_std = __color_tab
  349.         CURSOR_ON()
  350.         @upper_row+1, upper_col+2 SAY "Saving..."
  351.  
  352.         * save the sucker!
  353.  
  354.         IF .NOT. F_OPEN( input_file, temp_filename, &f_create )
  355.           ret_val = 6
  356.           going = .F.
  357.         ELSE
  358.           VLIST_Top( handle )
  359.           DO WHILE .NOT. VList_BOL( handle )
  360.             temp_str = RTRIM( Vlist_Cstr( handle ) )
  361.             F_PUT( input_file, temp_str + CHR( 13 ) + CHR( 10 ) )
  362.             Vlist_Skip( handle, &jl_forward )
  363.           ENDDO
  364.  
  365.           F_CLOSE( input_file )
  366.         ENDIF
  367.  
  368.         __color_std = old_std
  369.         RESTORE_AREA()
  370.  
  371.       CASE ret_val = &edit_save_exit .OR.;
  372.                    ret_val = &edit_save_continue .OR.;
  373.                    ret_val = &edit_error                && save
  374.  
  375.         IF ret_val = &edit_save_exit .OR.;
  376.                  ret_val = &edit_error
  377.  
  378.           * do they really want to exit without saving?
  379.           SAVE_AREA( upper_row, upper_col, upper_row+3, upper_col+29 )
  380.           FILL( upper_row, upper_col, upper_row+3, upper_col+29,;
  381.                 &double_box, " ", __color_bar, __color_tab, 6 )
  382.           old_std = __color_std
  383.           __color_std = __color_tab
  384.           CURSOR_ON()
  385.           IF ret_val = &edit_error
  386.             @upper_row+1, upper_col+2 SAY "ERROR!  Save text (Y/N)?"
  387.           ELSE
  388.             @upper_row+1, upper_col+2 SAY "Save before exit (Y/N)?"
  389.           ENDIF
  390.  
  391.           DO WHILE INKEY() <> 0
  392.           ENDDO
  393.  
  394.           REPEAT
  395.             dum = GET_KEY()
  396.           UNTIL CHR( dum ) $ "YyNn" .OR. dum=27
  397.  
  398.           __color_std = old_std
  399.           RESTORE_AREA()
  400.           IF dum = 27
  401.             LOOP
  402.           ENDIF
  403.  
  404.           IF dum <> 'Y' .AND. dum <> 'y'
  405.             go_ahead = .F.
  406.           ELSE
  407.             go_ahead = .T.
  408.           ENDIF
  409.  
  410.         ELSE
  411.           go_ahead = .T.
  412.         ENDIF
  413.  
  414.         IF go_ahead
  415.           SAVE_AREA( upper_row, upper_col, upper_row+3, upper_col+13 )
  416.           FILL( upper_row, upper_col, upper_row+3, upper_col+13,;
  417.                 &double_box, " ", __color_bar, __color_tab, 6 )
  418.           old_std = __color_std
  419.           __color_std = __color_tab
  420.           CURSOR_ON()
  421.           @upper_row+1, upper_col+2 SAY "Saving..."
  422.  
  423.           * save the sucker!
  424.  
  425.           M_OPEN( memoname, &mo_create )
  426.           VLIST_Top( handle )
  427.           DO WHILE .NOT. VList_BOL( handle )
  428.             temp_str = RTRIM( Vlist_Cstr( handle ) )
  429.             M_PUT( memoname, temp_str + CHR( 13 ) + CHR( 10 ) )
  430.             Vlist_Skip( handle, &jl_forward )
  431.           ENDDO
  432.  
  433.           M_CLOSE( memoname )
  434.  
  435.           __color_std = old_std
  436.           RESTORE_AREA()
  437.         ENDIF
  438.  
  439.         IF ret_val = &edit_save_exit
  440.           going = .F.
  441.           ret_val = 0
  442.         ELSE
  443.           IF ret_val = &edit_error
  444.             ret_val = 4
  445.             going = .F.
  446.           ELSE
  447.             going = .T.
  448.           ENDIF
  449.  
  450.         ENDIF
  451.  
  452.     ENDCASE
  453.  
  454.   ENDDO
  455.  
  456.   *- clean up memory
  457.   Vlist_Clear( handle )
  458.   Vlist_Clear( scrap )
  459.   Vlist_Clear( undelete )
  460.  
  461.   RETURN ret_val
  462. ENDPRO
  463.