Play move right-clicked in Edit Book dialog
[xboard.git] / dialogs.c
index 9c7a28a..5a904e5 100644 (file)
--- a/dialogs.c
+++ b/dialogs.c
@@ -846,20 +846,20 @@ SoundOptionsProc ()
 
 static void DefColor P((int n));
 static void AdjustColor P((int i));
+static void ThemeSel P((int n, int sel));
+static int BoardOptionsOK P((int n));
 
 static char oldPieceDir[MSG_SIZ];
+extern char *engineLine, *nickName; // defined later on
 
-static int
-BoardOptionsOK (int n)
-{
-    if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap; else lineGap = defaultLineGap;
-    InitDrawingParams(strcmp(oldPieceDir, appData.pieceDirectory));
-    InitDrawingSizes(-1, 0);
-    DrawPosition(True, NULL);
-    return 1;
-}
+#define THEMELIST 1
 
 static Option boardOptions[] = {
+{   0,LR|T2T, 0, NULL, NULL, NULL, NULL, Label, N_("Selectable themes:") },
+{ 300,LR|TB,200, NULL, (void*) engineMnemonic, (char*) &ThemeSel, NULL, ListBox, "" },
+{   0,LR|T2T, 0, NULL, NULL, NULL, NULL, Label, N_("New name for current theme:") },
+{ 0, 0, 0, NULL, (void*) &nickName, ".png", NULL, TextBox, "" },
+{ 0,SAME_ROW, 0, NULL, NULL, NULL, NULL, Break, NULL },
 { 0,          0, 70, NULL, (void*) &appData.whitePieceColor, "", NULL, TextBox, N_("White Piece Color:") },
 { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#FFFFCC", Button, "      " },
 /* TRANSLATORS: R = single letter for the color red */
@@ -913,6 +913,16 @@ static Option boardOptions[] = {
 { 0, 0, 0, NULL, (void*) &BoardOptionsOK, "", NULL, EndMark , "" }
 };
 
+static int
+BoardOptionsOK (int n)
+{
+    if(n && (n = SelectedListBoxItem(&boardOptions[THEMELIST])) > 0 && *engineList[n] != '#') { // called by pressing OK, and theme selected
+       ASSIGN(engineLine, engineList[n]);
+    }
+    LoadTheme();
+    return 1;
+}
+
 static void
 SetColorText (int n, char *buf)
 {
@@ -956,9 +966,32 @@ AdjustColor (int i)
 }
 
 void
+ThemeSel (int n, int sel)
+{
+    int nr;
+    char buf[MSG_SIZ];
+    if(sel < 1) buf[0] = NULLCHAR; // back to top level
+    else if(engineList[sel][0] == '#') safeStrCpy(buf, engineList[sel], MSG_SIZ); // group header, open group
+    else { // normal line, select engine
+       ASSIGN(engineLine, engineList[sel]);
+       LoadTheme();
+        PopDown(TransientDlg);
+       return;
+    }
+    nr = NamesToList(appData.themeNames, engineList, engineMnemonic, buf); // replace list by only the group contents
+    ASSIGN(engineMnemonic[0], buf);
+    LoadListBox(&boardOptions[THEMELIST], _("# no themes are defined"), -1, -1);
+    HighlightWithScroll(&boardOptions[THEMELIST], 0, nr);
+}
+
+void
 BoardOptionsProc ()
 {
    strncpy(oldPieceDir, appData.pieceDirectory, MSG_SIZ-1); // to see if it changed
+   ASSIGN(engineLine, "");
+   ASSIGN(nickName, "");
+   ASSIGN(engineMnemonic[0], "");
+   NamesToList(appData.themeNames, engineList, engineMnemonic, "");
    GenericPopUp(boardOptions, _("Board Options"), TransientDlg, BoardWindow, MODAL, 0);
 }
 
@@ -1001,7 +1034,7 @@ SendString (char *p)
 }
 
 void
-IcsTextProc ()
+IcsTextPopUp ()
 {
    int i=0, j;
    char *p, *q, *r;
@@ -1033,6 +1066,13 @@ IcsTextProc ()
    GenericPopUp(textOptions, _("ICS text menu"), TextMenuDlg, BoardWindow, NONMODAL, appData.topLevel);
 }
 
+void
+IcsTextProc ()
+{
+    if(shellUp[TextMenuDlg]) PopDown(TextMenuDlg);
+    else IcsTextPopUp();
+}
+
 //---------------------------------------------------- Edit Comment -----------------------------------
 
 static char *commentText;
@@ -1131,6 +1171,8 @@ EditCommentProc ()
 static void changeTags P((int n));
 static char *tagsText, **resPtr;
 
+static int TagsClick P((Option *opt, int n, int x, int y, char *val, int index));
+
 static int
 NewTagsCallback (int n)
 {
@@ -1142,11 +1184,18 @@ NewTagsCallback (int n)
 
 static Option tagsOptions[] = {
 {   0,   0,   0, NULL, NULL, NULL, NULL, Label,  NULL },
-{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 200, NULL, (void*) &tagsText, "", NULL, TextBox, "" },
+{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 200, NULL, (void*) &tagsText, "", (char **) &TagsClick, TextBox, "" },
 {   0,   0, 100, NULL, (void*) &changeTags, NULL, NULL, Button, N_("save changes") },
 { 0,SAME_ROW, 0, NULL, (void*) &NewTagsCallback, "", NULL, EndMark , "" }
 };
 
+static int TagsClick (Option *opt, int n, int x, int y, char *val, int index)
+{
+    if(!bookUp || n != 3) return FALSE; // only button-3 press in Edit Book is of interest
+    PlayBookMove(val, index);
+    return TRUE;
+}
+
 static void
 changeTags (int n)
 {
@@ -1753,7 +1802,7 @@ ContextMenu (Option *opt, int button, int x, int y, char *text, int index)
   if(wpTextMenu.x < 0) wpTextMenu.x = 0;
   if(wpTextMenu.y < 0) wpTextMenu.y = 0;
   wpTextMenu.width = wpTextMenu.height = -1;
-  IcsTextProc();
+  IcsTextPopUp();
   return TRUE;
 }
 
@@ -1975,7 +2024,7 @@ ConsoleWrite(char *message, int count)
 }
 
 void
-ChatProc ()
+ChatPopUp ()
 {
     if(GenericPopUp(chatOptions, _("ICS Interaction"), ChatDlg, BoardWindow, NONMODAL, appData.topLevel))
        AddHandler(&chatOptions[CHAT_PARTNER], ChatDlg, 2), AddHandler(&chatOptions[CHAT_IN], ChatDlg, 2); // treats return as OK
@@ -1986,6 +2035,13 @@ ChatProc ()
 }
 
 void
+ChatProc ()
+{
+    if(shellUp[ChatDlg]) PopDown(ChatDlg);
+    else ChatPopUp();
+}
+
+void
 ConsoleAutoPopUp (char *buf)
 {
        if(!appData.autoBox) return;
@@ -1997,7 +2053,7 @@ ConsoleAutoPopUp (char *buf)
                SetWidgetText(&chatOptions[CHAT_IN], newText, ChatDlg);
                if(shellUp[ChatDlg]) HardSetFocus (&chatOptions[CHAT_IN], ChatDlg); //why???
            } else { ASSIGN(line, buf); } // box did not exist: make sure it pops up with char in it
-           ChatProc();
+           ChatPopUp();
        } else PopUpMoveDialog(*buf);
 }
 
@@ -2886,10 +2942,9 @@ FileNamePopUp (char *label, char *def, char *filter, FileProc proc, char *openMo
 void
 ActivateTheme (int col)
 {
+    if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap; else lineGap = defaultLineGap;
+    InitDrawingParams(strcmp(oldPieceDir, appData.pieceDirectory));
+    InitDrawingSizes(-1, 0);
+    DrawPosition(True, NULL);
 }
 
-char *
-Col2Text (int n)
-{
-    return NULL;
-}