Back to index

tetex-bin  3.0
Defines | Functions | Variables
dialog.h File Reference
#include <dialogconfig.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <curses.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define USE_SHADOW   FALSE
#define USE_COLORS   TRUE
#define VERSION   "0.4"
#define ESC   27
#define TAB   9
#define MAX_LEN   2048
#define BUF_SIZE   (10*1024)
#define MIN(x, y)   (x < y ? x : y)
#define MAX(x, y)   (x > y ? x : y)
#define ACS_ULCORNER   '+'
#define ACS_LLCORNER   '+'
#define ACS_URCORNER   '+'
#define ACS_LRCORNER   '+'
#define ACS_HLINE   '-'
#define ACS_VLINE   '|'
#define ACS_LTEE   '+'
#define ACS_RTEE   '+'
#define ACS_UARROW   '^'
#define ACS_DARROW   'v'
#define screen_attr   attributes[0]
#define shadow_attr   attributes[1]
#define dialog_attr   attributes[2]
#define title_attr   attributes[3]
#define border_attr   attributes[4]
#define button_active_attr   attributes[5]
#define button_inactive_attr   attributes[6]
#define button_key_active_attr   attributes[7]
#define button_key_inactive_attr   attributes[8]
#define button_label_active_attr   attributes[9]
#define button_label_inactive_attr   attributes[10]
#define inputbox_attr   attributes[11]
#define inputbox_border_attr   attributes[12]
#define searchbox_attr   attributes[13]
#define searchbox_title_attr   attributes[14]
#define searchbox_border_attr   attributes[15]
#define position_indicator_attr   attributes[16]
#define menubox_attr   attributes[17]
#define menubox_border_attr   attributes[18]
#define item_attr   attributes[19]
#define item_selected_attr   attributes[20]
#define tag_attr   attributes[21]
#define tag_selected_attr   attributes[22]
#define tag_key_attr   attributes[23]
#define tag_key_selected_attr   attributes[24]
#define check_attr   attributes[25]
#define check_selected_attr   attributes[26]
#define uarrow_attr   attributes[27]
#define darrow_attr   attributes[28]
#define ATTRIBUTE_COUNT   29

Functions

void Usage (char *name)
void init_dialog (void)
void attr_clear (WINDOW *win, int height, int width, chtype attr)
void print_autowrap (WINDOW *win, char *prompt, int width, int y, int x)
void print_button (WINDOW *win, char *label, int y, int x, int selected)
void draw_box (WINDOW *win, int y, int x, int height, int width, chtype box, chtype border)
int strcasecmp ()
int dialog_yesno (char *title, char *prompt, int height, int width)
int dialog_msgbox (char *title, char *prompt, int height, int width, int pause)
int dialog_textbox (char *title, char *file, int height, int width)
int dialog_menu (char *title, char *prompt, int height, int width, int menu_height, int item_no, char **items)
int dialog_checklist (char *title, char *prompt, int height, int width, int list_height, int item_no, char **items)
int dialog_radiolist (char *title, char *prompt, int height, int width, int list_height, int item_no, char **items)
int dialog_inputbox (char *title, char *prompt, int height, int width, char *init)
int dialog_guage (char *title, char *prompt, int height, int width, int percent)

Variables

chtype attributes []
int separate_output

Define Documentation

#define ACS_DARROW   'v'

Definition at line 99 of file dialog.h.

#define ACS_HLINE   '-'

Definition at line 84 of file dialog.h.

#define ACS_LLCORNER   '+'

Definition at line 75 of file dialog.h.

#define ACS_LRCORNER   '+'

Definition at line 81 of file dialog.h.

#define ACS_LTEE   '+'

Definition at line 90 of file dialog.h.

#define ACS_RTEE   '+'

Definition at line 93 of file dialog.h.

#define ACS_UARROW   '^'

Definition at line 96 of file dialog.h.

#define ACS_ULCORNER   '+'

Definition at line 72 of file dialog.h.

#define ACS_URCORNER   '+'

Definition at line 78 of file dialog.h.

#define ACS_VLINE   '|'

Definition at line 87 of file dialog.h.

#define ATTRIBUTE_COUNT   29

Definition at line 138 of file dialog.h.

#define border_attr   attributes[4]

Definition at line 111 of file dialog.h.

#define BUF_SIZE   (10*1024)

Definition at line 66 of file dialog.h.

#define button_active_attr   attributes[5]

Definition at line 112 of file dialog.h.

Definition at line 113 of file dialog.h.

Definition at line 114 of file dialog.h.

Definition at line 115 of file dialog.h.

Definition at line 116 of file dialog.h.

Definition at line 117 of file dialog.h.

#define check_attr   attributes[25]

Definition at line 132 of file dialog.h.

#define check_selected_attr   attributes[26]

Definition at line 133 of file dialog.h.

#define darrow_attr   attributes[28]

Definition at line 135 of file dialog.h.

#define dialog_attr   attributes[2]

Definition at line 109 of file dialog.h.

#define ESC   27

Definition at line 63 of file dialog.h.

#define inputbox_attr   attributes[11]

Definition at line 118 of file dialog.h.

#define inputbox_border_attr   attributes[12]

Definition at line 119 of file dialog.h.

#define item_attr   attributes[19]

Definition at line 126 of file dialog.h.

#define item_selected_attr   attributes[20]

Definition at line 127 of file dialog.h.

#define MAX (   x,
  y 
)    (x > y ? x : y)

Definition at line 68 of file dialog.h.

#define MAX_LEN   2048

Definition at line 65 of file dialog.h.

#define menubox_attr   attributes[17]

Definition at line 124 of file dialog.h.

#define menubox_border_attr   attributes[18]

Definition at line 125 of file dialog.h.

#define MIN (   x,
  y 
)    (x < y ? x : y)

Definition at line 67 of file dialog.h.

Definition at line 123 of file dialog.h.

#define screen_attr   attributes[0]

Definition at line 107 of file dialog.h.

#define searchbox_attr   attributes[13]

Definition at line 120 of file dialog.h.

Definition at line 122 of file dialog.h.

#define searchbox_title_attr   attributes[14]

Definition at line 121 of file dialog.h.

#define shadow_attr   attributes[1]

Definition at line 108 of file dialog.h.

#define TAB   9

Definition at line 64 of file dialog.h.

#define tag_attr   attributes[21]

Definition at line 128 of file dialog.h.

#define tag_key_attr   attributes[23]

Definition at line 130 of file dialog.h.

Definition at line 131 of file dialog.h.

#define tag_selected_attr   attributes[22]

Definition at line 129 of file dialog.h.

#define title_attr   attributes[3]

Definition at line 110 of file dialog.h.

#define uarrow_attr   attributes[27]

Definition at line 134 of file dialog.h.

#define USE_COLORS   TRUE

Definition at line 57 of file dialog.h.

#define USE_SHADOW   FALSE

Definition at line 54 of file dialog.h.

#define VERSION   "0.4"

Definition at line 62 of file dialog.h.


Function Documentation

void attr_clear ( WINDOW win,
int  height,
int  width,
chtype  attr 
)

Definition at line 435 of file dialog.c.

