Added a command-line option -keepLineBreaksICS true/false to control line joining.
[xboard.git] / winboard / winboard.c
index bcd0c9c..884c85c 100644 (file)
@@ -1392,6 +1392,7 @@ ArgDescriptor argDescriptors[] = {
   { "firstNPS", ArgInt, (LPVOID) &appData.firstNPS, FALSE },\r
   { "secondNPS", ArgInt, (LPVOID) &appData.secondNPS, FALSE },\r
   { "noGUI", ArgTrue, (LPVOID) &appData.noGUI, FALSE },\r
+  { "keepLineBreaksICS", ArgBoolean, (LPVOID) &appData.noJoin, TRUE },\r
 \r
   // [HGM] placement: put all window layouts last in ini file, but man X,Y before all others\r
   { "minX", ArgZ, (LPVOID) &minX, FALSE }, // [HGM] placement: to make suer auxialary windows can be placed\r
@@ -5456,6 +5457,36 @@ LoadGameDialog(HWND hwnd, char* title)
   }\r
 }\r
 \r
+void UpdateICSWidth(HWND hText)\r
+{\r
+       HDC hdc;\r
+       TEXTMETRIC tm;\r
+       RECT rc;\r
+       HFONT hfont, hold_font;\r
+       LONG old_width, new_width;\r
+       \r
+       // get the text metrics\r
+       hdc = GetDC(hText);\r
+       hfont = CreateFontIndirect(&font[boardSize][CONSOLE_FONT]->lf);\r
+       hold_font = SelectObject(hdc, hfont);\r
+       GetTextMetrics(hdc, &tm);\r
+       SelectObject(hdc, hold_font);\r
+       DeleteObject(hfont);\r
+       ReleaseDC(hText, hdc);\r
+\r
+       // get the rectangle\r
+       SendMessage(hText, EM_GETRECT, 0, (LPARAM)&rc);\r
+\r
+       // update the width\r
+       new_width = (rc.right-rc.left) / tm.tmAveCharWidth;\r
+       old_width = GetWindowLong(hText, GWL_USERDATA);\r
+       if (new_width != old_width)\r
+       {\r
+               ics_update_width(new_width);\r
+               SetWindowLong(hText, GWL_USERDATA, new_width);\r
+       }\r
+}\r
+\r
 VOID\r
 ChangedConsoleFont()\r
 {\r
@@ -5495,6 +5526,7 @@ ChangedConsoleFont()
   paraf.dxOffset = WRAP_INDENT;\r
   SendMessage(hText, EM_SETPARAFORMAT, 0, (LPARAM) &paraf);\r
   SendMessage(hText, EM_EXSETSEL, 0, (LPARAM)&sel);\r
+  UpdateICSWidth(hText);\r
 }\r
 \r
 /*---------------------------------------------------------------------------*\\r
@@ -8099,12 +8131,15 @@ LRESULT CALLBACK
 ConsoleWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
 {\r
   static SnapData sd;\r
-  static HWND hText, hInput /*, hFocus*/;\r
-//  InputSource *is = consoleInputSource;\r
+  HWND hText, hInput;\r
   RECT rect;\r
   static int sizeX, sizeY;\r
   int newSizeX, newSizeY;\r
   MINMAXINFO *mmi;\r
+  WORD wMask;\r
+\r
+  hText = GetDlgItem(hDlg, OPT_ConsoleText);\r
+  hInput = GetDlgItem(hDlg, OPT_ConsoleInput);\r
 \r
   switch (message) {\r
   case WM_NOTIFY:\r
@@ -8113,21 +8148,18 @@ ConsoleWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       ENLINK *pLink = (ENLINK*)lParam;\r
       if (pLink->msg == WM_LBUTTONUP)\r
       {\r
-          TEXTRANGE tr;\r
-\r
-          tr.chrg = pLink->chrg;\r
-          tr.lpstrText = malloc(1+tr.chrg.cpMax-tr.chrg.cpMin);\r
-          hText = GetDlgItem(hDlg, OPT_ConsoleText);\r
-          SendMessage(hText, EM_GETTEXTRANGE, 0, (LPARAM)&tr);\r
-          ShellExecute(NULL, "open", tr.lpstrText, NULL, NULL, SW_SHOW);\r
-          free(tr.lpstrText);\r
+        TEXTRANGE tr;\r
+\r
+        tr.chrg = pLink->chrg;\r
+        tr.lpstrText = malloc(1+tr.chrg.cpMax-tr.chrg.cpMin);\r
+        SendMessage(hText, EM_GETTEXTRANGE, 0, (LPARAM)&tr);\r
+        ShellExecute(NULL, "open", tr.lpstrText, NULL, NULL, SW_SHOW);\r
+        free(tr.lpstrText);\r
       }\r
     }\r
     break;\r
   case WM_INITDIALOG: /* message: initialize dialog box */\r
     hwndConsole = hDlg;\r
-    hText = GetDlgItem(hDlg, OPT_ConsoleText);\r
-    hInput = GetDlgItem(hDlg, OPT_ConsoleInput);\r
     SetFocus(hInput);\r
     consoleTextWindowProc = (WNDPROC)\r
       SetWindowLong(hText, GWL_WNDPROC, (LONG) ConsoleTextSubclass);\r
@@ -8175,6 +8207,12 @@ ConsoleWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
        SetWindowPlacement(hDlg, &wp);\r
     }\r
 \r
+   // Allow hText to highlight URLs and send notifications on them\r
+   wMask = SendMessage(hText, EM_GETEVENTMASK, 0, 0L);\r
+   SendMessage(hText, EM_SETEVENTMASK, 0, wMask | ENM_LINK);\r
+   SendMessage(hText, EM_AUTOURLDETECT, TRUE, 0L);\r
+   SetWindowLong(hText, GWL_USERDATA, 79); // initialize the text window's width\r
+\r
     return FALSE;\r
 \r
   case WM_SETFOCUS:\r
@@ -8234,6 +8272,7 @@ ConsoleWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     return OnMoving( &sd, hDlg, wParam, lParam );\r
 \r
   case WM_EXITSIZEMOVE:\r
+       UpdateICSWidth(hText);\r
     return OnExitSizeMove( &sd, hDlg, wParam, lParam );\r
   }\r
 \r
@@ -8244,18 +8283,10 @@ ConsoleWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 VOID\r
 ConsoleCreate()\r
 {\r
-  HWND hCons, hText;\r
-  WORD wMask;\r
+  HWND hCons;\r
   if (hwndConsole) return;\r
   hCons = CreateDialog(hInst, szConsoleName, 0, NULL);\r
   SendMessage(hCons, WM_INITDIALOG, 0, 0);\r
-\r
-\r
-  // make the text item in the console do URL links\r
-  hText = GetDlgItem(hCons, OPT_ConsoleText);\r
-  wMask = SendMessage(hText, EM_GETEVENTMASK, 0, 0L);\r
-  SendMessage(hText, EM_SETEVENTMASK, 0, wMask | ENM_LINK);\r
-  SendMessage(hText, EM_AUTOURLDETECT, TRUE, 0L);\r
 }\r
 \r
 \r
@@ -9512,6 +9543,11 @@ DrawPosition(int fullRedraw, Board board)
   HDCDrawPosition(NULL, (BOOLEAN) fullRedraw, board); \r
 }\r
 \r
+void NotifyFrontendLogin()\r
+{\r
+       if (hwndConsole)\r
+               UpdateICSWidth(GetDlgItem(hwndConsole, OPT_ConsoleText));\r
+}\r
 \r
 VOID\r
 ResetFrontEnd()\r