From f1549d478be5058606811dac414d79492d1ebe5c Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sun, 23 Feb 2014 22:54:55 +0100 Subject: [PATCH] Play move right-clicked in Edit Book dialog A handler for button-3 down-clicks is added to the Edit Tags dialog, which fakes the clicked word was typed in the move type-in box. --- backend.h | 1 + book.c | 9 +++++++++ dialogs.c | 11 ++++++++++- winboard/wedittags.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletions(-) diff --git a/backend.h b/backend.h index 984c286..d62f510 100644 --- a/backend.h +++ b/backend.h @@ -204,6 +204,7 @@ int PromoScroll P((int x, int y)); void EditBookEvent P((void)); Boolean DisplayBook P((int moveNr)); void SaveToBook P((char *text)); +void PlayBookMove P((char *text, int index)); void HoverEvent P((int hiX, int hiY, int x, int y)); int PackGame P((Board board)); Boolean ParseFEN P((Board board, int *blackPlaysFirst, char *fen, Boolean autoSize)); diff --git a/book.c b/book.c index ec3f543..bb9d170 100644 --- a/book.c +++ b/book.c @@ -984,6 +984,15 @@ AddGameToBook (int always) } void +PlayBookMove(char *text, int index) +{ + char *start = text+index, *end = start; + while(start > text && start[-1] != ' ' && start[-1] != '\t') start--; + while(*end && *++end != ' ' && *end != '\n'); *end = NULLCHAR; // find clicked word + if(start != end) TypeInDoneEvent(start); // fake it was typed in move type-in +} + +void FlushBook () { FILE *f; diff --git a/dialogs.c b/dialogs.c index 0e15c59..5a904e5 100644 --- a/dialogs.c +++ b/dialogs.c @@ -1171,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) { @@ -1182,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) { diff --git a/winboard/wedittags.c b/winboard/wedittags.c index b3cf334..6a8b1c6 100644 --- a/winboard/wedittags.c +++ b/winboard/wedittags.c @@ -90,6 +90,7 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) GetClientRect(hDlg, &rect); sizeX = rect.right; sizeY = rect.bottom; + SendDlgItemMessage( hDlg, OPT_TagsText, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS ); if (wpTags.x != CW_USEDEFAULT && wpTags.y != CW_USEDEFAULT && wpTags.width != CW_USEDEFAULT && wpTags.height != CW_USEDEFAULT) { WINDOWPLACEMENT wp; @@ -157,6 +158,34 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } break; + case WM_NOTIFY: // [HGM] vari: cloned from whistory.c + if( wParam == OPT_TagsText ) { + MSGFILTER * lpMF = (MSGFILTER *) lParam; + + if( lpMF->msg == WM_RBUTTONDOWN ) { + POINTL pt; + LRESULT index; + + pt.x = LOWORD( lpMF->lParam ); + pt.y = HIWORD( lpMF->lParam ); + + index = SendDlgItemMessage( hDlg, OPT_TagsText, EM_CHARFROMPOS, 0, (LPARAM) &pt ); + + hwndText = GetDlgItem(hDlg, OPT_TagsText); // cloned from above + len = GetWindowTextLength(hwndText); + str = (char *) malloc(len + 1); + GetWindowText(hwndText, str, len + 1); + if(bookUp) PlayBookMove(str, index); + free(str); + + /* Zap the message for good: apparently, returning non-zero is not enough */ + lpMF->msg = WM_USER; + + return TRUE; + } + } + break; + case WM_SIZE: newSizeX = LOWORD(lParam); newSizeY = HIWORD(lParam); -- 1.7.0.4