Silverfrost Logo About Us | Contact Us


This format code provides a text editor and is by far the most complex format available. However, many applications will not require any of the embellishments detailed below. Note that %rs and %re are simpler to use but are limited to 32768 characters.

Two arguments are required, a pointer to the buffer containing the text to be edited, and an integer specifying the maximum size of the buffer. The text should be terminated by the null (CHAR(0)) character, and new lines should consist of carriage return/line feed pairs. This does not use the standard Windows edit control and as a result there is no limit (other than the total available memory) to the size of the text area. If the second argument (the length of the buffer) is set to zero, the edit box allocates its own memory for the buffer, re-sizing it as required.

%60eb denotes an edit box that displays 60 characters on one line (which is the same as %60.1eb). %60.20eb denotes an edit box that displays 60 characters by 20 lines.

The text itself has the format of a normal DOS text file (lines of text separated by a carriage return/line feed character pair) with a closing a null terminator. The edit box can also handle text lines separated by carriage return characters only, providing this is used consistently.

In order to read/write data to a file in this format the file should be opened in binary mode.

For example:

    CHARACTER*1000 buffer
    CHARACTER*80 fname
    INTEGER handle,err_code,bytes_read,nbytes,winio@
    CALL openr@(fname,handle,err_code)
    CALL readf@(buffer,handle,1000,bytes_read,err_code)
    CALL closef@(handle,err_code)
    CALL openw@(fname,handle,err_code)
    CALL writef@(buffer,handle,nbytes,err_code)

The only null character in the string must be at the end. You must include the null character when calculating the length of a string. In the above example, the Fortran INDEX intrinsic function has been used to obtain the size of the edit buffer. An alternative method is given below. Note that openr@ etc. are Silverfrost Fortran library routines.

<option list> is a list of items surrounded by square brackets and separated by commas. The entire (square-bracketed) list may be omitted if no options are required.


Supply and control a horizontal scroll bar.


Like hscrollbar but the user is prevented from scrolling horizontally until all characters have disappeared.


Supply and control a vertical scroll bar.


Inhibit all horizontal scrolling.


Inhibit all vertical scrolling.


Changes the action of Del, Backspace, and Enter keys so that they never split or join lines.


Uses a fixed font for the edit box, rather than the default variable font. (However, it is preferable to use %fn, with a monospaced font such as Courier New, before %eb in the format string.)


Causes the call-back to be called every time the box gains or loses the focus. Note that the over use of this option can cause annoying effects for the user and more importantly an infinite loop may be started if the result of an object gaining a focus is the shift of that focus to another object!


Uses tabs in the edit box in the normal way for an editor. Otherwise tabs are used to cycle through the various controls in the parent window.


Removes the line around the edit box without removing the blank border (no_border removes both). This option is particularly useful for edit boxes which fill a window.


Omit the blank border that by default is placed between the text and the surrounding box.


Prevents the user from changing the text. The cursor can still be used to scroll through the text.


The call-back function is invoked in such a way that the colours used for text and its background can be modified. This facility could be used, for example, to produce an editor which highlighted certain keywords. The use of this option is described further below.


Allows CLEARWIN_STRING@('CALLBACK_REASON') to be used within a call-back function. For %eb the possible returns include 'DATA_ALTERATION'.


Causes the edit box to save information to enable changes to be 'undone'. By default all changes are recorded and can be undone in reverse order. The program can also restrict the amount of undo information by calling a function. The standard call-back function 'EDIT_UNDO' is used to perform one level of undo each time it is invoked. Menus or buttons attached to this call-back will automatically become grey when no more undo information is available. The undo mechanism can reverse changes made using the keyboard/ mouse or by calling any of the edit-box related functions. However changes made by directly altering the buffer and calling WINDOW_UPDATE@ will not be recorded and cannot be reversed.


By default if, when you move the cursor up or down, you end up off the end of the line, the cursor will snap back to the end of the line. For some purposes, such as when you are using block marks (see below), this is inconvenient. Use the no_cursor_snap option to leave the cursor in free space on the end of the line.


Responds to a mouse (left) double click by calling the call-back function rather than by marking a word.


