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.
- To copy a selected area in the clipboard, the user must use:
- Alt+c under Ms-Dos,
- Ctrl+c under Ms-windows,
- the key defined as the copy keys under X11.
- To cut a selected area in the clipboard, the user must use:
- Alt+x under Ms-Dos,
- Ctrl+x under Ms-windows,
- the key defined as the cut keys under X11.
- To add the clipboard to the text, the user must use:
- Alt+v under Ms-Dos,
- Ctrl+v under Ms-windows,
- the key defined as the past keys under X11.
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 attached window (tx_window),
- the coordinates of lower left corner (tx_left,tx_top),
- the width (tx_height),
- the height (tx_width),
- the cursor position in numbers of characters and numbers
of lines (tx_cursor,tx_line),
- the number of the first displayed line (tx_1st_line),
- the number of the first row of displayed characters
(tx_1st_row),
- the state of the object, that can be:
- tx_state=Edited when the user is editing the text,
- tx_state=Editable when the user can edit the text but is not doing so,
- tx_state=View_only when the user can't modify the
displayed text.
- the number and position of the scrollbars. The edit area
can include no scrollbar (tx_scroll=Noscroll), or a vertical
scrollbar (tx_scroll=Vscroll), or a horizontal and a vertical
scrollbar (tx_scroll=Dscroll),
- the position of the vertical scrollbar (tx_hscroll) and
that of the horizontal scrollbar (tx_vscroll),
- the edited text, formatted under the type
string vetc
.
This type is called lines. The variable content is the present
text (tx_name),
- the flag that indicates if the text has been modified
(tx_modified=true) or not since it was created, or since it
was last saved.
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.