frinit, frsetrects, frinittick, frclear, frcharofpt, frptofchar, frinsert, frdelete, frselect, frtick, frselectpaint, frdrawsel, frdrawsel0, frgetmouse – frames of text
void frinit(Frame *f, Rectangle r, Font *ft, Image *b, Image **cols)
void frsetrects(Frame *f, Rectangle r, Image *b)
void frinittick(Frame *f)
void frclear(Frame *f, int resize)
ulong frcharofpt(Frame *f, Point pt)
Point frptofchar(Frame *f, ulong p)
void frinsert(Frame *f, Rune *r0, Rune *r1, ulong p)
int frdelete(Frame *f, ulong p0, ulong p1)
void frselect(Frame *f, Mousectl *m)
void frtick(Frame *f, Point pt, int up)
void frselectpaint(Frame *f, Point p0, Point p1, Image *col)
void frdrawsel(Frame *f, Point pt0, ulong p0, ulong p1,
Point frdrawsel0(Frame *f, Point pt0, ulong p0, ulong p1,
Image *back, Image *text)
This library supports
of editable text in a single font on raster displays, such as in
Frames may hold any character except NUL (0).
Long lines are folded and tabs are at fixed intervals.
The user-visible data structure, a
is defined in
typedef struct Frame Frame;
Font *font; /* of chars in the frame */
Display *display; /* on which frame appears */
Image *b; /* on which frame appears */
Image *cols[NCOL]; /* text and background colors */
Rectangle r; /* in which text appears */
Rectangle entire; /* of full frame */
ulong p0, p1; /* selection */
ushort nbox, nalloc;
ushort maxtab; /* max size of tab, in pixels */
ushort nchars; /* # runes in frame */
ushort nlines; /* # lines with text */
ushort maxlines; /* total # lines in frame */
ushort lastlinefull; /* last line fills frame */
ushort modified; /* changed since frselect() */
Image *tick; /* typing tick */
Image *tickback; /* saved image under tick */
int ticked; /* flag: is tick onscreen? */
is an internal type and is not used by the interface.
may be changed by the application provided the selection routines are called
afterwards to maintain a consistent display.
determines the size of tab stops.
sets it to 8 times the width of a
character in the font;
it may be changed before any text is added to the frame.
The other elements of the structure are maintained by the library and
should not be modified directly.
The text within frames
is not directly addressable;
instead frames are designed to work alongside
another structure that holds the text.
The typical application is to display a section of a longer document such
as a text file or terminal session.
Usually the program will keep its own copy of the
text in the window (probably as
an array of
and pass components of this text to the frame routines to
display the visible portion.
Only the text that is visible is held by the
the application must check
to determine, for example, whether new text needs to be appended
at the end of the
There are no routines in the library to allocate
instead the interface assumes that
will be components of larger structures.
so characters drawn in it will appear
in the single
It then calls
to initialize the geometry for the
is where the
is to be drawn;
defines the limit of the portion of the
the text will occupy.
may be null, allowing the other routines to be called to maintain the
associated data structure in, for example, an obscured window.
The array of
cols sets the colors in which text and borders will be drawn. The background of the frame will be drawn in
the background of highlighted text in
borders and scroll bar in
regular text in
and highlighted text in
frees the internal structures associated with
It does not clear the associated display.
is to be deallocated, the associated
must be freed separately.
argument should be non-zero if the frame is to be redrawn with
a different font; otherwise the frame will maintain some
data structures associated with the font.
To resize a
(q.v.) to recreate the display.
is being moved but not resized, that is, if the shape of its containing
rectangle is unchanged, it is sufficient to use
to copy the containing rectangle from the old to the new location and then call
to establish the new geometry.
(It is unnecessary to call
unless the font size has changed.)
No redrawing is necessary.
hold text as runes,
not as bytes.
returns the location of the upper left corner of the
rune, starting from 0, in the
holds fewer than
returns the location of the upper right corner of the last character in
is the inverse: it
returns the index of the closest rune whose image’s upper left corner
is up and to the left of
starting at rune index
the runes between
If a NUL (0) character
is inserted, chaos will ensue.
Tabs and newlines
are handled by the library, but all other characters,
including control characters, are just displayed.
For example, backspaces are printed; to erase
a character, use
deletes from the
the text between
points at the first rune beyond the deletion.
tracks the mouse to select a contiguous string of text in the
When called, a mouse button is typically down.
will return when the button state has changed (some buttons may
still be down) and will set
to the selected range of text.
Programs that wish to manage the selection themselves have several routines to help.
They involve the maintenance of the ‘tick’, the vertical line indicating a null selection
between characters, and the colored region representing a non-null selection.
is non-zero) or removes (if
is zero) the tick at the screen position indicated by
repaints a section of the frame, delimited by character positions
either with plain background or
entirely highlighted, according to the flag
managing the tick appropriately.
is the geometrical location of
on the screen; like all of the selection-helper routines’
arguments, it must be a value generated by
is a lower-level routine, taking as arguments a background color,
and text color,
It assumes that the tick is being handled (removed beforehand, replaced afterwards, as required)
by its caller.
uses a solid color,
to paint a region of the frame defined by the