{
/* ifdef HAVE_NCURSES
  wattrset(win, attr);    Set window to attribute 'attr'
  werase(win);
else */
  int i, j;

  wattrset(win, attr);    /* Set window to attribute 'attr' */
  for (i = 0; i < height; i++) {
    wmove(win, i, 0);
    for (j = 0; j < width; j++)
      waddch(win, ' ');
  }
  touchwin(win);
/* endif */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dialog_checklist ( char *  title,
char *  prompt,
int  height,
int  width,
int  list_height,
int  item_no,
char **  items 
)

Definition at line 34 of file checklist.c.

{
  int i, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
      scrolli = 0, max_choice, *status;
  WINDOW *dialog, *list;

  /* Allocate space for storing item on/off status */
  if ((status = malloc(sizeof(int)*item_no)) == NULL) {
    endwin();
    fprintf(stderr, "\nCan't allocate memory in dialog_checklist().\n");
    exit(-1);
  }
  /* Initializes status */
  for (i = 0; i < item_no; i++)
    status[i] = !strcasecmp(items[i*3 + 2], "on");

  max_choice = MIN(list_height, item_no);

  /* center dialog box on screen */
  x = (COLS - width)/2;
  y = (LINES - height)/2;
  
#ifdef HAVE_NCURSES
  if (use_shadow)
    draw_shadow(stdscr, y, x, height, width);
#endif
  dialog = newwin(height, width, y, x);
  keypad(dialog, TRUE);

  draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
  wattrset(dialog, border_attr);
  wmove(dialog, height-3, 0);
  waddch(dialog, ACS_LTEE);
  for (i = 0; i < width-2; i++)
    waddch(dialog, ACS_HLINE);
  wattrset(dialog, dialog_attr);
  waddch(dialog, ACS_RTEE);
  wmove(dialog, height-2, 1);
  for (i = 0; i < width-2; i++)
    waddch(dialog, ' ');

  if (title != NULL) {
    wattrset(dialog, title_attr);
    wmove(dialog, 0, (width - strlen(title))/2 - 1);
    waddch(dialog, ' ');
    waddstr(dialog, title);
    waddch(dialog, ' ');
  }
  wattrset(dialog, dialog_attr);
  print_autowrap(dialog, prompt, width, 1, 3);

  list_width = width-6;
  getyx(dialog, cur_y, cur_x);
  box_y = cur_y + 1;
  box_x = (width - list_width)/2 - 1;

  /* create new window for the list */
  list = subwin(dialog, list_height, list_width, y + box_y + 1, x + box_x + 1);
  keypad(list, TRUE);

  /* draw a box around the list items */
  draw_box(dialog, box_y, box_x, list_height+2, list_width+2, menubox_border_attr, menubox_attr);

  check_x = 0;
  item_x = 0;
  /* Find length of longest item in order to center checklist */
  for (i = 0; i < item_no; i++) {
    check_x = MAX(check_x, strlen(items[i*3]) + strlen(items[i*3 + 1]) + 6);
    item_x = MAX(item_x, strlen(items[i*3]));
  }
  check_x = (list_width - check_x) / 2;
  item_x = check_x + item_x + 6;

  /* Print the list */
  for (i = 0; i < max_choice; i++)
    print_item(list, items[i*3], items[i*3 + 1], status[i], i, i == choice);
  wnoutrefresh(list);

  if (list_height < item_no) {
    wattrset(dialog, darrow_attr);
    wmove(dialog, box_y + list_height + 1, box_x + check_x + 5);
    waddch(dialog, ACS_DARROW);
    wmove(dialog, box_y + list_height + 1, box_x + check_x + 6);
    waddstr(dialog, "(+)");
  }

  x = width/2-11;
  y = height-2;
  print_button(dialog, "Cancel", y, x+14, FALSE);
  print_button(dialog, "  OK  ", y, x, TRUE);
  wrefresh(dialog);

  while (key != ESC) {
    key = wgetch(dialog);
    /* Check if key pressed matches first character of any item tag in list */
    for (i = 0; i < max_choice; i++)
      if (toupper(key) == toupper(items[(scrolli+i)*3][0]))
        break;

    if (i < max_choice || (key >= '1' && key <= MIN('9', '0'+max_choice)) || 
        key == KEY_UP || key == KEY_DOWN || key == ' ' ||
        key == '+' || key == '-' ) {
      if (key >= '1' && key <= MIN('9', '0'+max_choice))
        i = key - '1';
      else if (key == KEY_UP || key == '-') {
        if (!choice) {
          if (scrolli) {
#ifdef BROKEN_WSCRL
    /* wscrl() in ncurses 1.8.1 seems to be broken, causing a segmentation
       violation when scrolling windows of height = 4, so scrolling is not
       used for now */
            scrolli--;
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            /* Reprint list to scroll down */
            for (i = 0; i < max_choice; i++)
              print_item(list, items[(scrolli+i)*3], items[(scrolli+i)*3 + 1], status[scrolli+i], i, i == choice);

#else

            /* Scroll list down */
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            if (list_height > 1) {
              /* De-highlight current first item before scrolling down */
              print_item(list, items[scrolli*3], items[scrolli*3 + 1], status[scrolli], 0, FALSE);
              scrollok(list, TRUE);
              wscrl(list, -1);
              scrollok(list, FALSE);
            }
            scrolli--;
            print_item(list, items[scrolli*3], items[scrolli*3 + 1], status[scrolli], 0, TRUE);
#endif
            wnoutrefresh(list);

            /* print the up/down arrows */
            wmove(dialog, box_y, box_x + check_x + 5);
            wattrset(dialog, scrolli ? uarrow_attr : menubox_attr);
            waddch(dialog, scrolli ? ACS_UARROW : ACS_HLINE);
            wmove(dialog, box_y, box_x + check_x + 6);
            waddch(dialog, scrolli ? '(' : ACS_HLINE);
            wmove(dialog, box_y, box_x + check_x + 7);
            waddch(dialog, scrolli ? '-' : ACS_HLINE);
            wmove(dialog, box_y, box_x + check_x + 8);
            waddch(dialog, scrolli ? ')' : ACS_HLINE);
            wattrset(dialog, darrow_attr);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 5);
            waddch(dialog, ACS_DARROW);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 6);
            waddch(dialog, '(');
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 7);
            waddch(dialog, '+');
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 8);
            waddch(dialog, ')');
            wmove(dialog, cur_y, cur_x);  /* Restore cursor position */
            wrefresh(dialog);
          }
          continue;    /* wait for another key press */
        }
        else
          i = choice - 1;
      }
      else if (key == KEY_DOWN || key == '+') {
        if (choice == max_choice - 1) {
          if (scrolli+choice < item_no-1) {
#ifdef BROKEN_WSCRL
    /* wscrl() in ncurses 1.8.1 seems to be broken, causing a segmentation
       violation when scrolling windows of height = 4, so scrolling is not
       used for now */
            scrolli++;
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            /* Reprint list to scroll up */
            for (i = 0; i < max_choice; i++)
              print_item(list, items[(scrolli+i)*3], items[(scrolli+i)*3 + 1], status[scrolli+i], i, i == choice);

#else

            /* Scroll list up */
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            if (list_height > 1) {
              /* De-highlight current last item before scrolling up */
              print_item(list, items[(scrolli+max_choice-1)*3], items[(scrolli+max_choice-1)*3 + 1], status[scrolli+max_choice-1], max_choice-1, FALSE);
              scrollok(list, TRUE);
              scroll(list);
              scrollok(list, FALSE);
            }
            scrolli++;
            print_item(list, items[(scrolli+max_choice-1)*3], items[(scrolli+max_choice-1)*3 + 1], status[scrolli+max_choice-1], max_choice-1, TRUE);
#endif
            wnoutrefresh(list);

            /* print the up/down arrows */
            wattrset(dialog, uarrow_attr);
            wmove(dialog, box_y, box_x + check_x + 5);
            waddch(dialog, ACS_UARROW);
            wmove(dialog, box_y, box_x + check_x + 6);
            waddstr(dialog, "(-)");
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 5);
            wattrset(dialog, scrolli+choice < item_no-1 ? darrow_attr : menubox_border_attr);
            waddch(dialog, scrolli+choice < item_no-1 ? ACS_DARROW : ACS_HLINE);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 6);
            waddch(dialog, scrolli+choice < item_no-1 ? '(' : ACS_HLINE);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 7);
            waddch(dialog, scrolli+choice < item_no-1 ? '+' : ACS_HLINE);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 8);
            waddch(dialog, scrolli+choice < item_no-1 ? ')' : ACS_HLINE);
            wmove(dialog, cur_y, cur_x);  /* Restore cursor position */
            wrefresh(dialog);
          }
          continue;    /* wait for another key press */
        }
        else
          i = choice + 1;
      }
      else if (key == ' ') {    /* Toggle item status */
        status[scrolli+choice] = !status[scrolli+choice];
        getyx(dialog, cur_y, cur_x);    /* Save cursor position */
        wmove(list, choice, check_x);
        wattrset(list, check_selected_attr);
        wprintw(list, "[%c]", status[scrolli+choice] ? 'X' : ' ');
        wnoutrefresh(list);
        wmove(dialog, cur_y, cur_x);  /* Restore cursor to previous position */
        wrefresh(dialog);
        continue;    /* wait for another key press */
      }

      if (i != choice) {
        /* De-highlight current item */
        getyx(dialog, cur_y, cur_x);    /* Save cursor position */
        print_item(list, items[(scrolli+choice)*3], items[(scrolli+choice)*3 + 1], status[scrolli+choice], choice, FALSE);

        /* Highlight new item */
        choice = i;
        print_item(list, items[(scrolli+choice)*3], items[(scrolli+choice)*3 + 1], status[scrolli+choice], choice, TRUE);
        wnoutrefresh(list);
        wmove(dialog, cur_y, cur_x);  /* Restore cursor to previous position */
        wrefresh(dialog);
      }
      continue;    /* wait for another key press */
    }

    switch (key) {
      case 'O':
      case 'o':
        delwin(dialog);
        for (i = 0; i < item_no; i++)
           if (status[i]) {
              if (separate_output) {
                  fprintf(stderr, "%s\n", items[i*3]);
              } else {
                  fprintf(stderr, "\"%s\" ", items[i*3]);
              }
           }
        free(status);
        return 0;
      case 'C':
      case 'c':
        delwin(dialog);
        free(status);
        return 1;
      case TAB:
      case KEY_LEFT:
      case KEY_RIGHT:
        if (!button) {
          button = 1;    /* Indicates "Cancel" button is selected */
          print_button(dialog, "  OK  ", y, x, FALSE);
          print_button(dialog, "Cancel", y, x+14, TRUE);
        }
        else {
          button = 0;    /* Indicates "OK" button is selected */
          print_button(dialog, "Cancel", y, x+14, FALSE);
          print_button(dialog, "  OK  ", y, x, TRUE);
        }
        wrefresh(dialog);
        break;
      case ' ':
      case '\n':
        delwin(dialog);
        if (!button)
          for (i = 0; i < item_no; i++)
             if (status[i]) {
                if (separate_output) {
                    fprintf(stderr, "%s\n", items[i*3]);
                } else {
                    fprintf(stderr, "\"%s\" ", items[i*3]);
                }
             }
        free(status);
        return button;
      case ESC:
        break;
    }
  }

  delwin(dialog);
  free(status);
  return -1;    /* ESC pressed */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dialog_guage ( char *  title,
char *  prompt,
int  height,
int  width,
int  percent 
)

