Make Chat Windows pseudo-tabbed
authorH.G. Muller <h.g.muller@hccnet.nl>
Tue, 16 Feb 2010 18:44:46 +0000 (19:44 +0100)
committerH.G. Muller <h.g.muller@hccnet.nl>
Fri, 19 Feb 2010 21:41:21 +0000 (22:41 +0100)
By adding buttons in every Chat Box to navigate directly to every other
Chat Box, a stacked set of Chat Windows behaves like a single tabbed
window, but can still be unstacked. The buttons turn grey to warn that
new text appeared in hidden boxes (i.e. not the one last brought to top).

common.h
winboard/resource.h
winboard/wchat.c
winboard/winboard.rc

index 745ceac..35c04c8 100644 (file)
--- a/common.h
+++ b/common.h
@@ -717,7 +717,7 @@ extern WindowPlacement wpGameList;
 extern WindowPlacement wpTags;
 
 // [HGM] chat  
-#define MAX_CHAT 3
+#define MAX_CHAT 5
 extern int chatCount;
 extern char chatPartner[MAX_CHAT][MSG_SIZ];
 
index 9092c29..f6a1f5f 100644 (file)
 #define IDC_Clear                      1725\r
 #define IDC_Send                       1726\r
 #define IDM_NewChat                    1727\r
+#define IDC_Focus1                     1730\r
+#define IDC_Focus2                     1731\r
+#define IDC_Focus3                     1732\r
+#define IDC_Focus4                     1733\r
 #define IDC_SPECIFY_ENG_STATIC          1814\r
 #define IDC_SPECIFY_SERVER_STATIC       1815\r
 #define OPT_MESS                        1818\r
index 8d53d7c..3b90b2c 100644 (file)
@@ -32,6 +32,7 @@
 #include <malloc.h>\r
 #include <commdlg.h>\r
 #include <dlgs.h>\r
+#include <Windowsx.h>\r
 \r
 #include "common.h"\r
 #include "frontend.h"\r
@@ -41,6 +42,7 @@
 #include "wsnap.h"\r
 \r
 int chatCount;\r
+static int onTop;\r
 extern char chatPartner[MAX_CHAT][MSG_SIZ];\r
 HANDLE chatHandle[MAX_CHAT];\r
 static WNDPROC chatInputWindowProc;\r
@@ -62,6 +64,7 @@ extern HINSTANCE hInst;
 extern HWND hwndMain;\r
 \r
 extern WindowPlacement wpChat[MAX_CHAT];\r
+extern WindowPlacement wpConsole;\r
 \r
 extern BoardSize boardSize;\r
 \r
@@ -192,7 +195,15 @@ LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam
                sprintf(buf, "Chat Window %s", first.tidy);\r
                SetWindowText(hDlg, buf);\r
         }\r
-//     chatPartner[partner][0] = 0;\r
+       for(i=0; i<MAX_CHAT; i++) if(chatHandle[i] && i != partner) {\r
+           // set our button in other open chats\r
+           SetDlgItemText(chatHandle[i], IDC_Focus1+partner-(i<partner), chatPartner[partner]);\r
+           EnableWindow( GetDlgItem(chatHandle[i], IDC_Focus1+partner-(i<partner)), 1 );\r
+           // and buttons for other chats in ours\r
+           SetDlgItemText(hDlg, IDC_Focus1+i-(i>partner), chatPartner[i]);\r
+       } else EnableWindow( GetDlgItem(hDlg, IDC_Focus1+i-(i>partner)), 1 );\r
+       for(i=0; i<MAX_CHAT-1; i++) { Button_SetStyle(GetDlgItem(hDlg, IDC_Focus1+i), BS_PUSHBUTTON|BS_LEFT, TRUE); }\r
+        SetWindowPos(hDlg, NULL, wpConsole.x, wpConsole.y, 0, 0, SWP_NOZORDER|SWP_NOSIZE);\r
        SendMessage( GetDlgItem(hDlg, IDC_ChatPartner), // [HGM] clickbox: initialize with requested handle\r
                        WM_SETTEXT, 0, (LPARAM) chatPartner[partner] );\r
        filterHasFocus[partner] = TRUE;\r
@@ -263,6 +274,10 @@ LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam
 \r
        case IDC_Change:\r
            GetDlgItemText(hDlg, IDC_ChatPartner, chatPartner[partner], MSG_SIZ);\r
+           for(i=0; i<MAX_CHAT; i++) if(chatHandle[i] && i != partner) {\r
+             // set our button in other open chats\r
+             SetDlgItemText(chatHandle[i], IDC_Focus1+partner-(i<partner), chatPartner[partner]);\r
+           }\r
            break;\r
 \r
        case IDC_Send:\r
