Back to index

tetex-bin  3.0
Functions | Variables
lib_slk.c File Reference
#include <curses.priv.h>
#include <ctype.h>
#include <term.h>

Go to the source code of this file.

Functions

static void slk_paint_info (WINDOW *win)
static int slk_failed (void)
 _nc_slk_initialize (WINDOW *stwin, int cols)
 slk_restore (void)

Variables

 _nc_slk_format = 0

Function Documentation

_nc_slk_initialize ( WINDOW stwin,
int  cols 
)

Definition at line 91 of file lib_slk.c.

{
    int i, x;
    int res = OK;
    unsigned max_length;

    T((T_CALLED("_nc_slk_initialize()")));

    if (SP->_slk) {         /* we did this already, so simply return */
       returnCode(OK);
    } else if ((SP->_slk = typeCalloc(SLK, 1)) == 0)
       returnCode(ERR);

    SP->_slk->ent = NULL;

    /*
     * If we use colors, vidputs() will suppress video attributes that conflict
     * with colors.  In that case, we're still guaranteed that "reverse" would
     * work.
     */
    if ((no_color_video & 1) == 0)
       SP->_slk->attr = A_STANDOUT;
    else
       SP->_slk->attr = A_REVERSE;

    SP->_slk->maxlab = ((num_labels > 0)
                     ? num_labels
                     : MAX_SKEY(_nc_slk_format));
    SP->_slk->maxlen = ((num_labels > 0)
                     ? label_width * label_height
                     : MAX_SKEY_LEN(_nc_slk_format));
    SP->_slk->labcnt = ((SP->_slk->maxlab < MAX_SKEY(_nc_slk_format))
                     ? MAX_SKEY(_nc_slk_format)
                     : SP->_slk->maxlab);

    if (SP->_slk->maxlen <= 0
       || SP->_slk->labcnt <= 0
       || (SP->_slk->ent = typeCalloc(slk_ent,
                                   (unsigned) SP->_slk->labcnt)) == NULL)
       returnCode(slk_failed());

    max_length = SP->_slk->maxlen;
    for (i = 0; i < SP->_slk->labcnt; i++) {

       if ((SP->_slk->ent[i].ent_text = (char *)_nc_doalloc(0, max_length + 1)) == 0)
           returnCode(slk_failed());
       memset(SP->_slk->ent[i].ent_text, 0, max_length + 1);

       if ((SP->_slk->ent[i].form_text = (char *)_nc_doalloc(0, max_length + 1)) == 0)
           returnCode(slk_failed());
       memset(SP->_slk->ent[i].form_text, 0, max_length + 1);

       memset(SP->_slk->ent[i].form_text, ' ', max_length);
       SP->_slk->ent[i].visible = (i < SP->_slk->maxlab);
    }
    if (_nc_slk_format >= 3) {     /* PC style */
       int gap = (cols - 3 * (3 + 4 * max_length)) / 2;

       if (gap < 1)
           gap = 1;

       for (i = x = 0; i < SP->_slk->maxlab; i++) {
           SP->_slk->ent[i].ent_x = x;
           x += max_length;
           x += (i == 3 || i == 7) ? gap : 1;
       }
       slk_paint_info(stwin);
    } else {
       if (_nc_slk_format == 2) {  /* 4-4 */
           int gap = cols - (SP->_slk->maxlab * max_length) - 6;

           if (gap < 1)
              gap = 1;
           for (i = x = 0; i < SP->_slk->maxlab; i++) {
              SP->_slk->ent[i].ent_x = x;
              x += max_length;
              x += (i == 3) ? gap : 1;
           }
       } else {
           if (_nc_slk_format == 1) {     /* 1 -> 3-2-3 */
              int gap = (cols - (SP->_slk->maxlab * max_length) - 5)
              / 2;

              if (gap < 1)
                  gap = 1;
              for (i = x = 0; i < SP->_slk->maxlab; i++) {
                  SP->_slk->ent[i].ent_x = x;
                  x += max_length;
                  x += (i == 2 || i == 4) ? gap : 1;
              }
           } else
              returnCode(slk_failed());
       }
    }
    SP->_slk->dirty = TRUE;
    if ((SP->_slk->win = stwin) == NULL) {
       returnCode(slk_failed());
    }

    /* We now reset the format so that the next newterm has again
     * per default no SLK keys and may call slk_init again to
     * define a new layout. (juergen 03-Mar-1999)
     */
    SP->slk_format = _nc_slk_format;
    _nc_slk_format = 0;
    returnCode(res);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int slk_failed ( void  ) [static]

Definition at line 76 of file lib_slk.c.

{
    if (SP->_slk) {
       FreeIfNeeded(SP->_slk->ent);
       free(SP->_slk);
       SP->_slk = (SLK *) 0;
    }
    return ERR;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void slk_paint_info ( WINDOW win) [static]

Definition at line 58 of file lib_slk.c.

{
    if (win && SP->slk_format == 4) {
       int i;

       mvwhline(win, 0, 0, 0, getmaxx(win));
       wmove(win, 0, 0);

       for (i = 0; i < SP->_slk->maxlab; i++) {
           mvwprintw(win, 0, SP->_slk->ent[i].ent_x, "F%d", i + 1);
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 203 of file lib_slk.c.

{
    T((T_CALLED("slk_restore()")));

    if (SP->_slk == NULL)
       return (ERR);
    SP->_slk->hidden = FALSE;
    SP->_slk->dirty = TRUE;
    /* we have to repaint info line eventually */
    slk_paint_info(SP->_slk->win);

    returnCode(slk_refresh());
}

Here is the call graph for this function:


Variable Documentation

Definition at line 51 of file lib_slk.c.