Responds to a mouse right click by calling the call-back function rather than by looking for a pop-up menu.

The edit box maintains a set of variables in a structure (called an EDIT_INFO structure) that controls the operation of the box. Normally these variables are hidden. However, much more detailed control of the edit box can be obtained by using the grave accent edit modifier and by supplying an array of the form:

INTEGER info(24)

If more than one edit box is open, each one must have its own EDIT_INFO structure.

The following example illustrates the use of this structure, making use of the following identifiers:






Cursor horizontal character position.



Cursor vertical character position.



Total number of lines in the buffer.



Address of edit buffer.



Size of buffer contents (excluding null terminator).



Size of memory block.



Address of the position corresponding to eb_h_position/eb_v_position.



Address of selected text if any.



Number of selected characters.



Set to VK_TAB etc. if this handles a key press.



Shift state corresponding to key.



Set to the number of the edit box (1 if only one edit box is open) when a call-back is invoked, reset afterwards. This value is used to identify which edit box is associated with the current use of a call-back function.



Set to 1 each time the buffer is modified.



Set when buffer is about to be closed.



Count of characters to colour.



Address within buffer for region to colour.



Address of foreground colours.



Address of background colours.



Reserved for future enhancements.

Users of FTN95 could define a TYPE corresponding to the EDIT_INFO array.

Although this structure is passed to most of the functions described below, you will not normally need to know its contents nor should you normally need to manipulate the buffer yourself. (You can do so it you wish, but you must remember to update the contents consistently and to make use of window_update@ at appropriate intervals.)

The following example takes the last example above and adapts it so that a) the edit box allocates its own buffer with address eb_buffer and b) the eb_modified flag is checked before a prompt to save the edited file.

 INTEGER handle,err_code,i,winio@
 INTEGER info(24),
1 eb_h_position,  eb_v_position,     eb_last_line,
2 eb_buffer,      eb_buffer_size,    eb_max_buffer_size,
3 eb_current_position,eb_selection,  eb_n_selected,
4 eb_vk_key,      eb_vk_shift,       eb_active,
5 eb_modified,    eb_closing,        eb_reserved(10)
1 (eb_h_position,    info(1)), (eb_v_position,     info(2)),
2 (eb_last_line,     info(3)), (eb_buffer,         info(4)),
3 (eb_buffer_size,   info(5)), (eb_max_buffer_size,info(6)),
4 (eb_current_position,info(7)), (eb_selection,    info(8)),
5 (eb_n_selected,      info(9)), (eb_vk_key,       info(10)),
6 (eb_vk_shift,        info(11)),(eb_active,       info(12)),
7 (eb_modified,        info(13)),(eb_closing,      info(14)),
8 (eb_reserved,        info(15))
   i=winio@('%cnSave changes?%2nl%6bt[Yes]  %6bt[No]')
     CALL openw@('myfile',handle,err_code)
     CALL writef@(CCORE1(eb_buffer),handle,eb_buffer_size,
+                 err_code)

Note the use of the Salford-supplied intrinsic function CCORE1 to return the character string at the given address.

The Salford-supplied intrinsic function LOC can be used when the address of a variable is required. For example, if an edit buffer is provided, the following fragment of code would give the position of any selected text in the window relative to the beginning of the file.

  CHARACTER*1000 buffer
  INTEGER position,info(24)

Note also that, if an edit buffer is provided, a call-back function can be used to monitor the size of the text in the buffer and to make a call to get_storage@ if it is getting full. If the buffer overflows, the system will generate a fatal error.

%eb can take the caret (^) format modifier to indicate that a call-back function is supplied (after the address of the EDIT_INFO structure if any). This function is called whenever the contents of the box change, a key is pressed, or the cursor is moved. If the call-back function does not handle the response to control keys such as Delete, BackSpace, etc., then it should return a zero value.

This format code can also use the tilde (~) format modifier to indicate that a grey control variable is supplied. This variable should precede the call-back function (if any) in the argument list.

An edit box will almost certainly contain information that the user will not wish to lose, so it is a good idea to use the %cc format to monitor the closure of the main window.



Copyright © 1999-2018 Silverfrost Limited