reindent some functions
[xboard.git] / xoptions.c
index c154030..f6cac78 100644 (file)
@@ -81,8 +81,7 @@ extern char *getenv();
 
 extern void SendToProgram P((char *message, ChessProgramState *cps));
 
-extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
-extern Display *xDisplay;
+extern Widget formWidget,  boardWidget, menuBarWidget;
 extern int squareSize;
 extern Pixmap xMarkPixmap;
 extern char *layoutName;
@@ -181,14 +180,14 @@ void ShufflePopUp()
     i = 0;
     XtSetArg(args[i], XtNresizable, True); i++;
     XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
-    shuffleShell = popup =
-      XtCreatePopupShell(_("New Shuffle Game"), transientShellWidgetClass,
-                        shellWidget, args, i);
-    
-    layout =
-      XtCreateManagedWidget(layoutName, formWidgetClass, popup,
-                           layoutArgs, XtNumber(layoutArgs));
-  
+//    shuffleShell = popup =
+//      XtCreatePopupShell(_("New Shuffle Game"), transientShellWidgetClass,
+//                      shellWidget, args, i);
+//    
+//    layout =
+//      XtCreateManagedWidget(layoutName, formWidgetClass, popup,
+//                         layoutArgs, XtNumber(layoutArgs));
+//  
     sprintf(def, "%d\n", appData.defaultFrcPosition);
     i = 0;
     XtSetArg(args[i], XtNlabel, _("Start-position number:")); i++;
@@ -207,10 +206,10 @@ void ShufflePopUp()
     XawDialogAddButton(dialog, _("off"), ShuffleCallback, (XtPointer) dialog);
     
     XtRealizeWidget(popup);
-    CatchDeleteWindow(popup, "ShufflePopDown");
+    //    CatchDeleteWindow(popup, "ShufflePopDown");
     
-    XQueryPointer(xDisplay, xBoardWindow, &root, &child,
-                 &x, &y, &win_x, &win_y, &mask);
+//    XQueryPointer(xDisplay, xBoardWindow, &root, &child,
+//               &x, &y, &win_x, &win_y, &mask);
     
     XtSetArg(args[0], XtNx, x - 10);
     XtSetArg(args[1], XtNy, y - 30);
