Previous Page TOC Next Page

Character User Interface (FMLI and ETI)

Windows

Introduction


An earlier section in this guide, "More about refresh() and Windows">More about refresh() and Windows" explained what windows and pads are and why you might want to use them. This section describes the ETI routines you use to manipulate and create windows and pads.

Output and Input


The routines that you use to send output to and get input from windows and pads are similar to those you use with stdscr. The only difference is that you have to give the name of the window to receive the action. Generally, these functions have names formed by putting the letter w at the beginning of the name of a stdscr routine and adding the window name as the first parameter. For example, addch('c') would become waddch(mywin, 'c') if you wanted to write the character c to the window mywin. Here's a list of the window (or w) versions of the output routines.


You can see from their declarations that these routines differ from the versions that manipulate stdscr only in their names and the addition of a win argument. Notice that the routines whose names begin with mvw take the win argument before the y, x coordinates, which is contrary to what the names imply. See curses(3X) for more information about these routines or the versions of the input routines getch(), getstr(), and so on that you should use with windows.

All w routines can be used with pads except for wrefresh() and wnoutrefresh() (see below). In place of these two routines, you have to use prefresh() and pnoutrefresh() with pads.

The Routines wnoutrefresh() and doupdate()


If you recall from the earlier discussion about refresh(), we said that it sends the output from stdscr to the terminal screen. We also said that it was a macro that expands to wrefresh(stdscr) (see "What Every ETI Program Needs" and "More about refresh() and Windows").

The wrefresh() routine is used to send the contents of a window (stdscr or one that you create) to a screen; it calls the routines wnoutrefresh() and doupdate(). Similarly, prefresh() sends the contents of a pad to a screen by calling pnoutrefresh() and doupdate().

Using wnoutrefresh()-or pnoutrefresh() (this discussion will be limited to the former routine for simplicity)-and doupdate(), you can update terminal screens more efficiently than using wrefresh() by itself. wrefresh() works by first calling wnoutrefresh(), which copies the named window to a data structure referred to as the virtual screen. The virtual screen contains what a program intends to display at a terminal. After calling wnoutrefresh(), wrefresh() then calls doupdate(), which compares the virtual screen to the physical screen and does the actual update. If you want to output several windows at once, calling wrefresh() will result in alternating calls to wnoutrefresh() and doupdate(), causing several bursts of output to a screen. However, by calling wnoutrefresh() for each window and then doupdate() only once, you can minimize the total number of characters transmitted and the processor time used. The following screen shows a sample program that uses only one doupdate().

Using wnoutrefresh() and doupdate()


Notice from the sample that you declare a new window at the beginning of an ETI program. The lines


declare two windows named w1 and w2 with the routine newwin() according to certain specifications. newwin() is discussed in more detail below.

The following figures illustrate the effect of wnoutrefresh() and doupdate() on these two windows, the virtual screen, and the physical screen.

Undisplayed Graphic

Undisplayed Graphic

Undisplayed Graphic

New Windows


Following are descriptions of the routines newwin() and subwin(), which you use to create new windows. For information about creating new pads with newpad() and subpad(), see the curses(3X) manual pages.

newwin()

NOTES

EXAMPLE


Recall the sample program using two windows. Also see the "The window Program" in Appendix D of this document.

subwin()

NOTES


CAUTION: Subwindows of subwindows do not work (as of the copyright date of this guide).

EXAMPLE


This program prints a border of w's around stdscr (the sides of your terminal screen) and a border of s's around the subwindow sub when it is run.For another example, see the window program in Appendix D of this document.

ETI Low-level Interface (curses) to High-level Functions


In the following chapters, we will consider the ETI high-level functions, which create and manipulate panels, menus, and forms. All application programs that use these high-level functions require a set of low-level ETI (curses) calls that properly initialize and terminate the programs. For convenience, you may want to isolate these calls in appropriate routines. The following screen shows one way you might do this. It lists routines to start low-level ETI, terminate it, and handle fatal errors.

Sample Routines for Low-Level ETI (curses) Interface


These house-keeping routines use two global variables, PGM and CURSES. PGM is initialized with the program's name, while the Boolean CURSES is initialized with FALSE because curses itself has not yet been invoked.

Function start_curses() calls the low-level routines previously mentioned and sets CURSES to TRUE to indicate that it has initialized curses. Function end_curses() checks if curses is initialized and,if so, sets the variable CURSES to FALSE and terminates curses. The check is necessary because endwin() returns an error if called when curses is not initialized.

Function error is a universal fatal error handler-called whether curses is initialized or not. It first calls end_curses() to terminate it if it is on, and then prints the program's name (PGM) and message passed to it. Finally, it terminates the program itself using exit().

Previous Page Page Top TOC Next Page