1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
#ifndef MENU_H
#define MENU_H
#if defined HAVE_NCURSESW_CURSES_H
# include <ncursesw/curses.h>
#elif defined HAVE_NCURSESW_H
# include <ncursesw.h>
#elif defined HAVE_NCURSES_CURSES_H
# include <ncurses/curses.h>
#elif defined HAVE_NCURSES_H
# include <ncurses.h>
#elif defined HAVE_CURSES_H
# include <curses.h>
#endif
#include "files.h"
#include "rbtree.h"
#ifdef __cplusplus
extern "C" {
#endif
enum menu_request
{
REQ_UP,
REQ_DOWN,
REQ_PGUP,
REQ_PGDOWN,
REQ_TOP,
REQ_BOTTOM
};
enum menu_align
{
MENU_ALIGN_RIGHT,
MENU_ALIGN_LEFT
};
#define FILE_TIME_STR_SZ 6
#define FILE_FORMAT_SZ 4
struct menu_item
{
char *title; /* Title of the item */
enum menu_align align; /* Align of the title */
int num; /* Position of the item starting from 0. */
/* Curses attributes in different states: */
int attr_normal;
int attr_sel;
int attr_marked;
int attr_sel_marked;
/* Associated file: */
char *file;
enum file_type type;
/* Additional information shown: */
char time[FILE_TIME_STR_SZ]; /* File time string */
char format[FILE_FORMAT_SZ]; /* File format */
int queue_pos; /* Position in the queue */
struct menu_item *next;
struct menu_item *prev;
};
struct menu
{
WINDOW *win;
struct menu_item *items;
int nitems; /* number of present items */
struct menu_item *top; /* first visible item */
struct menu_item *last; /* last item in the menu */
/* position and size */
int posx;
int posy;
int width;
int height;
struct menu_item *selected; /* selected item */
struct menu_item *marked; /* index of the marked item or -1 */
/* Flags for displaying information about the file. */
int show_time;
bool show_format;
int info_attr_normal; /* attributes for information about the file */
int info_attr_sel;
int info_attr_marked;
int info_attr_sel_marked;
int number_items; /* display item number (position) */
struct rb_tree *search_tree; /* RB tree for searching by file name */
};
/* Menu state: relative (to the first item) positions of the top and selected
* items. */
struct menu_state
{
int top_item;
int selected_item;
};
struct menu *menu_new (WINDOW *win, const int posx, const int posy,
const int width, const int height);
struct menu_item *menu_add (struct menu *menu, const char *title,
const enum file_type type, const char *file);
void menu_item_set_attr_normal (struct menu_item *mi, const int attr);
void menu_item_set_attr_sel (struct menu_item *mi, const int attr);
void menu_item_set_attr_sel_marked (struct menu_item *mi, const int attr);
void menu_item_set_attr_marked (struct menu_item *mi, const int attr);
void menu_item_set_time (struct menu_item *mi, const char *time);
void menu_item_set_format (struct menu_item *mi, const char *format);
void menu_item_set_queue_pos (struct menu_item *mi, const int pos);
void menu_free (struct menu *menu);
void menu_driver (struct menu *menu, const enum menu_request req);
void menu_setcurritem_title (struct menu *menu, const char *title);
void menu_setcurritem_file (struct menu *menu, const char *file);
void menu_draw (const struct menu *menu, const int active);
void menu_mark_item (struct menu *menu, const char *file);
void menu_set_state (struct menu *menu, const struct menu_state *st);
void menu_get_state (const struct menu *menu, struct menu_state *st);
void menu_update_size (struct menu *menu, const int posx, const int posy,
const int width, const int height);
void menu_unmark_item (struct menu *menu);
struct menu *menu_filter_pattern (const struct menu *menu, const char *pattern);
void menu_set_show_time (struct menu *menu, const int t);
void menu_set_show_format (struct menu *menu, const bool t);
void menu_set_info_attr_normal (struct menu *menu, const int attr);
void menu_set_info_attr_sel (struct menu *menu, const int attr);
void menu_set_info_attr_marked (struct menu *menu, const int attr);
void menu_set_info_attr_sel_marked (struct menu *menu, const int attr);
void menu_set_items_numbering (struct menu *menu, const int number);
enum file_type menu_item_get_type (const struct menu_item *mi);
char *menu_item_get_file (const struct menu_item *mi);
struct menu_item *menu_curritem (struct menu *menu);
void menu_item_set_title (struct menu_item *mi, const char *title);
int menu_nitems (const struct menu *menu);
struct menu_item *menu_find (struct menu *menu, const char *fname);
void menu_del_item (struct menu *menu, const char *fname);
void menu_item_set_align (struct menu_item *mi, const enum menu_align align);
int menu_is_visible (const struct menu *menu, const struct menu_item *mi);
void menu_swap_items (struct menu *menu, const char *file1, const char *file2);
void menu_make_visible (struct menu *menu, const char *file);
void menu_set_cursor (const struct menu *m);
#ifdef __cplusplus
}
#endif
#endif
|