Пример #1
0
/*
 * set the percentage
 */
int wdg_percentage_set(wdg_t *wo, size_t p, size_t max)
{
   WDG_WO_EXT(struct wdg_percentage, ww);

   /* set the percentage */
   ww->percent = p * 100 / max;
   
   WDG_DEBUG_MSG("wdg_percentage_set: %d", ww->percent);

   wdg_percentage_redraw(wo);

   /* reached the max, selfdestruct */
   if (p == max) {
      WDG_DEBUG_MSG("wdg_percentage_set: FINISHED");
      wdg_destroy_object(&wo);
      wdg_redraw_all();
      return WDG_PERCENTAGE_FINISHED;
   }

   /* user has requested to stop the task */
   if (ww->interrupt) {
      WDG_DEBUG_MSG("wdg_percentage_set: INTERRUPTED");
      ww->interrupt = 0;
      wdg_destroy_object(&wo);
      wdg_redraw_all();
      return WDG_PERCENTAGE_INTERRUPTED; 
   }

   return WDG_PERCENTAGE_UPDATED;
}
Пример #2
0
/*
 * copy the temp buffers to the real ones
 */
static void wdg_input_consolidate(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_input_handle, ww);
   char *buf;
   int i = 0, j;
   size_t buflen;
   void (*callback)(void);
   
   WDG_DEBUG_MSG("wdg_input_consolidate");
   
   while(ww->fields[i] != NULL) {
      /* get the buffer */
      buf = field_buffer(ww->fields[i+1], 0);
      buflen = strlen(buf);

      /* trim out the trailing spaces */
      for (j = buflen - 1; j >= 0; j--)
         if (buf[j] == ' ')
            buf[j] = 0;
         else
            break;
      
      /* copy the buffer in the real one */
      strcpy(ww->buffers[i/2], buf);
      
      /* skip the label */
      i += 2;
   }

   /* execute the callback */
   callback = ww->callback;
   wdg_destroy_object(&wo);
   wdg_redraw_all();
   WDG_EXECUTE(callback);
}
Пример #3
0
/* 
 * called to destroy a window
 */
static int wdg_dialog_destroy(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_dialog, ww);
   
   WDG_DEBUG_MSG("wdg_dialog_destroy");

   /* erase the window */
   wbkgd(ww->win, COLOR_PAIR(wo->screen_color));
   wbkgd(ww->sub, COLOR_PAIR(wo->screen_color));
   werase(ww->sub);
   werase(ww->win);
   wnoutrefresh(ww->sub);
   wnoutrefresh(ww->win);
   
   /* dealloc the structures */
   delwin(ww->sub);
   delwin(ww->win);

   /* free the text string */
   WDG_SAFE_FREE(ww->text);
   WDG_BUG_IF(ww->text != NULL);

   WDG_SAFE_FREE(wo->extend);

   return WDG_ESUCCESS;
}
Пример #4
0
/* 
 * called to create the file dialog
 */
void wdg_create_file(struct wdg_object *wo)
{
   struct wdg_file_handle *ww;
   
   WDG_DEBUG_MSG("wdg_create_file");
   
   /* set the callbacks */
   wo->destroy = wdg_file_destroy;
   wo->resize = wdg_file_resize;
   wo->redraw = wdg_file_redraw;
   wo->get_focus = wdg_file_get_focus;
   wo->lost_focus = wdg_file_lost_focus;
   wo->get_msg = wdg_file_get_msg;

   WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_file_handle));
   
   /* 
    * remember the initial path.
    * this has to be restored after the file is selected 
    */
   ww = (struct wdg_file_handle *)wo->extend;
   getcwd(ww->initpath, PATH_MAX);
  
   /* default geometry */
   ww->x = 50;
   ww->y = 18;
}
Пример #5
0
/*
 * sends command to the form
 */