@@ -283,6 +298,22 @@ LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam
            SendToICS(buf);\r
            break;\r
 \r
+       case IDC_Focus1:\r
+       case IDC_Focus2:\r
+       case IDC_Focus3:\r
+       case IDC_Focus4:\r
+           i = LOWORD(wParam) - IDC_Focus1;\r
+           if(i >= partner) i++;\r
+           onTop = i;\r
+           SetFocus(GetDlgItem(hDlg, IDC_Send));\r
+           if(chatHandle[i]) {\r
+               int j;\r
+               for(j=0; j<MAX_CHAT; j++) if(i != j && chatHandle[j])\r
+                   Button_SetState(GetDlgItem(chatHandle[j], IDC_Focus1+i-(j<i)), FALSE);\r
+               SetFocus(GetDlgItem(chatHandle[i], OPT_ChatInput));\r
+           }\r
+           break;\r
+\r
         default:\r
           break;\r
         }\r
@@ -293,6 +324,11 @@ LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam
        chatHandle[partner] = 0;\r
        chatPartner[partner][0] = 0;\r
         ChatPopDown();\r
+       for(i=0; i<MAX_CHAT; i++) if(chatHandle[i] && i != partner) {\r
+           // set our button in other open chats\r
+           SetDlgItemText(chatHandle[i], IDC_Focus1+partner-(i<partner), "");\r
+           EnableWindow( GetDlgItem(chatHandle[i], IDC_Focus1+partner-(i<partner)), 0 );\r
+       }\r
        EndDialog(hDlg, TRUE);\r
         break;\r
 \r
@@ -351,9 +387,12 @@ void ChatPopDown()
 \r
 void OutputChatMessage(int partner, char *text)\r
 {\r
+       int j;\r
        if(!chatHandle[partner]) return;\r
 \r
        int n = strlen(text);\r
        text[n+1] = 0; text[n] = '\n'; text[n-1] = '\r'; // Needs CR to not lose line breaks on copy-paste\r
        InsertIntoMemo(chatHandle[partner], text);\r
+       if(partner != onTop) for(j=0; j<MAX_CHAT; j++) if(j != partner && chatHandle[j])\r
+           Button_SetState(GetDlgItem(chatHandle[j], IDC_Focus1+partner-(j<partner)), TRUE);\r
 }\r
index 15d94dc..35f202f 100644 (file)
@@ -823,22 +823,25 @@ BEGIN
     ICON            IDI_TRANS_14,IDC_StateIcon2,164,84,20,20\r
 END\r
 \r
-DLG_Chat DIALOGEX 0, 0, 256, 106\r
+DLG_Chat DIALOGEX 0, 0, 290, 106\r
 STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME\r
 EXSTYLE WS_EX_TOOLWINDOW\r
 CAPTION "Chat Window"\r
 FONT 8, "MS Sans Serif"\r
 BEGIN\r
     LTEXT           "Chat partner:",IDC_STATIC,5,5,45,10\r
-    EDITTEXT        IDC_ChatPartner,50,3,100,13,ES_AUTOHSCROLL\r
-    PUSHBUTTON      "Change",IDC_Change,155,3,35,13\r
-    PUSHBUTTON      "Clear",IDC_Clear,198,3,25,13\r
-    DEFPUSHBUTTON   "Send",IDC_Send,228,3,25,13\r
+    EDITTEXT        IDC_ChatPartner,50,3,45,13,ES_AUTOHSCROLL\r
+    PUSHBUTTON      "",IDC_Focus1,100,3,30,13\r
+    PUSHBUTTON      "",IDC_Focus2,133,3,30,13\r
+    PUSHBUTTON      "",IDC_Focus3,166,3,30,13\r
+    PUSHBUTTON      "",IDC_Focus4,199,3,30,13\r
+    PUSHBUTTON      "Clear",IDC_Clear,232,3,25,13\r
+    DEFPUSHBUTTON   "Send",IDC_Send,262,3,25,13\r
     CONTROL         "",IDC_ChatMemo,"RICHEDIT",ES_MULTILINE | ES_READONLY |\r
                     ES_AUTOVSCROLL | WS_BORDER | WS_VSCROLL | \r
-                    WS_HSCROLL | WS_TABSTOP,3,17,250,70\r
+                    WS_HSCROLL | WS_TABSTOP,3,17,284,70\r
     CONTROL         "",OPT_ChatInput,"RICHEDIT",ES_AUTOHSCROLL | ES_NOHIDESEL | \r
-                    WS_BORDER | WS_TABSTOP,3,90,250,13\r
+                    WS_BORDER | WS_TABSTOP,3,90,284,13\r
 END\r
 \r
 DLG_EnginePlayOptions DIALOG DISCARDABLE  0, 0, 208, 202\r