OSDN Git Service

upgrade to 3.6.1
[jnethack/source.git] / win / X11 / dialogs.c
index 6ffe08a..b72ea9a 100644 (file)
@@ -1,25 +1,24 @@
 /*
  * Copyright 1991 University of Wisconsin-Madison
  *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
  * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of the University of Wisconsin-Madison not
- * be used in advertising or publicity pertaining to distribution of the
+ * documentation, and that the name of the University of Wisconsin-Madison
+ * not be used in advertising or publicity pertaining to distribution of the
  * software without specific, written prior permission.  The University of
  * Wisconsin-Madison makes no representations about the suitability of this
  * software for any purpose.  It is provided "as is" without express or
  * implied warranty.
  *
- * THE UNIVERSITY OF WISCONSIN-MADISON DISCLAIMS ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * THE UNIVERSITY OF WISCONSIN-MADISON DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  * FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF WISCONSIN-MADISON BE LIABLE
- *FOR
- * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
- * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
  * Author:  Tim Theisen             Department of Computer Sciences
  *          tim@cs.wisc.edu         University of Wisconsin-Madison
  *
  *    + Make the cancel button optional.
  *    + Put an #ifdef SPECIAL_CMAP around code to fix a colormap bug.
- *     We don't need it here.
+ *      We don't need it here.
  *    + Add the function positionpopup() from another part of ghostview
- *     to this code.
+ *      to this code.
  *
  * Modified 2/93, Various.
  *    + Added workaround for SYSV include problem.
  *    + Changed the default width response text widget to be as wide as the
- *     window itself.  Suggestion from David E. Wexelblat, dwex@goblin.org.
+ *      window itself.  Suggestion from David E. Wexelblat, dwex@goblin.org.
  *
  * Modified 5/2015, anonymous.
  *    + Include nethack's lint.h to get nhStr() macro.
  *    + Use nhStr() on string literals (or macros from <X11/StringDefs.h>
- *     that hide string literals) to cast away implicit 'const' in order
- *     to suppress "warning: assignment discards qualifers from pointer
- *     target type" issued by 'gcc -Wwrite-strings' as used by nethack.
- *     (For this file, always the second parameter to XtSetArg().)
+ *      that hide string literals) to cast away implicit 'const' in order
+ *      to suppress "warning: assignment discards qualifers from pointer
+ *      target type" issued by 'gcc -Wwrite-strings' as used by nethack.
+ *      (For this file, always the second parameter to XtSetArg().)
  *
- * $NHDT-Date: 1432512808 2015/05/25 00:13:28 $  $NHDT-Branch: master $:$NHDT-Revision: 1.6 $
+ * Modified 1/2016, Pat Rankin.
+ *    + Added minimum width argument to SetDialogResponse() so that the
+ *      text entry widget can be forced to wider than the default response.
+ *    + Make 'okay' button same width as 'cancel', and both wider than
+ *      default by a small arbitrary amount.
+ *
+ * $NHDT-Date: 1455157470 2016/02/11 02:24:30 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.9 $
  */
 
 /*
@@ -100,10 +105,10 @@ static const char cancel_accelerators[] = "#override\n\
      :<Ctrl>[: set() notify() unset()\n"; /* for keyboards w/o an ESC */
 
 /* Create a dialog widget.  It is just a form widget with
- *     a label prompt
- *     a text response
- *     an okay button
- *     an optional cancel button
+ *      a label prompt
+ *      a text response
+ *      an okay button
+ *      an optional cancel button
  */
 Widget
 CreateDialog(parent, name, okay_callback, cancel_callback)
@@ -115,75 +120,54 @@ XtCallbackProc cancel_callback;
     Widget form, prompt, response, okay, cancel;
     Arg args[20];
     Cardinal num_args;
+    Dimension owidth, cwidth;
 
     num_args = 0;
 #ifdef SPECIAL_CMAP
     if (special_cmap) {
-        XtSetArg(args[num_args], nhStr(XtNbackground), white);
-        num_args++;
+        XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++;
     }
 #endif