static int wdg_input_driver(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse)
{
   WDG_WO_EXT(struct wdg_input_handle, ww);
   int c, v;

   /* variable currently not used */
   (void) mouse;
   
   WDG_DEBUG_MSG("keypress driver: %d", key);
   
   /* virtualize the command */
   c = form_driver(ww->form, (v = wdg_input_virtualize(wo, key)) );
   
   set_field_back(current_field(ww->form), A_REVERSE);
   
   /* one item has been selected */
   if (c == E_UNKNOWN_COMMAND) {
      /* send a command to the form in order to validate the current field */
      form_driver(ww->form, REQ_NEXT_FIELD);
      /* 
       * put the temp buffer in the real one 
       * call the callback
       * and destroy the object
       */
      wdg_input_consolidate(wo);
      return WDG_EFINISHED;
   }

   wnoutrefresh(ww->fwin);
      
   return WDG_E_SUCCESS;
}
Пример #6
0
/* 
 * called by the messages dispatcher when the window is focused
 */
static int wdg_percentage_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse)
{
   WDG_WO_EXT(struct wdg_percentage, ww);
   
   /* handle the message */
   switch (key) {
      case KEY_MOUSE:
         /* is the mouse event within our edges ? */
         if (wenclose(ww->win, mouse->y, mouse->x))
            wdg_set_focus(wo);
         else 
            return -WDG_E_NOTHANDLED;
         break;

      case KEY_ESC:
      case CTRL('Q'):
         WDG_DEBUG_MSG("wdg_percentage_get_msg: user interrupt");
         /* 
          * user has requested to stop this task.
          * the next time the percentage will be set
          * the object will be destroyed and a correct value
          * will be returned.
          */
         ww->interrupt = 1;
         break;
         
      /* message not handled */
      default:
         return -WDG_E_NOTHANDLED;
         break;
   }
  
   return WDG_E_SUCCESS;
}
Пример #7
0
/*
 * print a string in the window
 */
void wdg_scroll_print(wdg_t *wo, int color, char *fmt, ...)
{
   WDG_WO_EXT(struct wdg_scroll, ww);
   size_t c = wdg_get_ncols(wo);
   size_t l = wdg_get_nlines(wo);
   size_t x = wdg_get_begin_x(wo);
   size_t y = wdg_get_begin_y(wo);
   va_list ap;
   
   WDG_DEBUG_MSG("wdg_scroll_print");

   /* move to the bottom of the pad */
   wdg_set_scroll(wo, ww->y_max - l + 1);

   wbkgdset(ww->sub, COLOR_PAIR(color));

   /* print the message */
   va_start(ap, fmt);
   vw_printw(ww->sub, fmt, ap);
   va_end(ap);
   
   wbkgdset(ww->sub, COLOR_PAIR(wo->window_color));
   
   WDG_PAD_REFRESH(ww, c, l, x, y);
}
Пример #8
0
/* 
 * called to destroy the menu
 */
static int wdg_input_destroy(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_input_handle, ww);
   size_t i = 0;
   
   WDG_DEBUG_MSG("wdg_input_destroy");

   /* erase the window */
   wbkgd(ww->win, COLOR_PAIR(wo->screen_color));
   werase(ww->win);
   wnoutrefresh(ww->win);

   /* destroy the internal form */
   wdg_input_form_destroy(wo);
   
   /* dealloc the structures */
   delwin(ww->win);
   
   /* free all the items */
   while(ww->fields[i] != NULL) 
      free_field(ww->fields[i++]);

   /* free the array */
   WDG_SAFE_FREE(ww->fields);

   /* free the buffer array */
   WDG_SAFE_FREE(ww->buffers);
   
   WDG_SAFE_FREE(wo->extend);

   return WDG_E_SUCCESS;
}
Пример #9
0
/*
 * destroy the dialog and
 * call the function associated to the button
 */
static void wdg_dialog_callback(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_dialog, ww);
   void (*callback)(void);
   
   WDG_DEBUG_MSG("wdg_dialog_callback");
   
   callback = ww->buttons[ww->focus_button].callback;
   wdg_destroy_object(&wo);
   wdg_redraw_all();
   WDG_EXECUTE(callback);
}
Пример #10
0
/* 
 * called to create a window
 */
void wdg_create_scroll(struct wdg_object *wo)
{
   WDG_DEBUG_MSG("wdg_create_scroll");
   
   /* set the callbacks */
   wo->destroy = wdg_scroll_destroy;
   wo->resize = wdg_scroll_resize;
   wo->redraw = wdg_scroll_redraw;
   wo->get_focus = wdg_scroll_get_focus;
   wo->lost_focus = wdg_scroll_lost_focus;
   wo->get_msg = wdg_scroll_get_msg;

   WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_scroll));
}
Пример #11
0
/* 
 * called to create the menu
 */
