Fix switching between pixmap and bitmap pieces
[xboard.git] / xoptions.c
index 16576f9..ab6efac 100644 (file)
@@ -624,6 +624,7 @@ int values[MAX_OPTIONS];
 ChessProgramState *currentCps;
 static Option *currentOption;
 extern Widget shells[];
+static Boolean browserUp;
 
 void CheckCallback(Widget ww, XtPointer data, XEvent *event, Boolean *b)
 {
@@ -659,6 +660,7 @@ void SpinCallback(w, client_data, call_data)
        XtSetArg(args[0], XtNstring, &q);
        XtGetValues(currentOption[data].handle, args, 1);
        for(r = ""; *q; q++) if(*q == '.') r = q; else if(*q == '/') r = ""; // last dot after last slash
+       browserUp = True;
        if(XsraSelFile(shells[0], currentOption[data].name, NULL, NULL, "", "", r,
                                  currentOption[data].type == PathName ? "p" : "f", NULL, &p)) {
                int len = strlen(p);
@@ -666,6 +668,7 @@ void SpinCallback(w, client_data, call_data)
                XtSetArg(args[0], XtNstring, p);
                XtSetValues(currentOption[data].handle, args, 1);
        }
+       browserUp = False;
        SetFocus(currentOption[data].handle, shells[0], (XEvent*) NULL, False);
        return;
     } else
@@ -732,8 +735,7 @@ char *trialSound;
 static int oldCores, oldPonder;
 int MakeColors P((void));
 void CreateGCs P((int redo));
-void CreateXPMBoard P((char *s, int kind));
-void CreateXPMPieces P((void));
+void CreateAnyPieces P((void));
 void GenericReadout();
 Widget shells[10];
 Widget marked[10];
@@ -785,6 +787,7 @@ void GenericPopDown(w, event, prms, nprms)
      Cardinal *nprms;
 {
     int n;
+    if(browserUp) return; // prevent closing dialog when it has an open file-browse daughter
     PopDown(prms[0][0] - '0');
 }
 
@@ -1145,12 +1148,11 @@ void AdjustColor(int i)
 
 void BoardOptionsOK(int n)
 {
-    extern int defaultLineGap;
+    extern int defaultLineGap, useImages, useImageSqs;
     if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap; else lineGap = defaultLineGap;
+    useImages = useImageSqs = 0;
     MakeColors(); CreateGCs(True);
-    CreateXPMPieces();
-    CreateXPMBoard(appData.liteBackTextureFile, 1);
-    CreateXPMBoard(appData.darkBackTextureFile, 0);
+    CreateAnyPieces();
     InitDrawingSizes(-1, 0);
     DrawPosition(True, NULL);
 }
@@ -1193,7 +1195,7 @@ Option boardOptions[] = {
 {    3, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "B" },
 {    4, 1, 0, NULL, (void*) &AdjustColor, NULL, NULL, Button, "D" },
 { 0, 0, 0, NULL, (void*) &appData.upsideDown, "", NULL, CheckBox, _("Flip Pieces Shogi Style        (Colored buttons restore default)") },
-{ 0, 0, 0, NULL, (void*) &appData.allWhite, "", NULL, CheckBox, _("Use Outline Pieces for Black") },
+//{ 0, 0, 0, NULL, (void*) &appData.allWhite, "", NULL, CheckBox, _("Use Outline Pieces for Black") },
 { 0, 0, 0, NULL, (void*) &appData.monoMode, "", NULL, CheckBox, _("Mono Mode") },
 { 0,-1, 5, NULL, (void*) &appData.overrideLineGap, "", NULL, Spin, _("Line Gap ( -1 = default for board size):") },
 { 0, 0, 0, NULL, (void*) &appData.liteBackTextureFile, "", NULL, FileName, _("Light-Squares Texture File:") },
@@ -1233,13 +1235,14 @@ void GenericReadout()
                    sscanf(val, "%f", &x);
                    if(x > currentOption[i].max) x = currentOption[i].max;
                    if(x < currentOption[i].min) x = currentOption[i].min;
-                   if(currentOption[i].value != x) {
+                   if(currentOption[i].type == Fractional)
+                       *(float*) currentOption[i].target = x; // engines never have float options!
+                   else if(currentOption[i].value != x) {
                        currentOption[i].value = x;
-                       if(currentCps) { // engines never have float options, so no decimals!
+                       if(currentCps) {
                            snprintf(buf, MSG_SIZ,  "option %s=%.0f\n", currentOption[i].name, x);
                            SendToProgram(buf, currentCps);
-                       } else if(currentOption[i].type == Spin) *(int*) currentOption[i].target = x;
-                       else *(float*) currentOption[i].target = x;
+                       } else *(int*) currentOption[i].target = x;
                    }
                    break;
                case CheckBox:
@@ -1276,6 +1279,7 @@ void GenericReadout()
                case Button:
                case SaveButton:
                case Label:
+               case Break:
              break;
            }
            if(currentOption[i].type == EndMark) break;
@@ -1493,7 +1497,7 @@ GenericPopUp(Option *option, char *title, int dlgNr)
            }
            option[i].handle = (void*)
                (dialog = last = XtCreateManagedWidget(option[i].name, commandWidgetClass, form, args, j));
