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 8827 - (hide annotations) (download) (as text)
Fri Jul 3 14:43:36 2020 UTC (3 years, 9 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/broadcast.cpp
File MIME type: text/x-c++src
File size: 26151 byte(s)
ブロードキャストコマンドのリアルタイム=ON時、Unicode化

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

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