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 * ------------------------------------------------------------------------
\r
11 * GNU XBoard is free software: you can redistribute it and/or modify
\r
12 * it under the terms of the GNU General Public License as published by
\r
13 * the Free Software Foundation, either version 3 of the License, or (at
\r
14 * your option) any later version.
\r
16 * GNU XBoard is distributed in the hope that it will be useful, but
\r
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
\r
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
19 * General Public License for more details.
\r
21 * You should have received a copy of the GNU General Public License
\r
22 * along with this program. If not, see http://www.gnu.org/licenses/.
\r
24 * ------------------------------------------------------------------------
\r
25 ** See the file ChangeLog for a revision history. */
\r
32 #include <windows.h> /* required for all Windows applications */
\r
33 #include <richedit.h>
\r
34 #include <commdlg.h>
\r
38 #include "frontend.h"
\r
39 #include "backend.h"
\r
40 #include "winboard.h"
\r
43 // templates for calls into back-end
\r
44 void RefreshMemoContent P((void));
\r
45 void MemoContentUpdated P((void));
\r
46 void FindMoveByCharIndex P(( int char_index ));
\r
48 #define DEFAULT_COLOR 0xFFFFFFFF
\r
53 static BOOLEAN moveHistoryDialogUp = FALSE;
\r
55 // ------------- low-level front-end actions called by MoveHistory back-end -----------------
\r
57 // low-level front-end, after calculating from & to is left to caller
\r
58 // it task is to highlight the indicated characters. (In WinBoard it makes them bold and blue.)
\r
59 void HighlightMove( int from, int to, Boolean highlight )
\r
62 HWND hMemo = GetDlgItem( moveHistoryDialog, IDC_MoveHistory );
\r
64 SendMessage( hMemo, EM_SETSEL, from, to);
\r
68 ZeroMemory( &cf, sizeof(cf) );
\r
70 cf.cbSize = sizeof(cf);
\r
71 cf.dwMask = CFM_BOLD | CFM_COLOR;
\r
74 cf.dwEffects |= CFE_BOLD;
\r
75 cf.crTextColor = RGB( 0x00, 0x00, 0xFF );
\r
78 cf.dwEffects |= CFE_AUTOCOLOR;
\r
81 SendMessage( hMemo, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf );
\r
84 // low-level front-end, but replace Windows data types to make it callable from back-end
\r
85 // its task is to clear the contents of the move-history text edit
\r
86 void ClearHistoryMemo()
\r
88 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, WM_SETTEXT, 0, (LPARAM) "" );
\r
91 // low-level front-end, made callable from back-end by passing flags and color numbers
\r
92 // its task is to append the given text to the text edit
\r
93 // the bold argument says 0 = normal, 1 = bold typeface
\r
94 // the colorNr argument says 0 = font-default, 1 = gray
\r
95 int AppendToHistoryMemo( char * text, int bold, int colorNr )
\r
98 DWORD flags = bold ? CFE_BOLD :0;
\r
99 DWORD color = colorNr ? GetSysColor(COLOR_GRAYTEXT) : DEFAULT_COLOR;
\r
101 HWND hMemo = GetDlgItem( moveHistoryDialog, IDC_MoveHistory );
\r
103 /* Select end of text */
\r
104 int cbTextLen = (int) SendMessage( hMemo, WM_GETTEXTLENGTH, 0, 0 );
\r
106 SendMessage( hMemo, EM_SETSEL, cbTextLen, cbTextLen );
\r
109 ZeroMemory( &cf, sizeof(cf) );
\r
111 cf.cbSize = sizeof(cf);
\r
112 cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_COLOR | CFM_UNDERLINE;
\r
113 cf.dwEffects = flags;
\r
115 if( color != DEFAULT_COLOR ) {
\r
116 cf.crTextColor = color;
\r
119 cf.dwEffects |= CFE_AUTOCOLOR;
\r
122 SendMessage( hMemo, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf );
\r
125 SendMessage( hMemo, EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) text );
\r
127 /* Return offset of appended text */
\r
131 // low-level front-end; wrapper for the code to scroll the mentioned character in view (-1 = end)
\r
132 void ScrollToCurrent(int caretPos)
\r
135 caretPos = (int) SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, WM_GETTEXTLENGTH, 0, 0 );
\r
136 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, EM_SETSEL, caretPos, caretPos );
\r
138 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, EM_SCROLLCARET, 0, 0 );
\r
142 // ------------------------------ call backs --------------------------
\r
144 // front-end. Universal call-back for any event. Recognized vents are dialog creation, OK and cancel button-press
\r
145 // (dead code, as these buttons do not exist?), mouse clicks on the text edit, and moving / sizing
\r
146 LRESULT CALLBACK HistoryDialogProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
\r
148 static SnapData sd;
\r
151 case WM_INITDIALOG:
\r
152 if( moveHistoryDialog == NULL ) {
\r
153 moveHistoryDialog = hDlg;
\r
155 /* Enable word wrapping and notifications */
\r
156 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, EM_SETTARGETDEVICE, 0, 0 );
\r
158 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS );
\r
161 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, MAKELPARAM(TRUE, 0 ));
\r
163 /* Restore window placement */
\r
164 RestoreWindowPlacement( hDlg, &wpMoveHistory );
\r
168 RefreshMemoContent();
\r
170 MemoContentUpdated();
\r
175 switch (LOWORD(wParam)) {
\r
177 EndDialog(hDlg, TRUE);
\r
181 EndDialog(hDlg, FALSE);
\r
191 if( wParam == IDC_MoveHistory ) {
\r
192 MSGFILTER * lpMF = (MSGFILTER *) lParam;
\r
194 if( lpMF->msg == WM_LBUTTONDBLCLK && (lpMF->wParam & (MK_CONTROL | MK_SHIFT)) == 0 ) {
\r
198 pt.x = LOWORD( lpMF->lParam );
\r
199 pt.y = HIWORD( lpMF->lParam );
\r
201 index = SendDlgItemMessage( hDlg, IDC_MoveHistory, EM_CHARFROMPOS, 0, (LPARAM) &pt );
\r
203 FindMoveByCharIndex( index ); // [HGM] also does the actual moving to it, now
\r
205 /* Zap the message for good: apparently, returning non-zero is not enough */
\r
206 lpMF->msg = WM_USER;
\r
214 SetWindowPos( GetDlgItem( moveHistoryDialog, IDC_MoveHistory ),
\r
216 H_MARGIN, V_MARGIN,
\r
217 LOWORD(lParam) - 2*H_MARGIN,
\r
218 HIWORD(lParam) - 2*V_MARGIN,
\r
222 case WM_GETMINMAXINFO:
\r
224 MINMAXINFO * mmi = (MINMAXINFO *) lParam;
\r
226 mmi->ptMinTrackSize.x = 100;
\r
227 mmi->ptMinTrackSize.y = 100;
\r
232 MoveHistoryPopDown();
\r
235 case WM_ENTERSIZEMOVE:
\r
236 return OnEnterSizeMove( &sd, hDlg, wParam, lParam );
\r
239 return OnSizing( &sd, hDlg, wParam, lParam );
\r
242 return OnMoving( &sd, hDlg, wParam, lParam );
\r
244 case WM_EXITSIZEMOVE:
\r
245 return OnExitSizeMove( &sd, hDlg, wParam, lParam );
\r
251 // ------------ standard entry points into MoveHistory code -----------
\r
254 VOID MoveHistoryPopUp()
\r
258 CheckMenuItem(GetMenu(hwndMain), IDM_ShowMoveHistory, MF_CHECKED);
\r
260 if( moveHistoryDialog ) {
\r
261 SendMessage( moveHistoryDialog, WM_INITDIALOG, 0, 0 );
\r
263 if( ! moveHistoryDialogUp ) {
\r
264 ShowWindow(moveHistoryDialog, SW_SHOW);
\r
268 lpProc = MakeProcInstance( (FARPROC) HistoryDialogProc, hInst );
\r
270 /* Note to self: dialog must have the WS_VISIBLE style set, otherwise it's not shown! */
\r
271 CreateDialog( hInst, MAKEINTRESOURCE(DLG_MoveHistory), hwndMain, (DLGPROC)lpProc );
\r
273 FreeProcInstance(lpProc);
\r
276 moveHistoryDialogUp = TRUE;
\r
278 // Note that in WIndows creating the dialog causes its call-back to perform
\r
279 // RefreshMemoContent() and MemoContentUpdated() immediately after it is realized.
\r
280 // To port this to X we might have to do that from here.
\r
284 VOID MoveHistoryPopDown()
\r
286 CheckMenuItem(GetMenu(hwndMain), IDM_ShowMoveHistory, MF_UNCHECKED);
\r
288 if( moveHistoryDialog ) {
\r
289 ShowWindow(moveHistoryDialog, SW_HIDE);
\r
292 moveHistoryDialogUp = FALSE;
\r
296 Boolean MoveHistoryIsUp()
\r
298 return moveHistoryDialogUp;
\r
302 Boolean MoveHistoryDialogExists()
\r
304 return moveHistoryDialog != NULL;
\r