Added width updates to ICS client on font and window size changes
authorEric Mullins <emwine@earthlink.net>
Sat, 10 Oct 2009 20:21:12 +0000 (14:21 -0600)
committerEric Mullins <emwine@earthlink.net>
Sat, 10 Oct 2009 20:21:12 +0000 (14:21 -0600)
What still needs to be done is placing an update call after login
to initialize with the correct width.  I didn't see where to put
that.

winboard/winboard.c

index 5fda158..e6fcb8b 100644 (file)
@@ -5456,6 +5456,29 @@ 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
+       \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
+       ics_update_width((rc.right-rc.left) / tm.tmAveCharWidth);\r
+}\r
+\r
 VOID\r
 ChangedConsoleFont()\r
 {\r
@@ -5495,6 +5518,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
@@ -8239,6 +8263,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