-    form =
-        XtCreateManagedWidget(name, formWidgetClass, parent, args, num_args);
+    form = XtCreateManagedWidget(name, formWidgetClass, parent,
+                                 args, num_args);
 
     num_args = 0;
 #ifdef SPECIAL_CMAP
     if (special_cmap) {
-        XtSetArg(args[num_args], nhStr(XtNforeground), black);
-        num_args++;
-        XtSetArg(args[num_args], nhStr(XtNbackground), white);
-        num_args++;
+        XtSetArg(args[num_args], nhStr(XtNforeground), black); num_args++;
+        XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++;
     }
 #endif
-    XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNresizable), True);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNborderWidth), 0);
-    num_args++;
+    XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNborderWidth), 0); num_args++;
 #if defined(X11R6) && defined(XI18N)
-    XtSetArg(args[num_args], XtNinternational, True);
-    num_args++;
+    XtSetArg(args[num_args], XtNinternational, True); num_args++;
 #endif
-    prompt = XtCreateManagedWidget("prompt", labelWidgetClass, form, args,
-                                   num_args);
+    prompt = XtCreateManagedWidget("prompt", labelWidgetClass, form,
+                                   args, num_args);
 
     num_args = 0;
 #ifdef SPECIAL_CMAP
     if (special_cmap) {
-        XtSetArg(args[num_args], nhStr(XtNforeground), black);
-        num_args++;
-        XtSetArg(args[num_args], nhStr(XtNbackground), white);
-        num_args++;
+        XtSetArg(args[num_args], nhStr(XtNforeground), black); num_args++;
+        XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++;
     }
 #endif
-    XtSetArg(args[num_args], nhStr(XtNfromVert), prompt);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNresizable), True);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNeditType), XawtextEdit);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNresize), XawtextResizeWidth);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNstring), "");
-    num_args++;
+    XtSetArg(args[num_args], nhStr(XtNfromVert), prompt); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNeditType), XawtextEdit); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNresize), XawtextResizeWidth); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNstring), ""); num_args++;
 #if defined(X11R6) && defined(XI18N)
-    XtSetArg(args[num_args], XtNinternational, True);
-    num_args++;
+    XtSetArg(args[num_args], XtNinternational, True); num_args++;
 #endif
     response = XtCreateManagedWidget("response", asciiTextWidgetClass, form,
                                      args, num_args);
@@ -191,69 +175,50 @@ XtCallbackProc cancel_callback;
     num_args = 0;
 #ifdef SPECIAL_CMAP
     if (special_cmap) {
-        XtSetArg(args[num_args], nhStr(XtNforeground), black);
-        num_args++;
-        XtSetArg(args[num_args], nhStr(XtNbackground), white);
-        num_args++;
+        XtSetArg(args[num_args], nhStr(XtNforeground), black); num_args++;
+        XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++;
     }
 #endif
-    XtSetArg(args[num_args], nhStr(XtNfromVert), response);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft);
-    num_args++;
-    XtSetArg(args[num_args], nhStr(XtNresizable), True);
-    num_args++;
+    XtSetArg(args[num_args], nhStr(XtNfromVert), response); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++;
+    XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++;
     XtSetArg(args[num_args], nhStr(XtNaccelerators),
-             XtParseAcceleratorTable(okay_accelerators));
-    num_args++;
+             XtParseAcceleratorTable(okay_accelerators)); num_args++;
 #if defined(X11R6) && defined(XI18N)
-    XtSetArg(args[num_args], XtNinternational, True);
-    num_args++;
+    XtSetArg(args[num_args], XtNinternational, True); num_args++;
 #endif
 /*JP
-    okay = XtCreateManagedWidget("okay", commandWidgetClass, form, args,
+    okay = XtCreateManagedWidget("okay", commandWidgetClass, form,
 */