void wdg_create_input(struct wdg_object *wo)
{
   WDG_DEBUG_MSG("wdg_create_input");
   
   /* set the callbacks */
   wo->destroy = wdg_input_destroy;
   wo->resize = wdg_input_resize;
   wo->redraw = wdg_input_redraw;
   wo->get_focus = wdg_input_get_focus;
   wo->lost_focus = wdg_input_lost_focus;
   wo->get_msg = wdg_input_get_msg;

   WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_input_handle));
}
Пример #12
0
/*
 * set the dimension of the pad
 */
void wdg_scroll_set_lines(wdg_t *wo, size_t lines)
{
   WDG_WO_EXT(struct wdg_scroll, ww);
   size_t c = wdg_get_ncols(wo);
   size_t l = wdg_get_nlines(wo);
   size_t oldlines = ww->y_max;
   
   WDG_DEBUG_MSG("wdg_scroll_set_lines");
  
   /* resize the pad */
   wresize(ww->sub, lines, c - 2);
    
   /* do the proper adjustements to the scroller */
   ww->y_max = lines;
   wdg_set_scroll(wo, ww->y_max - l + 1);
   
   /* adjust only the first time (when the user requests the change) */
   if (oldlines != lines)
      wmove(ww->sub, ww->y_scroll + 1, 0);
}
Пример #13
0
/* 
 * called by the messages dispatcher when the menu is focused
 */
static int wdg_input_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse)
{
   WDG_WO_EXT(struct wdg_input_handle, ww);

   WDG_DEBUG_MSG("keypress get msg: %d", key);
   
   /* handle the message */
   switch (key) {
         
      case KEY_MOUSE:
         /* is the mouse event within our edges ? */
         if (wenclose(ww->win, mouse->y, mouse->x)) {
            wdg_set_focus(wo);
            /* redraw the menu */
            wdg_input_redraw(wo);
         } else {
            return -WDG_E_NOTHANDLED;
         }
         break;
      
      case KEY_ESC:
      case CTRL('Q'):
         wdg_destroy_object(&wo);
         wdg_redraw_all();
         return WDG_EFINISHED;
         break;

      /* message not handled */
      default:
         if (wo->flags & WDG_OBJ_FOCUSED) {
            return wdg_input_driver(wo, key, mouse);
         } else {
            return -WDG_E_NOTHANDLED;
         }
         break;
   }
   
   return WDG_E_SUCCESS;
}
Пример #14
0
/* 
 * called to destroy a window
 */
static int wdg_window_destroy(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_window, ww);
   
   WDG_DEBUG_MSG("wdg_window_destroy (%p)", wo);

   /* erase the window */
   wbkgd(ww->win, COLOR_PAIR(wo->screen_color));
   wbkgd(ww->sub, COLOR_PAIR(wo->screen_color));
   werase(ww->sub);
   werase(ww->win);
   wnoutrefresh(ww->sub);
   wnoutrefresh(ww->win);
   
   /* dealloc the structures */
   delwin(ww->sub);
   delwin(ww->win);

   WDG_SAFE_FREE(wo->extend);

   return WDG_ESUCCESS;
}
Пример #15
0
/* 
 * called to destroy the file dialog
 */
static int wdg_file_destroy(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_file_handle, ww);
   
   WDG_DEBUG_MSG("wdg_file_destroy");

   /* erase the window */
   wbkgd(ww->win, COLOR_PAIR(wo->screen_color));
   werase(ww->win);
   wnoutrefresh(ww->win);

   /* destroy the internal menu */
   wdg_file_menu_destroy(wo);

   /* dealloc the structures */
   delwin(ww->win);
   
   /* restore the initial working directory */
   chdir(ww->initpath);

   WDG_SAFE_FREE(wo->extend);

   return WDG_E_SUCCESS;
}
Пример #16
0
/*
 * destroy the dialog and
 * call the function associated to the file open dialog
 */
