Updated copyright notice to 2012
[xboard.git] / xboard.c
index e777ea9..f29eb15 100644 (file)
--- a/xboard.c
+++ b/xboard.c
@@ -5,7 +5,7 @@
  * Massachusetts.
  *
  * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
- * 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+ * 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
  *
  * The following terms apply to Digital Equipment Corporation's copyright
  * interest in XBoard:
@@ -238,6 +238,8 @@ typedef struct {
     String name;
     String ref;
     MenuItem *mi;
+    int textWidth;
+    Widget subMenu;
 } Menu;
 
 int main P((int argc, char **argv));
@@ -253,7 +255,7 @@ void CreateXPMPieces P((void));
 void CreateXPMBoard P((char *s, int n));
 void CreatePieces P((void));
 void CreatePieceMenus P((void));
-Widget CreateMenuBar P((Menu *mb));
+Widget CreateMenuBar P((Menu *mb, int boardWidth));
 Widget CreateButtonBar P ((MenuItem *mi));
 #if ENABLE_NLS
 char *InsertPxlSize P((char *pattern, int targetPxlSize));
@@ -1113,8 +1115,8 @@ char globalTranslations[] =
    "\
    :<Key>F1: ManProc() \n \
    :<Key>F2: FlipViewProc() \n \
-   :Ctrl<KeyDown>.: TempBackwardProc() \n \
-   :Ctrl<KeyUp>.: TempForwardProc() \n \
+   :<KeyDown>Return: TempBackwardProc() \n \
+   :<KeyUp>Return: TempForwardProc() \n \
    :Ctrl<Key>1: AskQuestionProc(\"Direct command\",\
                                 \"Send to chess program:\",,1) \n \
    :Ctrl<Key>2: AskQuestionProc(\"Direct command\",\
@@ -1686,7 +1688,7 @@ void InitDrawingSizes(BoardSize boardSize, int flags)
     int i;
     static Dimension oldWidth, oldHeight;
     static VariantClass oldVariant;
-    static int oldDual = -1;
+    static int oldDual = -1, oldMono = -1;
 
     if(!formWidget) return;
 
@@ -1765,7 +1767,7 @@ void InitDrawingSizes(BoardSize boardSize, int flags)
     // [HGM] pieces: tailor piece bitmaps to needs of specific variant
     // (only for xpm)
 
-    if(gameInfo.variant == oldVariant) return; // and only if variant changed
+  if(gameInfo.variant != oldVariant) { // and only if variant changed
 
     if(useImages) {
       for(i=0; i<4; i++) {
@@ -1833,9 +1835,12 @@ void InitDrawingSizes(BoardSize boardSize, int flags)
        }
       }
     }
+  }
 #if HAVE_LIBXPM
+  if(appData.monoMode == oldMono)
     CreateAnimVars();
 #endif
+  oldMono = appData.monoMode;
 }
 #endif
 
@@ -2275,7 +2280,7 @@ XBoard square size (hint): %d\n\
     XtGetValues(formWidget, args, 1);
 
     j = 0;
-    widgetList[j++] = menuBarWidget = CreateMenuBar(menuBar);
+    widgetList[j++] = menuBarWidget = CreateMenuBar(menuBar, boardWidth);
     XtSetArg(args[0], XtNtop,    XtChainTop);
     XtSetArg(args[1], XtNbottom, XtChainTop);
     XtSetArg(args[2], XtNright,  XtChainLeft);
@@ -3946,13 +3951,16 @@ void CreateMenuBarPopup(parent, name, mb)
     }
 }
 
-Widget CreateMenuBar(mb)
+Widget CreateMenuBar(mb, boardWidth)
      Menu *mb;
+     int boardWidth;
 {
-    int j;
-    Widget anchor, menuBar;
+    int i, j, nr = 0, wtot = 0, widths[10];
+    Widget menuBar;
     Arg args[16];
     char menuName[MSG_SIZ];
+    Dimension w;
+    Menu *ma = mb;
 
     j = 0;
     XtSetArg(args[j], XtNorientation, XtorientHorizontal);  j++;
@@ -3966,22 +3974,28 @@ Widget CreateMenuBar(mb)
        strncat(menuName, mb->ref, MSG_SIZ - strlen(menuName) - 1);
        j = 0;
        XtSetArg(args[j], XtNmenuName, XtNewString(menuName));  j++;
-       if (tinyLayout) {
-           char shortName[2];
-            shortName[0] = mb->name[0];
-           shortName[1] = NULLCHAR;
-           XtSetArg(args[j], XtNlabel, XtNewString(shortName)); j++;
-       }
-      else {
-       XtSetArg(args[j], XtNlabel, XtNewString(_(mb->name))); j++;
-      }
-
+       XtSetArg(args[j], XtNlabel, XtNewString(_(mb->name)));  j++;
        XtSetArg(args[j], XtNborderWidth, 0);                   j++;
-       anchor = XtCreateManagedWidget(mb->name, menuButtonWidgetClass,
+       mb->subMenu = XtCreateManagedWidget(mb->name, menuButtonWidgetClass,
                                       menuBar, args, j);
        CreateMenuBarPopup(menuBar, menuName, mb);
+       j = 0;
+       XtSetArg(args[j], XtNwidth, &w);                   j++;
+       XtGetValues(mb->subMenu, args, j);
+       wtot += mb->textWidth = widths[nr++] = w;
        mb++;
     }
+    while(wtot > boardWidth - 40) {
+       int wmax=0, imax=0;
+       for(i=0; i<nr; i++) if(widths[i] > wmax) wmax = widths[imax=i];
+       widths[imax]--;
+       wtot--;
+    }
+    for(i=0; i<nr; i++) if(widths[i] != ma[i].textWidth) {
+       j = 0;
+       XtSetArg(args[j], XtNwidth, widths[i]);                   j++;
+       XtSetValues(ma[i].subMenu, args, j);
+    }
     return menuBar;
 }
 
@@ -4639,6 +4653,12 @@ void DrawSquare(row, column, piece, do_flash)
        }
     }
     if(!partnerUp && marker[row][column]) {
+       if(appData.monoMode) {
+           XFillArc(xDisplay, xBoardWindow, marker[row][column] == 2 ? darkSquareGC : lightSquareGC,
+                   x + squareSize/4, y+squareSize/4, squareSize/2, squareSize/2, 0, 64*360);
+           XDrawArc(xDisplay, xBoardWindow, marker[row][column] == 2 ? lightSquareGC : darkSquareGC,
+                   x + squareSize/4, y+squareSize/4, squareSize/2, squareSize/2, 0, 64*360);
+       } else
        XFillArc(xDisplay, xBoardWindow, marker[row][column] == 2 ? prelineGC : highlineGC,
                x + squareSize/4, y+squareSize/4, squareSize/2, squareSize/2, 0, 64*360);
     }