Definition at line 35 of file gauge.c.

{
  int i, x, y;
  char buf[BUFLEN];
  char prompt_buf[BUFLEN];
  WINDOW *dialog;

  /* center dialog box on screen */
  x = (COLS - width)/2;
  y = (LINES - height)/2;

#ifdef HAVE_NCURSES
  if (use_shadow)
    draw_shadow(stdscr, y, x, height, width);
#endif
  dialog = newwin(height, width, y, x);
  keypad(dialog, TRUE);

  do {
      werase(dialog);
      draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);

      if (title != NULL) {
         wattrset(dialog, title_attr);
         wmove(dialog, 0, (width - strlen(title))/2 - 1);
         waddch(dialog, ' ');
         waddstr(dialog, title);
         waddch(dialog, ' ');
      }

      wattrset(dialog, dialog_attr);
      print_autowrap(dialog, prompt, width-2, 1, 2);

      draw_box(dialog, height - 4, 3, 3, width - 6, dialog_attr, border_attr);

      wmove(dialog, height - 3, 4);
      wattrset(dialog, title_attr);
      for (i = 0; i < (width - 8); i++) {
         waddch(dialog, ' ');
      }

      wattrset(dialog, title_attr);
      wmove(dialog, height - 3, (width / 2) - 2);
      sprintf(buf, "%3d%%", percent);
      waddstr(dialog, buf);

      x = (percent * (width - 8)) / 100;
      wattrset(dialog, item_selected_attr);
      wmove(dialog, height - 3, 4);
      for (i = 0; i < x; i++) {
         waddch(dialog, winch(dialog));
      }
  
      wrefresh(dialog);

      if (feof(stdin)) {
         break;
      }
      
      fgets(buf, BUFLEN, stdin);
      if (buf[0] == 'X') {
         /* Next line is percentage */
         fgets(buf, BUFLEN, stdin);
         percent = atoi(buf);

         /* Rest is message text */
         prompt_buf[0] = '\0';
         while (strncmp(fgets(buf, BUFLEN, stdin), "XXX", 3)) {
             strcat(prompt_buf, buf);
         }
         prompt = prompt_buf;
      } else {
         percent = atoi(buf);
      }
  } while (1);
  
  delwin(dialog);
  return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dialog_inputbox ( char *  title,
char *  prompt,
int  height,
int  width,
char *  init 
)

Definition at line 28 of file inputbox.c.