-    okay = XtCreateManagedWidget("OK", commandWidgetClass, form, args,
-                                 num_args);
+    okay = XtCreateManagedWidget("OK", commandWidgetClass, form,
+                                 args, num_args);
     XtAddCallback(okay, XtNcallback, okay_callback, form);
+    XtSetArg(args[0], XtNwidth, &owidth);
+    XtGetValues(okay, args, ONE);
 
     /* Only create cancel button if there is a callback for it. */
     if (cancel_callback) {
         num_args = 0;
 #ifdef SPECIAL_CMAP
         if (special_cmap) {
-            XtSetArg(args[num_args], nhStr(XtNforeground), black);
-            num_args++;
-            XtSetArg(args[num_args], nhStr(XtNbackground), white);
-            num_args++;
+            XtSetArg(args[num_args], nhStr(XtNforeground), black); num_args++;
+            XtSetArg(args[num_args], nhStr(XtNbackground), white); num_args++;
         }
 #endif
-        XtSetArg(args[num_args], nhStr(XtNfromVert), response);
-        num_args++;
-        XtSetArg(args[num_args], nhStr(XtNfromHoriz), okay);
-        num_args++;
-        XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop);
-        num_args++;
-        XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop);
-        num_args++;
-        XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft);
-        num_args++;
-        XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft);
-        num_args++;
-        XtSetArg(args[num_args], nhStr(XtNresizable), True);
-        num_args++;
+        XtSetArg(args[num_args], nhStr(XtNfromVert), response); num_args++;
+        XtSetArg(args[num_args], nhStr(XtNfromHoriz), okay); num_args++;
+        XtSetArg(args[num_args], nhStr(XtNtop), XtChainTop); num_args++;
+        XtSetArg(args[num_args], nhStr(XtNbottom), XtChainTop); num_args++;
+        XtSetArg(args[num_args], nhStr(XtNleft), XtChainLeft); num_args++;
+        XtSetArg(args[num_args], nhStr(XtNright), XtChainLeft); num_args++;
+        XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++;
         XtSetArg(args[num_args], nhStr(XtNaccelerators),
-                 XtParseAcceleratorTable(cancel_accelerators));
-        num_args++;
+                 XtParseAcceleratorTable(cancel_accelerators)); num_args++;
 #if defined(X11R6) && defined(XI18N)
-        XtSetArg(args[num_args], XtNinternational, True);
-        num_args++;
+        XtSetArg(args[num_args], XtNinternational, True); num_args++;
 #endif
 /*JP
         cancel = XtCreateManagedWidget("cancel", commandWidgetClass, form,
@@ -262,7 +227,18 @@ XtCallbackProc cancel_callback;
                                        args, num_args);
         XtAddCallback(cancel, XtNcallback, cancel_callback, form);
         XtInstallAccelerators(response, cancel);
-    }
+        XtSetArg(args[0], XtNwidth, &cwidth);
+        XtGetValues(cancel, args, ONE);
+        /* widen the cancel button */
+        cwidth += 25;
+        XtSetArg(args[0], XtNwidth, cwidth);
+        XtSetValues(cancel, args, ONE);
+    } else
+        cwidth = owidth + 25;
+
+    /* make okay button same width as cancel, or widen it if no cancel */
+    XtSetArg(args[0], XtNwidth, cwidth);
+    XtSetValues(okay, args, ONE);
 
     XtInstallAccelerators(response, okay);
     XtSetKeyboardFocus(form, response);
@@ -317,12 +293,12 @@ Widget w;
     return XtNewString(s);
 }
 
-#define max(a, b) (((a) > (b)) ? (a) : (b))
 /* set the default reponse */
 void
-SetDialogResponse(w, s)
+SetDialogResponse(w, s, ln)
 Widget w;
 String s;
