To: vim-dev@vim.org Subject: Patch 5.6.041 Fcc: outbox From: Bram Moolenaar ------------ Patch 5.6.041 Problem: GUI: Athena, Motif and GTK don't give more than 10 dialog buttons. Solution: Remove the limit on the number of buttons. Also support the 'v' flag in 'guioptions'. For GTK: Center the buttons. For Athena: Center the dialog when it's wider than the window. Files: src/gui_athena.c, src/gui_gtk.c, src/gui_motif.c *** ../vim-5.6.40/src/gui_athena.c Tue Jul 27 18:17:39 1999 --- src/gui_athena.c Thu Mar 30 13:43:14 2000 *************** *** 922,930 **** Widget dialog; Widget dialogshell; Widget dialogmessage; ! #define MAXBUT 10 ! Widget dialogButton[MAXBUT]; int butcount; if (title == NULL) title = (char_u *)"Vim dialog"; --- 922,931 ---- Widget dialog; Widget dialogshell; Widget dialogmessage; ! Widget dialogButton; ! Widget prev_dialogButton = NULL; int butcount; + int vertical; if (title == NULL) title = (char_u *)"Vim dialog"; *************** *** 933,938 **** --- 934,942 ---- /* if our pointer is currently hidden, then we should show it. */ gui_mch_mousehide(FALSE); + /* Check 'v' flag in 'guioptions': vertical button placement. */ + vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL); + /* The shell is created each time, to make sure it is resized properly */ dialogshell = XtVaCreatePopupShell("dialogShell", transientShellWidgetClass, vimShell, *************** *** 942,948 **** goto error; dialog = XtVaCreateManagedWidget("dialog", formWidgetClass, dialogshell, ! XtNdefaultDistance, 30, XtNforeground, gui.menu_fg_pixel, XtNbackground, gui.menu_bg_pixel, NULL); --- 946,952 ---- goto error; dialog = XtVaCreateManagedWidget("dialog", formWidgetClass, dialogshell, ! XtNdefaultDistance, 20, XtNforeground, gui.menu_fg_pixel, XtNbackground, gui.menu_bg_pixel, NULL); *************** *** 967,973 **** return -1; p = buts; ! for (butcount = 0; butcount < MAXBUT; ++butcount) { for (next = p; *next; ++next) { --- 971,977 ---- return -1; p = buts; ! for (butcount = 0; *p; ++butcount) { for (next = p; *next; ++next) { *************** *** 979,985 **** break; } } ! dialogButton[butcount] = XtVaCreateManagedWidget("button", commandWidgetClass, dialog, XtNlabel, p, XtNtop, XtChainBottom, --- 983,989 ---- break; } } ! dialogButton = XtVaCreateManagedWidget("button", commandWidgetClass, dialog, XtNlabel, p, XtNtop, XtChainBottom, *************** *** 987,1008 **** XtNleft, XtChainLeft, XtNright, XtChainLeft, XtNfromVert, dialogmessage, XtNforeground, gui.menu_fg_pixel, XtNbackground, gui.menu_bg_pixel, XtNresizable, False, NULL); if (butcount > 0) ! XtVaSetValues(dialogButton[butcount], ! XtNfromHoriz, dialogButton[butcount - 1], NULL); ! XtAddCallback(dialogButton[butcount], XtNcallback, ! butproc, (XtPointer)butcount); ! if (*next == NUL) ! break; p = next; } - ++butcount; vim_free(buts); XtRealizeWidget(dialogshell); --- 991,1010 ---- XtNleft, XtChainLeft, XtNright, XtChainLeft, XtNfromVert, dialogmessage, + XtNvertDistance, vertical ? 4 : 20, XtNforeground, gui.menu_fg_pixel, XtNbackground, gui.menu_bg_pixel, XtNresizable, False, NULL); if (butcount > 0) ! XtVaSetValues(dialogButton, ! vertical ? XtNfromVert : XtNfromHoriz, prev_dialogButton, NULL); ! XtAddCallback(dialogButton, XtNcallback, butproc, (XtPointer)butcount); p = next; + prev_dialogButton = dialogButton; } vim_free(buts); XtRealizeWidget(dialogshell); *************** *** 1019,1024 **** --- 1021,1030 ---- (Position)((wv - wd) / 2), (Position)((hv - hd) / 2), &x, &y); + if (x < 0) + x = 0; + if (y < 0) + y = 0; XtVaSetValues(dialogshell, XtNx, x, XtNy, y, NULL); app = XtWidgetToApplicationContext(dialogshell); *** ../vim-5.6.40/src/gui_gtk.c Sat Mar 25 21:22:33 2000 --- src/gui_gtk.c Thu Mar 30 15:58:59 2000 *************** *** 945,975 **** char_u * buttons, /* names of buttons */ int def_but) /* default button */ { ! char_u *names; ! char_u *p; ! int i; ! int butcount; ! int dialog_status = -1; ! ! GtkWidget *dialog; ! GtkWidget *frame; ! GtkWidget *vbox; ! GtkWidget *table; ! GtkWidget *pixmap; ! GtkWidget *dialogmessage; ! GtkWidget *action_area; ! GtkWidget *sub_area; ! GtkWidget *separator; ! GtkAccelGroup *accel_group; ! ! GdkPixmap *icon = NULL; ! GdkBitmap *mask = NULL; ! char **icon_data = NULL; ! ! #define MAXBUT 10 ! GtkWidget *button[MAXBUT]; ! ButtonData data[MAXBUT]; ! CancelData cancel_data; if (title == NULL) title = (char_u *) "Vim dialog..."; --- 945,975 ---- char_u * buttons, /* names of buttons */ int def_but) /* default button */ { ! char_u *names; ! char_u *p; ! int i; ! int butcount; ! int dialog_status = -1; ! int vertical; ! ! GtkWidget *dialog; ! GtkWidget *frame; ! GtkWidget *vbox; ! GtkWidget *table; ! GtkWidget *pixmap; ! GtkWidget *dialogmessage; ! GtkWidget *action_area; ! GtkWidget *sub_area; ! GtkWidget *separator; ! GtkAccelGroup *accel_group; ! ! GdkPixmap *icon = NULL; ! GdkBitmap *mask = NULL; ! char **icon_data = NULL; ! ! GtkWidget **button; ! ButtonData *data; ! CancelData cancel_data; if (title == NULL) title = (char_u *) "Vim dialog..."; *************** *** 977,982 **** --- 977,985 ---- if ((type < 0) || (type > VIM_LAST_TYPE)) type = VIM_GENERIC; + /* Check 'v' flag in 'guioptions': vertical button placement. */ + vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL); + /* if our pointer is currently hidden, then we should show it. */ gui_mch_mousehide(FALSE); *************** *** 1054,1062 **** gtk_box_pack_end(GTK_BOX(vbox), action_area, FALSE, TRUE, 0); gtk_widget_show(action_area); ! sub_area = gtk_hbox_new(TRUE, 0); gtk_container_set_border_width(GTK_CONTAINER(sub_area), 0); ! gtk_box_pack_start(GTK_BOX(action_area), sub_area, FALSE, TRUE, 0); gtk_widget_show(sub_area); /* --- 1057,1069 ---- gtk_box_pack_end(GTK_BOX(vbox), action_area, FALSE, TRUE, 0); gtk_widget_show(action_area); ! /* Add a [vh]box in the hbox to center the buttons in the dialog. */ ! if (vertical) ! sub_area = gtk_vbox_new(FALSE, 0); ! else ! sub_area = gtk_hbox_new(FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(sub_area), 0); ! gtk_box_pack_start(GTK_BOX(action_area), sub_area, TRUE, FALSE, 0); gtk_widget_show(sub_area); /* *************** *** 1092,1106 **** } *p = NUL; /* Attach the new accelerator group to the window. */ accel_group = gtk_accel_group_new(); gtk_accel_group_attach(accel_group, GTK_OBJECT(dialog)); p = names; ! for (butcount = 0; butcount < MAXBUT; ++butcount) { ! char_u *next; ! GtkWidget *label; ! guint accel_key; /* Chunk out this single button. */ for (next = p; *next; ++next) { --- 1099,1128 ---- } *p = NUL; + /* Count the number of buttons and allocate button[] and data[]. */ + butcount = 1; + for (p = names; *p; ++p) + if (*p == DLG_BUTTON_SEP) + ++butcount; + button = (GtkWidget **)alloc((unsigned)(butcount * sizeof(GtkWidget *))); + data = (ButtonData *)alloc((unsigned)(butcount * sizeof(ButtonData))); + if (button == NULL || data == NULL) + { + vim_free(names); + vim_free(button); + vim_free(data); + return -1; + } + /* Attach the new accelerator group to the window. */ accel_group = gtk_accel_group_new(); gtk_accel_group_attach(accel_group, GTK_OBJECT(dialog)); p = names; ! for (butcount = 0; *p; ++butcount) { ! char_u *next; ! GtkWidget *label; ! guint accel_key; /* Chunk out this single button. */ for (next = p; *next; ++next) { *************** *** 1139,1157 **** GTK_SIGNAL_FUNC(dlg_button_clicked), (gpointer) &data[butcount]); ! if (*next == NUL) { ! gtk_box_pack_end(GTK_BOX(action_area), button[butcount], ! FALSE, TRUE, 0); ! break; ! } else { ! gtk_box_pack_start(GTK_BOX(sub_area), button[butcount], ! TRUE, TRUE, 0); ! } p = next; } vim_free(names); --def_but; /* 1 is first button */ if (def_but < 0) def_but = 0; --- 1161,1174 ---- GTK_SIGNAL_FUNC(dlg_button_clicked), (gpointer) &data[butcount]); ! gtk_box_pack_start(GTK_BOX(sub_area), button[butcount], ! TRUE, FALSE, 0); p = next; } vim_free(names); + --butcount; --def_but; /* 1 is first button */ if (def_but < 0) def_but = 0; *************** *** 1177,1182 **** --- 1194,1202 ---- /* let the garbage collector know that we don't need it anylonger */ gtk_accel_group_unref(accel_group); + + vim_free(button); + vim_free(data); return dialog_status; } *** ../vim-5.6.40/src/gui_motif.c Mon Nov 29 20:06:45 1999 --- src/gui_motif.c Thu Mar 30 13:44:50 2000 *************** *** 1000,1007 **** int butcount; static Widget dialogbb = NULL; static Widget dialogmessage = NULL; ! #define MAXBUT 10 ! Widget dialogButton[MAXBUT]; if (title == NULL) title = (char_u *)"Vim dialog"; --- 996,1003 ---- int butcount; static Widget dialogbb = NULL; static Widget dialogmessage = NULL; ! Widget *dialogButton; ! int vertical; if (title == NULL) title = (char_u *)"Vim dialog"; *************** *** 1032,1037 **** --- 1028,1036 ---- NULL); XmStringFree(label); + /* Check 'v' flag in 'guioptions': vertical button placement. */ + vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL); + /* Set the title of the Dialog window */ label = XmStringCreateSimple((char *)title); if (label == NULL) *************** *** 1039,1045 **** XtVaSetValues(dialogbb, XmNdialogTitle, label, XmNhorizontalSpacing, 20, ! XmNverticalSpacing, 20, NULL); XmStringFree(label); --- 1038,1044 ---- XtVaSetValues(dialogbb, XmNdialogTitle, label, XmNhorizontalSpacing, 20, ! XmNverticalSpacing, vertical ? 0 : 20, NULL); XmStringFree(label); *************** *** 1048,1058 **** if (buts == NULL) return -1; /* * Create the buttons. */ p = buts; ! for (butcount = 0; butcount < MAXBUT; ++butcount) { for (next = p; *next; ++next) { --- 1047,1069 ---- if (buts == NULL) return -1; + /* Count the number of buttons and allocate dialogButton[]. */ + butcount = 1; + for (p = buts; *p; ++p) + if (*p == DLG_BUTTON_SEP) + ++butcount; + dialogButton = (Widget *)alloc((unsigned)(butcount * sizeof(Widget))); + if (dialogButton == NULL) + { + vim_free(buts); + return -1; + } + /* * Create the buttons. */ p = buts; ! for (butcount = 0; *p; ++butcount) { for (next = p; *next; ++next) { *************** *** 1075,1104 **** XmNtopWidget, dialogmessage, NULL); XmStringFree(label); ! if (butcount == 0) ! XtVaSetValues(dialogButton[butcount], ! XmNleftAttachment, XmATTACH_FORM, ! NULL); ! else ! XtVaSetValues(dialogButton[butcount], ! XmNleftAttachment, XmATTACH_WIDGET, ! XmNleftWidget, dialogButton[butcount - 1], ! NULL); XtAddCallback(dialogButton[butcount], XmNactivateCallback, butproc, (XtPointer)butcount); - if (*next == NUL) - break; p = next; } - ++butcount; vim_free(buts); if (dfltbutton < 1) dfltbutton = 1; if (dfltbutton > butcount) dfltbutton = butcount; ! XtVaSetValues(dialogbb, XmNdefaultButton, dialogButton[dfltbutton - 1], NULL); XtManageChild(dialogbb); app = XtWidgetToApplicationContext(dialogbb); --- 1086,1116 ---- XmNtopWidget, dialogmessage, NULL); XmStringFree(label); ! if (butcount) ! { ! if (vertical) ! XtVaSetValues(dialogButton[butcount], ! XmNtopWidget, dialogButton[butcount - 1], ! NULL); ! else ! XtVaSetValues(dialogButton[butcount], ! XmNleftAttachment, XmATTACH_WIDGET, ! XmNleftWidget, dialogButton[butcount - 1], ! NULL); ! } XtAddCallback(dialogButton[butcount], XmNactivateCallback, butproc, (XtPointer)butcount); p = next; } vim_free(buts); if (dfltbutton < 1) dfltbutton = 1; if (dfltbutton > butcount) dfltbutton = butcount; ! XtVaSetValues(dialogbb, ! XmNdefaultButton, dialogButton[dfltbutton - 1], NULL); XtManageChild(dialogbb); app = XtWidgetToApplicationContext(dialogbb); *************** *** 1121,1126 **** --- 1133,1140 ---- XtUnmanageChild(dialogButton[butcount]); XtDestroyWidget(dialogButton[butcount]); } + + vim_free(dialogButton); return dialogStatus; } *** ../vim-5.6.40/src/version.c Thu Mar 30 16:44:48 2000 --- src/version.c Thu Mar 30 16:40:27 2000 *************** *** 420,421 **** --- 420,423 ---- { /* Add new patch number below this line */ + /**/ + 41, /**/ -- Yesterday is history. Tomorrow is a mystery. Today is a gift. That's why it is called 'present'. /-/-- Bram Moolenaar --- Bram@moolenaar.net --- http://www.moolenaar.net --\-\ \-\-- Vim: http://www.vim.org ---- ICCF Holland: http://www.vim.org/iccf --/-/