m_item_cur.c revision 50276
11573Srgrimes/****************************************************************************
21573Srgrimes * Copyright (c) 1998 Free Software Foundation, Inc.                        *
31573Srgrimes *                                                                          *
41573Srgrimes * Permission is hereby granted, free of charge, to any person obtaining a  *
51573Srgrimes * copy of this software and associated documentation files (the            *
61573Srgrimes * "Software"), to deal in the Software without restriction, including      *
71573Srgrimes * without limitation the rights to use, copy, modify, merge, publish,      *
81573Srgrimes * distribute, distribute with modifications, sublicense, and/or sell       *
91573Srgrimes * copies of the Software, and to permit persons to whom the Software is    *
101573Srgrimes * furnished to do so, subject to the following conditions:                 *
111573Srgrimes *                                                                          *
121573Srgrimes * The above copyright notice and this permission notice shall be included  *
131573Srgrimes * in all copies or substantial portions of the Software.                   *
141573Srgrimes *                                                                          *
151573Srgrimes * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16251672Semaste * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
171573Srgrimes * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
181573Srgrimes * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
191573Srgrimes * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
201573Srgrimes * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
211573Srgrimes * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
221573Srgrimes *                                                                          *
231573Srgrimes * Except as contained in this notice, the name(s) of the above copyright   *
241573Srgrimes * holders shall not be used in advertising or otherwise to promote the     *
251573Srgrimes * sale, use or other dealings in this Software without prior written       *
261573Srgrimes * authorization.                                                           *
271573Srgrimes ****************************************************************************/
281573Srgrimes
291573Srgrimes/****************************************************************************
301573Srgrimes *   Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997            *
311573Srgrimes ****************************************************************************/
321573Srgrimes
3350476Speter/***************************************************************************
341573Srgrimes* Module m_item_cur                                                        *
35249035Sdelphij* Set and get current menus item                                           *
361573Srgrimes***************************************************************************/
371573Srgrimes
381573Srgrimes#include "menu.priv.h"
391573Srgrimes
4047474SwesMODULE_ID("$Id: m_item_cur.c,v 1.11 1999/05/16 17:25:34 juergen Exp $")
4175845Sache
4247474Swes/*---------------------------------------------------------------------------
431573Srgrimes|   Facility      :  libnmenu
4459460Sphantom|   Function      :  int set_current_item(MENU *menu, const ITEM *item)
4559460Sphantom|
461573Srgrimes|   Description   :  Make the item the current item
4783206Sasmodai|
481573Srgrimes|   Return Values :  E_OK                - success
491573Srgrimes+--------------------------------------------------------------------------*/
5075845Sacheint set_current_item(MENU * menu, ITEM * item)
5175845Sache{
521573Srgrimes  if (menu && item && (item->imenu==menu))
531573Srgrimes    {
5447474Swes      if ( menu->status & _IN_DRIVER )
5547474Swes	RETURN(E_BAD_STATE);
561573Srgrimes
571573Srgrimes      assert( menu->curitem );
58240107Sdes      if (item != menu->curitem)
59240107Sdes	{
60240107Sdes	  if (menu->status & _LINK_NEEDED)
61240107Sdes	    {
62240107Sdes	      /*
63240107Sdes	       * Items are available, but they are not linked together.
64240107Sdes	       * So we have to link here.
6581285Sru	       */
6681285Sru	      _nc_Link_Items(menu);
671573Srgrimes	    }
681573Srgrimes	  assert(menu->pattern);
691573Srgrimes	  Reset_Pattern(menu);
701573Srgrimes	  /* adjust the window to make item visible and update the menu */
711573Srgrimes	  Adjust_Current_Item(menu,menu->toprow,item);
721573Srgrimes	}
731573Srgrimes    }
74119893Sru  else
751573Srgrimes    RETURN(E_BAD_ARGUMENT);
761573Srgrimes
771573Srgrimes  RETURN(E_OK);
7847474Swes}
7947474Swes
8047474Swes/*---------------------------------------------------------------------------
811573Srgrimes|   Facility      :  libnmenu
821573Srgrimes|   Function      :  ITEM *current_item(const MENU *menu)
831573Srgrimes|
841573Srgrimes|   Description   :  Return the menus current item
851573Srgrimes|
861573Srgrimes|   Return Values :  Item pointer or NULL if failure
8747474Swes+--------------------------------------------------------------------------*/
8879754SddITEM *current_item(const MENU * menu)
8947474Swes{
901573Srgrimes  return (menu && menu->items) ? menu->curitem : (ITEM *)0;
9147474Swes}
9275845Sache
9375845Sache/*---------------------------------------------------------------------------
94249035Sdelphij|   Facility      :  libnmenu
9575845Sache|   Function      :  int item_index(const ITEM *)
96108037Sru|
9747474Swes|   Description   :  Return the logical index of this item.
98108037Sru|
9947474Swes|   Return Values :  The index or ERR if this is an invalid item pointer
10047474Swes+--------------------------------------------------------------------------*/
10147474Swesint item_index(const ITEM *item)
10247474Swes{
10347474Swes  return (item && item->imenu) ? item->index : ERR;
104213476Skib}
105213476Skib
106213476Skib/* m_item_cur.c ends here */
107213476Skib