{
  int i, x, y, box_y, box_x, box_width,
      input_x = 0, scroll = 0, key = 0, button = -1;
  unsigned char instr[MAX_LEN+1];
  WINDOW *dialog;

  /* center dialog box on screen */
  x = (COLS - width)/2;
  y = (LINES - height)/2;
  
#ifdef HAVE_NCURSES
  if (use_shadow)
    draw_shadow(stdscr, y, x, height, width);
#endif
  dialog = newwin(height, width, y, x);
  keypad(dialog, TRUE);

  draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
  wattrset(dialog, border_attr);
  wmove(dialog, height-3, 0);
  waddch(dialog, ACS_LTEE);
  for (i = 0; i < width-2; i++)
    waddch(dialog, ACS_HLINE);
  wattrset(dialog, dialog_attr);
  waddch(dialog, ACS_RTEE);
  wmove(dialog, height-2, 1);
  for (i = 0; i < width-2; i++)
    waddch(dialog, ' ');

  if (title != NULL) {
    wattrset(dialog, title_attr);
    wmove(dialog, 0, (width - strlen(title))/2 - 1);
    waddch(dialog, ' ');
    waddstr(dialog, title);
    waddch(dialog, ' ');
  }
  wattrset(dialog, dialog_attr);
  print_autowrap(dialog, prompt, width, 1, 3);

  /* Draw the input field box */
  box_width = width-6;
  getyx(dialog, y, x);
  box_y = y + 2;
  box_x = (width - box_width)/2;
  draw_box(dialog, y+1, box_x-1, 3, box_width+2, border_attr, dialog_attr);

  x = width/2-11;
  y = height-2;
  print_button(dialog, "Cancel", y, x+14, FALSE);
  print_button(dialog, "  OK  ", y, x, TRUE);

  /* Set up the initial value */
  wmove(dialog, box_y, box_x);
  wattrset(dialog, inputbox_attr);
  if (!init) {
      instr[0] = '\0';
  } else {
      strcpy((char*)instr, init);
  }
  input_x = strlen((char*)instr);
  if (input_x >= box_width) {
      scroll = input_x - box_width + 1;
      input_x = box_width - 1;
      for (i = 0; i < box_width-1; i++) {
         waddch(dialog, instr[scroll+i]);
      }
  } else {
      waddstr(dialog, (char*)instr);
  }
  wmove(dialog, box_y, box_x + input_x);
  
  wrefresh(dialog);
  while (key != ESC) {
    key = wgetch(dialog);

    if (button == -1) {    /* Input box selected */
      switch (key) {
        case TAB:
        case KEY_UP:
        case KEY_DOWN:
          break;
        case KEY_LEFT:
          continue;
        case KEY_RIGHT:
          continue;
        case KEY_BACKSPACE:
          if (input_x || scroll) {
            wattrset(dialog, inputbox_attr);
            if (!input_x) {
              scroll = scroll < box_width-1 ? 0 : scroll-(box_width-1);
              wmove(dialog, box_y, box_x);
              for (i = 0; i < box_width; i++)
                waddch(dialog, instr[scroll+input_x+i] ? instr[scroll+input_x+i] : ' ');
              input_x = strlen((char*)instr) - scroll;
            }
            else
              input_x--;
            instr[scroll+input_x] = '\0';
            wmove(dialog, box_y, input_x + box_x);
            waddch(dialog, ' ');
            wmove(dialog, box_y, input_x + box_x);
            wrefresh(dialog);
          }
          continue;
        default:
          if (key < 0x100 && isprint(key)) {
            if (scroll+input_x < MAX_LEN) {
              wattrset(dialog, inputbox_attr);
              instr[scroll+input_x] = key;
              instr[scroll+input_x+1] = '\0';
              if (input_x == box_width-1) {
                scroll++;
                wmove(dialog, box_y, box_x);
                for (i = 0; i < box_width-1; i++)
                  waddch(dialog, instr[scroll+i]);
              }
              else {
                wmove(dialog, box_y, input_x++ + box_x);
                waddch(dialog, key);
              }
              wrefresh(dialog);
            } else
             flash(); /* Alarm user about overflow */
            continue;
          }
      }
    }

    switch (key) {
      case 'O':
      case 'o':
        delwin(dialog);
        fprintf(stderr, (char*)instr);
        return 0;
      case 'C':
      case 'c':
        delwin(dialog);
        return 1;
      case KEY_UP:
      case KEY_LEFT:
        switch (button) {
         case -1:
            button = 1;    /* Indicates "Cancel" button is selected */
           print_button(dialog, "  OK  ", y, x, FALSE);
           print_button(dialog, "Cancel", y, x+14, TRUE);
            wrefresh(dialog);
           break;
          case 0:
            button = -1;   /* Indicates input box is selected */
           print_button(dialog, "Cancel", y, x+14, FALSE);
           print_button(dialog, "  OK  ", y, x, TRUE);
            wmove(dialog, box_y, box_x + input_x);
            wrefresh(dialog);
            break;
          case 1:
           button = 0;    /* Indicates "OK" button is selected */
           print_button(dialog, "Cancel", y, x+14, FALSE);
           print_button(dialog, "  OK  ", y, x, TRUE);
            wrefresh(dialog);
            break;
        }
        break;
      case TAB:
      case KEY_DOWN:
      case KEY_RIGHT:
        switch (button) {
         case -1:
           button = 0;    /* Indicates "OK" button is selected */
           print_button(dialog, "Cancel", y, x+14, FALSE);
           print_button(dialog, "  OK  ", y, x, TRUE);
            wrefresh(dialog);
            break;
          case 0:
            button = 1;    /* Indicates "Cancel" button is selected */
           print_button(dialog, "  OK  ", y, x, FALSE);
           print_button(dialog, "Cancel", y, x+14, TRUE);
            wrefresh(dialog);
           break;
          case 1:
            button = -1;   /* Indicates input box is selected */
           print_button(dialog, "Cancel", y, x+14, FALSE);
           print_button(dialog, "  OK  ", y, x, TRUE);
            wmove(dialog, box_y, box_x + input_x);
            wrefresh(dialog);
            break;
        }
        break;
      case ' ':
      case '\n':
        delwin(dialog);
        fprintf(stderr, (char*)instr);
        return (button == -1 ? 0 : button);
      case ESC:
        break;
    }
  }

  delwin(dialog);
  return -1;    /* ESC pressed */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dialog_menu ( char *  title,
char *  prompt,
int  height,
int  width,
int  menu_height,
int  item_no,
char **  items 
)

Definition at line 34 of file menubox.c.

{
  int i, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
      scrolli = 0, max_choice;
  WINDOW *dialog, *menu;

  max_choice = MIN(menu_height, item_no);

  /* center dialog box on screen */
  x = (COLS - width)/2;
  y = (LINES - height)/2;
  
#ifdef HAVE_NCURSES
  if (use_shadow)
    draw_shadow(stdscr, y, x, height, width);
#endif
  dialog = newwin(height, width, y, x);
  keypad(dialog, TRUE);

  draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
  wattrset(dialog, border_attr);
  wmove(dialog, height-3, 0);
  waddch(dialog, ACS_LTEE);
  for (i = 0; i < width-2; i++)
    waddch(dialog, ACS_HLINE);
  wattrset(dialog, dialog_attr);
  waddch(dialog, ACS_RTEE);
  wmove(dialog, height-2, 1);
  for (i = 0; i < width-2; i++)
    waddch(dialog, ' ');

  if (title != NULL) {
    wattrset(dialog, title_attr);
    wmove(dialog, 0, (width - strlen(title))/2 - 1);
    waddch(dialog, ' ');
    waddstr(dialog, title);
    waddch(dialog, ' ');
  }
  wattrset(dialog, dialog_attr);
  print_autowrap(dialog, prompt, width, 1, 3);

  menu_width = width-6;
  getyx(dialog, cur_y, cur_x);
  box_y = cur_y + 1;
  box_x = (width - menu_width)/2 - 1;

  /* create new window for the menu */
  menu = subwin(dialog, menu_height, menu_width, y + box_y + 1, x + box_x + 1);
  keypad(menu, TRUE);

  /* draw a box around the menu items */
  draw_box(dialog, box_y, box_x, menu_height+2, menu_width+2, menubox_border_attr, menubox_attr);

  tag_x = 0;
  item_x = 0;
  /* Find length of longest item in order to center menu */
  for (i = 0; i < item_no; i++) {
    tag_x = MAX(tag_x, strlen(items[i*2]) + strlen(items[i*2 + 1]) + 2);
    item_x = MAX(item_x, strlen(items[i*2]));
  }
  tag_x = (menu_width - tag_x) / 2;
  item_x = tag_x + item_x + 2;

  /* Print the menu */
  for (i = 0; i < max_choice; i++)
    print_item(menu, items[i*2], items[i*2 + 1], i, i == choice);
  wnoutrefresh(menu);

  if (menu_height < item_no) {
    wattrset(dialog, darrow_attr);
    wmove(dialog, box_y + menu_height + 1, box_x + tag_x + 1);
    waddch(dialog, ACS_DARROW);
    wmove(dialog, box_y + menu_height + 1, box_x + tag_x + 2);
    waddstr(dialog,"(+)");
  }

  x = width/2-11;
  y = height-2;
  print_button(dialog, "Cancel", y, x+14, FALSE);
  print_button(dialog, "  OK  ", y, x, TRUE);
  wrefresh(dialog);

  while (key != ESC) {
    key = wgetch(dialog);
    /* Check if key pressed matches first character of any item tag in menu */
    for (i = 0; i < max_choice; i++)
      if (toupper(key) == toupper(items[(scrolli+i)*2][0]))
        break;
/*    i = (choice+scrolli+1) % max_choice ;
    while (i != choice+scrolli) {
      if (toupper(key) == toupper(items[i*2][0]))
         break;
      i = (i + 1) % max_choice;
    }
    */

    if (i < max_choice || (key >= '1' && key <= MIN('9', '0'+max_choice)) || 
        key == KEY_UP || key == KEY_DOWN || key == '-' || key == '+') {
      if (key >= '1' && key <= MIN('9', '0'+max_choice))
        i = key - '1';
      else if (key == KEY_UP || key == '-') {
        if (!choice) {
          if (scrolli) {
#ifdef BROKEN_WSCRL
    /* wscrl() in ncurses 1.8.1 seems to be broken, causing a segmentation
       violation when scrolling windows of height = 4, so scrolling is not
       used for now */
            scrolli--;
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            /* Reprint menu to scroll down */
            for (i = 0; i < max_choice; i++)
              print_item(menu, items[(scrolli+i)*2], items[(scrolli+i)*2 + 1], i, i == choice);

#else

            /* Scroll menu down */
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            if (menu_height > 1) {
              /* De-highlight current first item before scrolling down */
              print_item(menu, items[scrolli*2], items[scrolli*2 + 1], 0, FALSE);
              scrollok(menu, TRUE);
              wscrl(menu, -1);
              scrollok(menu, FALSE);
            }
            scrolli--;
            print_item(menu, items[scrolli*2], items[scrolli*2 + 1], 0, TRUE);
#endif
            wnoutrefresh(menu);

            /* print the up/down arrows */
            wmove(dialog, box_y, box_x + tag_x + 1);
            wattrset(dialog, scrolli ? uarrow_attr : menubox_attr);
            waddch(dialog, scrolli ? ACS_UARROW : ACS_HLINE);
            wmove(dialog, box_y, box_x + tag_x + 2);
            waddch(dialog, scrolli ? '(' : ACS_HLINE);
            wmove(dialog, box_y, box_x + tag_x + 3);
            waddch(dialog, scrolli ? '-' : ACS_HLINE);
            wmove(dialog, box_y, box_x + tag_x + 4);
            waddch(dialog, scrolli ? ')' : ACS_HLINE);
            wattrset(dialog, darrow_attr);
            wmove(dialog, box_y + menu_height + 1, box_x + tag_x + 1);
            waddch(dialog, ACS_DARROW);
            wmove(dialog, box_y + menu_height + 1, box_x + tag_x + 2);
            waddstr(dialog,"(+)");
            wmove(dialog, cur_y, cur_x);  /* Restore cursor position */
            wrefresh(dialog);
          }
          continue;    /* wait for another key press */
        }
        else
          i = choice - 1;
      }
      else if (key == KEY_DOWN || key == '+')
        if (choice == max_choice - 1) {
          if (scrolli+choice < item_no-1) {
#ifdef BROKEN_WSCRL
    /* wscrl() in ncurses 1.8.1 seems to be broken, causing a segmentation
       violation when scrolling windows of height = 4, so scrolling is not
       used for now */
            scrolli++;
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            /* Reprint menu to scroll up */
            for (i = 0; i < max_choice; i++)
              print_item(menu, items[(scrolli+i)*2], items[(scrolli+i)*2 + 1], i, i == choice);

#else

            /* Scroll menu up */
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            if (menu_height > 1) {
              /* De-highlight current last item before scrolling up */
              print_item(menu, items[(scrolli+max_choice-1)*2], items[(scrolli+max_choice-1)*2 + 1], max_choice-1, FALSE);
              scrollok(menu, TRUE);
              scroll(menu);
              scrollok(menu, FALSE);
            }
            scrolli++;
              print_item(menu, items[(scrolli+max_choice-1)*2], items[(scrolli+max_choice-1)*2 + 1], max_choice-1, TRUE);
#endif
            wnoutrefresh(menu);

            /* print the up/down arrows */
            wattrset(dialog, uarrow_attr);
            wmove(dialog, box_y, box_x + tag_x + 1);
            waddch(dialog, ACS_UARROW);
            wmove(dialog, box_y, box_x + tag_x + 2);
            waddstr(dialog,"(-)");
            wmove(dialog, box_y + menu_height + 1, box_x + tag_x + 1);
            wattrset(dialog, scrolli+choice < item_no-1 ? darrow_attr : menubox_border_attr);
            waddch(dialog, scrolli+choice < item_no-1 ? ACS_DARROW : ACS_HLINE);
            wmove(dialog, box_y + menu_height + 1, box_x + tag_x + 2);
            waddch(dialog, scrolli+choice < item_no-1 ? '(' : ACS_HLINE);
            wmove(dialog, box_y + menu_height + 1, box_x + tag_x + 3);
            waddch(dialog, scrolli+choice < item_no-1 ? '+' : ACS_HLINE);
            wmove(dialog, box_y + menu_height + 1, box_x + tag_x + 4);
            waddch(dialog, scrolli+choice < item_no-1 ? ')' : ACS_HLINE);
            wmove(dialog, cur_y, cur_x);  /* Restore cursor position */
            wrefresh(dialog);
          }
          continue;    /* wait for another key press */
        }
        else
          i = choice + 1;

      if (i != choice) {
        /* De-highlight current item */
        getyx(dialog, cur_y, cur_x);    /* Save cursor position */
        print_item(menu, items[(scrolli+choice)*2], items[(scrolli+choice)*2 + 1], choice, FALSE);

        /* Highlight new item */
        choice = i;
        print_item(menu, items[(scrolli+choice)*2], items[(scrolli+choice)*2 + 1], choice, TRUE);
        wnoutrefresh(menu);
        wmove(dialog, cur_y, cur_x);  /* Restore cursor to previous position */
        wrefresh(dialog);
      }
      continue;    /* wait for another key press */
    }

    switch (key) {
      case 'O':
      case 'o':
        delwin(dialog);
        fprintf(stderr, items[(scrolli+choice)*2]);
        return 0;
      case 'C':
      case 'c':
        delwin(dialog);
        return 1;
      case TAB:
      case KEY_LEFT:
      case KEY_RIGHT:
        if (!button) {
          button = 1;    /* Indicates "Cancel" button is selected */
          print_button(dialog, "  OK  ", y, x, FALSE);
          print_button(dialog, "Cancel", y, x+14, TRUE);
        }
        else {
          button = 0;    /* Indicates "OK" button is selected */
          print_button(dialog, "Cancel", y, x+14, FALSE);
          print_button(dialog, "  OK  ", y, x, TRUE);
        }
        wrefresh(dialog);
        break;
      case ' ':
      case '\n':
        delwin(dialog);
        if (!button)
          fprintf(stderr, items[(scrolli+choice)*2]);
        return button;
      case ESC:
        break;
    }
  }

  delwin(dialog);
  return -1;    /* ESC pressed */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dialog_msgbox ( char *  title,
char *  prompt,
int  height,
int  width,
int  pause 
)

Definition at line 29 of file msgbox.c.

{
  int i, x, y, key = 0;
  WINDOW *dialog;

  /* center dialog box on screen */
  x = (COLS - width)/2;
  y = (LINES - height)/2;

#ifdef HAVE_NCURSES
  if (use_shadow)
    draw_shadow(stdscr, y, x, height, width);
#endif
  dialog = newwin(height, width, y, x);
  keypad(dialog, TRUE);

  draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);

  if (title != NULL) {
    wattrset(dialog, title_attr);
    wmove(dialog, 0, (width - strlen(title))/2 - 1);
    waddch(dialog, ' ');
    waddstr(dialog, title);
    waddch(dialog, ' ');
  }
  wattrset(dialog, dialog_attr);
  print_autowrap(dialog, prompt, width-2, 1, 2);

  if (pause) {
    wattrset(dialog, border_attr);
    wmove(dialog, height-3, 0);
    waddch(dialog, ACS_LTEE);
    for (i = 0; i < width-2; i++)
      waddch(dialog, ACS_HLINE);
    wattrset(dialog, dialog_attr);
    waddch(dialog, ACS_RTEE);
    wmove(dialog, height-2, 1);
    for (i = 0; i < width-2; i++)
    waddch(dialog, ' ');
    print_button(dialog, "  OK  ", height-2, width/2-4, TRUE);
    wrefresh(dialog);
    while (key != ESC && key != '\n' && key != ' ')
      key = wgetch(dialog);
  }
  else {
    key = '\n';
    wrefresh(dialog);
  }

  delwin(dialog);
  return (key == ESC ? -1 : 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dialog_radiolist ( char *  title,
char *  prompt,
int  height,
int  width,
int  list_height,
int  item_no,
char **  items 
)

Definition at line 35 of file radiolist.c.

{
  int i, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
      scrolli = 0, max_choice, *status;
  WINDOW *dialog, *list;

  /* Allocate space for storing item on/off status */
  if ((status = malloc(sizeof(int)*item_no)) == NULL) {
    endwin();
    fprintf(stderr, "\nCan't allocate memory in dialog_radiolist().\n");
    exit(-1);
  }
  /* Initializes status */
  for (i = 0; i < item_no; i++)
    status[i] = !strcasecmp(items[i*3 + 2], "on");

  max_choice = MIN(list_height, item_no);

  /* center dialog box on screen */
  x = (COLS - width)/2;
  y = (LINES - height)/2;
  
#ifdef HAVE_NCURSES
  if (use_shadow)
    draw_shadow(stdscr, y, x, height, width);
#endif
  dialog = newwin(height, width, y, x);
  keypad(dialog, TRUE);

  draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
  wattrset(dialog, border_attr);
  wmove(dialog, height-3, 0);
  waddch(dialog, ACS_LTEE);
  for (i = 0; i < width-2; i++)
    waddch(dialog, ACS_HLINE);
  wattrset(dialog, dialog_attr);
  waddch(dialog, ACS_RTEE);
  wmove(dialog, height-2, 1);
  for (i = 0; i < width-2; i++)
    waddch(dialog, ' ');

  if (title != NULL) {
    wattrset(dialog, title_attr);
    wmove(dialog, 0, (width - strlen(title))/2 - 1);
    waddch(dialog, ' ');
    waddstr(dialog, title);
    waddch(dialog, ' ');
  }
  wattrset(dialog, dialog_attr);
  print_autowrap(dialog, prompt, width-2, 1, 3);

  list_width = width-6;
  getyx(dialog, cur_y, cur_x);
  box_y = cur_y + 1;
  box_x = (width - list_width)/2 - 1;

  /* create new window for the list */
  list = subwin(dialog, list_height, list_width, y + box_y + 1, x + box_x + 1);
  keypad(list, TRUE);

  /* draw a box around the list items */
  draw_box(dialog, box_y, box_x, list_height+2, list_width+2, menubox_border_attr, menubox_attr);

  check_x = 0;
  item_x = 0;
  /* Find length of longest item in order to center radiolist */
  for (i = 0; i < item_no; i++) {
    check_x = MAX(check_x, strlen(items[i*3]) + strlen(items[i*3 + 1]) + 6);
    item_x = MAX(item_x, strlen(items[i*3]));
  }
  check_x = (list_width - check_x) / 2;
  item_x = check_x + item_x + 6;

  /* Print the list */
  for (i = 0; i < max_choice; i++)
    print_item(list, items[i*3], items[i*3 + 1], status[i], i, i == choice);
  wnoutrefresh(list);

  if (list_height < item_no) {
    wattrset(dialog, darrow_attr);
    wmove(dialog, box_y + list_height + 1, box_x + check_x + 5);
    waddch(dialog, ACS_DARROW);
    wmove(dialog, box_y + list_height + 1, box_x + check_x + 6);
    waddstr(dialog, "(+)");
  }

  x = width/2-11;
  y = height-2;
  print_button(dialog, "Cancel", y, x+14, FALSE);
  print_button(dialog, "  OK  ", y, x, TRUE);
  wrefresh(dialog);

  while (key != ESC) {
    key = wgetch(dialog);
    /* Check if key pressed matches first character of any item tag in list */
    for (i = 0; i < max_choice; i++)
      if (toupper(key) == toupper(items[(scrolli+i)*3][0]))
        break;

    if (i < max_choice || (key >= '1' && key <= MIN('9', '0'+max_choice)) || 
        key == KEY_UP || key == KEY_DOWN || key == ' ' ||
        key == '+' || key == '-' ) {
      if (key >= '1' && key <= MIN('9', '0'+max_choice))
        i = key - '1';
      else if (key == KEY_UP || key == '-') {
        if (!choice) {
          if (scrolli) {
#ifdef BROKEN_WSCRL
    /* wscrl() in ncurses 1.8.1 seems to be broken, causing a segmentation
       violation when scrolling windows of height = 4, so scrolling is not
       used for now */
            scrolli--;
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            /* Reprint list to scroll down */
            for (i = 0; i < max_choice; i++)
              print_item(list, items[(scrolli+i)*3], items[(scrolli+i)*3 + 1], status[scrolli+i], i, i == choice);

#else

            /* Scroll list down */
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            if (list_height > 1) {
              /* De-highlight current first item before scrolling down */
              print_item(list, items[scrolli*3], items[scrolli*3 + 1], status[scrolli], 0, FALSE);
              scrollok(list, TRUE);
              wscrl(list, -1);
              scrollok(list, FALSE);
            }
            scrolli--;
            print_item(list, items[scrolli*3], items[scrolli*3 + 1], status[scrolli], 0, TRUE);
#endif
            wnoutrefresh(list);

            /* print the up/down arrows */
            wmove(dialog, box_y, box_x + check_x + 5);
            wattrset(dialog, scrolli ? uarrow_attr : menubox_attr);
            waddch(dialog, scrolli ? ACS_UARROW : ACS_HLINE);
            wmove(dialog, box_y, box_x + check_x + 6);
            waddch(dialog, scrolli ? '(' : ACS_HLINE);
            wmove(dialog, box_y, box_x + check_x + 7);
            waddch(dialog, scrolli ? '-' : ACS_HLINE);
            wmove(dialog, box_y, box_x + check_x + 8);
            waddch(dialog, scrolli ? ')' : ACS_HLINE);
            wattrset(dialog, darrow_attr);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 5);
            waddch(dialog, ACS_DARROW);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 6);
            waddch(dialog, '(');
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 7);
            waddch(dialog, '+');
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 8);
            waddch(dialog, ')');
            wmove(dialog, cur_y, cur_x);  /* Restore cursor position */
            wrefresh(dialog);
          }
          continue;    /* wait for another key press */
        }
        else
          i = choice - 1;
      }
      else if (key == KEY_DOWN || key == '+') {
        if (choice == max_choice - 1) {
          if (scrolli+choice < item_no-1) {
#ifdef BROKEN_WSCRL
    /* wscrl() in ncurses 1.8.1 seems to be broken, causing a segmentation
       violation when scrolling windows of height = 4, so scrolling is not
       used for now */
            scrolli++;
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            /* Reprint list to scroll up */
            for (i = 0; i < max_choice; i++)
              print_item(list, items[(scrolli+i)*3], items[(scrolli+i)*3 + 1], status[scrolli+i], i, i == choice);

#else

            /* Scroll list up */
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            if (list_height > 1) {
              /* De-highlight current last item before scrolling up */
              print_item(list, items[(scrolli+max_choice-1)*3], items[(scrolli+max_choice-1)*3 + 1], status[scrolli+max_choice-1], max_choice-1, FALSE);
              scrollok(list, TRUE);
              scroll(list);
              scrollok(list, FALSE);
            }
            scrolli++;
            print_item(list, items[(scrolli+max_choice-1)*3], items[(scrolli+max_choice-1)*3 + 1], status[scrolli+max_choice-1], max_choice-1, TRUE);
#endif
            wnoutrefresh(list);

            /* print the up/down arrows */
            wattrset(dialog, uarrow_attr);
            wmove(dialog, box_y, box_x + check_x + 5);
            waddch(dialog, ACS_UARROW);
            wmove(dialog, box_y, box_x + check_x + 6);
            waddstr(dialog, "(-)");
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 5);
            wattrset(dialog, scrolli+choice < item_no-1 ? darrow_attr : menubox_border_attr);
            waddch(dialog, scrolli+choice < item_no-1 ? ACS_DARROW : ACS_HLINE);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 6);
            waddch(dialog, scrolli+choice < item_no-1 ? '(' : ACS_HLINE);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 7);
            waddch(dialog, scrolli+choice < item_no-1 ? '+' : ACS_HLINE);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 8);
            waddch(dialog, scrolli+choice < item_no-1 ? ')' : ACS_HLINE);
            wmove(dialog, cur_y, cur_x);  /* Restore cursor position */
            wrefresh(dialog);
          }
          continue;    /* wait for another key press */
        }
        else
          i = choice + 1;
      }
      else if (key == ' ') {    /* Toggle item status */
       if (!status[scrolli+choice])
       {
         for (i=0; i<item_no; i++)
           status[i]=0;
         status[scrolli+choice]=1;
          getyx(dialog, cur_y, cur_x);    /* Save cursor position */
          for (i = 0; i < max_choice; i++)
            print_item(list, items[(scrolli+i)*3], items[(scrolli+i)*3 + 1], status[scrolli+i], i, i == choice);
          wnoutrefresh(list);
          wmove(dialog, cur_y, cur_x);  /* Restore cursor to previous position */
          wrefresh(dialog);
       }
        continue;    /* wait for another key press */
      }

      if (i != choice) {
        /* De-highlight current item */
        getyx(dialog, cur_y, cur_x);    /* Save cursor position */
       print_item(list, items[(scrolli+choice)*3], items[(scrolli+choice)*3 +1], status[scrolli+choice], choice, FALSE);
        /* Highlight new item */
        choice = i;
        print_item(list, items[(scrolli+choice)*3], items[(scrolli+choice)*3 + 1], status[scrolli+choice], choice, TRUE);
        wnoutrefresh(list);
        wmove(dialog, cur_y, cur_x);  /* Restore cursor to previous position */
        wrefresh(dialog);
      }
      continue;    /* wait for another key press */
    }

    switch (key) {
      case 'O':
      case 'o':
        delwin(dialog);
        for (i = 0; i < item_no; i++)
          if (status[i])
            fprintf(stderr, "%s", items[i*3]);
        free(status);
        return 0;
      case 'C':
      case 'c':
        delwin(dialog);
        free(status);
        return 1;
      case TAB:
      case KEY_LEFT:
      case KEY_RIGHT:
        if (!button) {
          button = 1;    /* Indicates "Cancel" button is selected */
          print_button(dialog, "  OK  ", y, x, FALSE);
          print_button(dialog, "Cancel", y, x+14, TRUE);
        }
        else {
          button = 0;    /* Indicates "OK" button is selected */
          print_button(dialog, "Cancel", y, x+14, FALSE);
          print_button(dialog, "  OK  ", y, x, TRUE);
        }
        wrefresh(dialog);
        break;
      case ' ':
      case '\n':
        delwin(dialog);
        if (!button)
          for (i = 0; i < item_no; i++)
            if (status[i])
              fprintf(stderr, items[i*3]);
        free(status);
        return button;
      case ESC:
        break;
    }
  }

  delwin(dialog);
  free(status);
  return -1;    /* ESC pressed */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dialog_textbox ( char *  title,
char *  file,
int  height,
int  width 
)

