3.10) The text edit objects.

type scrolllink = Noscroll
                | Vscroll
                | Dscroll;;

type gr_text =
  { tx_window : gr_window
  ; mutable tx_top : int
  ; mutable tx_left : int
  ; mutable tx_width : int
  ; mutable tx_height : int
  ; mutable tx_name : string vect
  ; mutable tx_cursor : int
  ; mutable tx_line : int
  ; mutable tx_1st_line : int
  ; mutable tx_1st_row : int
  ; mutable tx_state : string_state
  ; mutable tx_scroll : scrolllink
  ; mutable tx_vscroll : int
  ; mutable tx_hscroll : int
  ; mutable tx_modified : bool
  }
;;
The type gr_text sums all the variables needed to manage a text edit area. This management include cut-copy-past functions, text modifications, and scrollbar management. Other functions are provided to perform find-replace, go-to-line-number, save and load an ASCII file, get the selected area...

The type gr_text is composed of:

The associated functions are:
gr_lines_of_string : string -> string vect
gr_lines_of_string Str transforms the string Str with new line characters, into a vector of strings. The strings of the return vector don't have new line characters.
gr_string_of_lines : string vect -> string
gr_string_of_lines Lines transforms the vector of strings into a string.
gr_draw_text : gr_text -> unit
gr_draw_text txt draws the text edit object txt.
gr_text_managed : gr_text -> event -> bool
is the function used by Camlwin to manage the text edit objects.
The edit text object has many variables used only for its management. This is why the type tmp_text and a function to translate from the type tmp_text to gr_text are provided. With this functions, programmers can create an object of type gr_text just by setting the variables that define the object.
type tmp_text =
  { t_window : gr_window
  ; mutable t_top : int
  ; mutable t_left : int
  ; mutable t_width : int
  ; mutable t_height : int
  ; mutable t_name : string vect
  ; mutable t_state : string_state
  ; mutable t_scroll : scrolllink
  }
;;
gr_make_text : tmp_text -> gr_text
The type tmp_text defines the position and the size, the initial content, the number of scrollbars and the state of the object of type gr_text that the programmer which to build whishes the function gr_make_text.
type gr_search =
    FromCursor
  | FullText
  | FullSelected
;;
gr_text_find : gr_text -> string -> gr_search -> int * int
gr_text_find Txt Str be searches for the string Str in the contents of the edit text object Txt. The search begins at the top of the text (be=FullText) or at the cursor position (be=FromCursor) or in the selected area (be=FullSelected). The returned pair is the number of the character in the line and the number of the line where the search string ended in the text. The cursor is moved to the end of the found string. If the string Str wasn't found, the function returns (-1,-1), and the cursor is not moved
gr_text_goto : gr_text -> int * int -> unit
gr_text_goto Txt (x,y) moves the cursor of the edit text object Txt to the character immediately preceding the xth character on line y.
gr_text_replace : gr_text -> string -> string -> gr_search -> bool
gr_text_replace Txt Search Replace be replaces all the occurrences of the string Search in the text edit object Txt by the string Replace. The replacement starts at the top of the text (be=FullText) or at the present cursor position (be=FromCursor) or the replacement is only made in the selected area (be=FullSelected). The function returns a boolean indicating if the string Search was found.
gr_text_save : gr_text -> out_channel -> unit
gr_text_save Txt Channel saves the text of the text edit object Txt in the output stream Channel.
gr_text_load : gr_text -> in_channel -> unit
gr_text_load Txt Channel fills the text of the text edit object Txt with the contents of the input stream Channel.
gr_get_selected_text : gr_text -> string
gr_get_selected_text Txt returns the selected area of the text edit object Txt. If there is no selected area, returns an empty string.
gr_add_text : gr_text -> string -> unit
gr_add_text Txt Str adds the string Str into the text edit object Txt at the cursor position. The added string becomes the selected area, and the cursor is moved to the end of the string.
gr_del_selected_text : gr_text -> unit
gr_del_selected_text Txt deletes the selected area in the text edit object Txt.
gr_text_init : gr_text -> unit
gr_text_init Txt moves the cursor to the first character, moves the scrollbars to the top right position, sets the text to be unedited in the text edit object Txt.