1 /* $OpenBSD: m_cursor.c,v 1.5 1999/01/22 03:45:06 millert Exp $ */ 2 3 /**************************************************************************** 4 * Copyright (c) 1998 Free Software Foundation, Inc. * 5 * * 6 * Permission is hereby granted, free of charge, to any person obtaining a * 7 * copy of this software and associated documentation files (the * 8 * "Software"), to deal in the Software without restriction, including * 9 * without limitation the rights to use, copy, modify, merge, publish, * 10 * distribute, distribute with modifications, sublicense, and/or sell * 11 * copies of the Software, and to permit persons to whom the Software is * 12 * furnished to do so, subject to the following conditions: * 13 * * 14 * The above copyright notice and this permission notice shall be included * 15 * in all copies or substantial portions of the Software. * 16 * * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 24 * * 25 * Except as contained in this notice, the name(s) of the above copyright * 26 * holders shall not be used in advertising or otherwise to promote the * 27 * sale, use or other dealings in this Software without prior written * 28 * authorization. * 29 ****************************************************************************/ 30 31 /**************************************************************************** 32 * Author: Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> 1995,1997 * 33 ****************************************************************************/ 34 35 /*************************************************************************** 36 * Module m_cursor * 37 * Correctly position a menus cursor * 38 ***************************************************************************/ 39 40 #include "menu.priv.h" 41 42 MODULE_ID("$From: m_cursor.c,v 1.11 1998/12/06 04:23:09 tom Exp $") 43 44 /*--------------------------------------------------------------------------- 45 | Facility : libnmenu 46 | Function : _nc_menu_cursor_pos 47 | 48 | Description : Return position of logical cursor to current item 49 | 50 | Return Values : E_OK - success 51 | E_BAD_ARGUMENT - invalid menu 52 | E_NOT_POSTED - Menu is not posted 53 +--------------------------------------------------------------------------*/ 54 int _nc_menu_cursor_pos(const MENU* menu, 55 const ITEM* item, 56 int* pY, int* pX) 57 { 58 if (!menu || !pX || !pY) 59 return(E_BAD_ARGUMENT); 60 else 61 { 62 if ((ITEM*)0 == item) 63 item = menu->curitem; 64 assert(item!=(ITEM*)0); 65 66 if ( !( menu->status & _POSTED ) ) 67 return(E_NOT_POSTED); 68 69 *pX = item->x * (menu->spc_cols + menu->itemlen); 70 *pY = (item->y - menu->toprow) * menu->spc_rows; 71 } 72 return(E_OK); 73 } 74 75 /*--------------------------------------------------------------------------- 76 | Facility : libnmenu 77 | Function : pos_menu_cursor 78 | 79 | Description : Position logical cursor to current item in menu 80 | 81 | Return Values : E_OK - success 82 | E_BAD_ARGUMENT - invalid menu 83 | E_NOT_POSTED - Menu is not posted 84 +--------------------------------------------------------------------------*/ 85 int pos_menu_cursor(const MENU * menu) 86 { 87 WINDOW *win, *sub; 88 int x, y; 89 int err = _nc_menu_cursor_pos(menu,(ITEM*)0,&y,&x); 90 91 if (E_OK==err) 92 { 93 win = menu->userwin ? menu->userwin : stdscr; 94 sub = menu->usersub ? menu->usersub : win; 95 assert(win && sub); 96 97 if ((menu->opt & O_SHOWMATCH) && (menu->pindex > 0)) 98 x += ( menu->pindex + menu->marklen - 1); 99 100 wmove(sub,y,x); 101 102 if ( win != sub ) 103 { 104 wcursyncup(sub); 105 wsyncup(sub); 106 untouchwin(sub); 107 } 108 } 109 RETURN(err); 110 } 111 112 /* m_cursor.c ends here */ 113