@@ -246,6 +245,7 @@ int tcIncrement, tcMoves;
 void TimeControlPopDown()
 {
     if (!TimeControlUp) return;
+    previous = NULL;
     XtPopdown(TimeControlShell);
     XtDestroyWidget(TimeControlShell);
     TimeControlUp = False;
@@ -363,18 +363,18 @@ void TimeControlPopUp()
     i = 0;
     XtSetArg(args[i], XtNresizable, True); i++;
 //    XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
-    TimeControlShell = popup =
-      XtCreatePopupShell(_("TimeControl Menu"), transientShellWidgetClass,
-                        shellWidget, args, i);
-    
-    layout =
-      XtCreateManagedWidget(layoutName, formWidgetClass, popup,
-                           layoutArgs, XtNumber(layoutArgs));
-  
-    form =
-      XtCreateManagedWidget(layoutName, formWidgetClass, layout,
-                           formArgs, XtNumber(formArgs));
-  
+//    TimeControlShell = popup =
+//      XtCreatePopupShell(_("TimeControl Menu"), transientShellWidgetClass,
+//                      shellWidget, args, i);
+//    
+//    layout =
+//      XtCreateManagedWidget(layoutName, formWidgetClass, popup,
+//                         layoutArgs, XtNumber(layoutArgs));
+//  
+//    form =
+//      XtCreateManagedWidget(layoutName, formWidgetClass, layout,
+//                         formArgs, XtNumber(formArgs));
+//  
     j = 0;
 //    XtSetArg(args[j], XtNwidth,     (XtArgVal) 300); j++;
 //    XtSetArg(args[j], XtNheight,    (XtArgVal) 85); j++;
@@ -532,10 +532,10 @@ void TimeControlPopUp()
     XtAddCallback(b_cancel, XtNcallback, TimeControlPopDown, (XtPointer) 0);
 
     XtRealizeWidget(popup);
-    CatchDeleteWindow(popup, "TimeControlPopDown");
+    //    CatchDeleteWindow(popup, "TimeControlPopDown");
     
-    XQueryPointer(xDisplay, xBoardWindow, &root, &child,
-                 &x, &y, &win_x, &win_y, &mask);
+//    XQueryPointer(xDisplay, xBoardWindow, &root, &child,
+//               &x, &y, &win_x, &win_y, &mask);
     
     XtSetArg(args[0], XtNx, x - 10);
     XtSetArg(args[1], XtNy, y - 30);
@@ -568,6 +568,7 @@ Widget engDrawMoves, engThreshold, engRule, engRepeat;
 void EnginePopDown()
 {
     if (!EngineUp) return;
+    previous = NULL;
     XtPopdown(EngineShell);
     XtDestroyWidget(EngineShell);
     EngineUp = False;
@@ -603,8 +604,8 @@ void EngineCallback(w, client_data, call_data)
        // read all switches
        appData.periodicUpdates = ReadToggle(w1);
 //     appData.hideThinkingFromHuman = ReadToggle(w2);
-       appData.firstScoreIsAbsolute  = ReadToggle(w3);
-       appData.secondScoreIsAbsolute = ReadToggle(w4);
+       first.scoreIsAbsolute  = appData.firstScoreIsAbsolute  = ReadToggle(w3);
+       second.scoreIsAbsolute = appData.secondScoreIsAbsolute = ReadToggle(w4);
        appData.testClaims    = ReadToggle(w5);
        appData.checkMates    = ReadToggle(w6);
        appData.materialDraws = ReadToggle(w7);
@@ -652,18 +653,18 @@ void EnginePopUp()
     i = 0;
     XtSetArg(args[i], XtNresizable, True); i++;
 //    XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
-    EngineShell = popup =
-      XtCreatePopupShell(_("Adjudications"), transientShellWidgetClass,
-                        shellWidget, args, i);
-    
-    layout =
-      XtCreateManagedWidget(layoutName, formWidgetClass, popup,
-                           layoutArgs, XtNumber(layoutArgs));
-  
-    form =
-      XtCreateManagedWidget(layoutName, formWidgetClass, layout,
-                           formArgs, XtNumber(formArgs));
-  
+//    EngineShell = popup =
+//      XtCreatePopupShell(_("Adjudications"), transientShellWidgetClass,
+//                      shellWidget, args, i);
+//    
+//    layout =
+//      XtCreateManagedWidget(layoutName, formWidgetClass, popup,
+//                         layoutArgs, XtNumber(layoutArgs));
+//  
+//    form =
+//      XtCreateManagedWidget(layoutName, formWidgetClass, layout,
+//                         formArgs, XtNumber(formArgs));
+//  
     j = 0;
 //    XtSetArg(args[j], XtNwidth,     (XtArgVal) 250); j++;
 //    XtSetArg(args[j], XtNheight,    (XtArgVal) 400); j++;
@@ -866,10 +867,10 @@ void EnginePopUp()
     XtAddCallback(b_cancel, XtNcallback, EnginePopDown, (XtPointer) 0);
 
     XtRealizeWidget(popup);
-    CatchDeleteWindow(popup, "EnginePopDown");
-    
-    XQueryPointer(xDisplay, xBoardWindow, &root, &child,
-                 &x, &y, &win_x, &win_y, &mask);
+//    CatchDeleteWindow(popup, "EnginePopDown");
+//    
+//    XQueryPointer(xDisplay, xBoardWindow, &root, &child,
+//               &x, &y, &win_x, &win_y, &mask);
     
     XtSetArg(args[0], XtNx, x - 10);
     XtSetArg(args[1], XtNy, y - 30);
@@ -908,6 +909,7 @@ struct NewVarButton buttonDesc[] = {
     {N_("berolina"),          "#FFFFFF", 0, VariantBerolina},
     {N_("cylinder"),          "#FFFFFF", 0, VariantCylinder},
     {N_("shatranj"),          "#FFFFFF", 0, VariantShatranj},
+    {N_("makruk"),            "#FFFFFF", 0, VariantMakruk},
     {N_("atomic"),            "#FFFFFF", 0, VariantAtomic},
     {N_("two kings"),         "#FFFFFF", 0, VariantTwoKings},
     {N_("3-checks"),          "#FFFFFF", 0, Variant3Check},
@@ -1004,24 +1006,24 @@ void NewVariantPopUp()
     XtSetArg(args[i], XtNresizable, True); i++;
 //    XtSetArg(args[i], XtNwidth, 250); i++;
 //    XtSetArg(args[i], XtNheight, 300); i++;
-    NewVariantShell = popup =
-      XtCreatePopupShell(_("NewVariant Menu"), transientShellWidgetClass,
-                        shellWidget, args, i);
-    
-    layout =
-      XtCreateManagedWidget(layoutName, formWidgetClass, popup,
-                           layoutArgs, XtNumber(layoutArgs));
-  
-    form =
-      XtCreateManagedWidget("form", formWidgetClass, layout,
-                           formArgs, XtNumber(formArgs));
-  
+//    NewVariantShell = popup =
+//      XtCreatePopupShell(_("NewVariant Menu"), transientShellWidgetClass,
+//                      shellWidget, args, i);
+//    
+//    layout =
+//      XtCreateManagedWidget(layoutName, formWidgetClass, popup,
+//                         layoutArgs, XtNumber(layoutArgs));
+//  
+//    form =
+//      XtCreateManagedWidget("form", formWidgetClass, layout,
+//                         formArgs, XtNumber(formArgs));
+//  
     for(i = 0; buttonDesc[i].name != NULL; i++) {
        Pixel buttonColor;
        if (!appData.monoMode) {
            vFrom.addr = (caddr_t) buttonDesc[i].color;
            vFrom.size = strlen(buttonDesc[i].color);
-           XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
+           //      XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
            if (vTo.addr == NULL) {
                buttonColor = (Pixel) -1;
            } else {
@@ -1081,10 +1083,10 @@ void NewVariantPopUp()
     XtCreateManagedWidget("warning", labelWidgetClass, form, args, j);
 
            XtRealizeWidget(popup);
-    CatchDeleteWindow(popup, "NewVariantPopDown");
-    
-    XQueryPointer(xDisplay, xBoardWindow, &root, &child,
-                 &x, &y, &win_x, &win_y, &mask);
+//    CatchDeleteWindow(popup, "NewVariantPopDown");
+//    
+//    XQueryPointer(xDisplay, xBoardWindow, &root, &child,
+//               &x, &y, &win_x, &win_y, &mask);
     
     XtSetArg(args[0], XtNx, x - 10);
     XtSetArg(args[1], XtNy, y - 30);
@@ -1126,6 +1128,7 @@ struct UciControl controlDesc[] = {
 void UciPopDown()
 {
     if (!UciUp) return;
+    previous = NULL;
     XtPopdown(UciShell);
     XtDestroyWidget(UciShell);
     UciUp = False;
@@ -1198,19 +1201,19 @@ void UciPopUp()
     i = 0;
     XtSetArg(args[i], XtNresizable, True); i++;
 //    XtSetArg(args[i], XtNwidth, 300); i++;
-    UciShell = popup =
-      XtCreatePopupShell(_("Engine Settings"), transientShellWidgetClass,
-                        shellWidget, args, i);
-    
-    layout =
-      XtCreateManagedWidget(layoutName, formWidgetClass, popup,
-                           layoutArgs, XtNumber(layoutArgs));
-  
-    
-    form =
-      XtCreateManagedWidget("form", formWidgetClass, layout,
-                           formArgs, XtNumber(formArgs));
-  
+//    UciShell = popup =
+//      XtCreatePopupShell(_("Engine Settings"), transientShellWidgetClass,
+//                      shellWidget, args, i);
+//    
+//    layout =
+//      XtCreateManagedWidget(layoutName, formWidgetClass, popup,
+//                         layoutArgs, XtNumber(layoutArgs));
+//  
+//    
+//    form =
+//      XtCreateManagedWidget("form", formWidgetClass, layout,
+//                         formArgs, XtNumber(formArgs));
+//  
     j = 0;
     XtSetArg(args[j], XtNtop, XtChainTop);  j++;
     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;
@@ -1288,10 +1291,10 @@ void UciPopUp()
 //    XtAddCallback(w3, XtNcallback, UciCallback, (XtPointer) 0);
 
     XtRealizeWidget(popup);
-    CatchDeleteWindow(popup, "UciPopDown");
-    
-    XQueryPointer(xDisplay, xBoardWindow, &root, &child,
-                 &x, &y, &win_x, &win_y, &mask);
+//    CatchDeleteWindow(popup, "UciPopDown");
+//    
+//    XQueryPointer(xDisplay, xBoardWindow, &root, &child,
+//               &x, &y, &win_x, &win_y, &mask);
     
     XtSetArg(args[0], XtNx, x - 10);
     XtSetArg(args[1], XtNy, y - 30);
@@ -1324,6 +1327,7 @@ ChessProgramState *currentCps;
 void SettingsPopDown()
 {
     if (!SettingsUp) return;
+    previous = NULL;
     XtPopdown(SettingsShell);
     XtDestroyWidget(SettingsShell);
     SettingsUp = False;
@@ -1479,10 +1483,11 @@ void SettingsPopUp(ChessProgramState *cps)
     Widget popup, layout, dialog, edit=NULL, form, oldform, last, b_ok, b_cancel, leftMargin = NULL;
     Window root, child;
     int x, y, i, j, height, width, h, c;
-    int win_x, win_y;
+    int win_x, win_y, maxWidth, maxTextWidth;
     unsigned int mask;
     char def[80], *p, *q;
     static char pane[6] = "paneX";
+    Widget texts[100], forelast = NULL, anchor, widest;
 
     // to do: start up second engine if needed
     if(!cps->initDone || !cps->nrOptions) return; // nothing to be done
@@ -1492,13 +1497,13 @@ void SettingsPopUp(ChessProgramState *cps)
     height = cps->nrOptions / width + 1;
      i = 0;
     XtSetArg(args[i], XtNresizable, True); i++;
-    SettingsShell = popup =
-      XtCreatePopupShell(_("Settings Menu"), transientShellWidgetClass,
-                        shellWidget, args, i);
-    
-    layout =
-      XtCreateManagedWidget(layoutName, formWidgetClass, popup,
-                           layoutArgs, XtNumber(layoutArgs));
+//    SettingsShell = popup =
+//      XtCreatePopupShell(_("Settings Menu"), transientShellWidgetClass,
+//                      shellWidget, args, i);
+//    
+//    layout =
+//      XtCreateManagedWidget(layoutName, formWidgetClass, popup,
+//                         layoutArgs, XtNumber(layoutArgs));
   for(c=0; c<width; c++) {
     pane[4] = 'A'+c;
     form =
@@ -1509,8 +1514,9 @@ void SettingsPopUp(ChessProgramState *cps)
     XtSetValues(form, args, j);
     leftMargin = form;
  
-    last = NULL;
+    last = widest = NULL; anchor = forelast;
     for(h=0; h<height; h++) {
+       forelast = last;
        i = h + c*height;
         if(i >= cps->nrOptions) break;
        switch(cps->option[i].type) {
@@ -1521,12 +1527,13 @@ void SettingsPopUp(ChessProgramState *cps)
            XtSetArg(args[j], XtNfromVert, last);  j++;
            XtSetArg(args[j], XtNborderWidth, 0);  j++;
            XtSetArg(args[j], XtNjustify, XtJustifyLeft);  j++;
+           texts[h] =
            dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j);   
            j=0;
            XtSetArg(args[j], XtNfromVert, last);  j++;
            XtSetArg(args[j], XtNfromHoriz, dialog);  j++;
            XtSetArg(args[j], XtNborderWidth, 1); j++;
-           XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 100); j++;
+           XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 175); j++;
            XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
            XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
            XtSetArg(args[j], XtNdisplayCaret, False);  j++;
@@ -1579,7 +1586,7 @@ void SettingsPopUp(ChessProgramState *cps)
            XtSetArg(args[j], XtNfromVert, last);  j++;
            XtSetArg(args[j], XtNstate, cps->option[i].value);  j++;
            cps->option[i].handle = (void*) 
-               (last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j));   
+               (dialog = last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j));   
            XtAddCallback(last, XtNcallback, SettingsCallback,
                          (XtPointer)(intptr_t) (cps->option[i].type == SaveButton));
            break;
@@ -1603,25 +1610,62 @@ void SettingsPopUp(ChessProgramState *cps)
            break;
        }
     }
+
+    // make an attempt to align all spins and textbox controls
+    maxWidth = maxTextWidth = 0;
+    for(h=0; h<height; h++) {
+       i = h + c*height;
+        if(i >= cps->nrOptions) break;
+       if(cps->option[i].type == Spin || cps->option[i].type == TextBox) {
+           Dimension w;
+           j=0;
+           XtSetArg(args[j], XtNwidth, &w);  j++;
+           XtGetValues(texts[h], args, j);
+           if(cps->option[i].type == Spin) {
+               if(w > maxWidth) maxWidth = w;
+               widest = texts[h];
+           } else {
+               if(w > maxTextWidth) maxTextWidth = w;
+               if(!widest) widest = texts[h];
+           }
+       }
+    }
+    if(maxTextWidth + 110 < maxWidth)
+        maxTextWidth = maxWidth - 110;
+    else maxWidth = maxTextWidth + 110;
+    for(h=0; h<height; h++) {
+       i = h + c*height;
+        if(i >= cps->nrOptions) break;
+       j=0;
+       if(cps->option[i].type == Spin) {
+           XtSetArg(args[j], XtNwidth, maxWidth);  j++;
+           XtSetValues(texts[h], args, j);
+       } else
+       if(cps->option[i].type == TextBox) {
+           XtSetArg(args[j], XtNwidth, maxTextWidth);  j++;
+           XtSetValues(texts[h], args, j);
+       }
+    }
   }
     j=0;
-    XtSetArg(args[j], XtNfromVert, last);  j++;
+    XtSetArg(args[j], XtNfromVert, anchor ? anchor : last);  j++;
     XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
     XtSetArg(args[j], XtNtop, XtChainBottom);  j++;
-    XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
-    XtSetArg(args[j], XtNright, XtChainLeft);  j++;
+    XtSetArg(args[j], XtNleft, XtChainRight);  j++;
+    XtSetArg(args[j], XtNright, XtChainRight);  j++;
+    XtSetArg(args[j], XtNfromHoriz, widest ? widest : dialog);  j++;
     b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);   
     XtAddCallback(b_ok, XtNcallback, SettingsCallback, (XtPointer) 0);
 
-    XtSetArg(args[j], XtNfromHoriz, b_ok);  j++;
+    XtSetArg(args[j-1], XtNfromHoriz, b_ok);
     b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);   
     XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0);
 
     XtRealizeWidget(popup);
-    CatchDeleteWindow(popup, "SettingsPopDown");
-    
-    XQueryPointer(xDisplay, xBoardWindow, &root, &child,
-                 &x, &y, &win_x, &win_y, &mask);
+//    CatchDeleteWindow(popup, "SettingsPopDown");
+//    
+//    XQueryPointer(xDisplay, xBoardWindow, &root, &child,
+//               &x, &y, &win_x, &win_y, &mask);
     
     XtSetArg(args[0], XtNx, x - 10);
     XtSetArg(args[1], XtNy, y - 30);