Updated copyright notice to 2014
[xboard.git] / dialogs.c
index 8ea9f30..bb98b3f 100644 (file)
--- a/dialogs.c
+++ b/dialogs.c
@@ -1,7 +1,7 @@
 /*
  * dialogs.c -- platform-independent code for dialogs of XBoard
  *
- * Copyright 2000, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
+ * Copyright 2000, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
  * ------------------------------------------------------------------------
  *
  * GNU XBoard is free software: you can redistribute it and/or modify
@@ -368,13 +368,14 @@ static Option generalOptions[] = {
 { 0,  0, 0, NULL, (void*) &appData.autoFlipView, "", NULL, CheckBox, N_("Auto Flip View") },
 { 0,  0, 0, NULL, (void*) &appData.blindfold, "", NULL, CheckBox, N_("Blindfold") },
 { 0,  0, 0, NULL, (void*) &appData.dropMenu, "", NULL, CheckBox, N_("Drop Menu") },
+{ 0,  0, 0, NULL, (void*) &appData.variations, "", NULL, CheckBox, N_("Enable Variation Trees") },
 { 0,  0, 0, NULL, (void*) &appData.hideThinkingFromHuman, "", NULL, CheckBox, N_("Hide Thinking from Human") },
 { 0,  0, 0, NULL, (void*) &appData.highlightLastMove, "", NULL, CheckBox, N_("Highlight Last Move") },
 { 0,  0, 0, NULL, (void*) &appData.highlightMoveWithArrow, "", NULL, CheckBox, N_("Highlight with Arrow") },
-{ 0,  0, 0, NULL, (void*) &appData.ringBellAfterMoves, "", NULL, CheckBox, N_("Move Sound") },
 { 0,  0, 0, NULL, (void*) &appData.oneClick, "", NULL, CheckBox, N_("One-Click Moving") },
 { 0,  0, 0, NULL, (void*) &appData.periodicUpdates, "", NULL, CheckBox, N_("Periodic Updates (in Analysis Mode)") },
 { 0, SAME_ROW, 0, NULL, NULL, NULL, NULL, Break, "" },
+{ 0,  0, 0, NULL, (void*) &appData.autoExtend, "", NULL, CheckBox, N_("Play Move(s) of Clicked PV (Analysis)") },
 { 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") },
@@ -443,7 +444,7 @@ static Option variantDescriptors[] = {
 { VariantShogi,  SAME_ROW, 135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("shogi (9x9)")},
 { VariantSpartan,       0, 135, NULL, (void*) &Pick, "#FF0000", NULL, Button, N_("Spartan")},
 { VariantXiangqi, SAME_ROW,135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("xiangqi (9x10)")},
-{ VariantNormal,        0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_(" ")}, // dummy, to have good alignment
+{ -1,                   0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_(" ")}, // dummy, to have good alignment
 { VariantCourier, SAME_ROW,135, NULL, (void*) &Pick, "#BFFFBF", NULL, Button, N_("courier (12x8)")},
 { 0, NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" }
 };
@@ -476,8 +477,8 @@ Pick (int n)
        appData.pieceToCharTable = NULL;
        appData.pieceNickNames = "";
        appData.colorNickNames = "";
-       Reset(True, True);
         PopDown(TransientDlg);
+       Reset(True, True);
         return;
 }
 
@@ -576,6 +577,7 @@ Option icsOptions[] = {
 { 0, 0, 0, NULL, (void*) &appData.quietPlay, "",   NULL, CheckBox, N_("Quiet Play") },
 { 0, 0, 0, NULL, (void*) &appData.seekGraph, "",   NULL, CheckBox, N_("Seek Graph") },
 { 0, 0, 0, NULL, (void*) &appData.autoRefresh, "", NULL, CheckBox, N_("Auto-Refresh Seek Graph") },
+{ 0, 0, 0, NULL, (void*) &appData.autoBox, "", NULL, CheckBox, N_("Auto-InputBox PopUp") },
 { 0, 0, 0, NULL, (void*) &appData.premove, "",     NULL, CheckBox, N_("Premove") },
 { 0, 0, 0, NULL, (void*) &appData.premoveWhite, "", NULL, CheckBox, N_("Premove for White") },
 { 0, 0, 0, NULL, (void*) &appData.premoveWhiteText, "", NULL, TextBox, N_("First White Move:") },
@@ -653,6 +655,7 @@ LoadOptionsProc ()
 
 static Option saveOptions[] = {
 { 0, 0, 0, NULL, (void*) &appData.autoSaveGames, "", NULL, CheckBox, N_("Auto-Save Games") },
+{ 0, 0, 0, NULL, (void*) &appData.onlyOwn, "", NULL, CheckBox, N_("Own Games Only") },
 { 0, 0, 0, NULL, (void*) &appData.saveGameFile, ".pgn", NULL, FileName,  N_("Save Games on File:") },
 { 0, 0, 0, NULL, (void*) &appData.savePositionFile, ".fen", NULL, FileName,  N_("Save Final Positions on File:") },
 { 0, 0, 0, NULL, (void*) &appData.pgnEventHeader, "", NULL, TextBox,  N_("PGN Event Header:") },
@@ -919,7 +922,7 @@ IcsTextProc ()
    textOptions[i].target = NULL;
    textOptions[i].min = 2;
    MarkMenu("View.ICStextmenu", TextMenuDlg);
-   GenericPopUp(textOptions, _("ICS text menu"), TextMenuDlg, BoardWindow, NONMODAL, 1);
+   GenericPopUp(textOptions, _("ICS text menu"), TextMenuDlg, BoardWindow, NONMODAL, appData.topLevel);
 }
 
 //---------------------------------------------------- Edit Comment -----------------------------------
@@ -979,7 +982,7 @@ NewCommentPopup (char *title, char *text, int index)
     if(commentText) free(commentText); commentText = strdup(text);
     commentIndex = index;
     MarkMenu("View.Comments", CommentDlg);
-    if(GenericPopUp(commentOptions, title, CommentDlg, BoardWindow, NONMODAL, 1))
+    if(GenericPopUp(commentOptions, title, CommentDlg, BoardWindow, NONMODAL, appData.topLevel))
        AddHandler(&commentOptions[0], CommentDlg, 1);
 }
 
@@ -1054,7 +1057,7 @@ NewTagsPopup (char *text, char *msg)
     if(tagsText) free(tagsText); tagsText = strdup(text);
     tagsOptions[0].name = msg;
     MarkMenu("View.Tags", TagsDlg);
-    GenericPopUp(tagsOptions, title, TagsDlg, BoardWindow, NONMODAL, 1);
+    GenericPopUp(tagsOptions, title, TagsDlg, BoardWindow, NONMODAL, appData.topLevel);
 }
 
 void
@@ -1150,7 +1153,7 @@ ICSInputSendText ()
 void
 IcsKey (int n)
 {   // [HGM] input: let up-arrow recall previous line from history
-    char *val;
+    char *val = NULL; // to suppress spurious warning
 
     if (!shellUp[InputBoxDlg]) return;
     switch(n) {
@@ -1164,7 +1167,8 @@ IcsKey (int n)
       case -1:
        val = NextInHistory();
     }
-    SetWidgetText(&boxOptions[0], val ? val : "", InputBoxDlg);
+    SetWidgetText(&boxOptions[0], val = val ? val : "", InputBoxDlg);
+    SetInsertPos(&boxOptions[0], strlen(val));
 }
 
 static void
@@ -1226,6 +1230,7 @@ PopUpMoveDialog (char firstchar)
 void
 BoxAutoPopUp (char *buf)
 {
+       if(!appData.autoBox) return;
        if(appData.icsActive) { // text typed to board in ICS mode: divert to ICS input box
            if(DialogExists(InputBoxDlg)) { // box already exists: append to current contents
                char *p, newText[MSG_SIZ];
@@ -1362,7 +1367,7 @@ ShuffleOK (int n)
 }
 
 static Option shuffleOptions[] = {
-  {   0,  0,   50, NULL, (void*) &shuffleOpenings, NULL, NULL, CheckBox, N_("shuffle") },
+  {   0,  0,    0, NULL, (void*) &shuffleOpenings, NULL, NULL, CheckBox, N_("shuffle") },
   { 0,-1,2000000000, NULL, (void*) &appData.defaultFrcPosition, "", NULL, Spin, N_("Start-position number:") },
   {   0,  0,    0, NULL, (void*) &SetRandom, NULL, NULL, Button, N_("randomize") },
   {   0,  SAME_ROW,    0, NULL, (void*) &SetRandom, NULL, NULL, Button, N_("pick fixed") },
@@ -1693,7 +1698,7 @@ ChatSwitch (int n)
 void
 ChatProc ()
 {
-    if(GenericPopUp(chatOptions, _("Chat box"), ChatDlg, BoardWindow, NONMODAL, 0))
+    if(GenericPopUp(chatOptions, _("Chat box"), ChatDlg, BoardWindow, NONMODAL, appData.topLevel))
        AddHandler(&chatOptions[0], ChatDlg, 2), AddHandler(&chatOptions[6], ChatDlg, 2); // treats return as OK
     MarkMenu("View.OpenChatWindow", ChatDlg);
 }
@@ -1870,7 +1875,7 @@ DisplayMoveError (String message)
 {
     fromX = fromY = -1;
     ClearHighlights();
-    DrawPosition(FALSE, NULL);
+    DrawPosition(TRUE, NULL); // selective redraw would miss the from-square of the rejected move, displayed empty after drag, but not marked damaged!
     if (appData.debugMode || appData.matchMode) {
        fprintf(stderr, "%s: %s\n", programName, message);
     }
@@ -2195,7 +2200,7 @@ BoardPopUp (int squareSize, int lineGap, void *clockFontThingy)
     if(!appData.showButtonBar) for(i=W_BUTTON; i<W_BOARD; i++) mainOptions[i].type = -1;
     for(i=0; i<8; i++) mainOptions[i+1].choice = (char**) menuBar[i].mi;
     AppendEnginesToMenu(appData.recentEngineList);
-    GenericPopUp(mainOptions, "XBoard", BoardWindow, BoardWindow, NONMODAL, 1);
+    GenericPopUp(mainOptions, "XBoard", BoardWindow, BoardWindow, NONMODAL, 1); // allways top-level
     return mainOptions;
 }
 
@@ -2213,7 +2218,7 @@ SlaveExp (int n, int x, int y)
 Option dualOptions[] = { // auxiliary board window
 { 0, L2L|T2T,              198, NULL, NULL, NULL, NULL, Label, "White" }, // white clock
 { 0, R2R|T2T|SAME_ROW,     198, NULL, NULL, NULL, NULL, Label, "Black" }, // black clock
-{ 0, LR|T2T|BORDER,        401, NULL, NULL, NULL, NULL, Label, "message" }, // message field
+{ 0, LR|T2T|BORDER,        401, NULL, NULL, NULL, NULL, Label, "This feature is experimental" }, // message field
 { 401, LR|TT, 401, NULL, (char*) &SlaveExp, NULL, NULL, Graph, "shadow board" }, // board
 { 0,  NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" }
 };
@@ -2228,7 +2233,8 @@ SlavePopUp ()
     dualOptions[3].value = BOARD_HEIGHT*(squareSize + lineGap) + lineGap;
     dualOptions[3].max = dualOptions[2].max = size; // board width
     dualOptions[0].max = dualOptions[1].max = size/2 - 3; // clock width
-    GenericPopUp(dualOptions, "XBoard", DummyDlg, BoardWindow, NONMODAL, 1);
+    GenericPopUp(dualOptions, "XBoard", DummyDlg, BoardWindow, NONMODAL, appData.topLevel);
+    SlaveResize(dualOptions+3);
 }
 
 void
@@ -2464,12 +2470,12 @@ ListDir (int pathFlag)
                ASSIGN(fileList[filePtr], s); filePtr++;
            }
        }
-       if(filePtr == MAXFILES-2) { ASSIGN(fileList[filePtr], _("\177 next page")); filePtr++; }
+       if(filePtr == MAXFILES-2) { ASSIGN(fileList[filePtr], _("  next page")); filePtr++; }
        FREE(folderList[folderPtr]); folderList[folderPtr] = NULL;
        FREE(fileList[filePtr]); fileList[filePtr] = NULL;
        closedir(dir);
        extFlag = 0;         qsort((void*)folderList, folderPtr, sizeof(char*), &Comp);
-       extFlag = byExtension; qsort((void*)fileList, filePtr, sizeof(char*), &Comp);
+       extFlag = byExtension; qsort((void*)fileList, filePtr < MAXFILES-2 ? filePtr : MAXFILES-2, sizeof(char*), &Comp);
 }
 
 void
@@ -2481,13 +2487,17 @@ Refresh (int pathFlag)
     SetWidgetLabel(&browseOptions[0], title);
 }
 
+static char msg1[] = N_("FIRST TYPE DIRECTORY NAME HERE");
+static char msg2[] = N_("TRY ANOTHER NAME");
+
 void
 CreateDir (int n)
 {
     char *name, *errmsg = "";
     GetWidgetText(&browseOptions[n-1], &name);
-    if(!name[0]) errmsg = _("FIRST TYPE DIRECTORY NAME HERE"); else
-    if(mkdir(name, 0755)) errmsg = _("TRY ANOTHER NAME");
+    if(!strcmp(name, msg1) || !strcmp(name, msg2)) return;
+    if(!name[0]) errmsg = _(msg1); else
+    if(mkdir(name, 0755)) errmsg = _(msg2);
     else {
        chdir(name);
        Refresh(-1);
@@ -2500,7 +2510,7 @@ Switch (int n)
 {
     if(byExtension == (n == 4)) return;
     extFlag = byExtension = (n == 4);
-    qsort((void*)fileList, filePtr, sizeof(char*), &Comp);
+    qsort((void*)fileList, filePtr < MAXFILES-2 ? filePtr : MAXFILES-2, sizeof(char*), &Comp);
     LoadListBox(&browseOptions[6], "", -1, -1);
 }
 
@@ -2520,7 +2530,7 @@ SetTypeFilter (int n)
 void
 FileSelProc (int n, int sel)
 {
-    if(sel<0) return;
+    if(sel < 0 || fileList[sel] == NULL) return;
     if(sel == MAXFILES-2) { pageStart = cnt; Refresh(-1); return; }
     ASSIGN(fileName, fileList[sel]);
     if(BrowseOK(0)) PopDown(BrowserDlg);