static void wdg_file_callback(struct wdg_object *wo, const char *path, char *file)
{
   WDG_WO_EXT(struct wdg_file_handle, ww);
   void (*callback)(const char *, char *);
   char *p, *f;
   
   WDG_DEBUG_MSG("wdg_file_callback");
  
   /* save the values before destroying the object */
   callback = ww->callback;
   WDG_SAFE_STRDUP(p, path);
   WDG_SAFE_STRDUP(f, file);
  
   /* destroy the object */
   wdg_destroy_object(&wo);
   wdg_redraw_all();
   
   /* call the callback */
   WDG_EXECUTE(callback, p, f);

   /* free saved data */
   WDG_SAFE_FREE(f);
   WDG_SAFE_FREE(p);
}
Пример #17
0
/* 
 * called to create a window
 */
void wdg_create_dialog(struct wdg_object *wo)
{
   struct wdg_dialog *ww;

   WDG_DEBUG_MSG("wdg_create_dialog");
   
   /* set the callbacks */
   wo->destroy = wdg_dialog_destroy;
   wo->resize = wdg_dialog_resize;
   wo->redraw = wdg_dialog_redraw;
   wo->get_focus = wdg_dialog_get_focus;
   wo->lost_focus = wdg_dialog_lost_focus;
   wo->get_msg = wdg_dialog_get_msg;

   WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_dialog));

   ww = (struct wdg_dialog *)wo->extend;
  
   /* initialize the labels, the other fields are zeroed by the calloc */
   ww->buttons[0].label = " Ok ";
   ww->buttons[1].label = " Yes ";
   ww->buttons[2].label = " No ";
   ww->buttons[3].label = " Cancel ";
}
Пример #18
0
/*
 * create the internal menu for the files 
 */
static void wdg_file_menu_create(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_file_handle, ww);
   int mrows, mcols;
   int i;
   size_t c = wdg_get_ncols(wo);
   size_t x = wdg_get_begin_x(wo);
   size_t y = wdg_get_begin_y(wo);
   struct stat buf;

   /* the menu is already posted */
   if (ww->nitems)
      return;
 
   WDG_DEBUG_MSG("wdg_file_menu_create");
   
   /* get the working directory */
   getcwd(ww->curpath, PATH_MAX);
         
   /* scan the directory */
   ww->nlist = scandir(".", &ww->namelist, 0, alphasort);

   /* on error display the message in the box */
   if (ww->nlist <= 0) {
      ww->nitems = 2;
      WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *));
      ww->items[ww->nitems - 2] = new_item("/", "root");
      ww->items[ww->nitems - 1] = new_item("Cannot open the directory", "");
      item_opts_off(ww->items[ww->nitems - 1], O_SELECTABLE);
   } else {

      /* for each directory in the directory */
      for (i = 0; i < ww->nlist; i++) {
        
         /* 
          * transform the current dir into the root.
          * useful to exit from a path whose parent is not readable 
          */
         if (!strcmp(ww->namelist[i]->d_name, ".")) {
            strncpy(ww->namelist[i]->d_name, "/", 1);
            ww->nitems++;
            WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *));
            ww->items[ww->nitems - 1] = new_item(ww->namelist[i]->d_name, "root");
            continue;
         }
         
         /* get the file properties */
         stat(ww->namelist[i]->d_name, &buf);
         
         if (S_ISDIR(buf.st_mode)) {
            ww->nitems++;
            WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *));
            ww->items[ww->nitems - 1] = new_item(ww->namelist[i]->d_name, "[...]");
         }
         // if not readable
         //item_opts_off(ww->items[ww->nitems - 1], O_SELECTABLE);
      }
      
      /* and now add the files */
      for (i = 0; i < ww->nlist; i++) {
         
         /* get the file properties */
         stat(ww->namelist[i]->d_name, &buf);
         
         if (!S_ISDIR(buf.st_mode)) {
            ww->nitems++;
            WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *));
            ww->items[ww->nitems - 1] = new_item(ww->namelist[i]->d_name, "");
         }
      }
   }

   /* null terminate the array */
   WDG_SAFE_REALLOC(ww->items, (ww->nitems + 1) * sizeof(ITEM *));
   ww->items[ww->nitems] = NULL;
     
   /* create the menu */
   ww->m = new_menu(ww->items);

   /* set the dimensions */
   set_menu_format(ww->m, ww->y - 2, 1);
   set_menu_spacing(ww->m, 2, 0, 0);

   /* get the geometry to make a window */
   scale_menu(ww->m, &mrows, &mcols);

   /* 
    * if the menu is larger than the main window
    * adapt to the new dimensions
    */
   if (mcols > (int)c - 4) {
      ww->x = mcols + 4;
      wdg_file_redraw(wo);
      return;
   }
   /* create the window for the menu */
   ww->mwin = newwin(mrows, MAX(mcols, (int)c - 4), y + 1, x + 2);
   /* set the color */
   wbkgd(ww->mwin, COLOR_PAIR(wo->window_color));
   keypad(ww->mwin, TRUE);
  
   /* associate with the menu */
   set_menu_win(ww->m, ww->mwin);
   
   /* the subwin for the menu */
   set_menu_sub(ww->m, derwin(ww->mwin, mrows + 1, mcols, 1, 1));

   /* menu attributes */
   set_menu_mark(ww->m, "");
   set_menu_grey(ww->m, COLOR_PAIR(wo->window_color));
   set_menu_back(ww->m, COLOR_PAIR(wo->window_color));
   set_menu_fore(ww->m, COLOR_PAIR(wo->window_color) | A_REVERSE | A_BOLD);
   
   /* display the menu */
   post_menu(ww->m);

   wnoutrefresh(ww->mwin);
   
}
Пример #19
0
/* 
 * called to redraw the file dialog
 */
