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
154 Translate(hDlg, DLG_MoveHistory);
\r
156 /* Enable word wrapping and notifications */
\r
157 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, EM_SETTARGETDEVICE, 0, 0 );
\r
159 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS );
\r
162 SendDlgItemMessage( moveHistoryDialog, IDC_MoveHistory, WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, MAKELPARAM(TRUE, 0 ));
\r
164 /* Restore window placement */
\r
165 RestoreWindowPlacement( hDlg, &wpMoveHistory );
\r
169 RefreshMemoContent();
\r
171 MemoContentUpdated();
\r
176 switch (LOWORD(wParam)) {
\r
178 EndDialog(hDlg, TRUE);
\r
182 EndDialog(hDlg, FALSE);
\r
192 if( wParam == IDC_MoveHistory ) {
\r
193 MSGFILTER * lpMF = (MSGFILTER *) lParam;
\r
195 if( lpMF->msg == WM_LBUTTONDBLCLK && (lpMF->wParam & (MK_CONTROL | MK_SHIFT)) == 0 ) {
\r
199 pt.x = LOWORD( lpMF->lParam );
\r
200 pt.y = HIWORD( lpMF->lParam );
\r
202 index = SendDlgItemMessage( hDlg, IDC_MoveHistory, EM_CHARFROMPOS, 0, (LPARAM) &pt );
\r
204 FindMoveByCharIndex( index ); // [HGM] also does the actual moving to it, now
\r
206 /* Zap the message for good: apparently, returning non-zero is not enough */
\r
207 lpMF->msg = WM_USER;
\r
215 SetWindowPos( GetDlgItem( moveHistoryDialog, IDC_MoveHistory ),
\r
217 H_MARGIN, V_MARGIN,
\r
218 LOWORD(lParam) - 2*H_MARGIN,
\r
219 HIWORD(lParam) - 2*V_MARGIN,
\r
223 case WM_GETMINMAXINFO:
\r
225 MINMAXINFO * mmi = (MINMAXINFO *) lParam;
\r
227 mmi->ptMinTrackSize.x = 100;
\r
228 mmi->ptMinTrackSize.y = 100;
\r
233 MoveHistoryPopDown();
\r
236 case WM_ENTERSIZEMOVE:
\r
237 return OnEnterSizeMove( &sd, hDlg, wParam, lParam );
\r
240 return OnSizing( &sd, hDlg, wParam, lParam );
\r
243 return OnMoving( &sd, hDlg, wParam, lParam );
\r
245 case WM_EXITSIZEMOVE:
\r
246 return OnExitSizeMove( &sd, hDlg, wParam, lParam );
\r
252 // ------------ standard entry points into MoveHistory code -----------
\r
255 VOID MoveHistoryPopUp()
\r
259 CheckMenuItem(GetMenu(hwndMain), IDM_ShowMoveHistory, MF_CHECKED);
\r
261 if( moveHistoryDialog ) {
\r
262 SendMessage( moveHistoryDialog, WM_INITDIALOG, 0, 0 );
\r
264 if( ! moveHistoryDialogUp ) {
\r
265 ShowWindow(moveHistoryDialog, SW_SHOW);
\r
269 lpProc = MakeProcInstance( (FARPROC) HistoryDialogProc, hInst );
\r
271 /* Note to self: dialog must have the WS_VISIBLE style set, otherwise it's not shown! */
\r
272 CreateDialog( hInst, MAKEINTRESOURCE(DLG_MoveHistory), hwndMain, (DLGPROC)lpProc );
\r
274 FreeProcInstance(lpProc);
\r
277 moveHistoryDialogUp = TRUE;
\r
279 // Note that in WIndows creating the dialog causes its call-back to perform
\r
280 // RefreshMemoContent() and MemoContentUpdated() immediately after it is realized.
\r
281 // To port this to X we might have to do that from here.
\r
285 VOID MoveHistoryPopDown()
\r
287 CheckMenuItem(GetMenu(hwndMain), IDM_ShowMoveHistory, MF_UNCHECKED);
\r
289 if( moveHistoryDialog ) {
\r
290 ShowWindow(moveHistoryDialog, SW_HIDE);
\r
293 moveHistoryDialogUp = FALSE;
\r
297 Boolean MoveHistoryIsUp()
\r
299 return moveHistoryDialogUp;
\r
303 Boolean MoveHistoryDialogExists()
\r
305 return moveHistoryDialog != NULL;
\r