Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ttcomtester/teraterm/teraterm/broadcast.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26