Definition at line 41 of file textbox.c.

{
  int i, x, y, cur_x, cur_y, fpos, key = 0, dir, temp, temp1;
#ifdef HAVE_NCURSES
  int passed_end;
#endif
  char search_term[MAX_LEN+1], *tempptr, *found;
  WINDOW *dialog, *text;

  search_term[0] = '\0';    /* no search term entered yet */

  /* Open input file for reading */
  if ((fd = open(file, O_RDONLY)) == -1) {
    endwin();
    fprintf(stderr, "\nCan't open input file in dialog_textbox().\n");
    exit(-1);
  }
  /* Get file size. Actually, 'file_size' is the real file size - 1,
     since it's only the last byte offset from the beginning */
  if ((file_size = lseek(fd, 0, SEEK_END)) == -1) {
    endwin();
    fprintf(stderr, "\nError getting file size in dialog_textbox().\n");
    exit(-1);
  }
  /* Restore file pointer to beginning of file after getting file size */
  if (lseek(fd, 0, SEEK_SET) == -1) {
    endwin();
    fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
    exit(-1);
  }
  /* Allocate space for read buffer */
  if ((buf = malloc(BUF_SIZE+1)) == NULL) {
    endwin();
    fprintf(stderr, "\nCan't allocate memory in dialog_textbox().\n");
    exit(-1);
  }
  if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) {
    endwin();
    fprintf(stderr, "\nError reading file in dialog_textbox().\n");
    exit(-1);
  }
  buf[bytes_read] = '\0';    /* mark end of valid data */
  page = buf;    /* page is pointer to start of page to be displayed */

  /* center dialog box on screen */
  x = (COLS - width)/2;
  y = (LINES - height)/2;

