From: Ricardo Markiewicz Date: Thu, 1 Apr 2004 21:48:59 +0000 (+0000) Subject: * Comienzo agregar los menues (que no me andan :-() X-Git-Tag: svn_import_r684~659 X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/commitdiff_plain/d0db52f773115fe329e572cbf2ab22a741f11536?ds=sidebyside * Comienzo agregar los menues (que no me andan :-() --- diff --git a/gui/Makefile b/gui/Makefile index 293e4bd..e41a9ef 100644 --- a/gui/Makefile +++ b/gui/Makefile @@ -1,5 +1,5 @@ CFLAGS=-Wall -g -I/usr/include/libxml2 -LDFLAGS=-lncurses -lxml2 +LDFLAGS=-lmenu -lncurses -lxml2 all: gui diff --git a/gui/gui.c b/gui/gui.c index 0e8d344..6a820ac 100644 --- a/gui/gui.c +++ b/gui/gui.c @@ -1,6 +1,6 @@ #include -#include +#include #include #include #include @@ -10,26 +10,34 @@ static void finish(int sig); +typedef struct _my_menu_ { + MENU *menu; + ITEM *items[5]; + WINDOW *win; +} MyMENU; + void editar_articulo(WINDOW *win, t_Articulo *articulo); +MyMENU *build_mymenu(WINDOW *win); +void free_mymenu(MyMENU *); + int main(int argc, char *argv[]) { /* initialize your non-curses data structures here */ + int c; WINDOW *mainwin; - t_Form *form; - t_LstArticulos *articulos; - t_Articulo *art; + MyMENU *menu; + if (argc != 2) { printf("Modo de uso : %s archivo_de_articulos.xml\n", argv[0]); return 1; } - articulos = art_cargar(argv[1]); - /* Inicio Curses */ signal(SIGINT, finish); /* arrange interrupts to terminate */ mainwin = initscr(); /* initialize the curses library */ + menu = build_mymenu(mainwin); /* Verifico un tamaño minimo de consola */ if ((LINES < 25) || (COLS < 80)) { @@ -61,31 +69,84 @@ int main(int argc, char *argv[]) /* Ventana, caracter para linea vertical, caracter para linea horizontal*/ box(mainwin, ACS_VLINE, ACS_HLINE); /* Ventana, Y, X, Texto */ - mvwaddstr(mainwin, 2, 10, "Ejemplo de Formulario"); - - /* Creo el formulario */ - form = form_crear(mainwin); - form_agregar_widget(form, INPUT, "Numero de Articulo", 8, ""); - - form_ejecutar(form, 10, 10); - - art = art_obtener(articulos, form_obtener_valor(form, "Numero de Articulo")); + mvwaddstr(mainwin, 1, 1, "EMUFS"); + attron(COLOR_PAIR(2)); + mvwaddstr(mainwin, LINES-2, 1, "Presiones para salir"); + attroff(COLOR_PAIR(2)); + wrefresh(mainwin); + + post_menu(menu->menu); + wrefresh(menu->win); + + refresh(); + while((c = getch()) != KEY_F(1)) { + switch(c) { + case KEY_DOWN: + menu_driver(menu->menu, REQ_DOWN_ITEM); + break; + case KEY_UP: + menu_driver(menu->menu, REQ_UP_ITEM); +// break; +// case 10: + /*ITEM *cur; + void (*p)(char *); + + cur = current_item(my_menu); + p = item_userptr(cur); + p((char *)item_name(cur)); + pos_menu_cursor(my_menu); + */ + } + wrefresh(menu->win); + } - if (art != NULL) { - editar_articulo(mainwin, art); - } - /* Libero el formulario */ - + unpost_menu(menu->menu); + free_mymenu(menu); delwin(mainwin); endwin(); - form_destruir(form); - art_liberar(articulos); - MD_Listar(); return 0; } +MyMENU *build_mymenu(WINDOW *win) +{ + WINDOW *menu_win; + MyMENU *tmp = (MyMENU *)malloc(sizeof(MyMENU)); + if (tmp == NULL) return NULL; + + tmp->items[0] = new_item("Artículos", "Alta,baja,consulta y modificación de artículos."); + tmp->items[1] = new_item("Facturas", "Alta,baja,consulta y modificación de facturas."); + tmp->items[2] = new_item("Ver Registros", "Ver registros de un archivo."); + tmp->items[3] = new_item("Ver Bloques", "Ver bloques de un archivo."); + tmp->items[4] = NULL; + + tmp->menu = new_menu(tmp->items); + + tmp->win = menu_win = derwin(win, 8, 68, 3, 1); + keypad(menu_win, TRUE); + set_menu_mark(tmp->menu, " > "); + set_menu_win(tmp->menu, menu_win); + set_menu_sub(tmp->menu, derwin(menu_win, 8, 68, 3, 1)); + + box(menu_win, 0, 0); + mvwaddch(menu_win, 2, 0, ACS_LTEE); + mvwhline(menu_win, 2, 1, ACS_HLINE, 68); + mvwaddch(menu_win, 2, 68, ACS_RTEE); + return tmp; +} + +void free_mymenu(MyMENU *menu) +{ + delwin(menu->win); + free_item(menu->items[0]); + free_item(menu->items[1]); + free_item(menu->items[2]); + free_item(menu->items[3]); + free_menu(menu->menu); + free(menu); +} + void editar_articulo(WINDOW *win, t_Articulo *articulo) { t_Form *form;