+unsigned ln;
 {
 #ifndef XI18N
     Arg args[4];
@@ -332,11 +308,14 @@ String s;
     Widget response;
     XFontStruct *font;
     Dimension width, nwidth, leftMargin, rightMargin;
+    unsigned s_len = strlen(s);
 #ifdef XI18N
     XFontSet fontset;
     XFontSetExtents *extent;
 #endif
 
+    if (s_len < ln)
+        s_len = ln;
     response = XtNameToWidget(w, "response");
     XtSetArg(args[0], nhStr(XtNfont), &font);
     XtSetArg(args[1], nhStr(XtNleftMargin), &leftMargin);
@@ -345,7 +324,7 @@ String s;
 #ifndef XI18N
     XtGetValues(response, args, FOUR);
     /* width includes margins as per Xaw documentation */
-    nwidth = (font->max_bounds.width * strlen(s)) + leftMargin + rightMargin;
+    nwidth = font->max_bounds.width * (s_len + 1) + leftMargin + rightMargin;
 #else
     XtSetArg(args[4], XtNfontSet, &fontset);
     XtGetValues(response, args, FIVE);
@@ -378,8 +357,7 @@ ClearDialogResponse(w)
 }
 #endif
 
-/* Not a part of the original dialogs.c from ghostview ---------------------
- */
+/* Not a part of the original dialogs.c from ghostview -------------------- */
 
 /* position popup window under the cursor */
 void
@@ -403,12 +381,9 @@ boolean bottom; /* position y on bottom? */
     XQueryPointer(XtDisplay(toplevel), XtWindow(toplevel), &root, &child, &x,
                   &y, &dummyx, &dummyy, &dummymask);
     num_args = 0;
-    XtSetArg(args[num_args], XtNwidth, &width);
-    num_args++;
-    XtSetArg(args[num_args], XtNheight, &height);
-    num_args++;
-    XtSetArg(args[num_args], XtNborderWidth, &b_width);
-    num_args++;
+    XtSetArg(args[num_args], XtNwidth, &width); num_args++;
+    XtSetArg(args[num_args], XtNheight, &height); num_args++;
+    XtSetArg(args[num_args], XtNborderWidth, &b_width); num_args++;
     XtGetValues(w, args, num_args);
 
     /* position so that the cursor is center,center or center,bottom */
@@ -416,7 +391,7 @@ boolean bottom; /* position y on bottom? */
     x -= ((Position) width / 2);
     if (x < 0)
         x = 0;
-    if (x > (max_x = (Position)(XtScreen(w)->width - width)))
+    if (x > (max_x = (Position) (XtScreen(w)->width - width)))
         x = max_x;
 
     if (bottom) {
@@ -428,19 +403,16 @@ boolean bottom; /* position y on bottom? */
     }
     if (y < 0)
         y = 0;
-    if (y > (max_y = (Position)(XtScreen(w)->height - height)))
+    if (y > (max_y = (Position) (XtScreen(w)->height - height)))
         y = max_y;
 
     num_args = 0;
-    XtSetArg(args[num_args], XtNx, x);
-    num_args++;
-    XtSetArg(args[num_args], XtNy, y);
-    num_args++;
+    XtSetArg(args[num_args], XtNx, x); num_args++;
+    XtSetArg(args[num_args], XtNy, y); num_args++;
     XtSetValues(w, args, num_args);
 
-    /* Some older window managers ignore XtN{x,y}; hint the same values */
-    /* The {x,y} are not used by newer window managers; older ones need them
-     */
+    /* Some older window managers ignore XtN{x,y}; hint the same values.
+       {x,y} are not used by newer window managers; older ones need them. */
     XtRealizeWidget(w);
     hints = XAllocSizeHints();
     hints->flags = USPosition;
@@ -449,3 +421,5 @@ boolean bottom; /* position y on bottom? */
     XSetWMNormalHints(XtDisplay(w), XtWindow(w), hints);
     XFree(hints);
 }
+
+/*dialogs.c*/