This patch adds <Enter> to the characters that cause an automatic switch to the ICS...
[xboard.git] / winboard / winboard.c
index 4ab4f93..24fd967 100644 (file)
@@ -1393,7 +1393,9 @@ ArgDescriptor argDescriptors[] = {
   { "secondNPS", ArgInt, (LPVOID) &appData.secondNPS, FALSE },\r
   { "noGUI", ArgTrue, (LPVOID) &appData.noGUI, FALSE },\r
   { "keepLineBreaksICS", ArgBoolean, (LPVOID) &appData.noJoin, TRUE },\r
-\r
+  { "wrapContinuationSequence", ArgString, (LPVOID) &appData.wrapContSeq, FALSE },\r
+  { "useInternalWrap", ArgTrue, (LPVOID) &appData.useInternalWrap, FALSE }, /* noJoin usurps this if set */\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
   { "minY", ArgZ, (LPVOID) &minY, FALSE },\r
@@ -1494,6 +1496,10 @@ ParseFontName(char *name, MyFontParams *mfp)
   mfp->italic = (strchr(p, 'i') != NULL);\r
   mfp->underline = (strchr(p, 'u') != NULL);\r
   mfp->strikeout = (strchr(p, 's') != NULL);\r
+  mfp->charset = DEFAULT_CHARSET;\r
+  q = strchr(p, 'c');\r
+  if (q)\r
+    mfp->charset = (BYTE) atoi(q+1);\r
 }\r
 \r
 /* Color name parser.\r
@@ -1868,7 +1874,7 @@ LFfromMFP(LOGFONT* lf, MyFontParams *mfp)
   lf->lfItalic = mfp->italic;\r
   lf->lfUnderline = mfp->underline;\r
   lf->lfStrikeOut = mfp->strikeout;\r
-  lf->lfCharSet = DEFAULT_CHARSET;\r
+  lf->lfCharSet = mfp->charset;\r
   lf->lfOutPrecision = OUT_DEFAULT_PRECIS;\r
   lf->lfClipPrecision = CLIP_DEFAULT_PRECIS;\r
   lf->lfQuality = DEFAULT_QUALITY;\r
@@ -2491,13 +2497,14 @@ SaveSettings(char* name)
        for (bs=0; bs<NUM_SIZES; bs++) {\r
          MyFontParams *mfp = &font[bs][(int) ad->argLoc]->mfp;\r
           fprintf(f, "/size=%s ", sizeInfo[bs].name);\r
-         fprintf(f, "/%s=\"%s:%g%s%s%s%s%s\"\n",\r
+         fprintf(f, "/%s=\"%s:%g%s%s%s%s%sc%d\"\n",\r
            ad->argName, mfp->faceName, mfp->pointSize,\r
             mfp->bold || mfp->italic || mfp->underline || mfp->strikeout ? " " : "",\r
            mfp->bold ? "b" : "",\r
            mfp->italic ? "i" : "",\r
            mfp->underline ? "u" : "",\r
-           mfp->strikeout ? "s" : "");\r
+           mfp->strikeout ? "s" : "",\r
+            (int)mfp->charset);\r
        }\r
       }\r
       break;\r
@@ -5277,34 +5284,55 @@ LoadGameDialog(HWND hwnd, char* title)
   }\r
 }\r
 \r
+int get_term_width()\r
+{\r
+    HDC hdc;\r
+    TEXTMETRIC tm;\r
+    RECT rc;\r
+    HFONT hfont, hold_font;\r
+    LOGFONT lf;\r
+    HWND hText;\r
+\r
+    if (hwndConsole)\r
+        hText = GetDlgItem(hwndConsole, OPT_ConsoleText);\r
+    else\r
+        return 79;\r
+\r
+    // get the text metrics\r
+    hdc = GetDC(hText);\r
+    lf = font[boardSize][CONSOLE_FONT]->lf;\r
+    if (consoleCF.dwEffects & CFE_BOLD)\r
+        lf.lfWeight = FW_BOLD;\r
+    if (consoleCF.dwEffects & CFE_ITALIC)\r
+        lf.lfItalic = TRUE;\r
+    if (consoleCF.dwEffects & CFE_STRIKEOUT)\r
+        lf.lfStrikeOut = TRUE;\r
+    if (consoleCF.dwEffects & CFE_UNDERLINE)\r
+        lf.lfUnderline = TRUE;\r
+    hfont = CreateFontIndirect(&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
+    return (rc.right-rc.left) / tm.tmAveCharWidth;\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
+    LONG old_width, new_width;\r
+\r
+    new_width = get_term_width(hText, FALSE);\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
@@ -5400,7 +5428,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     \r
     JAWS_ALT_INTERCEPT\r
 \r
-    if (appData.icsActive && (char)wParam > ' ' && !((char)wParam >= '1' && (char)wParam <= '9')) { \r
+    if (appData.icsActive && ((char)wParam == '\r' || (char)wParam > ' ' && !((char)wParam >= '1' && (char)wParam <= '9'))) { \r
        // [HGM] movenum: for non-zero digits we always do type-in dialog\r
        HWND h = GetDlgItem(hwndConsole, OPT_ConsoleInput);\r
        if (IsIconic(hwndConsole)) ShowWindow(hwndConsole, SW_RESTORE);\r
@@ -8026,7 +8054,7 @@ ConsoleWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     }\r
 \r
    // Allow hText to highlight URLs and send notifications on them\r
-   wMask = SendMessage(hText, EM_GETEVENTMASK, 0, 0L);\r
+   wMask = (WORD) 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
@@ -10340,6 +10368,11 @@ RemoveInputSource(InputSourceRef isr)
   }\r
 }\r
 \r
+int no_wrap(char *message, int count)\r
+{\r
+    ConsoleOutput(message, count, FALSE);\r
+    return count;\r
+}\r
 \r
 int\r
 OutputToProcess(ProcRef pr, char *message, int count, int *outError)\r
@@ -10348,11 +10381,32 @@ OutputToProcess(ProcRef pr, char *message, int count, int *outError)
   int outCount = SOCKET_ERROR;\r
   ChildProc *cp = (ChildProc *) pr;\r
   static OVERLAPPED ovl;\r
+  static int line = 0;\r
 \r
-  if (pr == NoProc) {\r
-    ConsoleOutput(message, count, FALSE);\r
-    return count;\r
-  } \r
+  if (pr == NoProc)\r
+  {\r
+    if (appData.noJoin || !appData.useInternalWrap)\r
+      return no_wrap(message, count);\r
+    else\r
+    {\r
+      int width = get_term_width();\r
+      int len = wrap(NULL, message, count, width, &line);\r
+      char *msg = malloc(len);\r
+      int dbgchk;\r
+\r
+      if (!msg)\r
+        return no_wrap(message, count);\r
+      else\r
+      {\r
+        dbgchk = wrap(msg, message, count, width, &line);\r
+        if (dbgchk != len && appData.debugMode)\r
+            fprintf(debugFP, "wrap(): dbgchk(%d) != len(%d)\n", dbgchk, len);\r
+        ConsoleOutput(msg, len, FALSE);\r
+        free(msg);\r
+        return len;\r
+      }\r
+    }\r
+  }\r
 \r
   if (ovl.hEvent == NULL) {\r
     ovl.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);\r