1 /* $OpenBSD: m_spacing.c,v 1.7 2023/10/17 09:52:10 nicm Exp $ */ 2 3 /**************************************************************************** 4 * Copyright 2020 Thomas E. Dickey * 5 * Copyright 1998-2010,2012 Free Software Foundation, Inc. * 6 * * 7 * Permission is hereby granted, free of charge, to any person obtaining a * 8 * copy of this software and associated documentation files (the * 9 * "Software"), to deal in the Software without restriction, including * 10 * without limitation the rights to use, copy, modify, merge, publish, * 11 * distribute, distribute with modifications, sublicense, and/or sell * 12 * copies of the Software, and to permit persons to whom the Software is * 13 * furnished to do so, subject to the following conditions: * 14 * * 15 * The above copyright notice and this permission notice shall be included * 16 * in all copies or substantial portions of the Software. * 17 * * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 21 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 24 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 25 * * 26 * Except as contained in this notice, the name(s) of the above copyright * 27 * holders shall not be used in advertising or otherwise to promote the * 28 * sale, use or other dealings in this Software without prior written * 29 * authorization. * 30 ****************************************************************************/ 31 32 /**************************************************************************** 33 * Author: Juergen Pfeifer, 1995,1997 * 34 ****************************************************************************/ 35 36 /*************************************************************************** 37 * Module m_spacing * 38 * Routines to handle spacing between entries * 39 ***************************************************************************/ 40 41 #include "menu.priv.h" 42 43 MODULE_ID("$Id: m_spacing.c,v 1.7 2023/10/17 09:52:10 nicm Exp $") 44 45 #define MAX_SPC_DESC ((TABSIZE) ? (TABSIZE) : 8) 46 #define MAX_SPC_COLS ((TABSIZE) ? (TABSIZE) : 8) 47 #define MAX_SPC_ROWS (3) 48 49 /*--------------------------------------------------------------------------- 50 | Facility : libnmenu 51 | Function : int set_menu_spacing(MENU *menu,int desc, int r, int c); 52 | 53 | Description : Set the spacing between entries 54 | 55 | Return Values : E_OK - on success 56 +--------------------------------------------------------------------------*/ 57 MENU_EXPORT(int) 58 set_menu_spacing(MENU *menu, int s_desc, int s_row, int s_col) 59 { 60 MENU *m; /* split for ATAC workaround */ 61 62 T((T_CALLED("set_menu_spacing(%p,%d,%d,%d)"), 63 (void *)menu, s_desc, s_row, s_col)); 64 65 m = Normalize_Menu(menu); 66 67 assert(m); 68 if (m->status & _POSTED) 69 RETURN(E_POSTED); 70 71 if (((s_desc < 0) || (s_desc > MAX_SPC_DESC)) || 72 ((s_row < 0) || (s_row > MAX_SPC_ROWS)) || 73 ((s_col < 0) || (s_col > MAX_SPC_COLS))) 74 RETURN(E_BAD_ARGUMENT); 75 76 m->spc_desc = (short)(s_desc ? s_desc : 1); 77 m->spc_rows = (short)(s_row ? s_row : 1); 78 m->spc_cols = (short)(s_col ? s_col : 1); 79 _nc_Calculate_Item_Length_and_Width(m); 80 81 RETURN(E_OK); 82 } 83 84 /*--------------------------------------------------------------------------- 85 | Facility : libnmenu 86 | Function : int menu_spacing (const MENU *,int *,int *,int *); 87 | 88 | Description : Retrieve info about spacing between the entries 89 | 90 | Return Values : E_OK - on success 91 +--------------------------------------------------------------------------*/ 92 MENU_EXPORT(int) 93 menu_spacing(const MENU *menu, int *s_desc, int *s_row, int *s_col) 94 { 95 const MENU *m; /* split for ATAC workaround */ 96 97 T((T_CALLED("menu_spacing(%p,%p,%p,%p)"), 98 (const void *)menu, 99 (void *)s_desc, 100 (void *)s_row, 101 (void *)s_col)); 102 103 m = Normalize_Menu(menu); 104 105 assert(m); 106 if (s_desc) 107 *s_desc = m->spc_desc; 108 if (s_row) 109 *s_row = m->spc_rows; 110 if (s_col) 111 *s_col = m->spc_cols; 112 113 RETURN(E_OK); 114 } 115 116 /* m_spacing.c ends here */ 117