static int wdg_file_redraw(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_file_handle, ww);
   size_t c, l, x, y;
   
   WDG_DEBUG_MSG("wdg_file_redraw");
   
   /* default dimentions */
   wo->x1 = (current_screen.cols - ww->x) / 2;
   wo->y1 = (current_screen.lines - ww->y) / 2;
   wo->x2 = -wo->x1;
   wo->y2 = -wo->y1;
   
   c = wdg_get_ncols(wo);
   l = wdg_get_nlines(wo);
   x = wdg_get_begin_x(wo);
   y = wdg_get_begin_y(wo);

   /* deal with rouding */
   if (l != ww->y) l = ww->y;
   if (c != ww->x) c = ww->x;

   /* the window already exist */
   if (ww->win) {
      /* erase the border */
      wbkgd(ww->win, COLOR_PAIR(wo->screen_color));
      werase(ww->win);
      /* destroy the file list */ 
      wdg_file_menu_destroy(wo);
      
      touchwin(ww->win);
      wnoutrefresh(ww->win);
      
      /* resize the window and draw the new border */
      mvwin(ww->win, y, x);
      wresize(ww->win, l, c);

      wbkgd(ww->win, COLOR_PAIR(wo->window_color));
      werase(ww->win);
      
      /* create the file list */
      wdg_file_menu_create(wo);

      touchwin(ww->win);

      wdg_file_borders(wo);
     

   /* the first time we have to allocate the window */
   } else {

      /* create the menu window (fixed dimensions) */
      if ((ww->win = newwin(l, c, y, x)) == NULL)
         return -WDG_E_FATAL;

      /* create the file list */
      wdg_file_menu_create(wo);

      /* set the window color */
      wbkgd(ww->win, COLOR_PAIR(wo->window_color));
      redrawwin(ww->win);
      
      /* draw the titles */
      wdg_file_borders(wo);

      /* no scrolling */
      scrollok(ww->win, FALSE);
   }
   
   /* refresh the window */
   touchwin(ww->win);
   wnoutrefresh(ww->win);

   touchwin(ww->mwin);
   wnoutrefresh(ww->mwin);
   
   wo->flags |= WDG_OBJ_VISIBLE;

   return WDG_E_SUCCESS;
}
Пример #20
0
/*
 * this function will get the input from the user.
 * CAUTION: this is an hack, since it uses wgetch()
 * it will takeover the main dispatching loop !!!
 */
