4 * Author: H.G.Muller (August 2009)
\r
6 * ------------------------------------------------------------------------
\r
8 * GNU XBoard is free software: you can redistribute it and/or modify
\r
9 * it under the terms of the GNU General Public License as published by
\r
10 * the Free Software Foundation, either version 3 of the License, or (at
\r
11 * your option) any later version.
\r
13 * GNU XBoard is distributed in the hope that it will be useful, but
\r
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
16 * General Public License for more details.
\r
18 * You should have received a copy of the GNU General Public License
\r
19 * along with this program. If not, see http://www.gnu.org/licenses/. *
\r
21 *------------------------------------------------------------------------
\r
22 ** See the file ChangeLog for a revision history. */
\r
26 #include <windows.h> /* required for all Windows applications */
\r
27 #include <richedit.h>
\r
31 #include <commdlg.h>
\r
35 #include "winboard.h"
\r
36 #include "frontend.h"
\r
37 #include "backend.h"
\r
42 extern char chatPartner[MAX_CHAT][MSG_SIZ];
\r
43 HANDLE chatHandle[MAX_CHAT];
\r
45 void SendToICS P((char *s));
\r
49 /* Imports from backend.c */
\r
50 char * SavePart(char *str);
\r
51 extern int opponentKibitzes;
\r
53 /* Imports from winboard.c */
\r
54 extern HWND ChatDialog;
\r
56 extern HINSTANCE hInst;
\r
57 extern HWND hwndMain;
\r
59 extern WindowPlacement wpChat[MAX_CHAT];
\r
61 extern BoardSize boardSize;
\r
63 /* Module variables */
\r
67 // front end, although we might make GetWindowRect front end instead
\r
68 static int GetControlWidth( HWND hDlg, int id )
\r
72 GetWindowRect( GetDlgItem( hDlg, id ), &rc );
\r
74 return rc.right - rc.left;
\r
78 static int GetControlHeight( HWND hDlg, int id )
\r
82 GetWindowRect( GetDlgItem( hDlg, id ), &rc );
\r
84 return rc.bottom - rc.top;
\r
87 static void SetControlPos( HWND hDlg, int id, int x, int y, int width, int height )
\r
89 HWND hControl = GetDlgItem( hDlg, id );
\r
91 SetWindowPos( hControl, HWND_TOP, x, y, width, height, SWP_NOZORDER );
\r
94 // Also here some of the size calculations should go to the back end, and their actual application to a front-end routine
\r
95 static void ResizeWindowControls( HWND hDlg )
\r
100 int maxControlWidth;
\r
101 int buttonWidth, buttonHeight;
\r
103 /* Initialize variables */
\r
104 GetClientRect( hDlg, &rc );
\r
106 clientWidth = rc.right - rc.left;
\r
107 clientHeight = rc.bottom - rc.top;
\r
109 maxControlWidth = clientWidth - 2*H_MARGIN;
\r
110 buttonWidth = GetControlWidth(hDlg, IDC_Send);
\r
111 buttonHeight = GetControlHeight(hDlg, IDC_Send);
\r
113 /* Resize controls */
\r
114 SetControlPos( hDlg, IDC_Clear, maxControlWidth+H_MARGIN-2*buttonWidth-5, V_MARGIN, buttonWidth, buttonHeight );
\r
115 SetControlPos( hDlg, IDC_Send, maxControlWidth+H_MARGIN-buttonWidth, V_MARGIN, buttonWidth, buttonHeight );
\r
116 SetControlPos( hDlg, IDC_ChatMemo, H_MARGIN, 2*V_MARGIN+buttonHeight, maxControlWidth, clientHeight-3*V_MARGIN-2*buttonHeight );
\r
117 SetControlPos( hDlg, OPT_ChatInput, H_MARGIN, clientHeight-V_MARGIN-buttonHeight, maxControlWidth, buttonHeight );
\r
119 // InvalidateRect( GetDlgItem(hDlg,IDC_EngineMemo1), NULL, FALSE );
\r
120 // InvalidateRect( GetDlgItem(hDlg,IDC_EngineMemo2), NULL, FALSE );
\r
123 // front end. Actual printing of PV lines into the output field
\r
124 static void InsertIntoMemo( HANDLE hDlg, char * text )
\r
126 HANDLE hMemo = GetDlgItem(hDlg, IDC_ChatMemo);
\r
128 SendMessage( hMemo, EM_SETSEL, 1000000, 1000000 );
\r
130 SendMessage( hMemo, EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) text );
\r
131 SendMessage( hMemo, EM_SCROLLCARET, 0, 0);
\r
134 // This seems pure front end
\r
135 LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
\r
137 static SnapData sd;
\r
138 char buf[MSG_SIZ], mess[MSG_SIZ];
\r
139 int partner = -1, i;
\r
141 for(i=0; i<MAX_CHAT; i++) if(hDlg == chatHandle[i]) { partner = i; break; }
\r
144 case WM_INITDIALOG:
\r
146 for(i=0; i<MAX_CHAT; i++) if(chatHandle[i] == NULL) { partner = i; break; }
\r
147 chatHandle[partner] = hDlg;
\r
148 sprintf(buf, "Chat Window %s", first.tidy);
\r
149 SetWindowText(hDlg, buf);
\r
151 chatPartner[partner][0] = 0;
\r
156 switch (LOWORD(wParam)) {
\r
159 chatHandle[partner] = 0;
\r
160 chatPartner[partner][0] = 0;
\r
162 EndDialog(hDlg, TRUE);
\r
166 SendMessage( GetDlgItem(hDlg, IDC_ChatMemo), WM_SETTEXT, 0, (LPARAM) "" );
\r
170 GetDlgItemText(hDlg, IDC_ChatPartner, chatPartner[partner], MSG_SIZ);
\r
174 GetDlgItemText(hDlg, OPT_ChatInput, mess, MSG_SIZ);
\r
175 SetDlgItemText(hDlg, OPT_ChatInput, "");
\r
176 // from here on it could be back-end
\r
177 if(!strcmp("WHISPER", chatPartner[partner]))
\r
178 sprintf(buf, "whisper %s\n", mess); // WHISPER box uses "whisper" to send
\r
180 if(!atoi(chatPartner[partner])) {
\r
181 sprintf(buf, "> %s\n", mess); // echo only tells to handle, not channel
\r
182 InsertIntoMemo(hDlg, buf);
\r
184 sprintf(buf, "tell %s %s\n", chatPartner[partner], mess);
\r
196 chatHandle[partner] = 0;
\r
197 chatPartner[partner][0] = 0;
\r
199 EndDialog(hDlg, TRUE);
\r
203 ResizeWindowControls( hDlg );
\r
206 case WM_ENTERSIZEMOVE:
\r
207 return OnEnterSizeMove( &sd, hDlg, wParam, lParam );
\r
210 return OnSizing( &sd, hDlg, wParam, lParam );
\r
213 return OnMoving( &sd, hDlg, wParam, lParam );
\r
215 case WM_EXITSIZEMOVE:
\r
216 return OnExitSizeMove( &sd, hDlg, wParam, lParam );
\r
227 if(chatCount >= MAX_CHAT) return;
\r
229 CheckMenuItem(GetMenu(hwndMain), IDM_NewChat, MF_CHECKED);
\r
232 lpProc = MakeProcInstance( (FARPROC) ChatProc, hInst );
\r
234 /* Note to self: dialog must have the WS_VISIBLE style set, otherwise it's not shown! */
\r
235 CreateDialog( hInst, MAKEINTRESOURCE(DLG_Chat), hwndMain, (DLGPROC)lpProc );
\r
237 FreeProcInstance(lpProc);
\r
244 if(--chatCount <= 0)
\r
245 CheckMenuItem(GetMenu(hwndMain), IDM_NewChat, MF_UNCHECKED);
\r
249 //------------------------ pure back-end routines -------------------------------
\r
251 void OutputChatMessage(int partner, char *text)
\r
253 if(!chatHandle[partner]) return;
\r
255 InsertIntoMemo(chatHandle[partner], text);
\r