Cleaned up ConsoleWndProc (not complete, see below)
[xboard.git] / winboard / winboard.c
index bcd0c9c..5fda158 100644 (file)
@@ -8099,12 +8099,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 +8116,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 +8175,11 @@ 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
+\r
     return FALSE;\r
 \r
   case WM_SETFOCUS:\r
@@ -8244,18 +8249,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