| 1 |
/* |
| 2 |
* Copyright (C) 2020- TeraTerm Project |
| 3 |
* All rights reserved. |
| 4 |
* |
| 5 |
* Redistribution and use in source and binary forms, with or without |
| 6 |
* modification, are permitted provided that the following conditions |
| 7 |
* are met: |
| 8 |
* |
| 9 |
* 1. Redistributions of source code must retain the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer. |
| 11 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 12 |
* notice, this list of conditions and the following disclaimer in the |
| 13 |
* documentation and/or other materials provided with the distribution. |
| 14 |
* 3. The name of the author may not be used to endorse or promote products |
| 15 |
* derived from this software without specific prior written permission. |
| 16 |
* |
| 17 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR |
| 18 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 19 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 20 |
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
*/ |
| 28 |
|
| 29 |
// vtwin�������� |
| 30 |
|
| 31 |
#include "teraterm.h" |
| 32 |
#include "tttypes.h" |
| 33 |
#include "ttcommon.h" |
| 34 |
#include "ttwinman.h" |
| 35 |
#include "compat_win.h" |
| 36 |
#include "asprintf.h" |
| 37 |
#include "win32helper.h" |
| 38 |
|
| 39 |
#include <stdio.h> |
| 40 |
#define _CRTDBG_MAP_ALLOC |
| 41 |
#include <stdlib.h> |
| 42 |
#include <crtdbg.h> |
| 43 |
#include <string.h> |
| 44 |
#include <windowsx.h> |
| 45 |
#include <commctrl.h> |
| 46 |
#include <wchar.h> // for wmemcpy_s() |
| 47 |
|
| 48 |
#include "ttsetup.h" |
| 49 |
#include "keyboard.h" // for ShiftKey() ControlKey() |
| 50 |
#include "ttlib.h" |
| 51 |
#include "dlglib.h" |
| 52 |
#include "tt_res.h" |
| 53 |
#include "codeconv.h" |
| 54 |
#include "sendmem.h" |
| 55 |
//#include "clipboar.h" // TODO ���� |
| 56 |
#include "ttime.h" |
| 57 |
|
| 58 |
#include "broadcast.h" |
| 59 |
|
| 60 |
|
| 61 |
// WM_COPYDATA�������v���Z�X�����M������ (2005.1.22 yutaka) |
| 62 |
#define IPC_BROADCAST_COMMAND 1 // �S�[�������M |
| 63 |
#define IPC_MULTICAST_COMMAND 2 // �C�����[���Q�����M |
| 64 |
|
| 65 |
/* |
| 66 |
* COPYDATASTRUCT |
| 67 |
* |
| 68 |
* dwData |
| 69 |
* IPC_BROADCAST_COMMAND |
| 70 |
* lpData |
| 71 |
* +--------------+--+ |
| 72 |
* |string |\0| |
| 73 |
* +--------------+--+ |
| 74 |
* <--------------> |
| 75 |
* cbData |
| 76 |
* strlen(string) + 1 |
| 77 |
* (wcslen(string) + 1) * sizeof(wchar_t) |
| 78 |
* buf���������� \0 ���t������ |
| 79 |
* |
| 80 |
* dwData |
| 81 |
* IPC_MULTICAST_COMMAND |
| 82 |
* lpData |
| 83 |
* +------+--------------+--+ |
| 84 |
* |name\0|string |\0| |
| 85 |
* +------+--------------+--+ |
| 86 |
* <---------------------> |
| 87 |
* cbData |
| 88 |
* strlen(string) + 1 + strlen(string) |
| 89 |
* (wcslen(name) + 1 + wcslen(string)) * sizeof(wchar_t) |
| 90 |
* buf���������� \0 ���t������ |
| 91 |
*/ |
| 92 |
|
| 93 |
#define BROADCAST_LOGFILE L"broadcast.log" |
| 94 |
|
| 95 |
/** |
| 96 |
* ���������������t�@�C����(�t���p�X)������ |
| 97 |
* @return �t�@�C���� |
| 98 |
* �s�v���������� free() �������� |
| 99 |
*/ |
| 100 |
static wchar_t *GetHistoryFileName(TTTSet *ts_) |
| 101 |
{ |
| 102 |
wchar_t *fname = NULL; |
| 103 |
awcscats(&fname, ts_->HomeDirW, L"\\", BROADCAST_LOGFILE, NULL); |
| 104 |
return fname; |
| 105 |
} |
| 106 |
|
| 107 |
static void ApplyBroadCastCommandHisotry(HWND Dialog, wchar_t *historyfile) |
| 108 |
{ |
| 109 |
int i = 1; |
| 110 |
|
| 111 |
SendDlgItemMessage(Dialog, IDC_COMMAND_EDIT, CB_RESETCONTENT, 0, 0); |
| 112 |
do { |
| 113 |
wchar_t *EntName; |
| 114 |
wchar_t *Command; |
| 115 |
aswprintf(&EntName, L"Command%d", i); |
| 116 |
hGetPrivateProfileStringW(L"BroadcastCommands", EntName, L"", historyfile, &Command); |
| 117 |
if (Command != NULL && Command[0] != 0) { |
| 118 |
SendDlgItemMessageW(Dialog, IDC_COMMAND_EDIT, CB_ADDSTRING, |
| 119 |
0, (LPARAM)Command); |
| 120 |
} |
| 121 |
else { |
| 122 |
// �I�� |
| 123 |
i = ts.MaxBroadcatHistory; |
| 124 |
} |
| 125 |
free(Command); |
| 126 |
free(EntName); |
| 127 |
i++; |
| 128 |
} while (i <= ts.MaxBroadcatHistory); |
| 129 |
|
| 130 |
SendDlgItemMessage(Dialog, IDC_COMMAND_EDIT, CB_SETCURSEL,0,0); |
| 131 |
} |
| 132 |
|
| 133 |
BOOL IsUnicharSupport(HWND hwnd) |
| 134 |
{ |
| 135 |
LRESULT r = SendMessage(hwnd, WM_UNICHAR, UNICODE_NOCHAR, 0); |
| 136 |
return (BOOL)r; |
| 137 |
} |
| 138 |
|
| 139 |
// �h���b�v�_�E���������G�f�B�b�g�R���g���[���� |
| 140 |
// �T�u�N���X�������������E�C���h�E�v���V�[�W�� |
| 141 |
static WNDPROC OrigBroadcastEditProc; // Original window procedure |
| 142 |
static HWND BroadcastWindowList; |
| 143 |
static LRESULT CALLBACK BroadcastEditProc(HWND dlg, UINT msg, |
| 144 |
WPARAM wParam, LPARAM lParam) |
| 145 |
{ |
| 146 |
char buf[1024]; |
| 147 |
int len; |
| 148 |
static BOOL ime_mode = FALSE; |
| 149 |
|
| 150 |
switch (msg) { |
| 151 |
case WM_CREATE: |
| 152 |
ime_mode = FALSE; |
| 153 |
break; |
| 154 |
|
| 155 |
case WM_DESTROY: |
| 156 |
break; |
| 157 |
|
| 158 |
case WM_LBUTTONUP: |
| 159 |
// �������e�L�X�g�����������������������A�J�[�\���������������������B |
| 160 |
len = GetWindowText(dlg, buf, sizeof(buf)); |
| 161 |
SendMessage(dlg, EM_SETSEL, len, len); |
| 162 |
SetFocus(dlg); |
| 163 |
break; |
| 164 |
|
| 165 |
case WM_LBUTTONDOWN: |
| 166 |
case WM_RBUTTONDOWN: |
| 167 |
case WM_RBUTTONUP: |
| 168 |
SetFocus(dlg); |
| 169 |
break; |
| 170 |
|
| 171 |
case WM_KEYDOWN: |
| 172 |
case WM_KEYUP: |
| 173 |
case WM_SYSKEYDOWN: |
| 174 |
case WM_SYSKEYUP: |
| 175 |
if (ime_mode == FALSE) { |
| 176 |
int i; |
| 177 |
HWND hd; |
| 178 |
int count; |
| 179 |
|
| 180 |
if (wParam == 0x0d) { // Enter key |
| 181 |
SetWindowText(dlg, ""); |
| 182 |
SendMessage(dlg, EM_SETSEL, 0, 0); |
| 183 |
} |
| 184 |
|
| 185 |
count = (int)SendMessage(BroadcastWindowList, LB_GETCOUNT, 0, 0); |
| 186 |
for (i = 0 ; i < count ; i++) { |
| 187 |
if (SendMessage(BroadcastWindowList, LB_GETSEL, i, 0)) { |
| 188 |
hd = GetNthWin(i); |
| 189 |
if (hd) { |
| 190 |
PostMessage(hd, msg, wParam, lParam); |
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
return FALSE; |
| 195 |
} |
| 196 |
break; |
| 197 |
|
| 198 |
case WM_CHAR: |
| 199 |
// ��������������IDC_COMMAND_EDIT���c������������������ |
| 200 |
if (ime_mode == FALSE) { |
| 201 |
return FALSE; |
| 202 |
} |
| 203 |
break; |
| 204 |
|
| 205 |
case WM_IME_NOTIFY: |
| 206 |
switch (wParam) { |
| 207 |
case IMN_SETOPENSTATUS: |
| 208 |
// IME��On/Off���������� |
| 209 |
ime_mode = GetIMEOpenStatus(dlg); |
| 210 |
} |
| 211 |
break; |
| 212 |
|
| 213 |
case WM_IME_COMPOSITION: { |
| 214 |
if (CanUseIME()) { |
| 215 |
size_t len; |
| 216 |
const wchar_t *lpstr = GetConvStringW(dlg, lParam, &len); |
| 217 |
if (lpstr != NULL) { |
| 218 |
char32_t *strU32 = ToU32W(lpstr); |
| 219 |
int count = (int)SendMessage(BroadcastWindowList, LB_GETCOUNT, 0, 0); |
| 220 |
for (int i = 0 ; i < count ; i++) { |
| 221 |
if (SendMessage(BroadcastWindowList, LB_GETSEL, i, 0)) { |
| 222 |
HWND hwnd = GetNthWin(i); |
| 223 |
if (hwnd != NULL) { |
| 224 |
BOOL support_unichar = IsUnicharSupport(hwnd); |
| 225 |
if (!support_unichar) { |
| 226 |
for (size_t j = 0; j < len; j++) { |
| 227 |
::PostMessageW(hwnd, WM_CHAR, lpstr[j], 1); |
| 228 |
} |
| 229 |
} |
| 230 |
else { |
| 231 |
const char32_t *p = strU32; |
| 232 |
while (*p != 0) { |
| 233 |
::PostMessageW(hwnd, WM_UNICHAR, *p, 1); |
| 234 |
p++; |
| 235 |
} |
| 236 |
} |
| 237 |
} |
| 238 |
} |
| 239 |
} |
| 240 |
free((void *)lpstr); |
| 241 |
free(strU32); |
| 242 |
return FALSE; |
| 243 |
} |
| 244 |
} |
| 245 |
break; |
| 246 |
} |
| 247 |
default: |
| 248 |
break; |
| 249 |
} |
| 250 |
return CallWindowProcW(OrigBroadcastEditProc, dlg, msg, wParam, lParam); |
| 251 |
} |
| 252 |
|
| 253 |
static void UpdateBroadcastWindowList(HWND hWnd) |
| 254 |
{ |
| 255 |
int i, count; |
| 256 |
HWND hd; |
| 257 |
TCHAR szWindowText[256]; |
| 258 |
|
| 259 |
SendMessage(hWnd, LB_RESETCONTENT, 0, 0); |
| 260 |
|
| 261 |
count = GetRegisteredWindowCount(); |
| 262 |
for (i = 0 ; i < count ; i++) { |
| 263 |
hd = GetNthWin(i); |
| 264 |
if (hd == NULL) { |
| 265 |
break; |
| 266 |
} |
| 267 |
|
| 268 |
GetWindowText(hd, szWindowText, 256); |
| 269 |
SendMessage(hWnd, LB_INSERTSTRING, -1, (LPARAM)szWindowText); |
| 270 |
} |
| 271 |
} |
| 272 |
|
| 273 |
static COPYDATASTRUCT *BuildBroadcastCDSW(const wchar_t *buf) |
| 274 |
{ |
| 275 |
COPYDATASTRUCT *cds = (COPYDATASTRUCT *)malloc(sizeof(COPYDATASTRUCT)); |
| 276 |
size_t buflen = wcslen(buf); |
| 277 |
|
| 278 |
cds->dwData = IPC_BROADCAST_COMMAND; |
| 279 |
cds->cbData = (DWORD)(buflen * sizeof(wchar_t)); // '\0' ���������� |
| 280 |
cds->lpData = (void *)buf; |
| 281 |
|
| 282 |
return cds; |
| 283 |
} |
| 284 |
|
| 285 |
static COPYDATASTRUCT *BuildMulticastCDSW(const wchar_t *name, const wchar_t *buf) |
| 286 |
{ |
| 287 |
size_t buflen = wcslen(buf); |
| 288 |
size_t nlen = wcslen(name) + 1; |
| 289 |
size_t msglen = nlen + buflen; |
| 290 |
wchar_t *msg = (wchar_t *)malloc(msglen * sizeof(wchar_t)); |
| 291 |
if (msg == NULL) { |
| 292 |
return NULL; |
| 293 |
} |
| 294 |
wcscpy_s(msg, msglen, name); |
| 295 |
wmemcpy_s(msg + nlen, msglen - nlen, buf, buflen); |
| 296 |
|
| 297 |
COPYDATASTRUCT *cds = (COPYDATASTRUCT *)malloc(sizeof(COPYDATASTRUCT)); |
| 298 |
if (cds == NULL) { |
| 299 |
free(msg); |
| 300 |
return NULL; |
| 301 |
} |
| 302 |
cds->dwData = IPC_MULTICAST_COMMAND; |
| 303 |
cds->cbData = (DWORD)(msglen * sizeof(wchar_t)); |
| 304 |
cds->lpData = msg; |
| 305 |
|
| 306 |
return cds; |
| 307 |
} |
| 308 |
|
| 309 |
/* |
| 310 |
* �_�C�A���O���I���������E�B���h�E�����A���������e�E�B���h�E�����������u���[�h�L���X�g���[�h�B |
| 311 |
* ���A���^�C�����[�h�� off ���������p�������B |
| 312 |
*/ |
| 313 |
static void SendBroadcastMessageToSelected(HWND HVTWin, HWND hWnd, int parent_only, const wchar_t *buf) |
| 314 |
{ |
| 315 |
COPYDATASTRUCT *cds = BuildBroadcastCDSW(buf); |
| 316 |
|
| 317 |
if (parent_only) { |
| 318 |
// �e�E�B���h�E������ WM_COPYDATA ���b�Z�[�W������ |
| 319 |
SendMessage(GetParent(hWnd), WM_COPYDATA, (WPARAM)HVTWin, (LPARAM)cds); |
| 320 |
} |
| 321 |
else { |
| 322 |
// �_�C�A���O���I���������E�B���h�E�����b�Z�[�W������ |
| 323 |
int count = (int)SendMessage(BroadcastWindowList, LB_GETCOUNT, 0, 0); |
| 324 |
for (int i = 0 ; i < count ; i++) { |
| 325 |
// ���X�g�{�b�N�X���I�������������� |
| 326 |
if (SendMessage(BroadcastWindowList, LB_GETSEL, i, 0)) { |
| 327 |
HWND hd = GetNthWin(i); |
| 328 |
if (hd != NULL) { |
| 329 |
// WM_COPYDATA���g�����A�v���Z�X�����M���s���B |
| 330 |
SendMessage(hd, WM_COPYDATA, (WPARAM)HVTWin, (LPARAM)cds); |
| 331 |
} |
| 332 |
} |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
free(cds); |
| 337 |
} |
| 338 |
|
| 339 |
/** |
| 340 |
* �S Tera Term ��COPYDATASTRUCT�����M���� |
| 341 |
* @param[in] hWnd ���M�� |
| 342 |
* @param[in] cds COPYDATASTRUCT |
| 343 |
*/ |
| 344 |
static void SendCDS(HWND hWnd, const COPYDATASTRUCT *cds) |
| 345 |
{ |
| 346 |
int count = GetRegisteredWindowCount(); |
| 347 |
for (int i = 0 ; i < count ; i++) { |
| 348 |
HWND hd = GetNthWin(i); |
| 349 |
if (hd == NULL) { |
| 350 |
break; |
| 351 |
} |
| 352 |
// WM_COPYDATA���g�����A�v���Z�X�����M���s���B |
| 353 |
SendMessage(hd, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)cds); |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
/* |
| 358 |
* �S Tera Term �����b�Z�[�W�����M�����u���[�h�L���X�g���[�h�B |
| 359 |
* "sendbroadcast"�}�N���R�}���h�����������p�������B |
| 360 |
*/ |
| 361 |
void SendBroadcastMessage(HWND HVTWin, HWND hWnd, const wchar_t *buf) |
| 362 |
{ |
| 363 |
COPYDATASTRUCT *cds = BuildBroadcastCDSW(buf); |
| 364 |
SendCDS(HVTWin, cds); |
| 365 |
free(cds); |
| 366 |
} |
| 367 |
|
| 368 |
static COPYDATASTRUCT *BuildMulticastCopyData(const char *name, const char *buf) |
| 369 |
{ |
| 370 |
size_t buflen = strlen(buf); |
| 371 |
size_t nlen = strlen(name) + 1; |
| 372 |
size_t msglen = nlen + buflen; |
| 373 |
char *msg = (char *)malloc(msglen); |
| 374 |
if (msg == NULL) { |
| 375 |
return NULL; |
| 376 |
} |
| 377 |
strcpy_s(msg, msglen, name); |
| 378 |
memcpy_s(msg + nlen, msglen - nlen, buf, buflen); |
| 379 |
|
| 380 |
COPYDATASTRUCT *cds = (COPYDATASTRUCT *)malloc(sizeof(COPYDATASTRUCT)); |
| 381 |
if (cds == NULL) { |
| 382 |
free(msg); |
| 383 |
return NULL; |
| 384 |
} |
| 385 |
cds->dwData = IPC_MULTICAST_COMMAND; |
| 386 |
cds->cbData = (DWORD)msglen; |
| 387 |
cds->lpData = msg; |
| 388 |
|
| 389 |
return cds; |
| 390 |
} |
| 391 |
|
| 392 |
/* |
| 393 |
* �C���� Tera Term �Q�����b�Z�[�W�����M�����}���`�L���X�g���[�h�B���������A |
| 394 |
* �u���[�h�L���X�g���M���s���A���M�������b�Z�[�W�������I�������B |
| 395 |
* "sendmulticast"�}�N���R�}���h�����������p�������B |
| 396 |
*/ |
| 397 |
void SendMulticastMessage(HWND HVTWin_, HWND hWnd, const wchar_t *name, const wchar_t *buf) |
| 398 |
{ |
| 399 |
COPYDATASTRUCT *cdsW = BuildMulticastCDSW(name, buf); |
| 400 |
SendCDS(HVTWin_, cdsW); |
| 401 |
free(cdsW->lpData); |
| 402 |
free(cdsW); |
| 403 |
} |
| 404 |
|
| 405 |
void SetMulticastName(const wchar_t *name) |
| 406 |
{ |
| 407 |
// TODO MulticastName �� wchar_t �� |
| 408 |
char *nameA = ToCharW(name); |
| 409 |
strncpy_s(ts.MulticastName, sizeof(ts.MulticastName), nameA, _TRUNCATE); |
| 410 |
free(nameA); |
| 411 |
} |
| 412 |
|
| 413 |
static int CompareMulticastName(const wchar_t *name) |
| 414 |
{ |
| 415 |
// TODO MulticastName �� wchar_t �� |
| 416 |
wchar_t *MulticastNameW = ToWcharA(ts.MulticastName); |
| 417 |
int result = wcscmp(MulticastNameW, name); |
| 418 |
free(MulticastNameW); |
| 419 |
return result; |
| 420 |
} |
| 421 |
|
| 422 |
// |
| 423 |
// ���������^�[�~�i���������R�}���h�����M�������[�h���X�_�C�A���O���\�� |
| 424 |
// (2005.1.22 yutaka) |
| 425 |
// |
| 426 |
static INT_PTR CALLBACK BroadcastCommandDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) |
| 427 |
{ |
| 428 |
static const DlgTextInfo TextInfos[] = { |
| 429 |
{ 0, "DLG_BROADCAST_TITLE" }, |
| 430 |
{ IDC_HISTORY_CHECK, "DLG_BROADCAST_HISTORY" }, |
| 431 |
{ IDC_ENTERKEY_CHECK, "DLG_BROADCAST_ENTER" }, |
| 432 |
{ IDC_PARENT_ONLY, "DLG_BROADCAST_PARENTONLY" }, |
| 433 |
{ IDC_REALTIME_CHECK, "DLG_BROADCAST_REALTIME" }, |
| 434 |
{ IDOK, "DLG_BROADCAST_SUBMIT" }, |
| 435 |
{ IDCANCEL, "BTN_CLOSE" }, |
| 436 |
}; |
| 437 |
LRESULT checked; |
| 438 |
LRESULT history; |
| 439 |
static HWND hwndBroadcast = NULL; // Broadcast dropdown |
| 440 |
static HWND hwndBroadcastEdit = NULL; // Edit control on Broadcast dropdown |
| 441 |
// for resize |
| 442 |
RECT rc_dlg, rc, rc_ok; |
| 443 |
POINT p; |
| 444 |
static int ok2right, cancel2right, cmdlist2ok, list2bottom, list2right; |
| 445 |
// for update list |
| 446 |
const int list_timer_id = 100; |
| 447 |
const int list_timer_tick = 1000; // msec |
| 448 |
static int prev_instances = 0; |
| 449 |
// for status bar |
| 450 |
static HWND hStatus = NULL; |
| 451 |
static int init_width, init_height; |
| 452 |
|
| 453 |
switch (msg) { |
| 454 |
case WM_SHOWWINDOW: |
| 455 |
if (wp) { // show |
| 456 |
// Tera Term window list |
| 457 |
UpdateBroadcastWindowList(GetDlgItem(hWnd, IDC_LIST)); |
| 458 |
return TRUE; |
| 459 |
} |
| 460 |
break; |
| 461 |
|
| 462 |
case WM_INITDIALOG: { |
| 463 |
// ���W�I�{�^�����f�t�H���g�� CR �������B |
| 464 |
SendMessage(GetDlgItem(hWnd, IDC_RADIO_CR), BM_SETCHECK, BST_CHECKED, 0); |
| 465 |
// �f�t�H���g���`�F�b�N�{�b�N�X�� checked �����������B |
| 466 |
SendMessage(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), BM_SETCHECK, BST_CHECKED, 0); |
| 467 |
// history �����f���� (2007.3.3 maya) |
| 468 |
if (ts.BroadcastCommandHistory) { |
| 469 |
SendMessage(GetDlgItem(hWnd, IDC_HISTORY_CHECK), BM_SETCHECK, BST_CHECKED, 0); |
| 470 |
} |
| 471 |
wchar_t *historyfile = GetHistoryFileName(&ts); |
| 472 |
ApplyBroadCastCommandHisotry(hWnd, historyfile); |
| 473 |
free(historyfile); |
| 474 |
|
| 475 |
// �G�f�B�b�g�R���g���[�����t�H�[�J�X�������� |
| 476 |
SetFocus(GetDlgItem(hWnd, IDC_COMMAND_EDIT)); |
| 477 |
|
| 478 |
// �T�u�N���X�����������A���^�C�����[�h������ (2008.1.21 yutaka) |
| 479 |
hwndBroadcast = GetDlgItem(hWnd, IDC_COMMAND_EDIT); |
| 480 |
hwndBroadcastEdit = GetWindow(hwndBroadcast, GW_CHILD); |
| 481 |
OrigBroadcastEditProc = (WNDPROC)SetWindowLongPtrW(hwndBroadcastEdit, GWLP_WNDPROC, (LONG_PTR)BroadcastEditProc); |
| 482 |
// �f�t�H���g��on�B�c����disable�B |
| 483 |
SendMessage(GetDlgItem(hWnd, IDC_REALTIME_CHECK), BM_SETCHECK, BST_CHECKED, 0); // default on |
| 484 |
EnableWindow(GetDlgItem(hWnd, IDC_HISTORY_CHECK), FALSE); |
| 485 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), FALSE); |
| 486 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), FALSE); |
| 487 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), FALSE); |
| 488 |
EnableWindow(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), FALSE); |
| 489 |
EnableWindow(GetDlgItem(hWnd, IDC_PARENT_ONLY), FALSE); |
| 490 |
|
| 491 |
// Tera Term window list |
| 492 |
BroadcastWindowList = GetDlgItem(hWnd, IDC_LIST); |
| 493 |
UpdateBroadcastWindowList(BroadcastWindowList); |
| 494 |
|
| 495 |
// I18N |
| 496 |
SetDlgTextsW(hWnd, TextInfos, _countof(TextInfos), ts.UILanguageFileW); |
| 497 |
|
| 498 |
// �_�C�A���O�������T�C�Y������ |
| 499 |
GetWindowRect(hWnd, &rc_dlg); |
| 500 |
init_width = rc_dlg.right - rc_dlg.left; |
| 501 |
init_height = rc_dlg.bottom - rc_dlg.top; |
| 502 |
|
| 503 |
// �����T�C�Y�����K�v���l���v�Z |
| 504 |
GetClientRect(hWnd, &rc_dlg); |
| 505 |
p.x = rc_dlg.right; |
| 506 |
p.y = rc_dlg.bottom; |
| 507 |
ClientToScreen(hWnd, &p); |
| 508 |
|
| 509 |
GetWindowRect(GetDlgItem(hWnd, IDOK), &rc_ok); |
| 510 |
ok2right = p.x - rc_ok.left; |
| 511 |
|
| 512 |
GetWindowRect(GetDlgItem(hWnd, IDCANCEL), &rc); |
| 513 |
cancel2right = p.x - rc.left; |
| 514 |
|
| 515 |
GetWindowRect(GetDlgItem(hWnd, IDC_COMMAND_EDIT), &rc); |
| 516 |
cmdlist2ok = rc_ok.left - rc.right; |
| 517 |
|
| 518 |
GetWindowRect(GetDlgItem(hWnd, IDC_LIST), &rc); |
| 519 |
list2bottom = p.y - rc.bottom; |
| 520 |
list2right = p.x - rc.right; |
| 521 |
|
| 522 |
// ���T�C�Y�A�C�R�����E�����\���������������A�X�e�[�^�X�o�[���t�����B |
| 523 |
InitCommonControls(); |
| 524 |
hStatus = CreateStatusWindow( |
| 525 |
WS_CHILD | WS_VISIBLE | |
| 526 |
CCS_BOTTOM | SBARS_SIZEGRIP, NULL, hWnd, 1); |
| 527 |
|
| 528 |
// ���X�g�X�V�^�C�}�[���J�n |
| 529 |
SetTimer(hWnd, list_timer_id, list_timer_tick, NULL); |
| 530 |
|
| 531 |
return FALSE; |
| 532 |
} |
| 533 |
|
| 534 |
case WM_COMMAND: |
| 535 |
switch (wp) { |
| 536 |
case IDC_ENTERKEY_CHECK | (BN_CLICKED << 16): |
| 537 |
// �`�F�b�N���L���������A���W�I�{�^�����L���E�������������B |
| 538 |
checked = SendMessage(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), BM_GETCHECK, 0, 0); |
| 539 |
if (checked & BST_CHECKED) { // ���s�R�[�h���� |
| 540 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), TRUE); |
| 541 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), TRUE); |
| 542 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), TRUE); |
| 543 |
|
| 544 |
} else { |
| 545 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), FALSE); |
| 546 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), FALSE); |
| 547 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), FALSE); |
| 548 |
} |
| 549 |
return TRUE; |
| 550 |
|
| 551 |
case IDC_REALTIME_CHECK | (BN_CLICKED << 16): |
| 552 |
checked = SendMessage(GetDlgItem(hWnd, IDC_REALTIME_CHECK), BM_GETCHECK, 0, 0); |
| 553 |
if (checked & BST_CHECKED) { // check���� |
| 554 |
// new handler |
| 555 |
hwndBroadcast = GetDlgItem(hWnd, IDC_COMMAND_EDIT); |
| 556 |
hwndBroadcastEdit = GetWindow(hwndBroadcast, GW_CHILD); |
| 557 |
OrigBroadcastEditProc = (WNDPROC)SetWindowLongPtrW(hwndBroadcastEdit, GWLP_WNDPROC, (LONG_PTR)BroadcastEditProc); |
| 558 |
|
| 559 |
EnableWindow(GetDlgItem(hWnd, IDC_HISTORY_CHECK), FALSE); |
| 560 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), FALSE); |
| 561 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), FALSE); |
| 562 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), FALSE); |
| 563 |
EnableWindow(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), FALSE); |
| 564 |
EnableWindow(GetDlgItem(hWnd, IDC_PARENT_ONLY), FALSE); |
| 565 |
EnableWindow(GetDlgItem(hWnd, IDC_LIST), TRUE); // true |
| 566 |
} else { |
| 567 |
// restore old handler |
| 568 |
SetWindowLongPtrW(hwndBroadcastEdit, GWLP_WNDPROC, (LONG_PTR)OrigBroadcastEditProc); |
| 569 |
|
| 570 |
EnableWindow(GetDlgItem(hWnd, IDC_HISTORY_CHECK), TRUE); |
| 571 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), TRUE); |
| 572 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), TRUE); |
| 573 |
EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), TRUE); |
| 574 |
EnableWindow(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), TRUE); |
| 575 |
EnableWindow(GetDlgItem(hWnd, IDC_PARENT_ONLY), TRUE); |
| 576 |
EnableWindow(GetDlgItem(hWnd, IDC_LIST), TRUE); // true |
| 577 |
} |
| 578 |
return TRUE; |
| 579 |
} |
| 580 |
|
| 581 |
switch (LOWORD(wp)) { |
| 582 |
case IDOK: |
| 583 |
{ |
| 584 |
wchar_t buf[256 + 3]; |
| 585 |
//memset(buf, 0, sizeof(buf)); |
| 586 |
|
| 587 |
// realtime mode�������AEnter key���������B |
| 588 |
// cf. http://logmett.com/forum/viewtopic.php?f=8&t=1601 |
| 589 |
// (2011.3.14 hirata) |
| 590 |
checked = SendMessage(GetDlgItem(hWnd, IDC_REALTIME_CHECK), BM_GETCHECK, 0, 0); |
| 591 |
if (checked & BST_CHECKED) { // check���� |
| 592 |
wcsncpy_s(buf, _countof(buf), L"\n", _TRUNCATE); |
| 593 |
SetDlgItemTextA(hWnd, IDC_COMMAND_EDIT, ""); |
| 594 |
} |
| 595 |
else { |
| 596 |
UINT ret = GetDlgItemTextW(hWnd, IDC_COMMAND_EDIT, buf, 256 - 1); |
| 597 |
if (ret == 0) { // error |
| 598 |
memset(buf, 0, sizeof(buf)); |
| 599 |
} |
| 600 |
|
| 601 |
// �u���[�h�L���X�g�R�}���h������������ (2007.3.3 maya) |
| 602 |
history = SendMessage(GetDlgItem(hWnd, IDC_HISTORY_CHECK), BM_GETCHECK, 0, 0); |
| 603 |
if (history) { |
| 604 |
wchar_t *historyfile = GetHistoryFileName(&ts); |
| 605 |
if (LoadTTSET()) { |
| 606 |
(*AddValueToList)(historyfile, buf, L"BroadcastCommands", L"Command", |
| 607 |
ts.MaxBroadcatHistory); |
| 608 |
FreeTTSET(); |
| 609 |
} |
| 610 |
ApplyBroadCastCommandHisotry(hWnd, historyfile); |
| 611 |
free(historyfile); |
| 612 |
ts.BroadcastCommandHistory = TRUE; |
| 613 |
} |
| 614 |
else { |
| 615 |
ts.BroadcastCommandHistory = FALSE; |
| 616 |
} |
| 617 |
checked = SendMessage(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), BM_GETCHECK, 0, 0); |
| 618 |
if (checked & BST_CHECKED) { // ���s�R�[�h���� |
| 619 |
if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_CRLF), BM_GETCHECK, 0, 0) & BST_CHECKED) { |
| 620 |
wcsncat_s(buf, _countof(buf), L"\r\n", _TRUNCATE); |
| 621 |
|
| 622 |
} else if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_CR), BM_GETCHECK, 0, 0) & BST_CHECKED) { |
| 623 |
wcsncat_s(buf, _countof(buf), L"\r", _TRUNCATE); |
| 624 |
|
| 625 |
} else if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_LF), BM_GETCHECK, 0, 0) & BST_CHECKED) { |
| 626 |
wcsncat_s(buf, _countof(buf), L"\n", _TRUNCATE); |
| 627 |
|
| 628 |
} else { |
| 629 |
wcsncat_s(buf, _countof(buf), L"\r", _TRUNCATE); |
| 630 |
|
| 631 |
} |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
// 337: 2007/03/20 �`�F�b�N�������������e�E�B���h�E���������M |
| 636 |
checked = SendMessage(GetDlgItem(hWnd, IDC_PARENT_ONLY), BM_GETCHECK, 0, 0); |
| 637 |
|
| 638 |
SendBroadcastMessageToSelected(HVTWin, hWnd, (int)checked, buf); |
| 639 |
} |
| 640 |
|
| 641 |
// ���[�h���X�_�C�A���O�����x�������������A�A�v���P�[�V�������I���������� |
| 642 |
// �j���������������A�������u�E�B���h�E�v���V�[�W�������v���s�v���v�������B(yutaka) |
| 643 |
#if 0 |
| 644 |
_SetWindowLongPtrW(hwndBroadcastEdit, GWLP_WNDPROC, (LONG_PTR)OrigBroadcastEditProc); |
| 645 |
#endif |
| 646 |
|
| 647 |
//EndDialog(hDlgWnd, IDOK); |
| 648 |
return TRUE; |
| 649 |
|
| 650 |
case IDCANCEL: |
| 651 |
EndDialog(hWnd, 0); |
| 652 |
//DestroyWindow(hWnd); |
| 653 |
|
| 654 |
return TRUE; |
| 655 |
|
| 656 |
case IDC_COMMAND_EDIT: |
| 657 |
if (HIWORD(wp) == CBN_DROPDOWN) { |
| 658 |
wchar_t *historyfile = GetHistoryFileName(&ts); |
| 659 |
ApplyBroadCastCommandHisotry(hWnd, historyfile); |
| 660 |
free(historyfile); |
| 661 |
} |
| 662 |
return FALSE; |
| 663 |
|
| 664 |
case IDC_LIST: |
| 665 |
// �����I���A�v���P�[�V�������������������������������A |
| 666 |
// �uSHIFT+�N���b�N�v�������A���I���I�����T�|�[�g�����B |
| 667 |
// (2009.9.28 yutaka) |
| 668 |
if (HIWORD(wp) == LBN_SELCHANGE && ShiftKey()) { |
| 669 |
int i, cur, prev; |
| 670 |
|
| 671 |
cur = ListBox_GetCurSel(BroadcastWindowList); |
| 672 |
prev = -1; |
| 673 |
for (i = cur - 1 ; i >= 0 ; i--) { |
| 674 |
if (ListBox_GetSel(BroadcastWindowList, i)) { |
| 675 |
prev = i; |
| 676 |
break; |
| 677 |
} |
| 678 |
} |
| 679 |
if (prev != -1) { |
| 680 |
// �������I���������������������A���������A���I�������B |
| 681 |
for (i = prev ; i < cur ; i++) { |
| 682 |
ListBox_SetSel(BroadcastWindowList, TRUE, i); |
| 683 |
} |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
return FALSE; |
| 688 |
|
| 689 |
default: |
| 690 |
return FALSE; |
| 691 |
} |
| 692 |
break; |
| 693 |
|
| 694 |
case WM_CLOSE: |
| 695 |
//DestroyWindow(hWnd); |
| 696 |
EndDialog(hWnd, 0); |
| 697 |
return TRUE; |
| 698 |
|
| 699 |
case WM_SIZE: |
| 700 |
{ |
| 701 |
// ���z�u |
| 702 |
int dlg_w, dlg_h; |
| 703 |
RECT rc_dlg; |
| 704 |
RECT rc; |
| 705 |
POINT p; |
| 706 |
|
| 707 |
// �V�����_�C�A���O���T�C�Y������ |
| 708 |
GetClientRect(hWnd, &rc_dlg); |
| 709 |
dlg_w = rc_dlg.right; |
| 710 |
dlg_h = rc_dlg.bottom; |
| 711 |
|
| 712 |
// OK button |
| 713 |
GetWindowRect(GetDlgItem(hWnd, IDOK), &rc); |
| 714 |
p.x = rc.left; |
| 715 |
p.y = rc.top; |
| 716 |
ScreenToClient(hWnd, &p); |
| 717 |
SetWindowPos(GetDlgItem(hWnd, IDOK), 0, |
| 718 |
dlg_w - ok2right, p.y, 0, 0, |
| 719 |
SWP_NOSIZE | SWP_NOZORDER); |
| 720 |
|
| 721 |
// Cancel button |
| 722 |
GetWindowRect(GetDlgItem(hWnd, IDCANCEL), &rc); |
| 723 |
p.x = rc.left; |
| 724 |
p.y = rc.top; |
| 725 |
ScreenToClient(hWnd, &p); |
| 726 |
SetWindowPos(GetDlgItem(hWnd, IDCANCEL), 0, |
| 727 |
dlg_w - cancel2right, p.y, 0, 0, |
| 728 |
SWP_NOSIZE | SWP_NOZORDER); |
| 729 |
|
| 730 |
// Command Edit box |
| 731 |
GetWindowRect(GetDlgItem(hWnd, IDC_COMMAND_EDIT), &rc); |
| 732 |
p.x = rc.left; |
| 733 |
p.y = rc.top; |
| 734 |
ScreenToClient(hWnd, &p); |
| 735 |
SetWindowPos(GetDlgItem(hWnd, IDC_COMMAND_EDIT), 0, |
| 736 |
0, 0, dlg_w - p.x - ok2right - cmdlist2ok, p.y, |
| 737 |
SWP_NOMOVE | SWP_NOZORDER); |
| 738 |
|
| 739 |
// List Edit box |
| 740 |
GetWindowRect(GetDlgItem(hWnd, IDC_LIST), &rc); |
| 741 |
p.x = rc.left; |
| 742 |
p.y = rc.top; |
| 743 |
ScreenToClient(hWnd, &p); |
| 744 |
SetWindowPos(GetDlgItem(hWnd, IDC_LIST), 0, |
| 745 |
0, 0, dlg_w - p.x - list2right , dlg_h - p.y - list2bottom, |
| 746 |
SWP_NOMOVE | SWP_NOZORDER); |
| 747 |
|
| 748 |
// status bar |
| 749 |
SendMessage(hStatus , msg , wp , lp); |
| 750 |
} |
| 751 |
return TRUE; |
| 752 |
|
| 753 |
case WM_GETMINMAXINFO: |
| 754 |
{ |
| 755 |
// �_�C�A���O�������T�C�Y���������������������������� |
| 756 |
LPMINMAXINFO lpmmi; |
| 757 |
lpmmi = (LPMINMAXINFO)lp; |
| 758 |
lpmmi->ptMinTrackSize.x = init_width; |
| 759 |
lpmmi->ptMinTrackSize.y = init_height; |
| 760 |
} |
| 761 |
return FALSE; |
| 762 |
|
| 763 |
case WM_TIMER: |
| 764 |
{ |
| 765 |
int n; |
| 766 |
|
| 767 |
if (wp != list_timer_id) |
| 768 |
break; |
| 769 |
|
| 770 |
n = GetRegisteredWindowCount(); |
| 771 |
if (n != prev_instances) { |
| 772 |
prev_instances = n; |
| 773 |
UpdateBroadcastWindowList(BroadcastWindowList); |
| 774 |
} |
| 775 |
} |
| 776 |
return TRUE; |
| 777 |
|
| 778 |
case WM_VKEYTOITEM: |
| 779 |
// ���X�g�{�b�N�X���L�[����(CTRL+A)���������A�S�I���B |
| 780 |
if ((HWND)lp == BroadcastWindowList) { |
| 781 |
if (ControlKey() && LOWORD(wp) == 'A') { |
| 782 |
int i, n; |
| 783 |
|
| 784 |
//OutputDebugPrintf("msg %x wp %x lp %x\n", msg, wp, lp); |
| 785 |
n = GetRegisteredWindowCount(); |
| 786 |
for (i = 0 ; i < n ; i++) { |
| 787 |
ListBox_SetSel(BroadcastWindowList, TRUE, i); |
| 788 |
} |
| 789 |
} |
| 790 |
} |
| 791 |
return TRUE; |
| 792 |
|
| 793 |
default: |
| 794 |
//OutputDebugPrintf("msg %x wp %x lp %x\n", msg, wp, lp); |
| 795 |
return FALSE; |
| 796 |
} |
| 797 |
return TRUE; |
| 798 |
} |
| 799 |
|
| 800 |
static HWND hDlgWnd = NULL; |
| 801 |
|
| 802 |
void BroadCastShowDialog(HINSTANCE hInst, HWND hWnd) |
| 803 |
{ |
| 804 |
RECT prc, rc; |
| 805 |
LONG x, y; |
| 806 |
|
| 807 |
if (hDlgWnd != NULL) { |
| 808 |
goto activate; |
| 809 |
} |
| 810 |
|
| 811 |
SetDialogFont(ts.DialogFontNameW, ts.DialogFontPoint, ts.DialogFontCharSet, |
| 812 |
ts.UILanguageFileW, "Tera Term", "DLG_SYSTEM_FONT"); |
| 813 |
|
| 814 |
// CreateDialogW() �����������_�C�A���O���A |
| 815 |
// �G�f�B�b�g�{�b�N�X��IME���������������������������� (20/05/27,Windows10 64bit) |
| 816 |
// �y�[�X�g��ok |
| 817 |
hDlgWnd = TTCreateDialog(hInst, MAKEINTRESOURCE(IDD_BROADCAST_DIALOG), |
| 818 |
hWnd, BroadcastCommandDlgProc); |
| 819 |
|
| 820 |
if (hDlgWnd == NULL) { |
| 821 |
return; |
| 822 |
} |
| 823 |
|
| 824 |
// �_�C�A���O���E�B���h�E���^�����z�u���� (2008.1.25 yutaka) |
| 825 |
::GetWindowRect(hWnd, &prc); |
| 826 |
::GetWindowRect(hDlgWnd, &rc); |
| 827 |
x = prc.left; |
| 828 |
y = prc.top - (rc.bottom - rc.top); |
| 829 |
if (y < 0) { |
| 830 |
y = 0; |
| 831 |
} |
| 832 |
::SetWindowPos(hDlgWnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); |
| 833 |
|
| 834 |
activate:; |
| 835 |
::ShowWindow(hDlgWnd, SW_SHOW); |
| 836 |
} |
| 837 |
|
| 838 |
BOOL BroadCastReceive(const COPYDATASTRUCT *cds) |
| 839 |
{ |
| 840 |
wchar_t *strW_ptr; |
| 841 |
size_t strW_len = 0; |
| 842 |
|
| 843 |
switch (cds->dwData) { |
| 844 |
case IPC_BROADCAST_COMMAND: { |
| 845 |
strW_len = cds->cbData / sizeof(wchar_t); |
| 846 |
strW_ptr = (wchar_t *)malloc((strW_len + 1) * sizeof(wchar_t)); |
| 847 |
wmemcpy_s(strW_ptr, strW_len, (wchar_t *)cds->lpData, strW_len); |
| 848 |
strW_ptr[strW_len] = 0; // �O���� |
| 849 |
break; |
| 850 |
} |
| 851 |
case IPC_MULTICAST_COMMAND: { |
| 852 |
wchar_t *name = (wchar_t *)cds->lpData; |
| 853 |
|
| 854 |
// �}���`�L���X�g�����`�F�b�N���� |
| 855 |
if (CompareMulticastName(name) != 0) { |
| 856 |
// ���O���������������������������� |
| 857 |
return TRUE; |
| 858 |
} |
| 859 |
|
| 860 |
// �}���`�L���X�g�������������������� |
| 861 |
size_t nlen = wcslen(name); |
| 862 |
strW_len = cds->cbData / sizeof(wchar_t) - nlen - 1; // -1 = name �� '\0' |
| 863 |
strW_ptr = (wchar_t *)malloc((strW_len + 1) * sizeof(wchar_t)); |
| 864 |
wmemcpy_s(strW_ptr, strW_len, (wchar_t *)cds->lpData + nlen + 1, strW_len); |
| 865 |
strW_ptr[strW_len] = 0; // �O���� |
| 866 |
break; |
| 867 |
} |
| 868 |
|
| 869 |
default: |
| 870 |
// �m���������b�Z�[�W������ |
| 871 |
return TRUE; |
| 872 |
} |
| 873 |
|
| 874 |
// �[�������������������� |
| 875 |
SendMem *sm = SendMemTextW(strW_ptr, strW_len); |
| 876 |
if (sm != NULL) { |
| 877 |
SendMemInitEcho(sm, FALSE); |
| 878 |
SendMemInitDelay(sm, SENDMEM_DELAYTYPE_PER_LINE, 10, 0); |
| 879 |
SendMemStart(sm); |
| 880 |
} |
| 881 |
|
| 882 |
return TRUE; |
| 883 |
} |