patch-2.1.110 linux/scripts/lxdialog/menubox.c
Next file: linux/CREDITS
Previous file: linux/scripts/lxdialog/Makefile
Back to the patch index
Back to the overall index
- Lines: 154
- Date:
Mon Jul 20 17:23:32 1998
- Orig file:
v2.1.109/linux/scripts/lxdialog/menubox.c
- Orig date:
Sat Apr 27 03:18:18 1996
diff -u --recursive --new-file v2.1.109/linux/scripts/lxdialog/menubox.c linux/scripts/lxdialog/menubox.c
@@ -19,6 +19,37 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+/*
+ * Changes by Clifford Wolf (god@clifford.at)
+ *
+ * [ 1998-06-13 ]
+ *
+ * *) A bugfix for the Page-Down problem
+ *
+ * *) Formerly when I used Page Down and Page Up, the cursor would be set
+ * to the first position in the menu box. Now lxdialog is a bit
+ * smarter and works more like other menu systems (just have a look at
+ * it).
+ *
+ * *) Formerly if I selected something my scrolling would be broken because
+ * lxdialog is re-invoked by the Menuconfig shell script, can't
+ * remember the last scrolling position, and just sets it so that the
+ * cursor is at the bottom of the box. Now it writes the temporary file
+ * lxdialog.scrltmp which contains this information. The file is
+ * deleted by lxdialog if the user leaves a submenu or enters a new
+ * one, but it would be nice if Menuconfig could make another "rm -f"
+ * just to be sure. Just try it out - you will recognise a difference!
+ *
+ * [ 1998-06-14 ]
+ *
+ * *) Now lxdialog is crash-safe against broken "lxdialog.scrltmp" files
+ * and menus change their size on the fly.
+ *
+ * *) If for some reason the last scrolling position is not saved by
+ * lxdialog, it sets the scrolling so that the selected item is in the
+ * middle of the menu box, not at the bottom.
+ */
+
#include "dialog.h"
static int menu_width, item_x;
@@ -123,6 +154,7 @@
int i, j, x, y, box_x, box_y;
int key = 0, button = 0, scroll = 0, choice = 0, first_item = 0, max_choice;
WINDOW *dialog, *menu;
+ FILE *f;
max_choice = MIN (menu_height, item_no);
@@ -178,9 +210,26 @@
item_x = (menu_width - item_x) / 2;
- if (choice >= max_choice){
- scroll = first_item = choice - max_choice + 1;
- choice = max_choice-1;
+ /* get the scroll info from the temp file */
+ if ( (f=fopen("lxdialog.scrltmp","r")) != NULL ) {
+ if ( (fscanf(f,"%d\n",&scroll) == 1) && (scroll <= choice) &&
+ (scroll+max_choice > choice) && (scroll >= 0) &&
+ (scroll+max_choice <= item_no) ) {
+ first_item = scroll;
+ choice = choice - scroll;
+ fclose(f);
+ } else {
+ remove("lxdialog.scrltmp");
+ fclose(f);
+ f=NULL;
+ }
+ }
+ if ( (choice >= max_choice) || (f==NULL && choice >= max_choice/2) ) {
+ if (choice >= item_no-max_choice/2)
+ scroll = first_item = item_no-max_choice;
+ else
+ scroll = first_item = choice - max_choice/2;
+ choice = choice - scroll;
}
/* Print the menu */
@@ -262,26 +311,34 @@
} else if (key == KEY_PPAGE) {
scrollok (menu, TRUE);
- for (i=0; (i < max_choice) && (scroll > 0); i++) {
- wscrl (menu, -1);
- scroll--;
- print_item (menu, items[scroll * 2 + 1], 0, FALSE,
- (items[scroll*2][0] != ':'));
+ for (i=0; (i < max_choice); i++) {
+ if (scroll > 0) {
+ wscrl (menu, -1);
+ scroll--;
+ print_item (menu, items[scroll * 2 + 1], 0, FALSE,
+ (items[scroll*2][0] != ':'));
+ } else {
+ if (choice > 0)
+ choice--;
+ }
}
scrollok (menu, FALSE);
- choice = 0;
} else if (key == KEY_NPAGE) {
- scrollok (menu, TRUE);
- for (i=0; (i < max_choice) && (scroll+max_choice < item_no); i++) {
- scroll(menu);
- scroll++;
- print_item (menu, items[(scroll+max_choice-1)*2+1],
- max_choice-1, FALSE,
- (items[(scroll+max_choice-1)*2][0] != ':'));
+ for (i=0; (i < max_choice); i++) {
+ if (scroll+max_choice < item_no) {
+ scrollok (menu, TRUE);
+ scroll(menu);
+ scrollok (menu, FALSE);
+ scroll++;
+ print_item (menu, items[(scroll+max_choice-1)*2+1],
+ max_choice-1, FALSE,
+ (items[(scroll+max_choice-1)*2][0] != ':'));
+ } else {
+ if (choice+1 < max_choice)
+ choice++;
+ }
}
- scrollok (menu, FALSE);
- choice = 0;
} else
choice = i;
@@ -313,6 +370,11 @@
case 'y':
case 'n':
case 'm':
+ /* save scroll info */
+ if ( (f=fopen("lxdialog.scrltmp","w")) != NULL ) {
+ fprintf(f,"%d\n",scroll);
+ fclose(f);
+ }
delwin (dialog);
fprintf(stderr, "%s\n", items[(scroll + choice) * 2]);
switch (key) {
@@ -336,6 +398,7 @@
else
fprintf(stderr, "%s\n", items[(scroll + choice) * 2]);
+ remove("lxdialog.scrltmp");
return button;
case 'e':
case 'x':
@@ -346,5 +409,6 @@
}
delwin (dialog);
+ remove("lxdialog.scrltmp");
return -1; /* ESC pressed */
}
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov