Implement searching games in Game List for a position
[xboard.git] / xoptions.c
index e1b4ef3..31750ba 100644 (file)
@@ -98,7 +98,7 @@ void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b)
     XtGetValues(w, args, 1);
     j = 1;
     XtSetArg(args[0], XtNdisplayCaret, True);
-    if(!strchr(s, '\n')) XtSetArg(args[1], XtNinsertPosition, strlen(s)), j++;
+    if(!strchr(s, '\n') && strlen(s) < 80) XtSetArg(args[1], XtNinsertPosition, strlen(s)), j++;
     XtSetValues(w, args, j);
     XtSetKeyboardFocus((Widget) data, w);
     previous = w;
@@ -237,7 +237,7 @@ void CreateComboPopup(parent, name, n, mb)
 
 // cloned from Engine Settings dialog (and later merged with it)
 
-extern WindowPlacement wpComment, wpTags;
+extern WindowPlacement wpComment, wpTags, wpMoveHistory;
 char *trialSound;
 static int oldCores, oldPonder;
 int MakeColors P((void));
@@ -247,7 +247,7 @@ int GenericReadout P((int selected));
 Widget shells[10];
 Widget marked[10];
 Boolean shellUp[10];
-WindowPlacement *wp[10] = { NULL, &wpComment, &wpTags };
+WindowPlacement *wp[10] = { NULL, &wpComment, &wpTags, NULL, NULL, NULL, NULL, &wpMoveHistory };
 Option *dialogOptions[10];
 
 void MarkMenu(char *item, int dlgNr)
@@ -303,13 +303,22 @@ extern Option installOptions[], matchOptions[];
 char *engineNr[] = { N_("First Engine"), N_("Second Engine"), NULL };
 char *engineList[100] = {" "}, *engineMnemonic[100] = {""};
 
-void AddLine(Option *opt, char *s)
+int AppendText(Option *opt, char *s)
 {
     XawTextBlock t;
+    char *v;
+    int len;
+    GetWidgetText(opt, &v);
+    len = strlen(v);
     t.ptr = s; t.firstPos = 0; t.length = strlen(s); t.format = XawFmt8Bit;
-    XawTextReplace(opt->handle, 9999, 9999, &t);
-    t.ptr = "\n"; t.length = 1;
-    XawTextReplace(opt->handle, 9999, 9999, &t);
+    XawTextReplace(opt->handle, len, len, &t);
+    return len;
+}
+
+void AddLine(Option *opt, char *s)
+{
+    AppendText(opt, s);
+    AppendText(opt, "\n");
 }
 
 void AddToTourney(int n)
@@ -356,6 +365,7 @@ int GeneralOptionsOK(int n)
 }
 
 Option generalOptions[] = {
+{ 0,  0, 0, NULL, (void*) &appData.whitePOV, "", NULL, CheckBox, N_("Absolute Analysis Scores") },
 { 0,  0, 0, NULL, (void*) &appData.sweepSelect, "", NULL, CheckBox, N_("Almost Always Queen (Detour Under-Promote)") },
 { 0,  0, 0, NULL, (void*) &appData.animateDragging, "", NULL, CheckBox, N_("Animate Dragging") },
 { 0,  0, 0, NULL, (void*) &appData.animate, "", NULL, CheckBox, N_("Animate Moving") },
@@ -373,12 +383,14 @@ Option generalOptions[] = {
 { 0,  0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, N_("Ponder Next Move") },
 { 0,  0, 0, NULL, (void*) &appData.popupExitMessage, "", NULL, CheckBox, N_("Popup Exit Messages") },
 { 0,  0, 0, NULL, (void*) &appData.popupMoveErrors, "", NULL, CheckBox, N_("Popup Move Errors") },
+{ 0,  0, 0, NULL, (void*) &appData.showEvalInMoveHistory, "", NULL, CheckBox, N_("Scores in Move List") },
 { 0,  0, 0, NULL, (void*) &appData.showCoords, "", NULL, CheckBox, N_("Show Coordinates") },
 { 0,  0, 0, NULL, (void*) &appData.markers, "", NULL, CheckBox, N_("Show Target Squares") },
 { 0,  0, 0, NULL, (void*) &appData.testLegality, "", NULL, CheckBox, N_("Test Legality") },
 { 0, 0, 10, NULL, (void*) &appData.flashCount, "", NULL, Spin, N_("Flash Moves (0 = no flashing):") },
 { 0, 1, 10, NULL, (void*) &appData.flashRate, "", NULL, Spin, N_("Flash Rate (high = fast):") },
 { 0, 5, 100,NULL, (void*) &appData.animSpeed, "", NULL, Spin, N_("Animation Speed (high = slow):") },
+{ 0,  1, 5, NULL, (void*) &appData.zoom, "", NULL, Spin, N_("Zoom factor in Evaluation Graph:") },
 { 0,  0, 0, NULL, (void*) &GeneralOptionsOK, "", NULL, EndMark , "" }
 };
 
@@ -442,8 +454,9 @@ Option variantDescriptors[] = {
 { VariantSuicide, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("suicide")},
 { VariantCapaRandom, 1, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("CRC (10x8)")},
 { VariantGiveaway, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("give-away")},
-{ VariantSpartan, 1, 135, NULL, (void*) &Pick, "#FF0000", NULL, Button, N_("Spartan")},
+{ VariantGrand, 1, 135, NULL, (void*) &Pick, "#5070FF", NULL, Button, N_("grand (10x10)")},
 { VariantLosers, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("losers")},
+{ VariantSpartan, 1, 135, NULL, (void*) &Pick, "#FF0000", NULL, Button, N_("Spartan")},
 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("Board size ( -1 = default for selected variant):")},
 { 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.NrRanks, "", NULL, Spin, N_("Number of Board Ranks:") },
 { 0, -1, BOARD_FILES, NULL, (void*) &appData.NrFiles, "", NULL, Spin, N_("Number of Board Files:") },
@@ -541,12 +554,27 @@ Option icsOptions[] = {
 { 0, 0, 0, NULL, (void*) &IcsOptionsOK, "", NULL, EndMark , "" }
 };
 
+char *modeNames[] = { N_("Exact match"), N_("Shown position is subset"), N_("Same material and Pawn chain"), N_("Same material"), NULL };
+char *modeValues[] = { "1", "2", "3", "4" };
+char *searchMode;
+
+int LoadOptionsOK()
+{
+    appData.searchMode = atoi(searchMode);
+    return 1;
+}
+
 Option loadOptions[] = {
 { 0, 0, 0, NULL, (void*) &appData.autoDisplayTags, "", NULL, CheckBox, N_("Auto-Display Tags") },
 { 0, 0, 0, NULL, (void*) &appData.autoDisplayComment, "", NULL, CheckBox, N_("Auto-Display Comment") },
 { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("Auto-Play speed of loaded games\n(0 = instant, -1 = off):") },
 { 0, -1, 10000000, NULL, (void*) &appData.timeDelay, "", NULL, Fractional, N_("Seconds per Move:") },
-{ 0,  0, 0, NULL, NULL, "", NULL, EndMark , "" }
+{   0,  0,    0, NULL, NULL, NULL, NULL, Label,  N_("\nThresholds for position filtering in game list:") },
+{ 0, 0, 5000, NULL, (void*) &appData.eloThreshold1, "", NULL, Spin, N_("Elo of strongest player at least:") },
+{ 0, 0, 5000, NULL, (void*) &appData.eloThreshold2, "", NULL, Spin, N_("Elo of weakest player at least:") },
+{ 0, 0, 5000, NULL, (void*) &appData.dateThreshold, "", NULL, Spin, N_("No games before year:") },
+{ 1, 0, 180, NULL, (void*) &searchMode, (char*) modeNames, modeValues, ComboBox, N_("Seach mode:") },
+{ 0,  0, 0, NULL, (void*) &LoadOptionsOK, "", NULL, EndMark , "" }
 };
 
 Option saveOptions[] = {
@@ -660,7 +688,6 @@ void RefreshColor(int source, int n)
 {
     int col, j, r, g, b, step = 10;
     char *s, buf[MSG_SIZ]; // color string
-    Arg args[5];
     GetWidgetText(&currentOption[source], &s);
     if(sscanf(s, "#%x", &col) != 1) return;   // malformed
     b = col & 0xFF; g = col & 0xFF00; r = col & 0xFF0000;
@@ -1207,6 +1234,7 @@ void LoadOptionsProc(w, event, prms, nprms)
      String *prms;
      Cardinal *nprms;
 {
+   ASSIGN(searchMode, modeValues[appData.searchMode-1]);
    GenericPopUp(loadOptions, _("Load Game Options"), 0);
 }
 
@@ -1383,7 +1411,7 @@ int NewComCallback(int n)
 
 void SaveChanges(int n)
 {
-    GetWidgetText(&currentOption[0], &commentText);
+    GenericReadout(0);
     ReplaceComment(commentIndex, commentText);
 }
 
@@ -1394,15 +1422,22 @@ Option commentOptions[] = {
 {   0,  1,    0, NULL, (void*) &NewComCallback, "", NULL, EndMark , "" }
 };
 
+void ClearTextWidget(Option *opt)
+{
+//    XtCallActionProc(opt->handle, "select-all", NULL, NULL, 0);
+//    XtCallActionProc(opt->handle, "kill-selection", NULL, NULL, 0);
+    Arg arg;
+    XtSetArg(arg, XtNstring, ""); // clear without disturbing selection!
+    XtSetValues(opt->handle, &arg, 1);
+}
+
 void ClearComment(int n)
 {
-    XtCallActionProc(commentOptions[0].handle, "select-all", NULL, NULL, 0);
-    XtCallActionProc(commentOptions[0].handle, "kill-selection", NULL, NULL, 0);
+    ClearTextWidget(&commentOptions[0]);
 }
 
 void NewCommentPopup(char *title, char *text, int index)
 {
-    Widget edit;
     Arg args[16];
 
     if(shells[1]) { // if already exists, alter title and content
@@ -1417,7 +1452,7 @@ void NewCommentPopup(char *title, char *text, int index)
        XtOverrideTranslations(commentOptions[0].handle, XtParseTranslationTable(commentTranslations));
 }
 
-static char *tagsText, *msgText;
+static char *tagsText;
 
 int NewTagsCallback(int n)
 {
@@ -1427,8 +1462,8 @@ int NewTagsCallback(int n)
 
 void changeTags(int n)
 {
-    GetWidgetText(&currentOption[1], &tagsText);
-    if(bookUp) SaveToBook(tagsText); else\r
+    GenericReadout(1);
+    if(bookUp) SaveToBook(tagsText); else
     ReplaceTags(tagsText, &gameInfo);
 }
 
@@ -1441,7 +1476,6 @@ Option tagsOptions[] = {
 
 void NewTagsPopup(char *text, char *msg)
 {
-    Widget edit;
     Arg args[16];
     char *title = bookUp ? _("Edit book") : _("Tags");
 
@@ -1493,14 +1527,13 @@ void TypeInProc(w, event, prms, nprms)
      String *prms;
      Cardinal *nprms;
 {
-    Arg args[2];
-    String val;
+    char *val;
 
     if(prms[0][0] == '1') {
        GetWidgetText(&boxOptions[0], &val);
-       TypeInDoneEvent((char*)val);
+       TypeInDoneEvent(val);
     }
-    PopDown(0);\r
+    PopDown(0);
 }
 
 char moveTypeInTranslations[] =
@@ -1624,7 +1657,6 @@ void SetRandom(int n)
 {
     int r = n==2 ? -1 : rand() & (1<<30)-1;
     char buf[MSG_SIZ];
-    Arg args[2];
     snprintf(buf, MSG_SIZ,  "%d", r);
     SetWidgetText(&shuffleOptions[1], buf, 0);
     SetWidgetState(&shuffleOptions[0], True);
@@ -1660,6 +1692,7 @@ int TcOK(int n)
     if(tcType == 0 && tmpMoves <= 0) return 0;
     if(tcType == 2 && tmpInc <= 0) return 0;
     GetWidgetText(&currentOption[4], &tc); // get original text, in case it is min:sec
+    searchTime = 0;
     switch(tcType) {
       case 0:
        if(!ParseTimeControl(tc, -1, tmpMoves)) return 0;