-           if(option[i].choice && !currentCps) {
+           if(option[i].choice && ((char*)option[i].choice)[0] == '#' && !currentCps) {
                SetColor( *(char**) option[i-1].target, last);
                XtAddEventHandler(option[i-1].handle, KeyReleaseMask, False, ColorChanged, (XtPointer)(intptr_t) i-1);
            }
@@ -1888,7 +1892,7 @@ extern char ICSInputTranslations[];
 char *icsText;
 
 Option boxOptions[] = {
-{   0, 20,  400, NULL, (void*) &icsText, "", NULL, TextBox, "" },
+{   0, 30,  400, NULL, (void*) &icsText, "", NULL, TextBox, "" },
 {   0,  3,    0, NULL, NULL, "", NULL, EndMark , "" }
 };
 
@@ -1919,6 +1923,49 @@ void InputBoxPopup()
        XtOverrideTranslations(boxOptions[0].handle, XtParseTranslationTable(ICSInputTranslations));
 }
 
+void TypeInProc(w, event, prms, nprms)
+     Widget w;
+     XEvent *event;
+     String *prms;
+     Cardinal *nprms;
+{
+    Arg args[2];
+    String val;
+
+    if(prms[0][0] == '1') {
+       XtSetArg(args[0], XtNstring, &val);
+       XtGetValues(boxOptions[0].handle, args, 1);
+       TypeInDoneEvent((char*)val);
+    }
+    PopDown(0);\r
+}
+
+char moveTypeInTranslations[] =
+    "<Key>Return: TypeInProc(1) \n"
+    "<Key>Escape: TypeInProc(0) \n";
+
+void PopUpMoveDialog(char firstchar)
+{
+    static char buf[2];
+    buf[0] = firstchar; icsText = buf;
+    if(GenericPopUp(boxOptions, _("Type a move"), 0))
+       XtOverrideTranslations(boxOptions[0].handle, XtParseTranslationTable(moveTypeInTranslations));
+}
+
+void MoveTypeInProc(Widget widget, caddr_t unused, XEvent *event)
+{
+    char buf[10], keys[32];
+    KeySym sym;
+    KeyCode metaL, metaR;
+    int n = XLookupString(&(event->xkey), buf, 10, &sym, NULL);
+    XQueryKeymap(xDisplay,keys);
+    metaL = XKeysymToKeycode(xDisplay, XK_Meta_L);
+    metaR = XKeysymToKeycode(xDisplay, XK_Meta_R);
+    if ( n == 1 && *buf > 32 && !(keys[metaL>>3]&1<<(metaL&7)) && !(keys[metaR>>3]&1<<(metaR&7))) // printable, no alt
+       PopUpMoveDialog(*buf);
+
+}
+
 void
 SettingsPopUp(ChessProgramState *cps)
 {