Example #1
0
set_menu_win(MENU * menu, WINDOW *win)
{
  T((T_CALLED("set_menu_win(%p,%p)"), (void *)menu, (void *)win));

  if (menu)
    {
      if (menu->status & _POSTED)
	RETURN(E_POSTED);
      else
#if NCURSES_SP_FUNCS
	{
	  /* We ensure that userwin is never null. So even if a null
	     WINDOW parameter is passed, we store the SCREENS stdscr.
	     The only MENU that can have a null userwin is the static
	     _nc_default_Menu.
	   */
	  SCREEN *sp = _nc_screen_of(menu->userwin);

	  menu->userwin = win ? win : sp->_stdscr;
	  _nc_Calculate_Item_Length_and_Width(menu);
	}
#else
	menu->userwin = win;
#endif
    }
  else
    _nc_Default_Menu.userwin = win;

  RETURN(E_OK);
}
Example #2
0
set_menu_mark (MENU * menu, const char * mark)
{
  int l;

  if ( mark && (*mark != '\0') && Is_Printable_String(mark) )
    l = strlen(mark);
  else
    l = 0;

  if ( menu )
    {
      char *old_mark = menu->mark;
      unsigned short old_status = menu->status;

      if (menu->status & _POSTED)
	{
	  /* If the menu is already posted, the geometry is fixed. Then
	     we can only accept a mark with exactly the same length */
	  if (menu->marklen != l) 
	    RETURN(E_BAD_ARGUMENT);
	}	
      menu->marklen = l;
      if (l)
	{
	  menu->mark = (char *)malloc(l+1);
	  if (menu->mark)
	    {
	      strcpy(menu->mark, mark);
	      if (menu != &_nc_Default_Menu)
		menu->status |= _MARK_ALLOCATED;
	    }
	  else
	    {
	      menu->mark = old_mark;
	      RETURN(E_SYSTEM_ERROR);
	    }
	}
      else
	menu->mark = (char *)0;
      
      if ((old_status & _MARK_ALLOCATED) && old_mark)
	free(old_mark);

      if (menu->status & _POSTED)
	{
	  _nc_Draw_Menu( menu );
	  _nc_Show_Menu( menu );
	}
      else
	{
	  /* Recalculate the geometry */
	  _nc_Calculate_Item_Length_and_Width( menu );			
	}
    }
  else
    {
      return set_menu_mark(&_nc_Default_Menu, mark);
    }
  RETURN(E_OK);
}
Example #3
0
set_menu_spacing(MENU * menu, int s_desc, int s_row, int s_col)
{
  MENU *m;			/* split for ATAC workaround */

  T((T_CALLED("set_menu_spacing(%p,%d,%d,%d)"),
     (void *)menu, s_desc, s_row, s_col));

  m = Normalize_Menu(menu);

  assert(m);
  if (m->status & _POSTED)
    RETURN(E_POSTED);

  if (((s_desc < 0) || (s_desc > MAX_SPC_DESC)) ||
      ((s_row < 0) || (s_row > MAX_SPC_ROWS)) ||
      ((s_col < 0) || (s_col > MAX_SPC_COLS)))
    RETURN(E_BAD_ARGUMENT);

  m->spc_desc = (short)(s_desc ? s_desc : 1);
  m->spc_rows = (short)(s_row ? s_row : 1);
  m->spc_cols = (short)(s_col ? s_col : 1);
  _nc_Calculate_Item_Length_and_Width(m);

  RETURN(E_OK);
}
Example #4
0
set_menu_format(MENU * menu, int rows, int cols)
{
    int total_rows, total_cols;

    T((T_CALLED("set_menu_format(%p,%d,%d)"), menu, rows, cols));

    if (rows < 0 || cols < 0)
        RETURN(E_BAD_ARGUMENT);

    if (menu)
    {
        if (menu->status & _POSTED)
            RETURN(E_POSTED);

        if (!(menu->items))
            RETURN(E_NOT_CONNECTED);

        if (rows == 0)
            rows = menu->frows;
        if (cols == 0)
            cols = menu->fcols;

        if (menu->pattern)
            Reset_Pattern(menu);

        menu->frows = rows;
        menu->fcols = cols;

        assert(rows > 0 && cols > 0);
        total_rows = (menu->nitems - 1) / cols + 1;
        total_cols = (menu->opt & O_ROWMAJOR) ?
                     minimum(menu->nitems, cols) :
                     (menu->nitems - 1) / total_rows + 1;

        menu->rows = total_rows;
        menu->cols = total_cols;
        menu->arows = minimum(total_rows, rows);
        menu->toprow = 0;
        menu->curitem = *(menu->items);
        assert(menu->curitem);
        menu->status |= _LINK_NEEDED;
        _nc_Calculate_Item_Length_and_Width(menu);
    }
    else
    {
        if (rows > 0)
            _nc_Default_Menu.frows = rows;
        if (cols > 0)
            _nc_Default_Menu.fcols = cols;
    }

    RETURN(E_OK);
}
Example #5
0
set_menu_sub(MENU * menu, WINDOW *win)
{
  T((T_CALLED("set_menu_sub(%p,%p)"), menu, win));

  if (menu)
    {
      if (menu->status & _POSTED)
	RETURN(E_POSTED);
      menu->usersub = win;
      _nc_Calculate_Item_Length_and_Width(menu);
    }
  else
    _nc_Default_Menu.usersub = win;

  RETURN(E_OK);
}
Example #6
0
set_menu_opts(MENU * menu, Menu_Options opts)
{
  T((T_CALLED("set_menu_opts(%p,%d)"), menu, opts));

  opts &= ALL_MENU_OPTS;

  if (opts & ~ALL_MENU_OPTS)
    RETURN(E_BAD_ARGUMENT);

  if (menu)
    {
      if (menu->status & _POSTED)
	RETURN(E_POSTED);

      if ((opts & O_ROWMAJOR) != (menu->opt & O_ROWMAJOR))
	{
	  /* we need this only if the layout really changed ... */
	  if (menu->items && menu->items[0])
	    {
	      menu->toprow = 0;
	      menu->curitem = menu->items[0];
	      assert(menu->curitem);
	      set_menu_format(menu, menu->frows, menu->fcols);
	    }
	}

      menu->opt = opts;

      if (opts & O_ONEVALUE)
	{
	  ITEM **item;

	  if (((item = menu->items) != (ITEM **) 0))
	    for (; *item; item++)
	      (*item)->value = FALSE;
	}

      if (opts & O_SHOWDESC)	/* this also changes the geometry */
	_nc_Calculate_Item_Length_and_Width(menu);
    }
  else
    _nc_Default_Menu.opt = opts;

  RETURN(E_OK);
}