/*\r
* wedittags.c -- EditTags window for WinBoard\r
*\r
- * Copyright 1995, 2009, 2010, 2011 Free Software Foundation, Inc.\r
+ * Copyright 1995, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Free Software Foundation, Inc.\r
*\r
* Enhancements Copyright 2005 Alessandro Scotti\r
*\r
#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
\r
/* Module globals */\r
static char *editTagsText, **resPtr;\r
+static HWND memo;\r
BOOL editTagsUp = FALSE;\r
BOOL canEditTags = FALSE;\r
\r
{\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
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
if (canEditTags) {\r
SetWindowText(hDlg, _("Edit Tags"));\r
SetFocus(hwndText);\r
}\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
case WM_COMMAND:\r
switch (LOWORD(wParam)) {\r
case IDOK:\r
+ case OPT_TagsSave:\r
if (canEditTags) {\r
char *p, *q;\r
/* Read changed options from the dialog box */\r
else\r
*p++ = *q++;\r
}\r
- *p = NULLCHAR;\r
- if(resPtr) *resPtr = strdup(str), err = 0; else\r
+ *p = NULLCHAR; err = 0;\r
+ if(resPtr) *resPtr = strdup(str); else\r
+ if(bookUp) SaveToBook(str), DisplayBook(currentMove); else\r
err = ReplaceTags(str, &gameInfo);\r
if (err) DisplayError(_("Error replacing tags."), err);\r
\r
free(str);\r
}\r
- TagsPopDown();\r
+ if(LOWORD(wParam) == IDOK) TagsPopDown();\r
return TRUE;\r
\r
case IDCANCEL:\r
return TRUE;\r
\r
case OPT_EditTags:\r
+ if(bookUp) addToBookFlag = !addToBookFlag; else\r
EditTagsEvent();\r
return TRUE;\r
\r
}\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
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 = FALSE;\r
+ editTagsUp = bookUp = addToBookFlag = FALSE;\r
}\r
\r
\r
if (editTagsDialog) {\r
SendMessage(editTagsDialog, WM_INITDIALOG, 0, 0);\r
ShowWindow(editTagsDialog, SW_SHOW);\r
+ if(bookUp) SetFocus(hwndMain);\r
} else {\r
lpProc = MakeProcInstance((FARPROC)EditTagsDialog, hInst);\r
CreateDialog(hInst, MAKEINTRESOURCE(DLG_EditTags),\r
\r
VOID EditTagsProc()\r
{\r
- if (editTagsUp) {\r
+ if (editTagsUp && !bookUp) {\r
TagsPopDown();\r
} else {\r
EditTagsEvent();\r