2 * wedittags.c -- EditTags window for WinBoard
5 * Copyright 1995 Free Software Foundation, Inc.
7 * ------------------------------------------------------------------------
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * ------------------------------------------------------------------------
26 #include <windows.h> /* required for all Windows applications */
42 static char *editTagsText;
43 HWND editTagsDialog = NULL;
44 BOOL editTagsUp = FALSE;
45 BOOL canEditTags = FALSE;
46 int editTagsX, editTagsY, editTagsW, editTagsH;
48 /* Imports from winboard.c */
49 extern HINSTANCE hInst;
51 extern BoardSize boardSize;
54 EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
56 static HANDLE hwndText;
57 static int sizeX, sizeY;
58 int len, newSizeX, newSizeY, flags;
65 case WM_INITDIALOG: /* message: initialize dialog box */
66 /* Initialize the dialog items */
67 hwndText = GetDlgItem(hDlg, OPT_TagsText);
68 SendMessage(hwndText, WM_SETFONT,
69 (WPARAM)font[boardSize][EDITTAGS_FONT]->hf, MAKELPARAM(FALSE, 0));
70 SetDlgItemText(hDlg, OPT_TagsText, editTagsText);
71 EnableWindow(GetDlgItem(hDlg, OPT_TagsCancel), canEditTags);
72 EnableWindow(GetDlgItem(hDlg, OPT_EditTags), !canEditTags);
73 SendMessage(hwndText, EM_SETREADONLY, !canEditTags, 0);
75 SetWindowText(hDlg, "Edit Tags");
78 SetWindowText(hDlg, "Tags");
79 SetFocus(GetDlgItem(hDlg, IDOK));
81 if (!editTagsDialog) {
82 editTagsDialog = hDlg;
84 GetClientRect(hDlg, &rect);
87 if (editTagsX != CW_USEDEFAULT && editTagsY != CW_USEDEFAULT &&
88 editTagsW != CW_USEDEFAULT && editTagsH != CW_USEDEFAULT) {
90 EnsureOnScreen(&editTagsX, &editTagsY);
91 wp.length = sizeof(WINDOWPLACEMENT);
94 wp.ptMaxPosition.x = wp.ptMaxPosition.y = 0;
95 wp.rcNormalPosition.left = editTagsX;
96 wp.rcNormalPosition.right = editTagsX + editTagsW;
97 wp.rcNormalPosition.top = editTagsY;
98 wp.rcNormalPosition.bottom = editTagsY + editTagsH;
99 SetWindowPlacement(hDlg, &wp);
101 GetClientRect(hDlg, &rect);
102 newSizeX = rect.right;
103 newSizeY = rect.bottom;
104 ResizeEditPlusButtons(hDlg, hwndText, sizeX, sizeY,
113 switch (LOWORD(wParam)) {
117 /* Read changed options from the dialog box */
118 len = GetWindowTextLength(hwndText);
119 str = (char *) malloc(len + 1);
120 GetWindowText(hwndText, str, len + 1);
123 if (*q == '\r'|| *q == '\n')
129 err = ReplaceTags(str, &gameInfo);
130 if (err) DisplayError("Error replacing tags.", err);
152 newSizeX = LOWORD(lParam);
153 newSizeY = HIWORD(lParam);
154 ResizeEditPlusButtons(hDlg, hwndText, sizeX, sizeY, newSizeX, newSizeY);
159 case WM_GETMINMAXINFO:
160 /* Prevent resizing window too small */
161 mmi = (MINMAXINFO *) lParam;
162 mmi->ptMinTrackSize.x = 100;
163 mmi->ptMinTrackSize.y = 100;
169 VOID TagsPopDown(void)
171 if (editTagsDialog) ShowWindow(editTagsDialog, SW_HIDE);
172 CheckMenuItem(GetMenu(hwndMain), IDM_EditTags, MF_UNCHECKED);
177 VOID EitherTagsPopUp(char *tags, char *msg, BOOLEAN edit)
182 if (msg == NULL) msg = "";
183 p = (char *) malloc(2 * (strlen(tags) + strlen(msg)) + 2);
186 if (*tags == '\n') *q++ = '\r';
189 if (*msg != NULLCHAR) {
193 if (*msg == '\n') *q++ = '\r';
198 if (editTagsText != NULL) free(editTagsText);
202 CheckMenuItem(GetMenu(hwndMain), IDM_EditTags, MF_CHECKED);
203 if (editTagsDialog) {
204 SendMessage(editTagsDialog, WM_INITDIALOG, 0, 0);
205 ShowWindow(editTagsDialog, SW_SHOW);
207 lpProc = MakeProcInstance((FARPROC)EditTagsDialog, hInst);
208 CreateDialog(hInst, MAKEINTRESOURCE(DLG_EditTags),
209 hwndMain, (DLGPROC)lpProc);
210 FreeProcInstance(lpProc);
215 VOID TagsPopUp(char *tags, char *msg)
217 HWND hwnd = GetActiveWindow();
218 EitherTagsPopUp(tags, msg, FALSE);
219 SetActiveWindow(hwnd);
222 VOID EditTagsPopUp(char *tags)
224 EitherTagsPopUp(tags, "", TRUE);