############################################################################### # This patch adds support for GPM to linux-dialog (lxdialog) # making it possible to configure your kernel with the mouse # using 'make menuconfig' # # this patch also fixes a 'bug' in lxdialog. It will check # if the height and width parameters aren't out of range (instead # of segfaulting). # # To apply this patch, copy this file to /usr/src/linux/scripts/lxdialog # and then execute the folowing commands: # $ cd /usr/src/linux/scripts/lxdiaàîÿ¿&% log # $ patch < linux-2.x-lxdialog-GPM.patch # $ rm linux-2.x-lxdialog-GPM.patch # $ make clean # # Once that's finished, go back to /usr/src/linux and type 'make menuconfig' # Now you're mouse should work (at least if GPM is installed and running) # # Author: Andy Knuts (akke@shell.elite.be) # # diff -Nur lxdialog/Makefile lxdialog_gpm/Makefile --- lxdialog/Makefile Mon Apr 3 18:42:40 2000 +++ lxdialog_gpm/Makefile Mon Apr 3 18:41:17 2000 @@ -1,9 +1,9 @@ CC = $(HOSTCC) CPP = $(HOSTCC) -E -CFLAGS = $(HOSTCFLAGS) -DLOCALE +CFLAGS = $(HOSTCFLAGS) -DLOCALE `./ifgpm 1` LDFLAGS = -s -L . -LDLIBS = -lncurses +LDLIBS = -lncurses `./ifgpm 0` ifeq (/usr/include/ncurses/ncurses.h, $(wildcard /usr/include/ncurses/ncurses.h)) CFLAGS += -I/usr/include/ncurses -DCURSES_LOC="" @@ -19,13 +19,15 @@ endif endif - OBJS = checklist.o menubox.o textbox.o yesno.o inputbox.o \ - util.o lxdialog.o msgbox.o + util.o msgbox.o lxdialog.o SRCS = $(OBJS:.o=.c) -all: ncurses lxdialog +all: gpm ncurses lxdialog + +gpm: + chmod 700 ./ifgpm lxdialog: $(OBJS) diff -Nur lxdialog/checklist.c lxdialog_gpm/checklist.c --- lxdialog/checklist.c Mon Apr 3 18:42:40 2000 +++ lxdialog_gpm/checklist.c Mon Apr 3 18:41:17 2000 @@ -5,6 +5,9 @@ * Stuart Herbert - S.Herbert@sheffield.ac.uk: radiolist extension * Alessandro Rubini - rubini@ipvvis.unipv.it: merged the two * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) + * 04032000: Added GPM support: Andy Knuts (akke@shell.elite.be) + * 04032000: Added height and width checking on paramaters: Andy Knuts + * (akke@shell.elite.be) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,6 +25,10 @@ */ #include "dialog.h" +#ifdef GPM +#include +extern int mouse; +#endif static int list_width, check_x, item_x, checkflag; @@ àîÿ¿&% -108,6 +115,21 @@ wrefresh (dialog); } +#ifdef GPM +/* + * Display the page buttons. + */ +static void +print_page_buttons(WINDOW *page, int celbutton, int height) +{ + wattrset(page, (celbutton==0)?tag_selected_attr:tag_attr); + mvwprintw(page,0,0,"+"); + wattrset(page, (celbutton==1)?tag_selected_attr:tag_attr); + mvwprintw(page, height-1,0,"+"); + wnoutrefresh (page); +} +#endif + /* * Display a dialog box with a list of options that can be turned on or off * The `flag' parameter is used to select between radiolist and checklist. @@ -117,10 +139,69 @@ int list_height, int item_no, const char * const * items, int flag) { - int i, x, y, box_x, box_y; + int i, x=(COLS - width) / 2, y=(LINES - height) / 2, box_x, box_y; int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status; WINDOW *dialog, *list; - +#ifdef GPM + WINDOW *page; + int bttnxstart, bttny, gpmchoice; + int gpmhandler(Gpm_Event *ePtr,àîÿ¿&% void *clientdata) { + if (ePtr->type&GPM_DOWN) { + if (!strcmp((char *)clientdata,"SELECT")) return '\n'; + else if (!strcmp((char *)clientdata,"HELP")) return '?'; + else if (!strcmp((char *)clientdata,"LIST")) { + print_item (list, items[(scroll + choice) * 3 + 1], + status[scroll + choice], choice, FALSE); + choice = MIN((ePtr->y - box_y + 1), max_choice-1); + if (choice < 0) choice=0; + print_item (list, items[(scroll + choice) * 3 + 1], + status[scroll + choice], choice, TRUE); + wnoutrefresh (list); + wrefresh(dialog); + } else if (!strcmp((char *)clientdata,"PAGEUP")) return KEY_UP; + else if (!strcmp((char *)clientdata,"PAGEDOWN")) return KEY_DOWN; + } else + if (ePtr->type&GPM_ENTER) { + if (!strcmp((char *)clientdata,"SELECT")) { + button=0; + print_buttons(dialog, height, width, button); + wrefresh (dialog); + } else + if (!strcmp((char *)clientdata,"HELP")) { + button=1; + print_buttons(dialog, height, width, button); + wrefreshàîÿ¿&% (dialog); + } else + if (!strcmp((char *)clientdata,"PAGEUP")) { + print_page_buttons(page, 0, list_height); + wrefresh(dialog); + } else + if (!strcmp((char *)clientdata,"PAGEDOWN")) { + print_page_buttons(page, 1, list_height); + wrefresh(dialog); + } + } else + if (ePtr->type==GPM_MOVE) { + /* only triggerd when mouse moves over list area */ + if (gpmchoice < 0 || gpmchoice > max_choice - 1) gpmchoice=0; + print_item (list, items[(scroll + gpmchoice) * 3 + 1], + status[scroll + gpmchoice], gpmchoice, (gpmchoice==choice)?TRUE:FALSE); + gpmchoice = MIN((ePtr->y - box_y + 1), max_choice-1); + wattrset (list, menubox_attr); + mvwaddch(list, gpmchoice, item_x-5, '*'); + wnoutrefresh (list); + wrefresh(dialog); + } + return 0; + } + if (mouse) { + bttnxstart=x+(width / 2 - 11); + bttny=y+(height - 2); + Gpm_PushRoi(bttnxstart,bttny,bttnxstart+7,bttny,GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, "SELECT"); + Gpm_PushRoi(bàîÿ¿&% ttnxstart+14,bttny,bttnxstart+14+7,bttny,GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, "HELP"); + Gpm_PushRoi(x+3,y+2,x+width-6,y+height-5,GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE|GPM_MOVE, gpmhandler, "LIST"); + } +#endif checkflag = flag; /* Allocate space for storing item on/off status */ @@ -140,10 +221,6 @@ max_choice = MIN (list_height, item_no); - /* center dialog box on screen */ - x = (COLS - width) / 2; - y = (LINES - height) / 2; - draw_shadow (stdscr, y, x, height, width); dialog = newwin (height, width, y, x); @@ -178,10 +255,19 @@ list_width = width - 6; box_y = height - list_height - 5; box_x = (width - list_width) / 2 - 1; - +#ifdef GPM + if (mouse) { + /* create small window for gpm -pageup and -pagedown */ + page = subwin (dialog, list_height, 1, y + box_y + 1, x + box_x + list_width); + Gpm_PushRoi(x + box_x + list_width - 1, y + box_y + 1, x + box_x + list_width + 1, y + box_y + 1, GPM_DOWN|Gàîÿ¿&% PM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, "PAGEUP"); + Gpm_PushRoi(x + box_x + list_width - 1, y + box_y + list_height, x + box_x + list_width + 1, y + box_y + list_height, GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, "PAGEDOWN"); + /* create new window for the list */ + list = subwin (dialog, list_height, list_width-2, y+box_y+1, x+box_x+1); + } else list = subwin (dialog, list_height, list_width, y+box_y+1, x+box_x+1); +#else /* create new window for the list */ list = subwin (dialog, list_height, list_width, y+box_y+1, x+box_x+1); - +#endif keypad (list, TRUE); /* draw a box around the list items */ @@ -207,6 +293,10 @@ status[i+scroll], i, i == choice); } +#ifdef GPM + if (mouse) print_page_buttons(page, -1, list_height); +#endif + wnoutrefresh (list); print_arrows(dialog, choice, item_no, scroll, @@ -215,15 +305,21 @@ print_buttons(dialog, height, width, 0); while (key != ESC) { +#ifdef GPM + if (mouse) + key = Gpm_Wàîÿ¿&% getch(dialog); + else + key = wgetch (dialog); +#else key = wgetch (dialog); - +#endif for (i = 0; i < max_choice; i++) if (toupper(key) == toupper(items[(scroll+i)*3+1][0])) break; if ( i < max_choice || key == KEY_UP || key == KEY_DOWN || - key == '+' || key == '-' ) { + key == '+' || key == '-') { if (key == KEY_UP || key == '-') { if (!choice) { if (!scroll) diff -Nur lxdialog/dialog.h lxdialog_gpm/dialog.h --- lxdialog/dialog.h Mon Apr 3 18:42:40 2000 +++ lxdialog_gpm/dialog.h Mon Apr 3 18:41:17 2000 @@ -3,6 +3,7 @@ * dialog.h -- common declarations for all dialog modules * * AUTHOR: Savio Lam (lam836@cs.cuhk.hk) + * 04032000: Added GPM support: Andy Knuts (akke@shell.elite.be) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -137,7 +138,12 @@ extern void create_rc (const char *filename); extern int parse_rc (vàîÿ¿&% oid); +#ifdef GPM +int init_gpm(int visible); +#endif +int checkheight (int height); +int checkwidth (int width); void init_dialog (void); void end_dialog (void); void attr_clear (WINDOW * win, int height, int width, chtype attr); diff -Nur lxdialog/ifgpm lxdialog_gpm/ifgpm --- lxdialog/ifgpm Thu Jan 1 01:00:00 1970 +++ lxdialog_gpm/ifgpm Mon Apr 3 18:41:17 2000 @@ -0,0 +1,14 @@ +# +# Check for GPM (gpm.h) +# (for lxdialog - GPM support) +# author: Andy Knuts (akke@shell.elite.be) +# +#!/bin/sh +x=`find /usr/include/ /usr/local/include -maxdepth 1 -name 'gpm.h'` +if [ "$$x" ]; then + if [ "$1" == "0" ]; then + echo "-lgpm" + else + echo "-DGPM" + fi +fi \ No newline at end of file diff -Nur lxdialog/inputbox.c lxdialog_gpm/inputbox.c --- lxdialog/inputbox.c Mon Apr 3 18:42:40 2000 +++ lxdialog_gpm/inputbox.c Mon Apr 3 18:41:17 2000 @@ -3,6 +3,9 @@ * * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfwàîÿ¿&% com) + * 04032000: Added GPM support: Andy Knuts (akke@shell.elite.be) + * 04032000: Added height and width checking on paramaters: Andy Knuts + * (akke@shell.elite.be) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -20,6 +23,10 @@ */ #include "dialog.h" +#ifdef GPM +#include +extern int mouse; +#endif unsigned char dialog_input_result[MAX_LEN + 1]; @@ -46,15 +53,39 @@ dialog_inputbox (const char *title, const char *prompt, int height, int width, const char *init) { - int i, x, y, box_y, box_x, box_width; + int i, x=(COLS - width) / 2, y=(LINES - height) / 2, box_y, box_x, box_width; int input_x = 0, scroll = 0, key = 0, button = -1; unsigned char *instr = dialog_input_result; WINDOW *dialog; - - /* center dialog box on screen */ - x = (COLS - width) / 2; - y = (LINES - height) / 2; - +#ifdef GPM + àîÿ¿&% int bttnxstart, bttny; + int gpmhandler(Gpm_Event *ePtr, void *clientdata) { + if (ePtr->type&GPM_DOWN) { + if (!strcmp((char *)clientdata,"OK")) return 'O'; + else if (!strcmp((char *)clientdata,"HELP")) return '?'; + else if (!strcmp((char *)clientdata,"IFIELD")) { + button=1; + return TAB; + }; + } else + if (ePtr->type&GPM_ENTER) { + if (strcmp((char *)clientdata,"IFIELD")) { + if (!strcmp((char *)clientdata,"OK")) button=0; + else button=1; + print_buttons(dialog, height, width, button); + wrefresh (dialog); + } + } + return 0; + } + if (mouse) { + bttnxstart=x+(width / 2 - 11); + bttny=y+(height - 2); + Gpm_PushRoi(bttnxstart,bttny,bttnxstart+6,bttny,GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, "OK"); + Gpm_PushRoi(bttnxstart+13,bttny,bttnxstart+13+7,bttny,GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, "HELP"); + Gpm_PushRoi(x+2, y+3, x+width-3, y+3, GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, "IFIELD"); + } +#endif draw_shadow (àîÿ¿&% stdscr, y, x, height, width); @@ -121,8 +152,14 @@ wrefresh (dialog); while (key != ESC) { - key = wgetch (dialog); - +#ifdef GPM + if (mouse) + key = Gpm_Wgetch(dialog); + else + key = wgetch (dialog); +#else + key = wgetch (dialog); +#endif if (button == -1) { /* Input box selected */ switch (key) { case TAB: diff -Nur lxdialog/lxdialog.c lxdialog_gpm/lxdialog.c --- lxdialog/lxdialog.c Mon Apr 3 18:42:40 2000 +++ lxdialog_gpm/lxdialog.c Mon Apr 3 18:41:17 2000 @@ -3,6 +3,9 @@ * * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) + * 04032000: Added GPM support: Andy Knuts (akke@shell.elite.be) + * 04032000: Added height and width checking on paramaters: Andy Knuts + * (akke@shell.elite.be) * * This program is free software; you can redistribute it and/or * modify it under the tàîÿ¿&% erms of the GNU General Public License @@ -21,6 +24,11 @@ #include "dialog.h" +#ifdef GPM +#include +int mouse=0; +#endif + static void Usage (const char *name); typedef int (jumperFn) (const char *title, int argc, const char * const * argv); @@ -53,6 +61,35 @@ #include #endif +#ifdef GPM +int +init_gpm(int visible) { + char *s, t[4]; + int vc; + Gpm_Connect conn; + s=ttyname(fileno(stdin)); + gpm_zerobased=1; + conn.eventMask=~0; + conn.defaultMask=GPM_MOVE|GPM_HARD; + conn.maxMod=~0; + conn.minMod=0; + gpm_visiblepointer=visible; + if (sscanf(s,"/dev/tty%d%s",&vc,t)==1) + if (Gpm_Open(&conn,0) != -1) return 1; + return 0; +} +#endif + +int checkheight (int height) { + if (height <= 0 || height > LINES) return 0; + else return 1; +} + +int checkwidth (int width) { + if (width <= 0 || width > COLS) return 0; + else return 1; +} + int main (int argc, const char * const * argv) { @@ -125,6 +162,9 @@ iàîÿ¿&% nit_dialog (); +#ifdef GPM + if (init_gpm(1)) mouse=1; +#endif retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset); if (clear_screen) { /* clear screen before exit */ @@ -133,6 +173,11 @@ } end_dialog(); + if (retval == -5) { + fprintf (stderr, "Incorrect HEIGHT or WIDTH value !\n"); + Usage(argv[0]); + } + exit (retval); } @@ -161,6 +206,7 @@ \n --textbox \ \n --inputbox []\ \n --yesno \ +\n --msgbox \ \n", name, name); exit (-1); } @@ -172,55 +218,74 @@ int j_menu (const char *t, int ac, const char * const * av) { - return dialog_menu (t, av[2], atoi (av[3]), atoi (av[4]), - atoi (av[5]), av[6], (ac - 6) / 2, av + 7); + if (checkheight(atoi(av[3]) && checkwidth(atoi(av[4])) && + checkheight(atoi(av[5])))) + return dialog_menu (t, av[2], atoi (av[3]), atoi (av[4]), + atoi (av[5]), av[6],àîÿ¿&% (ac - 6) / 2, av + 7); + else return -5; } int j_checklist (const char *t, int ac, const char * const * av) { - return dialog_checklist (t, av[2], atoi (av[3]), atoi (av[4]), - atoi (av[5]), (ac - 6) / 3, av + 6, FLAG_CHECK); + if (checkheight(atoi(av[3]) && checkwidth(atoi(av[4])) && + checkheight(atoi(av[5])))) + return dialog_checklist (t, av[2], atoi (av[3]), atoi (av[4]), + atoi (av[5]), (ac - 6) / 3, av + 6, FLAG_CHECK); + else return -5; } int j_radiolist (const char *t, int ac, const char * const * av) { - return dialog_checklist (t, av[2], atoi (av[3]), atoi (av[4]), - atoi (av[5]), (ac - 6) / 3, av + 6, FLAG_RADIO); + if (checkheight(atoi(av[3]) && checkwidth(atoi(av[4])) && + checkheight(atoi(av[5])))) + return dialog_checklist (t, av[2], atoi (av[3]), atoi (av[4]), + atoi (av[5]), (ac - 6) / 3, av + 6, FLAG_RADIO); + else return -5; } int j_textbox (const char *t, int ac, const char * const * av) { - return àîÿ¿&% dialog_textbox (t, av[2], atoi (av[3]), atoi (av[4])); + if (checkheight(atoi(av[3])) && checkwidth(atoi(av[4]))) + return dialog_textbox (t, av[2], atoi (av[3]), atoi (av[4])); + else return -5; } int j_yesno (const char *t, int ac, const char * const * av) { - return dialog_yesno (t, av[2], atoi (av[3]), atoi (av[4])); + if (checkheight(atoi(av[3])) && checkwidth(atoi(av[4]))) + return dialog_yesno (t, av[2], atoi (av[3]), atoi (av[4])); + else return -5; } int j_inputbox (const char *t, int ac, const char * const * av) { - int ret = dialog_inputbox (t, av[2], atoi (av[3]), atoi (av[4]), + if (checkheight(atoi(av[3])) && checkwidth(atoi(av[4]))) { + int ret = dialog_inputbox (t, av[2], atoi (av[3]), atoi (av[4]), ac == 6 ? av[5] : (char *) NULL); - if (ret == 0) - fprintf(stderr, dialog_input_result); - return ret; + if (ret == 0) + fprintf(stderr, dialog_input_result); + return retàîÿ¿&% ; + } else return -5; } int j_msgbox (const char *t, int ac, const char * const * av) { - return dialog_msgbox (t, av[2], atoi (av[3]), atoi (av[4]), 1); + if (checkheight(atoi(av[3])) && checkwidth(atoi(av[4]))) + return dialog_msgbox (t, av[2], atoi (av[3]), atoi (av[4]), 1); + else return -5; } int j_infobox (const char *t, int ac, const char * const * av) { - return dialog_msgbox (t, av[2], atoi (av[3]), atoi (av[4]), 0); + if (checkheight(atoi(av[3])) && checkwidth(atoi(av[4]))) + return dialog_msgbox (t, av[2], atoi (av[3]), atoi (av[4]), 0); + else return -5; } diff -Nur lxdialog/menubox.c lxdialog_gpm/menubox.c --- lxdialog/menubox.c Mon Apr 3 18:42:40 2000 +++ lxdialog_gpm/menubox.c Mon Apr 3 18:41:17 2000 @@ -3,6 +3,9 @@ * * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcapw@cfw.com) + * 04032000: Added GPM support: Andy Knuts (akke@shell.elite.be) + * 04032000àîÿ¿&% : Added height and width checking on paramaters: Andy Knuts + * (akke@shell.elite.be) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -57,6 +60,10 @@ */ #include "dialog.h" +#ifdef GPM +#include +extern int mouse; +#endif static int menu_width, item_x; @@ -155,6 +162,21 @@ wrefresh (win); } +#ifdef GPM +/* + * Display the page buttons. + */ +static void +print_page_buttons(WINDOW *page, int celbutton, int height) +{ + wattrset(page, (celbutton==0)?tag_selected_attr:tag_attr); + mvwprintw(page,0,0,"+"); + wattrset(page, (celbutton==1)?tag_selected_attr:tag_attr); + mvwprintw(page, height-1,0,"+"); + wnoutrefresh (page); +} +#endif + /* * Display a menu for choosing among a number of options */ @@ -164,17 +186,78 @@ const char * const * items) { - int i, j, x, y, box_x, box_y; + + àîÿ¿&% int i, j, x=(COLS - width) / 2, y=(LINES - height) / 2, box_x, box_y; int key = 0, button = 0, scroll = 0, choice = 0, first_item = 0, max_choice; WINDOW *dialog, *menu; FILE *f; - +#ifdef GPM + WINDOW *page; + int bttnxstart, bttny, gpmchoice=0; + int gpmhandler(Gpm_Event *ePtr, void *clientdata) { + if (ePtr->type&GPM_DOWN) { + if (!strcmp((char *)clientdata,"SELECT")) return '\n'; + else if (!strcmp((char *)clientdata,"EXIT")) return ESC; + else if (!strcmp((char *)clientdata,"HELP")) return '?'; + else if (!strcmp((char *)clientdata,"MENU")) { + print_item (menu, items[(scroll+choice)*2+1], choice, FALSE, + (items[(scroll+choice)*2][0] != ':')); + choice = MIN((ePtr->y - box_y + 1), max_choice-1); + if (choice < 0) choice=0; + wattrset (menu, menubox_attr); + print_item (menu, items[(scroll+choice)*2+1], choice, TRUE, + (items[(scroll+choice)*2][0] != ':')); + wnoutrefresh (menu); + wrefresh(dialog); + return ' '; + } else if (!stràîÿ¿&% cmp((char *)clientdata,"PAGEUP")) return KEY_PPAGE; + else if (!strcmp((char *)clientdata,"PAGEDOWN")) return KEY_NPAGE; + } else + if (ePtr->type&GPM_ENTER) { + if (!strcmp((char *)clientdata,"SELECT")) { + button=0; + print_buttons(dialog, height, width, button); + wrefresh (dialog); + } else if (!strcmp((char *)clientdata,"EXIT")) { + button=1; + print_buttons(dialog, height, width, button); + wrefresh (dialog); + } else if (!strcmp((char *)clientdata,"HELP")) { + button=2; + print_buttons(dialog, height, width, button); + wrefresh (dialog); + } else if (!strcmp((char *)clientdata,"PAGEUP")) { + print_page_buttons(page, 0, menu_height); + wrefresh(dialog); + } else if (!strcmp((char *)clientdata,"PAGEDOWN")) { + print_page_buttons(page, 1, menu_height); + wrefresh(dialog); + } + } else + if (ePtr->type==GPM_MOVE) { + /* only triggerd when mouse moves over menu area */ + print_item (menu, items[(scroll+gpmchoice)*2+1], gpmchoice, (choice==gpmchoiceàîÿ¿&% )?TRUE:FALSE, + (items[(scroll+gpmchoice)*2][0] != ':')); + gpmchoice = MIN((ePtr->y - box_y + 1), max_choice-1); + if (gpmchoice < 0) gpmchoice=0; + wattrset (menu, menubox_attr); + mvwaddch(menu, gpmchoice, item_x-1, '*'); + wnoutrefresh (menu); + wrefresh(dialog); + } + return 0; + } + if (mouse) { + bttnxstart=x+(width / 2 - 16); + bttny=y+(height - 2); + Gpm_PushRoi(bttnxstart,bttny,bttnxstart+7,bttny,GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, "SELECT"); + Gpm_PushRoi(bttnxstart+12,bttny,bttnxstart+12+7,bttny,GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, "EXIT"); + Gpm_PushRoi(bttnxstart+24,bttny,bttnxstart+24+7,bttny,GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, "HELP"); + Gpm_PushRoi(x+3,y+2,x+width-6,y+height-5,GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE|GPM_MOVE, gpmhandler, "MENU"); + } +#endif max_choice = MIN (menu_height, item_no); - /* center dialog box on screen */ - x = (COLS - width) / 2; - y = (LINES - height) / 2; - draw_shadàîÿ¿&% ow (stdscr, y, x, height, width); dialog = newwin (height, width, y, x); @@ -208,12 +291,28 @@ print_autowrap (dialog, prompt, width - 2, 1, 3); menu_width = width - 6; + box_y = height - menu_height - 5; + + box_x = (width - menu_width) / 2 - 3; box_x = (width - menu_width) / 2 - 1; +#ifdef GPM + if (mouse) { /* create small window for gpm -pageup and -pagedown */ + page = subwin (dialog, menu_height, 1, y + box_y + 1, x + box_x + menu_width); + Gpm_PushRoi(x + box_x + menu_width - 1, y + box_y + 1, x + box_x + menu_width + 1, y + box_y + 1,GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, "PAGEUP"); + Gpm_PushRoi(x + box_x + menu_width - 1, y + box_y + menu_height, x + box_x + menu_width + 1, y + box_y + menu_height, GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, "PAGEDOWN"); + /* create new window for the menu */ + menu = subwin (dialog, menu_height, menu_width - 2, + y + box_y + 1, x + box_x + 1); + } else menu = subwin (diaàîÿ¿&% log, menu_height, menu_width, + y + box_y + 1, x + box_x + 1); +#else /* create new window for the menu */ menu = subwin (dialog, menu_height, menu_width, y + box_y + 1, x + box_x + 1); +#endif + keypad (menu, TRUE); /* draw a box around the menu items */ @@ -261,16 +360,25 @@ (items[(first_item + i)*2][0] != ':')); } +#ifdef GPM + if (mouse) print_page_buttons(page, -1, menu_height); +#endif + wnoutrefresh (menu); print_arrows(dialog, item_no, scroll, box_y, box_x+item_x+1, menu_height); print_buttons (dialog, height, width, 0); - while (key != ESC) { - key = wgetch(dialog); - +#ifdef GPM + if (mouse) + key = Gpm_Wgetch(dialog); + else + key = wgetch (dialog); +#else + key = wgetch (dialog); +#endif if (key < 256 && isalpha(key)) key = tolower(key); if (strchr("ynm", key)) @@ -334,7 +442,7 @@ } else if (key == KEY_PPAGE) { scrollok (menu, TRUE); - àîÿ¿&% for (i=0; (i < max_choice); i++) { + for (i=0; (i < max_choice); i++) { if (scroll > 0) { wscrl (menu, -1); scroll--; @@ -373,6 +481,9 @@ box_y, box_x+item_x+1, menu_height); wnoutrefresh (menu); +#ifdef GPM + if (mouse) wnoutrefresh (page); +#endif wrefresh (dialog); continue; /* wait for another key press */ @@ -423,8 +534,8 @@ remove("lxdialog.scrltmp"); return button; - case 'e': case 'x': + case 'e': key = ESC; case ESC: break; diff -Nur lxdialog/msgbox.c lxdialog_gpm/msgbox.c --- lxdialog/msgbox.c Mon Apr 3 18:42:40 2000 +++ lxdialog_gpm/msgbox.c Mon Apr 3 18:41:17 2000 @@ -3,6 +3,9 @@ * * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcapw@cfw.com) + * 04032000: Added GPM support: Andy Knuts (akke@shell.elite.be) + * 04032000: Added heighàîÿ¿&% t and width checking on paramaters: Andy Knuts + * (akke@shell.elite.be) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -20,6 +23,10 @@ */ #include "dialog.h" +#ifdef GPM +#include +extern int mouse; +#endif /* * Display a message box. Program will pause and display an "OK" button @@ -29,12 +36,20 @@ dialog_msgbox (const char *title, const char *prompt, int height, int width, int pause) { - int i, x, y, key = 0; + int i, x=(COLS - width) / 2, y=(LINES - height) / 2, key = 0; WINDOW *dialog; - - /* center dialog box on screen */ - x = (COLS - width) / 2; - y = (LINES - height) / 2; +#ifdef GPM + int bttnx, bttny; + int gpmhandler(Gpm_Event *ePtr, void *clientdata) { + if (ePtr->type&GPM_DOWN) return '\n'; + return 0; + } + if (mouse) { + bttnx=x+(width / 2 - 4); + bttny=y+(height - 2); + Gpm_PushRoi(btàîÿ¿&% tnx,bttny,bttnx+7,bttny,GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, NULL); + } +#endif draw_shadow (stdscr, y, x, height, width); @@ -74,7 +89,15 @@ wrefresh (dialog); while (key != ESC && key != '\n' && key != ' ' && key != 'O' && key != 'o' && key != 'X' && key != 'x') - key = wgetch (dialog); +#ifdef GPM + if (mouse) + key = Gpm_Wgetch(dialog); + else + key = wgetch (dialog); +#else + key = wgetch (dialog); +#endif + } else { key = '\n'; wrefresh (dialog); diff -Nur lxdialog/textbox.c lxdialog_gpm/textbox.c --- lxdialog/textbox.c Mon Apr 3 18:42:40 2000 +++ lxdialog_gpm/textbox.c Mon Apr 3 18:41:17 2000 @@ -3,6 +3,9 @@ * * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) + * 04032000: Added GPM support: Andy Knuts (akke@shell.elite.be) + * 04032000: Added height and width checking on paramaters: Andy Knuts + * àîÿ¿&% (akke@shell.elite.be) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -20,6 +23,10 @@ */ #include "dialog.h" +#ifdef GPM +#include +extern int mouse; +#endif static void back_lines (int n); static void print_page (WINDOW * win, int height, int width); @@ -37,11 +44,37 @@ int dialog_textbox (const char *title, const char *file, int height, int width) { - int i, x, y, cur_x, cur_y, fpos, key = 0; + int i, x=(COLS - width) / 2, y=(LINES - height) / 2, cur_x, cur_y, fpos, key = 0; int passed_end; char search_term[MAX_LEN + 1]; WINDOW *dialog, *text; +#ifdef GPM + int bttnx, bttny; + int gpmhandler(Gpm_Event *ePtr, void *clientdata) { + if (!strcmp((char *)clientdata,"Exit")) { + if (ePtr->type&GPM_DOWN) { + return '\n'; + } + } else { + if (ePtr->type&GPM_DOWN) { + if (ePtr->buttons&GPM_B_LEFT) { + return KEY_NPAGE; + } else { + return àîÿ¿&% KEY_PPAGE; + } + } + } + return 0; + } + if (mouse) { + bttnx=x+width / 2 - 4; + bttny=y+height - 2; + Gpm_PushRoi(bttnx, bttny, bttnx+8, bttny, GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE ,gpmhandler, "Exit"); + Gpm_PushRoi(x+1,y+1,width,height-2, GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE ,gpmhandler, "Text"); + } +#endif + search_term[0] = '\0'; /* no search term entered yet */ /* Open input file for reading */ @@ -78,21 +111,16 @@ buf[bytes_read] = '\0'; /* mark end of valid data */ page = buf; /* page is pointer to start of page to be displayed */ - /* center dialog box on screen */ - x = (COLS - width) / 2; - y = (LINES - height) / 2; - - draw_shadow (stdscr, y, x, height, width); dialog = newwin (height, width, y, x); keypad (dialog, TRUE); /* Create window for text region, used for scrolling text */ - text = subwin (dialog, height - 4, width - 2, y + 1, x + 1); + text = subwin (dialog, heigàîÿ¿&% ht - 4, width - 4, y + 1, x + 1); + wattrset (text, dialog_attr); wbkgdset (text, dialog_attr & A_COLOR); - keypad (text, TRUE); /* register the new window, along with its borders */ @@ -132,7 +160,14 @@ wrefresh (dialog); while ((key != ESC) && (key != '\n')) { +#ifdef GPM + if (mouse) + key = Gpm_Wgetch(dialog); + else + key = wgetch (dialog); +#else key = wgetch (dialog); +#endif switch (key) { case 'E': /* Exit */ case 'e': diff -Nur lxdialog/util.c lxdialog_gpm/util.c --- lxdialog/util.c Mon Apr 3 18:42:40 2000 +++ lxdialog_gpm/util.c Mon Apr 3 18:41:17 2000 @@ -3,6 +3,9 @@ * * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) + * 04032000: Added GPM support: Andy Knuts (akke@shell.elite.be) + * 04032000: Added height and width checking on paramaters: Andy Knuts + * (akke@shell.elite.be) * * This program is freàîÿ¿&% e software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -357,3 +360,4 @@ return 0; } + diff -Nur lxdialog/yesno.c lxdialog_gpm/yesno.c --- lxdialog/yesno.c Mon Apr 3 18:42:40 2000 +++ lxdialog_gpm/yesno.c Mon Apr 3 18:41:17 2000 @@ -3,6 +3,9 @@ * * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) + * 04032000: Added GPM support: Andy Knuts (akke@shell.elite.be) + * 04032000: Added height and width checking on paramaters: Andy Knuts + * (akke@shell.elite.be) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -20,6 +23,10 @@ */ #include "dialog.h" +#ifdef GPM +#include +extern int mouse; +#endif /* * Display termination buttons @@ -43,12 +50,31 @@ int dialog_yesno (const char *title, const char *prompàîÿ¿&% t, int height, int width) { - int i, x, y, key = 0, button = 0; + int i, x = (COLS - width) / 2, y = (LINES - height) / 2, key = 0, button = 0; WINDOW *dialog; - /* center dialog box on screen */ - x = (COLS - width) / 2; - y = (LINES - height) / 2; +#ifdef GPM + int bttnxstart, bttny; + int gpmhandler(Gpm_Event *ePtr, void *clientdata) { + if (ePtr->type&GPM_DOWN) { + if (!strcmp((char *)clientdata,"YES")) return 'Y'; + else return 'N'; + } else + if (ePtr->type&GPM_ENTER) { + if (!strcmp((char *)clientdata,"YES")) button=0; + else button=1; + print_buttons(dialog, height, width, button); + wrefresh (dialog); + } + return 0; + } + if (mouse) { + bttnxstart=x+(width/2-10); + bttny=(y+(height-2)); + Gpm_PushRoi(bttnxstart,bttny,bttnxstart+6,bttny,GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, "YES"); + Gpm_PushRoi(bttnxstart+13,bttny,bttnxstart+13+7,bttny,GPM_DOWN|GPM_UP|GPM_ENTER|GPM_LEAVE, gpmhandler, "NO"); + } +#endif draw_shadowàîÿ¿&% (stdscr, y, x, height, width); @@ -83,8 +109,16 @@ print_buttons(dialog, height, width, 0); + while (key != ESC) { +#ifdef GPM + if (mouse) + key = Gpm_Wgetch(dialog); + else + key = wgetch (dialog); +#else key = wgetch (dialog); +#endif switch (key) { case 'Y': case 'y':