#ifdef HAVE_NCURSES
  if (use_shadow)
    draw_shadow(stdscr, y, x, height, width);
#endif
  dialog = newwin(height, width, y, x);
  keypad(dialog, TRUE);

  /* Create window for text region, used for scrolling text */
/*  text = newwin(height-4, width-2, y+1, x+1); */
  text = subwin(dialog, height-4, width-2, y+1, x+1);
  keypad(text, TRUE);

  draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);

  wattrset(dialog, border_attr);
  wmove(dialog, height-3, 0);
  waddch(dialog, ACS_LTEE);
  for (i = 0; i < width-2; i++)
    waddch(dialog, ACS_HLINE);
  wattrset(dialog, dialog_attr);
  waddch(dialog, ACS_RTEE);
  wmove(dialog, height-2, 1);
  for (i = 0; i < width-2; i++)
    waddch(dialog, ' ');

  if (title != NULL) {
    wattrset(dialog, title_attr);
    wmove(dialog, 0, (width - strlen(title))/2 - 1);
    waddch(dialog, ' ');
    waddstr(dialog, title);
    waddch(dialog, ' ');
  }
  print_button(dialog, " EXIT ", height-2, width/2-4, TRUE);
  wnoutrefresh(dialog);
  getyx(dialog, cur_y, cur_x);    /* Save cursor position */

  /* Print first page of text */
  attr_clear(text, height-4, width-2, dialog_attr);
  print_page(text, height-4, width-2);
  print_position(dialog, height, width);
  wmove(dialog, cur_y, cur_x);    /* Restore cursor position */
  wrefresh(dialog);

  while ((key != ESC) && (key != '\n')) {
    key = wgetch(dialog);
    switch (key) {
      case 'E':    /* Exit */
      case 'e':
        delwin(dialog);
        free(buf);
        close(fd);
        return 0;
      case 'g':    /* First page */
      case KEY_HOME:
        if (!begin_reached) {
          begin_reached = 1;
          /* First page not in buffer? */
          if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
            endwin();
            fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
            exit(-1);
          }
          if (fpos > bytes_read) {    /* Yes, we have to read it in */
            if (lseek(fd, 0, SEEK_SET) == -1) {
              endwin();
              fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
              exit(-1);
            }
            if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) {
              endwin();
              fprintf(stderr, "\nError reading file in dialog_textbox().\n");
              exit(-1);
            }
            buf[bytes_read] = '\0';
          }
          page = buf;
          print_page(text, height-4, width-2);
          print_position(dialog, height, width);
          wmove(dialog, cur_y, cur_x);    /* Restore cursor position */
          wrefresh(dialog);
        }
        break;
      case 'G':    /* Last page */
