Implement hover command
[xboard.git] / dialogs.c
index 4aa6478..a7d30f6 100644 (file)
--- a/dialogs.c
+++ b/dialogs.c
@@ -426,7 +426,7 @@ static Option variantDescriptors[] = {
 { 0, 0, 275, NULL, NULL, NULL, NULL, Label, warning },
 { 0, 0, 275, NULL, NULL, NULL, NULL, Label, "Variants marked with * can only be played\nwith legality testing off"},
 { 0, SAME_ROW, 0, NULL, NULL, NULL, NULL, Break, ""},
-{ VariantFairy,         0, 135, NULL, (void*) &Pick, "#BFBFBF", NULL, Button, N_("fairy")},
+{ VariantASEAN,         0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("ASEAN")},
 { VariantGreat,  SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Great Shatranj (10x8)")},
 { VariantSChess,        0, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Seirawan")},
 { VariantFalcon, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("falcon (10x8)")},
@@ -444,7 +444,8 @@ 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
+{ VariantFairy,         0, 135, NULL, (void*) &Pick, "#BFBFBF", NULL, Button, N_("fairy")},
+//{ VariantNormal,        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 , "" }
 };
@@ -477,8 +478,8 @@ Pick (int n)
        appData.pieceToCharTable = NULL;
        appData.pieceNickNames = "";
        appData.colorNickNames = "";
-       Reset(True, True);
         PopDown(TransientDlg);
+       Reset(True, True);
         return;
 }
 
@@ -578,6 +579,7 @@ Option icsOptions[] = {
 { 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.quitNext, "", NULL, CheckBox, N_("Quit after game") },
 { 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:") },
@@ -655,6 +657,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:") },
@@ -921,7 +924,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 -----------------------------------
@@ -981,7 +984,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);
 }
 
@@ -1025,7 +1028,7 @@ static char *tagsText;
 static int
 NewTagsCallback (int n)
 {
-    ReplaceTags(tagsText, &gameInfo);
+    if(!bookUp) ReplaceTags(tagsText, &gameInfo);
     return 1;
 }
 
@@ -1040,7 +1043,7 @@ static void
 changeTags (int n)
 {
     GenericReadout(tagsOptions, 1);
-    if(bookUp) SaveToBook(tagsText); else
+    if(bookUp) SaveToBook(tagsText), DisplayBook(currentMove); else
     ReplaceTags(tagsText, &gameInfo);
 }
 
@@ -1056,7 +1059,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
@@ -1166,7 +1169,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
@@ -1228,8 +1232,8 @@ 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(!appData.autoBox) return;
            if(DialogExists(InputBoxDlg)) { // box already exists: append to current contents
                char *p, newText[MSG_SIZ];
                GetWidgetText(&boxOptions[0], &p);
@@ -1696,7 +1700,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);
 }
@@ -1873,7 +1877,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);
     }
@@ -2140,6 +2144,7 @@ Exp (int n, int x, int y)
        if(SeekGraphClick(Press, x, y, 1)) return NULL;
        if(but1 && !PromoScroll(x, y)) DragPieceMove(x, y);
        if(but3) MovePV(x, y, lineGap + BOARD_HEIGHT * (squareSize + lineGap));
+       if(appData.highlightDragging) HoverEvent(hi2X, hi2Y, x, y);
        return NULL;
     }
     if(n != 10 && PopDown(PromoDlg)) fromX = fromY = -1; // user starts fiddling with board when promotion dialog is up
@@ -2198,7 +2203,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;
 }
 
@@ -2231,7 +2236,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
@@ -2467,12 +2473,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
@@ -2503,7 +2509,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);
 }
 
@@ -2523,7 +2529,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);