1 /* $OpenBSD: m_cursor.c,v 1.7 2001/01/22 18:02:03 millert Exp $ */ 2 3 /**************************************************************************** 4 * Copyright (c) 1998,2000 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@gmx.net> 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.14 2000/12/10 02:16:48 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 NCURSES_EXPORT(int) 55 _nc_menu_cursor_pos 56 (const MENU* menu, const ITEM* item, 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 NCURSES_EXPORT(int) 86 pos_menu_cursor (const MENU * menu) 87 { 88 WINDOW *win, *sub; 89 int x, y; 90 int err = _nc_menu_cursor_pos(menu,(ITEM*)0,&y,&x); 91 92 if (E_OK==err) 93 { 94 win = menu->userwin ? menu->userwin : stdscr; 95 sub = menu->usersub ? menu->usersub : win; 96 assert(win && sub); 97 98 if ((menu->opt & O_SHOWMATCH) && (menu->pindex > 0)) 99 x += ( menu->pindex + menu->marklen - 1); 100 101 wmove(sub,y,x); 102 103 if ( win != sub ) 104 { 105 wcursyncup(sub); 106 wsyncup(sub); 107 untouchwin(sub); 108 } 109 } 110 RETURN(err); 111 } 112 113 /* m_cursor.c ends here */ 114