home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / FOXPRO / VEDIT060 / SOURCE / VEDIT7.PRG < prev    next >
Text File  |  1992-09-25  |  3KB  |  117 lines

  1. #INCLUDE KEYS.HDR
  2. #INCLUDE vlist.hdr
  3. #INCLUDE vmouse.hdr
  4. #INCLUDE vedit.hdr
  5. #INCLUDE STRING.HDR
  6. #INCLUDE WARN.HDR
  7.  
  8. PROCEDURE VEdit_Word_Wrap
  9.   PARAMETERS VALUE LONG handle,;
  10.              VALUE UINT mini,;
  11.              VALUE LOGICAL blp,;  && stop on first blank
  12.              VALUE UINT right_margin,;
  13.              VALUE UINT hard_margin,;
  14.                    UINT current_element,;
  15.                    UINT current_column
  16.  
  17.   VARDEF
  18.     UINT    temp_loc
  19.     UINT    temp_len
  20.     CHAR    temp_str, old_str
  21.     CHAR    carry
  22.     LOGICAL going, first
  23.     LOGICAL altered
  24.     UINT    old
  25.   ENDDEF
  26.  
  27.   first    = .T.
  28.   Vlist_Goto( handle, mini )
  29.   going    = .T.
  30.   carry    = ""
  31.   altered  = .F.
  32.  
  33.   DO WHILE going
  34.     temp_str = RTRIM( Vlist_Cstr( handle ) )
  35.     IF LEN( carry ) <> 0
  36.       IF ( LEN( temp_str ) = 0 ) .OR. ( LEFT( temp_str, 1 ) = CHR( 9 ) ) .OR.;
  37.                  ( LEFT( temp_str, 1 ) = CHR( 32 ) )
  38.         Vlist_Cinsert( handle, &jl_normal, &jl_default,;
  39.              carry+SPACE( hard_margin-LEN( carry ) ) )
  40.         temp_str = carry
  41.         carry    = ""
  42.       ELSE
  43.         temp_str = carry + " " + temp_str
  44.         temp_str = RTRIM( temp_str )
  45.         carry    = ""
  46.       ENDIF
  47.  
  48.       altered = .T.
  49.     ELSE
  50.       altered = .F.
  51.     ENDIF
  52.  
  53.     temp_len = LEN( temp_str )
  54.  
  55.     IF temp_len >= right_margin
  56.       temp_loc = VEdit_Last_Space( right_margin, temp_str )
  57.       old_str = temp_str
  58.       IF ( temp_loc = 0 )
  59.         *- no spaces at all?  uh oh!
  60.         carry    = SUBSTR( temp_str, right_margin, 250 )
  61.         temp_str = RTRIM( LEFT( temp_str, right_margin-1 ) )
  62.       ELSE
  63.         carry    = TRIM( SUBSTR( temp_str, temp_loc+1, 250 ) )
  64.         temp_str = RTRIM( LEFT( temp_str, temp_loc-1 ) )
  65.       ENDIF
  66.  
  67.       IF first .AND. ( current_column > temp_loc )
  68.         IF current_column < LEN( old_str )
  69.           current_column = LEN( carry ) - ( LEN( old_str ) - current_column )
  70.         ELSE
  71.           current_column  = LEN( TRIM( carry ) ) + 1
  72.           ** or:   current_column = LEN( carry ) + 2
  73.           **       carry = carry + " "
  74.         ENDIF
  75.  
  76.         current_element = current_element + 1
  77.       ENDIF
  78.  
  79.       temp_str = LEFT( temp_str, hard_margin )
  80.       temp_str = temp_str + SPACE( hard_margin - LEN( temp_str ) )
  81.       Vlist_Cedit( handle, temp_str )
  82.     ELSE
  83.       IF altered
  84.         temp_str = LEFT( temp_str, hard_margin )
  85.         temp_str = temp_str + SPACE( hard_margin - LEN( temp_str ) )
  86.         Vlist_Cedit( handle, temp_str )
  87.         altered  = .F.
  88.       ENDIF
  89.  
  90.       IF blp
  91.       * we are done since there is no wrapping here!
  92.         going = .F.
  93.         LOOP
  94.       ENDIF
  95.  
  96.     ENDIF
  97.  
  98.     Vlist_Skip( handle, &jl_forward )
  99.     IF Vlist_Bol( handle )
  100.       IF LEN( carry ) > 0
  101.         carry = LEFT( carry, hard_margin )
  102.         carry = carry + SPACE( hard_margin - LEN( carry ) )
  103.         Vlist_Add( handle, carry )
  104.       ENDIF
  105.  
  106.       going = .F.
  107.     ENDIF
  108.  
  109.     IF first
  110.       first = .F.
  111.     ENDIF
  112.  
  113.   ENDDO
  114.  
  115.   Vlist_Goto( handle, mini )
  116. ENDPRO
  117.