Display PV right-clicked from EngineOutput window
[xboard.git] / winboard / wengineoutput.c
index bb51525..2acb145 100644 (file)
@@ -223,12 +223,39 @@ void ResizeWindowControls( int mode )
     InvalidateRect( GetDlgItem(hDlg,IDC_EngineMemo2), NULL, FALSE );\r
 }\r
 \r
+static int currentPV, highTextStart[2], highTextEnd[2];\r
+extern RECT boardRect;\r
+\r
+VOID\r
+GetMemoLine(HWND hDlg, int x, int y)\r
+{      // [HGM] pv: translate click to PV line, and load it for display\r
+       char buf[10000];\r
+       int index, start, end, memo;\r
+       POINT pt;\r
+\r
+       pt.x = x; pt.y = y;\r
+       memo = currentPV ? IDC_EngineMemo2 : IDC_EngineMemo1;\r
+       index = SendDlgItemMessage( hDlg, memo, EM_CHARFROMPOS, 0, (LPARAM) &pt );\r
+       GetDlgItemText(hDlg, memo, buf, sizeof(buf));\r
+       if(LoadMultiPV(x, y, buf, index, &start, &end)) {\r
+           SetCapture(hDlg);\r
+           SendMessage( outputField[currentPV][nMemo], EM_SETSEL, (WPARAM)start, (LPARAM)end );\r
+           highTextStart[currentPV] = start; highTextEnd[currentPV] = end;\r
+           SetFocus(outputField[currentPV][nMemo]);\r
+       }\r
+}\r
+\r
 // front end. Actual printing of PV lines into the output field\r
 void InsertIntoMemo( int which, char * text, int where )\r
 {\r
     SendMessage( outputField[which][nMemo], EM_SETSEL, where, where ); // [HGM] multivar: choose insertion point\r
 \r
     SendMessage( outputField[which][nMemo], EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) text );\r
+    if(where < highTextStart[which]) { // [HGM] multiPVdisplay: move highlighting\r
+       int len = strlen(text);\r
+       highTextStart[which] += len; highTextEnd[which] += len;\r
+       SendMessage( outputField[which][nMemo], EM_SETSEL, highTextStart[which], highTextEnd[which] );\r
+    }\r
 }\r
 \r
 // front end. Associates an icon with an output field ("control" in Windows jargon).\r
@@ -261,6 +288,9 @@ LRESULT CALLBACK EngineOutputProc( HWND hDlg, UINT message, WPARAM wParam, LPARA
 \r
             ResizeWindowControls( windowMode );\r
 \r
+            SendDlgItemMessage( hDlg, IDC_EngineMemo1, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS );\r
+            SendDlgItemMessage( hDlg, IDC_EngineMemo2, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS );\r
+\r
            /* Set font */\r
            SendDlgItemMessage( engineOutputDialog, IDC_EngineMemo1, WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, MAKELPARAM(TRUE, 0 ));\r
            SendDlgItemMessage( engineOutputDialog, IDC_EngineMemo2, WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, MAKELPARAM(TRUE, 0 ));\r
@@ -287,6 +317,27 @@ LRESULT CALLBACK EngineOutputProc( HWND hDlg, UINT message, WPARAM wParam, LPARA
 \r
         break;\r
 \r
+    case WM_MOUSEMOVE:\r
+        MovePV(LOWORD(lParam) - boardRect.left, HIWORD(lParam) - boardRect.top, boardRect.bottom - boardRect.top);\r
+        break;\r
+\r
+    case WM_RBUTTONUP:\r
+        ReleaseCapture();\r
+        SendMessage( outputField[currentPV][nMemo], EM_SETSEL, 0, 0 );\r
+        highTextStart[currentPV] = highTextEnd[currentPV] = 0;\r
+        UnLoadPV();\r
+        break;\r
+\r
+    case WM_NOTIFY:\r
+        if( wParam == IDC_EngineMemo1 || wParam == IDC_EngineMemo2 ) {\r
+            MSGFILTER * lpMF = (MSGFILTER *) lParam;\r
+            if( lpMF->msg == WM_RBUTTONDOWN && (lpMF->wParam & (MK_CONTROL | MK_SHIFT)) == 0 ) {\r
+                currentPV = (wParam == IDC_EngineMemo2);\r
+                GetMemoLine(hDlg, LOWORD(lpMF->lParam), HIWORD(lpMF->lParam));\r
+            }\r
+        }\r
+        break;\r
+\r
     case WM_GETMINMAXINFO:\r
         {\r
             MINMAXINFO * mmi = (MINMAXINFO *) lParam;\r