void wdg_input_get_input(wdg_t *wo)
{
   int key, ret;
   struct wdg_mouse_event mouse;
  
   WDG_DEBUG_MSG("wdg_input_get_input");
   
   /* dispatch keys to self */
   WDG_LOOP {

      key = wgetch(stdscr);
     
      switch (key) {

         /* don't switch focus... */
         case KEY_TAB:
            break;
         
         case KEY_CTRL_L:
            /* redrawing the screen is equivalent to resizing it */
         case KEY_RESIZE:
            /* the screen has been resized */
            wdg_redraw_all();
            /* update the screen */
            doupdate();
            break;
            
         case ERR:
            /* non-blocking input reached the timeout */
            /* sleep for milliseconds */
            napms(WDG_INPUT_TIMEOUT * 10);
            refresh();
            doupdate();
            break;
            
         default:

#ifdef NCURSES_MOUSE_VERSION
            /* handle mouse events */
            if (key == KEY_MOUSE) {
               MEVENT event;
            
               getmouse(&event);
               mouse_trafo(&event.y, &event.x, TRUE);
               mouse.x = event.x;
               mouse.y = event.y;
               mouse.event = event.bstate;
            }
#else            
            /* we don't support mouse events */
            memset(&mouse, 0, sizeof(mouse));
#endif
            /* dispatch the user input */
            ret = wdg_input_get_msg(wo, key, &mouse); 
            /* update the screen */
            doupdate();

            /* 
             * if the object is destroyed or the input finished, 
             * then return to the main loop
             */
            if (ret == WDG_EFINISHED) {
               WDG_DEBUG_MSG("wdg_input_get_input: return to main loop");
               return;
            }
            
            break;
      }
   }
   

}
Пример #21
0
/* 
 * called to redraw a window
 */
static int wdg_dialog_redraw(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_dialog, ww);
   size_t c, l, x, y;
   size_t lines, cols;
   
   WDG_DEBUG_MSG("wdg_dialog_redraw");
 
   /* calculate the dimension and position */
   wdg_dialog_get_size(wo, &lines, &cols);

   /* center on the screen, but not outside the edges */
   if (cols + 4 >= current_screen.cols)
      wo->x1 = 0;
   else
      wo->x1 = (current_screen.cols - (cols + 4)) / 2;
   
   wo->y1 = (current_screen.lines - (lines + 4)) / 2;
   wo->x2 = -wo->x1;
   wo->y2 = -wo->y1;
   
   /* get the cohorditates as usual */
   c = wdg_get_ncols(wo);
   l = wdg_get_nlines(wo);
   x = wdg_get_begin_x(wo);
   y = wdg_get_begin_y(wo);
   
   /* deal with rouding */
   if (l != lines + 4) l = lines + 4;
   if (c != cols + 4) c = cols + 4;
 
   /* the window already exist */
   if (ww->win) {
      /* erase the border */
      wbkgd(ww->win, COLOR_PAIR(wo->screen_color));
      werase(ww->win);
      touchwin(ww->win);
      wnoutrefresh(ww->win);
      
      /* resize the window and draw the new border */
      mvwin(ww->win, y, x);
      wresize(ww->win, l, c);
      wdg_dialog_border(wo);
      wdg_dialog_buttons(wo);
      
      /* resize the actual window and touch it */
      mvwin(ww->sub, y + 2, x + 2);
      wresize(ww->sub, l - 4, c - 4);
      /* set the window color */
      wbkgdset(ww->sub, COLOR_PAIR(wo->window_color));

   /* the first time we have to allocate the window */
   } else {

      /* create the outher window */
      if ((ww->win = newwin(l, c, y, x)) == NULL)
         return -WDG_EFATAL;

      /* draw the borders */
      wdg_dialog_border(wo);
      wdg_dialog_buttons(wo);

      /* create the inner (actual) window */
      if ((ww->sub = newwin(l - 4, c - 4, y + 2, x + 2)) == NULL)
         return -WDG_EFATAL;
      
      /* set the window color */
      wbkgdset(ww->sub, COLOR_PAIR(wo->window_color));
      werase(ww->sub);
      redrawwin(ww->sub);

   }
  
   /* print the message text */
   wmove(ww->sub, 0, 0);
   wprintw(ww->sub, ww->text);
   
   /* refresh the window */
   redrawwin(ww->sub);
   redrawwin(ww->win);
   wnoutrefresh(ww->win);
   wnoutrefresh(ww->sub);
   
   wo->flags |= WDG_OBJ_VISIBLE;

   return WDG_ESUCCESS;
}
Пример #22
0
/* 
 * called to redraw a window
 */