#ifdef HAVE_NCURSES
      case KEY_END:
#endif
        end_reached = 1;
        /* Last page not in buffer? */
        if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
          endwin();
          fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
          exit(-1);
        }
        if (fpos < file_size) {    /* Yes, we have to read it in */
          if (lseek(fd, -BUF_SIZE, SEEK_END) == -1) {
            endwin();
            fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
            exit(-1);
          }
          if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) {
            endwin();
            fprintf(stderr, "\nError reading file in dialog_textbox().\n");
            exit(-1);
          }
          buf[bytes_read] = '\0';
        }
        page = buf + bytes_read;
        back_lines(height-4);
        print_page(text, height-4, width-2);
        print_position(dialog, height, width);
        wmove(dialog, cur_y, cur_x);    /* Restore cursor position */
        wrefresh(dialog);
        break;
      case 'K':    /* Previous line */
      case 'k':
      case KEY_UP:
        if (!begin_reached) {
          back_lines(page_length+1);
#ifdef HAVE_NCURSES
          /* We don't call print_page() here but use scrolling to ensure
             faster screen update. However, 'end_reached' and 'page_length'
             should still be updated, and 'page' should point to start of
             next page. This is done by calling get_line() in the following
             'for' loop. */
          scrollok(text, TRUE);
          wscrl(text, -1);    /* Scroll text region down one line */
          scrollok(text, FALSE);
          page_length = 0;
          passed_end = 0;
          for (i = 0; i < height-4; i++) {
            if (!i) {
              print_line(text, 0, width-2);    /* print first line of page */
              wnoutrefresh(text);
            }
            else
              get_line();    /* Called to update 'end_reached' and 'page' */
            if (!passed_end)
              page_length++;
            if (end_reached && !passed_end)
              passed_end = 1;
          }
#else
          print_page(text, height-4, width-2);
#endif
          print_position(dialog, height, width);
          wmove(dialog, cur_y, cur_x);    /* Restore cursor position */
          wrefresh(dialog);
        }
        break;
      case 'B':    /* Previous page */
      case 'b':
      case KEY_PPAGE:
        if (!begin_reached) {
          back_lines(page_length + height-4);
          print_page(text, height-4, width-2);
          print_position(dialog, height, width);
          wmove(dialog, cur_y, cur_x);    /* Restore cursor position */
          wrefresh(dialog);
        }
        break;
      case 'J':    /* Next line */
      case 'j':
      case KEY_DOWN:
        if (!end_reached) {
          begin_reached = 0;
          scrollok(text, TRUE);
          scroll(text);    /* Scroll text region up one line */
          scrollok(text, FALSE);
          print_line(text, height-5, width-2);
#ifndef HAVE_NCURSES
          wmove(text, height-5, 0);
          waddch(text, ' ');
          wmove(text, height-5, width-3);
          waddch(text, ' ');
#endif
          wnoutrefresh(text);
          print_position(dialog, height, width);
          wmove(dialog, cur_y, cur_x);    /* Restore cursor position */
          wrefresh(dialog);
        }
        break;
      case ' ':    /* Next page */
      case KEY_NPAGE:
        if (!end_reached) {
          begin_reached = 0;
          print_page(text, height-4, width-2);
          print_position(dialog, height, width);
          wmove(dialog, cur_y, cur_x);    /* Restore cursor position */
          wrefresh(dialog);
        }
        break;
      case '0':    /* Beginning of line */
      case 'H':    /* Scroll left */
      case 'h':
      case KEY_LEFT:
        if (hscroll > 0) {
          if (key == '0')
            hscroll = 0;
          else
            hscroll--;
          /* Reprint current page to scroll horizontally */
          back_lines(page_length);
          print_page(text, height-4, width-2);
          wmove(dialog, cur_y, cur_x);    /* Restore cursor position */
          wrefresh(dialog);
        }
        break;
      case 'L':    /* Scroll right */
      case 'l':
      case KEY_RIGHT:
        if (hscroll < MAX_LEN) {
          hscroll++;
          /* Reprint current page to scroll horizontally */
          back_lines(page_length);
          print_page(text, height-4, width-2);
          wmove(dialog, cur_y, cur_x);    /* Restore cursor position */
          wrefresh(dialog);
        }
        break;
      case '/':    /* Forward search */
      case 'n':    /* Repeat forward search */
      case '?':    /* Backward search */
      case 'N':    /* Repeat backward search */
        /* set search direction */
        dir = (key == '/' || key == 'n') ? 1 : 0;
        if (dir ? !end_reached : !begin_reached) {
          if (key == 'n' || key == 'N') {
            if (search_term[0] == '\0') {    /* No search term yet */
              fprintf(stderr, "\a");    /* beep */
              break;
            }
         }
          else    /* Get search term from user */
            if (get_search_term(text, search_term, height-4, width-2) == -1) {
              /* ESC pressed in get_search_term(). Reprint page to clear box */
              wattrset(text, dialog_attr);
              back_lines(page_length);
              print_page(text, height-4, width-2);
              wmove(dialog, cur_y, cur_x);    /* Restore cursor position */
              wrefresh(dialog);
              break;
            }
          /* Save variables for restoring in case search term can't be found */
          tempptr = page;
          temp = begin_reached;
          temp1 = end_reached;
          if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
            endwin();
            fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
            exit(-1);
          }
          fpos -= bytes_read;
          /* update 'page' to point to next (previous) line before
             forward (backward) searching */
          back_lines(dir ? page_length-1 : page_length+1);
          found = NULL;
          if (dir)    /* Forward search */
            while((found = strstr(get_line(), search_term)) == NULL) {
              if (end_reached)
                break;
           }
          else    /* Backward search */
            while((found = strstr(get_line(), search_term)) == NULL) {
              if (begin_reached)
                break;
              back_lines(2);
            }
          if (found == NULL) {    /* not found */
            fprintf(stderr, "\a");    /* beep */
            /* Restore program state to that before searching */
            if (lseek(fd, fpos, SEEK_SET) == -1) {
              endwin();
              fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
              exit(-1);
            }
            if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) {
              endwin();
              fprintf(stderr, "\nError reading file in dialog_textbox().\n");
              exit(-1);
            }
            buf[bytes_read] = '\0';
            page = tempptr;
            begin_reached = temp;
            end_reached = temp1;
            /* move 'page' to point to start of current page in order to
               re-print current page. Note that 'page' always points to
               start of next page, so this is necessary */
            back_lines(page_length);
          }
          else    /* Search term found */
            back_lines(1);
          /* Reprint page */
          wattrset(text, dialog_attr);
          print_page(text, height-4, width-2);
          if (found != NULL)
            print_position(dialog, height, width);
          wmove(dialog, cur_y, cur_x);    /* Restore cursor position */
          wrefresh(dialog);
        }
        else    /* no need to find */
          fprintf(stderr, "\a");    /* beep */
        break;
      case ESC:
        break;
    }
  }

  delwin(dialog);
  free(buf);
  close(fd);
  return -1;    /* ESC pressed */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dialog_yesno ( char *  title,
char *  prompt,
int  height,
int  width 
)

