Fix multi-leg promotions
[xboard.git] / winboard / wedittags.c
index b3cf334..6b4362d 100644 (file)
@@ -1,7 +1,8 @@
 /*\r
  * wedittags.c -- EditTags window for WinBoard\r
  *\r
- * Copyright 1995, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.\r
+ * Copyright 1995, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free\r
+ * Software Foundation, Inc.\r
  *\r
  * Enhancements Copyright 2005 Alessandro Scotti\r
  *\r
@@ -26,6 +27,7 @@
 #include "config.h"\r
 \r
 #include <windows.h>   /* required for all Windows applications */\r
+#include <richedit.h>\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include <malloc.h>\r
@@ -43,6 +45,7 @@
 \r
 /* Module globals */\r
 static char *editTagsText, **resPtr;\r
+static HWND memo;\r
 BOOL editTagsUp = FALSE;\r
 BOOL canEditTags = FALSE;\r
 \r
@@ -56,7 +59,7 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 {\r
   static HANDLE hwndText;\r
   static int sizeX, sizeY;\r
-  int len, newSizeX, newSizeY, flags;\r
+  int len, newSizeX, newSizeY;\r
   char *str;\r
   RECT rect;\r
   MINMAXINFO *mmi;\r
@@ -66,14 +69,15 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
   case WM_INITDIALOG: /* message: initialize dialog box */\r
     /* Initialize the dialog items */\r
     Translate(hDlg, DLG_EditTags);\r
-   hwndText = GetDlgItem(hDlg, OPT_TagsText);\r
+   hwndText = memo = GetDlgItem(hDlg, OPT_TagsText);\r
     SendMessage(hwndText, WM_SETFONT, \r
       (WPARAM)font[boardSize][EDITTAGS_FONT]->hf, MAKELPARAM(FALSE, 0));\r
     SetDlgItemText(hDlg, OPT_TagsText, editTagsText);\r
     EnableWindow(GetDlgItem(hDlg, OPT_TagsCancel), canEditTags);\r
-    EnableWindow(GetDlgItem(hDlg, OPT_EditTags), !canEditTags);\r
+    EnableWindow(GetDlgItem(hDlg, OPT_EditTags), !canEditTags || bookUp);\r
     SendMessage(hwndText, EM_SETREADONLY, !canEditTags, 0);\r
     if (bookUp) {\r
+      SetDlgItemText(hDlg, OPT_EditTags, _("&Play Move"));\r
       SetWindowText(hDlg, _("Edit Book"));\r
       SetFocus(hwndText);\r
     } else\r
@@ -86,10 +90,10 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     }\r
     if (!editTagsDialog) {\r
       editTagsDialog = hDlg;\r
-      flags = SWP_NOZORDER;\r
       GetClientRect(hDlg, &rect);\r
       sizeX = rect.right;\r
       sizeY = rect.bottom;\r
+      SendDlgItemMessage( hDlg, OPT_TagsText, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS );\r
       if (wpTags.x != CW_USEDEFAULT && wpTags.y != CW_USEDEFAULT &&\r
          wpTags.width != CW_USEDEFAULT && wpTags.height != CW_USEDEFAULT) {\r
        WINDOWPLACEMENT wp;\r
@@ -149,6 +153,7 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       return TRUE;\r
       \r
     case OPT_EditTags:\r
+      if(bookUp) addToBookFlag = !addToBookFlag; else\r
       EditTagsEvent();\r
       return TRUE;\r
 \r
@@ -157,6 +162,34 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     }\r
     break;\r
 \r
+  case WM_NOTIFY: // [HGM] vari: cloned from whistory.c\r
+        if( wParam == OPT_TagsText ) {\r
+            MSGFILTER * lpMF = (MSGFILTER *) lParam;\r
+\r
+            if( lpMF->msg == WM_RBUTTONDOWN ) {\r
+                POINTL pt;\r
+                LRESULT index;\r
+\r
+                pt.x = LOWORD( lpMF->lParam );\r
+                pt.y = HIWORD( lpMF->lParam );\r
+\r
+                index = SendDlgItemMessage( hDlg, OPT_TagsText, EM_CHARFROMPOS, 0, (LPARAM) &pt );\r
+\r
+               hwndText = GetDlgItem(hDlg, OPT_TagsText); // cloned from above\r
+               len = GetWindowTextLength(hwndText);\r
+               str = (char *) malloc(len + 1);\r
+               GetWindowText(hwndText, str, len + 1);\r
+               if(bookUp) PlayBookMove(str, index);\r
+               free(str);\r
+\r
+                /* Zap the message for good: apparently, returning non-zero is not enough */\r
+                lpMF->msg = WM_USER;\r
+\r
+                return TRUE;\r
+            }\r
+        }\r
+        break;\r
+\r
   case WM_SIZE:\r
     newSizeX = LOWORD(lParam);\r
     newSizeY = HIWORD(lParam);\r
@@ -175,11 +208,17 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
   return FALSE;\r
 }\r
 \r
+VOID AddBookMove(char *text)\r
+{\r
+    SendMessage( memo, EM_SETSEL, 999999, 999999 ); // [HGM] multivar: choose insertion point\r
+    SendMessage( memo, EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) text );\r
+}\r
+\r
 VOID TagsPopDown(void)\r
 {\r
   if (editTagsDialog) ShowWindow(editTagsDialog, SW_HIDE);\r
   CheckMenuItem(GetMenu(hwndMain), IDM_Tags, MF_UNCHECKED);\r
-  editTagsUp = bookUp = FALSE;\r
+  editTagsUp = bookUp = addToBookFlag = FALSE;\r
 }\r
 \r
 \r