]> ncurses.scripts.mit.edu Git - ncurses.git/blob - menu/m_cursor.c
ncurses 4.1
[ncurses.git] / menu / m_cursor.c
1 /*-----------------------------------------------------------------------------+
2 |           The ncurses menu library is  Copyright (C) 1995-1997               |
3 |             by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de>                 |
4 |                          All Rights Reserved.                                |
5 |                                                                              |
6 | Permission to use, copy, modify, and distribute this software and its        |
7 | documentation for any purpose and without fee is hereby granted, provided    |
8 | that the above copyright notice appear in all copies and that both that      |
9 | copyright notice and this permission notice appear in supporting             |
10 | documentation, and that the name of the above listed copyright holder(s) not |
11 | be used in advertising or publicity pertaining to distribution of the        |
12 | software without specific, written prior permission.                         | 
13 |                                                                              |
14 | THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO  |
15 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-  |
16 | NESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR   |
17 | ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RE- |
18 | SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
19 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH    |
20 | THE USE OR PERFORMANCE OF THIS SOFTWARE.                                     |
21 +-----------------------------------------------------------------------------*/
22
23 /***************************************************************************
24 * Module menu_cursor                                                       *
25 * Correctly position a menus cursor                                        *
26 ***************************************************************************/
27
28 #include "menu.priv.h"
29
30 MODULE_ID("$Id: m_cursor.c,v 1.7 1997/05/01 16:47:26 juergen Exp $")
31
32 /*---------------------------------------------------------------------------
33 |   Facility      :  libnmenu  
34 |   Function      :  pos_menu_cursor  
35 |   
36 |   Description   :  Position logical cursor to current item in menu
37 |
38 |   Return Values :  E_OK            - success
39 |                    E_BAD_ARGUMENT  - invalid menu
40 |                    E_NOT_POSTED    - Menu is not posted
41 +--------------------------------------------------------------------------*/
42 int pos_menu_cursor(const MENU * menu)
43 {
44   if (!menu)
45     RETURN(E_BAD_ARGUMENT);
46   else
47     {
48       ITEM *item;
49       int x, y;
50       WINDOW *win, *sub;
51       
52       if ( !( menu->status & _POSTED ) )
53         RETURN(E_NOT_POSTED);
54       
55       item = menu->curitem;
56       assert(item);
57       
58       x = item->x * (menu->spc_cols + menu->itemlen);
59       y = (item->y - menu->toprow) * menu->spc_rows;
60       win = menu->userwin ? menu->userwin : stdscr;
61       sub = menu->usersub ? menu->usersub : win;
62       assert(win && sub);
63       
64       if ((menu->opt & O_SHOWMATCH) && (menu->pindex > 0))
65         x += ( menu->pindex + menu->marklen - 1);
66       
67       wmove(sub,y,x);
68       
69       if ( win != sub )
70         {
71           wcursyncup(sub);
72           wsyncup(sub);
73           untouchwin(sub);
74         } 
75     }
76   RETURN(E_OK);
77 }
78
79 /* m_cursor.c ends here */