static int wdg_scroll_redraw(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_scroll, ww);
   size_t c = wdg_get_ncols(wo);
   size_t l = wdg_get_nlines(wo);
   size_t x = wdg_get_begin_x(wo);
   size_t y = wdg_get_begin_y(wo);
   
   WDG_DEBUG_MSG("wdg_scroll_redraw");
 
   /* the window already exist */
   if (ww->win) {
      /* erase the border */
      wbkgd(ww->win, COLOR_PAIR(wo->screen_color));
      werase(ww->win);
      touchwin(ww->win);
      wnoutrefresh(ww->win);
      
      /* resize the window and draw the new border */
      mvwin(ww->win, y, x);
      wresize(ww->win, l, c);
      wdg_scroll_border(wo);
      
      /* set the window color */
      wbkgd(ww->sub, COLOR_PAIR(wo->window_color));
      touchwin(ww->sub);
      /* the pad is resized only orizzontally.
       * the vertical dimension can be larger than the screen */
      wdg_scroll_set_lines(wo, ww->y_max);
      /* refresh it */
      WDG_PAD_REFRESH(ww, c, l, x, y);

   /* the first time we have to allocate the window */
   } else {
      
      /* a default value waiting for wdg_scroll_set_lines() */
      ww->y_max = l * 5;

      /* create the outher window */
      if ((ww->win = newwin(l, c, y, x)) == NULL)
         return -WDG_EFATAL;

      /* draw the borders */
      wdg_scroll_border(wo);
      /* initialize the pointer */
      wdg_set_scroll(wo, ww->y_max - l + 1);
      
      /* create the inner (actual) window */
      if ((ww->sub = newpad(ww->y_max, c - 2)) == NULL)
         return -WDG_EFATAL;
      
      /* set the window color */
      wbkgd(ww->sub, COLOR_PAIR(wo->window_color));
      touchwin(ww->sub);

      /* move to the bottom of the pad */
      wmove(ww->sub, ww->y_scroll + 1, 0);

      /* permit scroll in the pad */
      scrollok(ww->sub, TRUE);
   }
  
   /* refresh the window */
   touchwin(ww->sub);
   wnoutrefresh(ww->win);
   WDG_PAD_REFRESH(ww, c, l, x, y);
   
   wo->flags |= WDG_OBJ_VISIBLE;

   return WDG_ESUCCESS;
}
Пример #23
0
/* 
 * called to redraw a window
 */
static int wdg_window_redraw(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_window, ww);
   size_t c = wdg_get_ncols(wo);
   size_t l = wdg_get_nlines(wo);
   size_t x = wdg_get_begin_x(wo);
   size_t y = wdg_get_begin_y(wo);
   
   WDG_DEBUG_MSG("wdg_window_redraw");
 
   /* the window already exist */
   if (ww->win) {
      /* erase the border */
      wbkgd(ww->win, COLOR_PAIR(wo->screen_color));
      werase(ww->win);
      touchwin(ww->win);
      wnoutrefresh(ww->win);
      
      /* resize the window and draw the new border */
      mvwin(ww->win, y, x);
      wresize(ww->win, l, c);
      wdg_window_border(wo);
      
      /* resize the actual window and touch it */
      mvwin(ww->sub, y + 1, x + 1);
      wresize(ww->sub, l - 2, c - 2);
      /* set the window color */
      wbkgd(ww->sub, COLOR_PAIR(wo->window_color));

   /* the first time we have to allocate the window */
   } else {

      /* create the outher window */
      if ((ww->win = newwin(l, c, y, x)) == NULL)
         return -WDG_EFATAL;

      /* draw the borders */
      wdg_window_border(wo);

      /* create the inner (actual) window */
      if ((ww->sub = newwin(l - 2, c - 2, y + 1, x + 1)) == NULL)
         return -WDG_EFATAL;
      
      /* set the window color */
      wbkgd(ww->sub, COLOR_PAIR(wo->window_color));
      werase(ww->sub);
      redrawwin(ww->sub);

      /* initialize the pointer */
      wmove(ww->sub, 0, 0);

      scrollok(ww->sub, TRUE);

   }
   
   /* refresh the window */
   redrawwin(ww->sub);
   redrawwin(ww->win);
   wnoutrefresh(ww->win);
   wnoutrefresh(ww->sub);
   
   wo->flags |= WDG_OBJ_VISIBLE;

   return WDG_ESUCCESS;
}