| 1 |
/***************************************************************************
|
| 2 |
menu.h - description
|
| 3 |
-------------------
|
| 4 |
Copyright : (C) 2004-2025 by Leaflet
|
| 5 |
Email : leaflet@leafok.com
|
| 6 |
***************************************************************************/
|
| 7 |
|
| 8 |
/***************************************************************************
|
| 9 |
* *
|
| 10 |
* This program is free software; you can redistribute it and/or modify *
|
| 11 |
* it under the terms of the GNU General Public License as published by *
|
| 12 |
* the Free Software Foundation; either version 3 of the License, or *
|
| 13 |
* (at your option) any later version. *
|
| 14 |
* *
|
| 15 |
***************************************************************************/
|
| 16 |
|
| 17 |
#ifndef _MENU_H_
|
| 18 |
#define _MENU_H_
|
| 19 |
|
| 20 |
#include "common.h"
|
| 21 |
#include "trie_dict.h"
|
| 22 |
#include <stdint.h>
|
| 23 |
#include <sys/shm.h>
|
| 24 |
|
| 25 |
#define MAX_MENUITEM_LENGTH 50
|
| 26 |
#define MAX_ITEMS_PER_MENU 30
|
| 27 |
#define MAX_MENUNAME_LENGTH 256
|
| 28 |
#define MAX_MENUACTION_LENGTH 20
|
| 29 |
#define MAX_MENUTITLE_LENGTH 50
|
| 30 |
#define MAX_MENU_SCR_NAME_LENGTH 20
|
| 31 |
#define MAX_MENU_SCR_BUF_LENGTH 2000
|
| 32 |
#define MAX_MENUS 256
|
| 33 |
#define MAX_MENUITEMS 5120
|
| 34 |
#define MAX_MENU_DEPTH 50
|
| 35 |
|
| 36 |
typedef uint64_t MENU_ID;
|
| 37 |
typedef uint64_t MENU_ITEM_ID;
|
| 38 |
typedef uint64_t MENU_SCREEN_ID;
|
| 39 |
|
| 40 |
struct menu_item_t
|
| 41 |
{
|
| 42 |
int16_t row, col;
|
| 43 |
char action[MAX_MENUACTION_LENGTH];
|
| 44 |
MENU_ID action_menu_id;
|
| 45 |
int8_t submenu;
|
| 46 |
int priv, level;
|
| 47 |
char name[MAX_MENUNAME_LENGTH];
|
| 48 |
char text[MAX_MENUITEM_LENGTH];
|
| 49 |
};
|
| 50 |
typedef struct menu_item_t MENU_ITEM;
|
| 51 |
|
| 52 |
struct menu_title_t
|
| 53 |
{
|
| 54 |
int16_t row, col;
|
| 55 |
int8_t show;
|
| 56 |
char text[MAX_MENUTITLE_LENGTH];
|
| 57 |
};
|
| 58 |
typedef struct menu_title_t MENU_TITLE;
|
| 59 |
|
| 60 |
struct menu_screen_t
|
| 61 |
{
|
| 62 |
char name[MAX_MENU_SCR_NAME_LENGTH];
|
| 63 |
int64_t buf_offset;
|
| 64 |
int64_t buf_length;
|
| 65 |
};
|
| 66 |
typedef struct menu_screen_t MENU_SCREEN;
|
| 67 |
|
| 68 |
struct menu_t
|
| 69 |
{
|
| 70 |
char name[MAX_MENUNAME_LENGTH];
|
| 71 |
MENU_TITLE title;
|
| 72 |
MENU_SCREEN_ID screen_id;
|
| 73 |
int8_t screen_show;
|
| 74 |
int16_t screen_row, screen_col;
|
| 75 |
MENU_ITEM_ID items[MAX_ITEMS_PER_MENU];
|
| 76 |
int16_t item_count;
|
| 77 |
};
|
| 78 |
typedef struct menu_t MENU;
|
| 79 |
|
| 80 |
struct menu_set_t
|
| 81 |
{
|
| 82 |
int shmid;
|
| 83 |
void *p_reserved;
|
| 84 |
void *p_menu_pool;
|
| 85 |
void *p_menu_item_pool;
|
| 86 |
void *p_menu_screen_pool;
|
| 87 |
char *p_menu_screen_buf;
|
| 88 |
char *p_menu_screen_buf_free;
|
| 89 |
int16_t menu_count;
|
| 90 |
int16_t menu_item_count;
|
| 91 |
int16_t menu_screen_count;
|
| 92 |
TRIE_NODE *p_menu_name_dict;
|
| 93 |
TRIE_NODE *p_menu_screen_dict;
|
| 94 |
MENU_ID menu_id_path[MAX_MENU_DEPTH];
|
| 95 |
int16_t menu_item_pos[MAX_MENU_DEPTH];
|
| 96 |
int16_t choose_step;
|
| 97 |
int8_t menu_item_display[MAX_ITEMS_PER_MENU];
|
| 98 |
int16_t menu_item_r_row[MAX_ITEMS_PER_MENU];
|
| 99 |
int16_t menu_item_r_col[MAX_ITEMS_PER_MENU];
|
| 100 |
};
|
| 101 |
typedef struct menu_set_t MENU_SET;
|
| 102 |
|
| 103 |
extern MENU_SET *p_bbs_menu;
|
| 104 |
|
| 105 |
extern int load_menu(MENU_SET *p_menu_set, const char *conf_file);
|
| 106 |
extern int unload_menu(MENU_SET *p_menu_set);
|
| 107 |
|
| 108 |
extern int load_menu_shm(MENU_SET *p_menu_set);
|
| 109 |
extern int unload_menu_shm(MENU_SET *p_menu_set);
|
| 110 |
|
| 111 |
extern int menu_control(MENU_SET *p_menu_set, int key);
|
| 112 |
extern int display_menu(MENU_SET *p_menu_set);
|
| 113 |
|
| 114 |
inline MENU *get_menu(MENU_SET *p_menu_set, const char *menu_name)
|
| 115 |
{
|
| 116 |
MENU *value = NULL;
|
| 117 |
|
| 118 |
trie_dict_get(p_menu_set->p_menu_name_dict, menu_name, (int64_t *)&value);
|
| 119 |
|
| 120 |
return ((MENU *)value);
|
| 121 |
}
|
| 122 |
|
| 123 |
inline MENU *get_menu_by_id(MENU_SET *p_menu_set, MENU_ID menu_id)
|
| 124 |
{
|
| 125 |
if (menu_id < 0 || menu_id >= p_menu_set->menu_count)
|
| 126 |
{
|
| 127 |
return NULL;
|
| 128 |
}
|
| 129 |
|
| 130 |
return (p_menu_set->p_menu_pool + sizeof(MENU) * menu_id);
|
| 131 |
}
|
| 132 |
|
| 133 |
inline MENU_ITEM *get_menu_item_by_id(MENU_SET *p_menu_set, MENU_ITEM_ID menu_item_id)
|
| 134 |
{
|
| 135 |
if (menu_item_id < 0 || menu_item_id >= p_menu_set->menu_item_count)
|
| 136 |
{
|
| 137 |
return NULL;
|
| 138 |
}
|
| 139 |
|
| 140 |
return (p_menu_set->p_menu_item_pool + sizeof(MENU_ITEM) * menu_item_id);
|
| 141 |
}
|
| 142 |
|
| 143 |
inline MENU_SCREEN *get_menu_screen_by_id(MENU_SET *p_menu_set, MENU_SCREEN_ID menu_screen_id)
|
| 144 |
{
|
| 145 |
if (menu_screen_id < 0 || menu_screen_id >= p_menu_set->menu_screen_count)
|
| 146 |
{
|
| 147 |
return NULL;
|
| 148 |
}
|
| 149 |
|
| 150 |
return (p_menu_set->p_menu_screen_pool + sizeof(MENU_ITEM) * menu_screen_id);
|
| 151 |
}
|
| 152 |
|
| 153 |
#endif //_MENU_H_
|