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