Definition at line 28 of file yesno.c.

{
  int i, x, y, key = 0, button = 0;
  WINDOW *dialog;

  /* center dialog box on screen */
  x = (COLS - width)/2;
  y = (LINES - height)/2;
  
#ifdef HAVE_NCURSES
  if (use_shadow)
    draw_shadow(stdscr, y, x, height, width);
#endif
  dialog = newwin(height, width, y, x);
  keypad(dialog, TRUE);

  draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
  wattrset(dialog, border_attr);
  wmove(dialog, height-3, 0);
  waddch(dialog, ACS_LTEE);
  for (i = 0; i < width-2; i++)
    waddch(dialog, ACS_HLINE);
  wattrset(dialog, dialog_attr);
  waddch(dialog, ACS_RTEE);
  wmove(dialog, height-2, 1);
  for (i = 0; i < width-2; i++)
    waddch(dialog, ' ');

  if (title != NULL) {
    wattrset(dialog, title_attr);
    wmove(dialog, 0, (width - strlen(title))/2 - 1);
    waddch(dialog, ' ');
    waddstr(dialog, title);
    waddch(dialog, ' ');
  }
  wattrset(dialog, dialog_attr);
  print_autowrap(dialog, prompt, width, 1, 3);

  x = width/2-10;
  y = height-2;
  print_button(dialog, "  No  ", y, x+13, FALSE);
  print_button(dialog, " Yes ", y, x, TRUE);
  wrefresh(dialog);

  while (key != ESC) {
    key = wgetch(dialog);
    switch (key) {
      case 'Y':
      case 'y':
        delwin(dialog);
        return 0;
      case 'N':
      case 'n':
        delwin(dialog);
        return 1;
      case TAB:
      case KEY_UP:
      case KEY_DOWN:
      case KEY_LEFT:
      case KEY_RIGHT:
        if (!button) {
          button = 1;    /* Indicates "No" button is selected */
          print_button(dialog, " Yes ", y, x, FALSE);
          print_button(dialog, "  No  ", y, x+13, TRUE);
        }
        else {
          button = 0;    /* Indicates "Yes" button is selected */
          print_button(dialog, "  No  ", y, x+13, FALSE);
          print_button(dialog, " Yes ", y, x, TRUE);
        }
        wrefresh(dialog);
        break;
      case ' ':
      case '\n':
        delwin(dialog);
        return button;
      case ESC:
        break;
    }
  }

  delwin(dialog);
  return -1;    /* ESC pressed */
}

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_box ( WINDOW win,
int  y,
int  x,
int  height,
int  width,
chtype  box,
chtype  border 
)

Definition at line 556 of file dialog.c.

{
  int i, j;

  wattrset(win, 0);
  for (i = 0; i < height; i++) {
    wmove(win, y + i, x);
    for (j = 0; j < width; j++)
      if (!i && !j)
        waddch(win, border | ACS_ULCORNER);
      else if (i == height-1 && !j)
        waddch(win, border | ACS_LLCORNER);
      else if (!i && j == width-1)
        waddch(win, box | ACS_URCORNER);
      else if (i == height-1 && j == width-1)
        waddch(win, box | ACS_LRCORNER);
      else if (!i)
        waddch(win, border | ACS_HLINE);
      else if (i == height-1)
        waddch(win, box | ACS_HLINE);
      else if (!j)
        waddch(win, border | ACS_VLINE);
      else if (j == width-1)
        waddch(win, box | ACS_VLINE);
      else
        waddch(win, box | ' ');
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 370 of file dialog.c.

{
  int i;
  
#ifdef HAVE_NCURSES
  if (parse_rc() == -1)    /* Read the configuration file */
    exit(-1);
#endif

  initscr();     /* Init curses */
  keypad(stdscr, TRUE);
  cbreak();
  noecho();

#ifdef HAVE_NCURSES
  if (use_colors || use_shadow)    /* Set up colors */
    color_setup();
#endif

  /* Set screen to screen attribute */
  attr_clear(stdscr, LINES, COLS, screen_attr);

  /* Display background title if it exists ... - SLH */
  if (backtitle != NULL)
  {
    wattrset(stdscr, screen_attr);
    wmove(stdscr, 0, 1);
    waddstr(stdscr,backtitle);
    wmove(stdscr, 1, 1);
    for(i=1; i<COLS-1; i++)
      waddch(stdscr, ACS_HLINE);
  }
  
  wnoutrefresh(stdscr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void print_autowrap ( WINDOW win,
char *  prompt,
int  width,
int  y,
int  x 
)

Definition at line 461 of file dialog.c.

{
  int first = 1, cur_x, cur_y;
  char tempstr[MAX_LEN+1], *word, *tempptr, *tempptr1;

  strcpy(tempstr, prompt);
  if ((strstr(tempstr, "\\n") != NULL) ||
      (strchr(tempstr, '\n') != NULL)) {    /* Prompt contains "\n" or '\n' */
    word = tempstr;
    cur_y = y;
    wmove(win, cur_y, x);
    while (1) {
      tempptr = strstr(word, "\\n");
      tempptr1 = strchr(word, '\n');
      if (tempptr == NULL && tempptr1 == NULL)
        break;
      else if (tempptr == NULL) {    /* No more "\n" */
        tempptr = tempptr1;
        tempptr[0] = '\0';
      }
      else if (tempptr1 == NULL) {    /* No more '\n' */
        tempptr[0] = '\0';
        tempptr++;
      }
      else {    /* Prompt contains both "\n" and '\n' */
        if (strlen(tempptr)-2 < strlen(tempptr1)-1) {
          tempptr = tempptr1;
          tempptr[0] = '\0';
        }
        else {
          tempptr[0] = '\0';
          tempptr++;
        }
      }

      waddstr(win, word);
      word = tempptr + 1;
      wmove(win, ++cur_y, x);
    }
    waddstr(win, word);
  }
  else if (strlen(tempstr) <= width-x*2) {    /* If prompt is short */
    wmove(win, y, (width - strlen(tempstr)) / 2);
    waddstr(win, tempstr);
  }
  else {
    cur_x = x;
    cur_y = y;
    /* Print prompt word by word, wrap around if necessary */
    while ((word = strtok(first ? tempstr : NULL, " ")) != NULL) {
      if (first)    /* First iteration */
        first = 0;
      if (cur_x+strlen(word) > width) {    /* wrap around to next line */
        cur_y++;
        cur_x = x;
      }
      wmove(win, cur_y, cur_x);
      waddstr(win, word);
      getyx(win, cur_y, cur_x);
      cur_x++;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void print_button ( WINDOW win,
char *  label,
int  y,
int  x,
int  selected 
)

Definition at line 530 of file dialog.c.

{
  int i, temp;

  wmove(win, y, x);
  wattrset(win, selected ? button_active_attr : button_inactive_attr);
  waddstr(win, "<");
  temp = strspn(label, " ");
  label += temp;
  wattrset(win, selected ? button_label_active_attr : button_label_inactive_attr);
  for (i = 0; i < temp; i++)
    waddch(win, ' ');
  wattrset(win, selected ? button_key_active_attr : button_key_inactive_attr);
  waddch(win, label[0]);
  wattrset(win, selected ? button_label_active_attr : button_label_inactive_attr);
  waddstr(win, label+1);
  wattrset(win, selected ? button_active_attr : button_inactive_attr);
  waddstr(win, ">");
  wmove(win, y, x+temp+1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Usage ( char *  name)

Definition at line 340 of file dialog.c.

{
  fprintf(stderr, "\
\ndialog version 0.3, by Savio Lam (lam836@cs.cuhk.hk).\
\n  patched to version %s by Stuart Herbert (S.Herbert@shef.ac.uk)\
\n\
\n* Display dialog boxes from shell scripts *\
\n\
\nUsage: %s --clear\
\n       %s --create-rc <file>\
\n       %s [--title <title>] [--separate-output] [--backtitle <backtitle>] [--clear] <Box options>\
\n\
\nBox options:\
\n\
\n  --yesno     <text> <height> <width>\
\n  --msgbox    <text> <height> <width>\
\n  --infobox   <text> <height> <width>\
\n  --inputbox  <text> <height> <width> [<init>]\
\n  --textbox   <file> <height> <width>\
\n  --menu      <text> <height> <width> <menu height> <tag1> <item1>...\
\n  --checklist <text> <height> <width> <list height> <tag1> <item1> <status1>...\
\n  --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...\
\n  --guage     <text> <height> <width> <percent>\n", VERSION, name, name, name);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 96 of file dialog.c.