2 * Move history for WinBoard
\r
4 * Author: Alessandro Scotti (Dec 2005)
\r
5 * front-end code split off by HGM
\r
7 * Copyright 2005 Alessandro Scotti
\r
9 * Enhancements Copyright 2009, 2010, 2014, 2015 Free Software Foundation, Inc.
\r
11 * ------------------------------------------------------------------------
\r
13 * GNU XBoard is free software: you can redistribute it and/or modify
\r
14 * it under the terms of the GNU General Public License as published by
\r
15 * the Free Software Foundation, either version 3 of the License, or (at
\r
16 * your option) any later version.
\r
18 * GNU XBoard is distributed in the hope that it will be useful, but
\r
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
21 * General Public License for more details.
\r
23 * You should have received a copy of the GNU General Public License
\r
24 * along with this program. If not, see http://www.gnu.org/licenses/.
\r
26 * ------------------------------------------------------------------------
\r
27 ** See the file ChangeLog for a revision history. */
\r
34 #include <windows.h> /* required for all Windows applications */
\r
35 #include <richedit.h>
\r
36 #include <commdlg.h>
\r
40 #include "frontend.h"
\r
41 #include "backend.h"
\r
42 #include "winboard.h"
\r
45 // templates for calls into back-end
\r
46 void RefreshMemoContent P((void));
\r
47 void MemoContentUpdated P((void));
\r
48 void FindMoveByCharIndex P(( int char_index ));
\r
50 #define DEFAULT_COLOR 0xFFFFFFFF
\r
55 static BOOLEAN moveHistoryDialogUp = FALSE;
\r
57 // ------------- low-level front-end actions called by MoveHistory back-end -----------------
\r
59 // low-level front-end, after calculating from & to is left to caller
\r
60 // it task is to highlight the indicated characters. (In WinBoard it makes them bold and blue.)
\r
61 void HighlightMove( int from, int to, Boolean highlight )
\r
64 HWND hMemo = GetDlgItem( moveHistoryDialog, IDC_MoveHistory );
\r
66 SendMessage( hMemo, EM_SETSEL, from, to);
\r
70 ZeroMemory( &cf, sizeof(cf) );
\r
72 cf.cbSize = sizeof(cf);
\r
73 cf.dwMask = CFM_BOLD | CFM_COLOR;
\r
76 cf.dwEffects |= CFE_BOLD;
\r
77 cf.crTextColor = RGB( 0x00, 0x00, 0xFF );
\r
80 cf.dwEffects |= CFE_AUTOCOLOR;
\r
83 SendMessage( hMemo, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf );
\r
86 // low-level front-end, but replace Windows data types to make it callable from back-end
\r
87 // its task is to clear the contents of the move-history text edit
\r
88 void ClearHistoryMemo()
\r
90 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, WM_SETTEXT, 0, (LPARAM) "" );
\r
93 // low-level front-end, made callable from back-end by passing flags and color numbers
\r
94 // its task is to append the given text to the text edit
\r
95 // the bold argument says 0 = normal, 1 = bold typeface
\r
96 // the colorNr argument says 0 = font-default, 1 = gray
\r
97 int AppendToHistoryMemo( char * text, int bold, int colorNr )
\r
100 DWORD flags = bold ? CFE_BOLD :0;
\r
101 DWORD color = colorNr ? GetSysColor(COLOR_GRAYTEXT) : DEFAULT_COLOR;
\r
103 HWND hMemo = GetDlgItem( moveHistoryDialog, IDC_MoveHistory );
\r
105 /* Select end of text */
\r
106 int cbTextLen = (int) SendMessage( hMemo, WM_GETTEXTLENGTH, 0, 0 );
\r
108 SendMessage( hMemo, EM_SETSEL, cbTextLen, cbTextLen );
\r
111 ZeroMemory( &cf, sizeof(cf) );
\r
113 cf.cbSize = sizeof(cf);
\r
114 cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_COLOR | CFM_UNDERLINE;
\r
115 cf.dwEffects = flags;
\r
117 if( color != DEFAULT_COLOR ) {
\r
118 cf.crTextColor = color;
\r
121 cf.dwEffects |= CFE_AUTOCOLOR;
\r
124 SendMessage( hMemo, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf );
\r
127 SendMessage( hMemo, EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) text );
\r
129 /* Return offset of appended text */
\r
133 // low-level front-end; wrapper for the code to scroll the mentioned character in view (-1 = end)
\r
134 void ScrollToCurrent(int caretPos)
\r
137 caretPos = (int) SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, WM_GETTEXTLENGTH, 0, 0 );
\r
138 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, EM_SETSEL, caretPos, caretPos );
\r
140 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, EM_SCROLLCARET, 0, 0 );
\r
144 // ------------------------------ call backs --------------------------
\r
146 // front-end. Universal call-back for any event. Recognized vents are dialog creation, OK and cancel button-press
\r
147 // (dead code, as these buttons do not exist?), mouse clicks on the text edit, and moving / sizing
\r
148 LRESULT CALLBACK HistoryDialogProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
\r
150 static SnapData sd;
\r
153 case WM_INITDIALOG:
\r
154 if( moveHistoryDialog == NULL ) {
\r
155 moveHistoryDialog = hDlg;
\r
156 Translate(hDlg, DLG_MoveHistory);
\r
158 /* Enable word wrapping and notifications */
\r
159 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, EM_SETTARGETDEVICE, 0, 0 );
\r
161 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS );
\r
164 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, MAKELPARAM(TRUE, 0 ));
\r
166 /* Restore window placement */
\r
167 RestoreWindowPlacement( hDlg, &wpMoveHistory );
\r
171 RefreshMemoContent();
\r
173 MemoContentUpdated();
\r
178 switch (LOWORD(wParam)) {
\r
180 EndDialog(hDlg, TRUE);
\r
184 EndDialog(hDlg, FALSE);
\r
194 if( wParam == IDC_MoveHistory ) {
\r
195 MSGFILTER * lpMF = (MSGFILTER *) lParam;
\r
197 if( lpMF->msg == WM_LBUTTONDBLCLK && (lpMF->wParam & (MK_CONTROL | MK_SHIFT)) == 0 ) {
\r
201 pt.x = LOWORD( lpMF->lParam );
\r
202 pt.y = HIWORD( lpMF->lParam );
\r
204 index = SendDlgItemMessage( hDlg, IDC_MoveHistory, EM_CHARFROMPOS, 0, (LPARAM) &pt );
\r
206 FindMoveByCharIndex( index ); // [HGM] also does the actual moving to it, now
\r
208 /* Zap the message for good: apparently, returning non-zero is not enough */
\r
209 lpMF->msg = WM_USER;
\r
217 SetWindowPos( GetDlgItem( moveHistoryDialog, IDC_MoveHistory ),
\r
219 H_MARGIN, V_MARGIN,
\r
220 LOWORD(lParam) - 2*H_MARGIN,
\r
221 HIWORD(lParam) - 2*V_MARGIN,
\r
225 case WM_GETMINMAXINFO:
\r
227 MINMAXINFO * mmi = (MINMAXINFO *) lParam;
\r
229 mmi->ptMinTrackSize.x = 100;
\r
230 mmi->ptMinTrackSize.y = 100;
\r
235 MoveHistoryPopDown();
\r
238 case WM_ENTERSIZEMOVE:
\r
239 return OnEnterSizeMove( &sd, hDlg, wParam, lParam );
\r
242 return OnSizing( &sd, hDlg, wParam, lParam );
\r
245 return OnMoving( &sd, hDlg, wParam, lParam );
\r
247 case WM_EXITSIZEMOVE:
\r
248 return OnExitSizeMove( &sd, hDlg, wParam, lParam );
\r
254 // ------------ standard entry points into MoveHistory code -----------
\r
257 VOID MoveHistoryPopUp()
\r
261 CheckMenuItem(GetMenu(hwndMain), IDM_ShowMoveHistory, MF_CHECKED);
\r
263 if( moveHistoryDialog ) {
\r
264 SendMessage( moveHistoryDialog, WM_INITDIALOG, 0, 0 );
\r
266 if( ! moveHistoryDialogUp ) {
\r
267 ShowWindow(moveHistoryDialog, SW_SHOW);
\r
271 lpProc = MakeProcInstance( (FARPROC) HistoryDialogProc, hInst );
\r
273 /* Note to self: dialog must have the WS_VISIBLE style set, otherwise it's not shown! */
\r
274 CreateDialog( hInst, MAKEINTRESOURCE(DLG_MoveHistory), hwndMain, (DLGPROC)lpProc );
\r
276 FreeProcInstance(lpProc);
\r
279 moveHistoryDialogUp = TRUE;
\r
281 // Note that in WIndows creating the dialog causes its call-back to perform
\r
282 // RefreshMemoContent() and MemoContentUpdated() immediately after it is realized.
\r
283 // To port this to X we might have to do that from here.
\r
287 VOID MoveHistoryPopDown()
\r
289 CheckMenuItem(GetMenu(hwndMain), IDM_ShowMoveHistory, MF_UNCHECKED);
\r
291 if( moveHistoryDialog ) {
\r
292 ShowWindow(moveHistoryDialog, SW_HIDE);
\r
295 moveHistoryDialogUp = FALSE;
\r
299 Boolean MoveHistoryIsUp()
\r
301 return moveHistoryDialogUp;
\r
305 Boolean MoveHistoryDialogExists()
\r
307 return moveHistoryDialog != NULL;
\r