X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwedittags.c;h=6b4362d0ebf24ebb97ecd1b8ca48243482e1113c;hb=HEAD;hp=19f1bd4d82e41af6a3ea36164cb7393cef25db68;hpb=570f0d333ffba03730d5bc5a69ef5a509247104f;p=xboard.git diff --git a/winboard/wedittags.c b/winboard/wedittags.c index 19f1bd4..6b4362d 100644 --- a/winboard/wedittags.c +++ b/winboard/wedittags.c @@ -1,8 +1,10 @@ /* * wedittags.c -- EditTags window for WinBoard - * $Id: wedittags.c,v 2.1 2003/10/27 19:21:02 mann Exp $ * - * Copyright 1995,2009 Free Software Foundation, Inc. + * Copyright 1995, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free + * Software Foundation, Inc. + * + * Enhancements Copyright 2005 Alessandro Scotti * * ------------------------------------------------------------------------ * @@ -25,6 +27,7 @@ #include "config.h" #include /* required for all Windows applications */ +#include #include #include #include @@ -34,17 +37,17 @@ #include #include "common.h" -#include "winboard.h" #include "frontend.h" #include "backend.h" -#include "wedittags.h" +#include "winboard.h" + +#define _(s) T_(s) /* Module globals */ -static char *editTagsText; -HWND editTagsDialog = NULL; +static char *editTagsText, **resPtr; +static HWND memo; BOOL editTagsUp = FALSE; BOOL canEditTags = FALSE; -int editTagsX, editTagsY, editTagsW, editTagsH; /* Imports from winboard.c */ extern HINSTANCE hInst; @@ -56,7 +59,7 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static HANDLE hwndText; static int sizeX, sizeY; - int len, newSizeX, newSizeY, flags; + int len, newSizeX, newSizeY; char *str; RECT rect; MINMAXINFO *mmi; @@ -65,38 +68,44 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) switch (message) { case WM_INITDIALOG: /* message: initialize dialog box */ /* Initialize the dialog items */ - hwndText = GetDlgItem(hDlg, OPT_TagsText); + Translate(hDlg, DLG_EditTags); + hwndText = memo = GetDlgItem(hDlg, OPT_TagsText); SendMessage(hwndText, WM_SETFONT, (WPARAM)font[boardSize][EDITTAGS_FONT]->hf, MAKELPARAM(FALSE, 0)); SetDlgItemText(hDlg, OPT_TagsText, editTagsText); EnableWindow(GetDlgItem(hDlg, OPT_TagsCancel), canEditTags); - EnableWindow(GetDlgItem(hDlg, OPT_EditTags), !canEditTags); + EnableWindow(GetDlgItem(hDlg, OPT_EditTags), !canEditTags || bookUp); SendMessage(hwndText, EM_SETREADONLY, !canEditTags, 0); + if (bookUp) { + SetDlgItemText(hDlg, OPT_EditTags, _("&Play Move")); + SetWindowText(hDlg, _("Edit Book")); + SetFocus(hwndText); + } else if (canEditTags) { - SetWindowText(hDlg, "Edit Tags"); + SetWindowText(hDlg, _("Edit Tags")); SetFocus(hwndText); } else { - SetWindowText(hDlg, "Tags"); + SetWindowText(hDlg, _("Tags")); SetFocus(GetDlgItem(hDlg, IDOK)); } if (!editTagsDialog) { editTagsDialog = hDlg; - flags = SWP_NOZORDER; GetClientRect(hDlg, &rect); sizeX = rect.right; sizeY = rect.bottom; - if (editTagsX != CW_USEDEFAULT && editTagsY != CW_USEDEFAULT && - editTagsW != CW_USEDEFAULT && editTagsH != CW_USEDEFAULT) { + 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; - EnsureOnScreen(&editTagsX, &editTagsY); + EnsureOnScreen(&wpTags.x, &wpTags.y, 0, 0); wp.length = sizeof(WINDOWPLACEMENT); wp.flags = 0; wp.showCmd = SW_SHOW; wp.ptMaxPosition.x = wp.ptMaxPosition.y = 0; - wp.rcNormalPosition.left = editTagsX; - wp.rcNormalPosition.right = editTagsX + editTagsW; - wp.rcNormalPosition.top = editTagsY; - wp.rcNormalPosition.bottom = editTagsY + editTagsH; + wp.rcNormalPosition.left = wpTags.x; + wp.rcNormalPosition.right = wpTags.x + wpTags.width; + wp.rcNormalPosition.top = wpTags.y; + wp.rcNormalPosition.bottom = wpTags.y + wpTags.height; SetWindowPlacement(hDlg, &wp); GetClientRect(hDlg, &rect); @@ -113,6 +122,7 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: + case OPT_TagsSave: if (canEditTags) { char *p, *q; /* Read changed options from the dialog box */ @@ -121,18 +131,20 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) GetWindowText(hwndText, str, len + 1); p = q = str; while (*q) { - if (*q == '\r'|| *q == '\n') + if (*q == '\r') q++; else *p++ = *q++; } - *p = NULLCHAR; + *p = NULLCHAR; err = 0; + if(resPtr) *resPtr = strdup(str); else + if(bookUp) SaveToBook(str), DisplayBook(currentMove); else err = ReplaceTags(str, &gameInfo); - if (err) DisplayError("Error replacing tags.", err); + if (err) DisplayError(_("Error replacing tags."), err); free(str); } - TagsPopDown(); + if(LOWORD(wParam) == IDOK) TagsPopDown(); return TRUE; case IDCANCEL: @@ -141,6 +153,7 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) return TRUE; case OPT_EditTags: + if(bookUp) addToBookFlag = !addToBookFlag; else EditTagsEvent(); return TRUE; @@ -149,6 +162,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); @@ -167,11 +208,17 @@ EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) return FALSE; } +VOID AddBookMove(char *text) +{ + SendMessage( memo, EM_SETSEL, 999999, 999999 ); // [HGM] multivar: choose insertion point + SendMessage( memo, EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) text ); +} + VOID TagsPopDown(void) { if (editTagsDialog) ShowWindow(editTagsDialog, SW_HIDE); - CheckMenuItem(GetMenu(hwndMain), IDM_EditTags, MF_UNCHECKED); - editTagsUp = FALSE; + CheckMenuItem(GetMenu(hwndMain), IDM_Tags, MF_UNCHECKED); + editTagsUp = bookUp = addToBookFlag = FALSE; } @@ -200,10 +247,11 @@ VOID EitherTagsPopUp(char *tags, char *msg, BOOLEAN edit) editTagsText = p; canEditTags = edit; - CheckMenuItem(GetMenu(hwndMain), IDM_EditTags, MF_CHECKED); + CheckMenuItem(GetMenu(hwndMain), IDM_Tags, MF_CHECKED); if (editTagsDialog) { SendMessage(editTagsDialog, WM_INITDIALOG, 0, 0); ShowWindow(editTagsDialog, SW_SHOW); + if(bookUp) SetFocus(hwndMain); } else { lpProc = MakeProcInstance((FARPROC)EditTagsDialog, hInst); CreateDialog(hInst, MAKEINTRESOURCE(DLG_EditTags), @@ -220,14 +268,15 @@ VOID TagsPopUp(char *tags, char *msg) SetActiveWindow(hwnd); } -VOID EditTagsPopUp(char *tags) +VOID EditTagsPopUp(char *tags, char **dest) { + resPtr = dest; EitherTagsPopUp(tags, "", TRUE); } VOID EditTagsProc() { - if (editTagsUp) { + if (editTagsUp && !bookUp) { TagsPopDown(); } else { EditTagsEvent();