Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10394 - (hide annotations) (download) (as text)
Sat Dec 3 06:40:18 2022 UTC (16 months, 1 week ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/vtwin.cpp
File MIME type: text/x-c++src
File size: 141206 byte(s)
通知関連のAPIを整理した

- ttermpro.exe 内部用とplugin用に分離した
  - ttcmn_notify.h plugin用
  - ttcmn_notify2.h 内部用
    - API名は Notify2...()
- トレイアイコンを出したままにできるAPIを追加
  - Notify2SetBallonDontHide()
1 doda 6806 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3 nmaya 9048 * (C) 2004- TeraTerm Project
4 doda 6806 * All rights reserved.
5     *
6 doda 6841 * Redistribution and use in source and binary forms, with or without
7     * modification, are permitted provided that the following conditions
8     * are met:
9 doda 6806 *
10 doda 6841 * 1. Redistributions of source code must retain the above copyright
11     * notice, this list of conditions and the following disclaimer.
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the distribution.
15     * 3. The name of the author may not be used to endorse or promote products
16     * derived from this software without specific prior written permission.
17 doda 6806 *
18 doda 6841 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 doda 6806 */
29 maya 3227 /* IPv6 modification is Copyright(C) 2000 Jun-ya Kato <kato@win6.jp> */
30    
31     /* TERATERM.EXE, VT window */
32    
33 zmatsuo 9230 // SDK7.0�������AWIN32_IE���K�������`��������
34     #if _MSC_VER == 1400 // VS2005����������
35     #if !defined(_WIN32_IE)
36     #define _WIN32_IE 0x0501
37     #endif
38     #endif
39    
40 maya 3227 #include "teraterm.h"
41     #include "tttypes.h"
42 zmatsuo 9244 #include "tttypes_key.h"
43 maya 3227
44     #include "ttcommon.h"
45     #include "ttwinman.h"
46     #include "ttsetup.h"
47     #include "keyboard.h"
48     #include "buffer.h"
49     #include "vtterm.h"
50     #include "vtdisp.h"
51     #include "ttdialog.h"
52     #include "ttime.h"
53     #include "commlib.h"
54     #include "clipboar.h"
55     #include "filesys.h"
56     #include "telnet.h"
57     #include "tektypes.h"
58     #include "ttdde.h"
59     #include "ttlib.h"
60 zmatsuo 7528 #include "dlglib.h"
61 maya 3227 #include "helpid.h"
62     #include "teraprn.h"
63     #include <winsock2.h>
64     #include <ws2tcpip.h>
65     #include "ttplug.h" /* TTPLUG */
66 zmatsuo 7589 #include "teraterml.h"
67 zmatsuo 8770 #include "buffer.h"
68 zmatsuo 9518 #include "cyglib.h"
69 zmatsuo 10385 #include "theme.h"
70 maya 3227
71     #include <stdio.h>
72 zmatsuo 8463 #define _CRTDBG_MAP_ALLOC
73 maya 3227 #include <stdlib.h>
74 zmatsuo 8463 #include <crtdbg.h>
75 maya 3227 #include <string.h>
76     #include <io.h>
77     #include <errno.h>
78    
79 zmatsuo 9230 #include <shlobj.h>
80     #include <windows.h>
81 maya 3227 #include <windowsx.h>
82 yutakapon 3898 #include <imm.h>
83 zmatsuo 7542 #include <dbt.h>
84 zmatsuo 7487 #include <assert.h>
85 doda 8445 #include <wchar.h>
86 zmatsuo 9230 #include <htmlhelp.h>
87 maya 3227
88     #include "tt_res.h"
89     #include "vtwin.h"
90     #include "addsetting.h"
91 yutakapon 4385 #include "winjump.h"
92 doda 7089 #include "sizetip.h"
93 zmatsuo 7148 #include "dnddlg.h"
94 zmatsuo 7527 #include "tekwin.h"
95 zmatsuo 7457 #include "compat_win.h"
96 doda 8445 #include "unicode_test.h"
97     #if UNICODE_DEBUG
98 zmatsuo 8122 #include "tipwin.h"
99 doda 8445 #endif
100     #include "codeconv.h"
101     #include "sendmem.h"
102 zmatsuo 8588 #include "sendfiledlg.h"
103 zmatsuo 8749 #include "setting.h"
104 zmatsuo 8823 #include "broadcast.h"
105 zmatsuo 8899 #include "asprintf.h"
106 zmatsuo 9115 #include "teraprn.h"
107 zmatsuo 9339 #include "setupdirdlg.h"
108 zmatsuo 10134 #include "themedlg.h"
109 zmatsuo 10130 #include "ttcmn_static.h"
110 zmatsuo 10394 #include "ttcmn_notify2.h"
111 maya 3227
112 zmatsuo 9611 #include <initguid.h>
113 zmatsuo 9615 #if _MSC_VER < 1600
114     // Visual Studio 2005,2008 �������A2010���������o�[�W����������
115 maya 6101 DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, \
116     0xC0, 0x4F, 0xB9, 0x51, 0xED);
117 zmatsuo 9611 #else
118     #include <usbiodef.h> // GUID_DEVINTERFACE_USB_DEVICE
119     #endif
120    
121 zmatsuo 9361 #include "win32helper.h"
122 salarm 6100
123 zmatsuo 8519 #define VTClassName L"VTWin32"
124 zmatsuo 7528
125 maya 3227 // �E�B���h�E�������{�^�����L�������� (2005.1.15 yutaka)
126     #define WINDOW_MAXMIMUM_ENABLED 1
127    
128 doda 3580 static BOOL TCPLocalEchoUsed = FALSE;
129     static BOOL TCPCRSendUsed = FALSE;
130    
131 doda 5341 static BOOL IgnoreRelease = FALSE;
132    
133 salarm 6100 static HDEVNOTIFY hDevNotify = NULL;
134    
135 salarm 6076 static int AutoDisconnectedPort = -1;
136    
137 youlab 9554 static BOOL SendScpDoing;
138     static WCHAR **DropListsSendScp;
139     static int DropListCountSendScp;
140     static int DropListsSendScpIndex;
141    
142 zmatsuo 9383 UnicodeDebugParam_t UnicodeDebugParam;
143     typedef struct {
144     char dbcs_lead_byte;
145     } vtwin_work_t;
146     static vtwin_work_t vtwin_work;
147 zmatsuo 7485
148 zmatsuo 9115 extern "C" PrintFile *PrintFile_;
149 doda 8445
150 maya 3227 /////////////////////////////////////////////////////////////////////////////
151     // CVTWindow
152    
153     // Tera Term�N������URL������mouse over������������ (2005.4.2 yutaka)
154 zmatsuo 7528 static void SetMouseCursor(const char *cursor)
155 maya 3227 {
156     HCURSOR hc;
157     LPCTSTR name = NULL;
158     int i;
159    
160     for (i = 0 ; MouseCursor[i].name ; i++) {
161     if (_stricmp(cursor, MouseCursor[i].name) == 0) {
162     name = MouseCursor[i].id;
163     break;
164     }
165     }
166 maya 3392 if (name == NULL) {
167 maya 3227 return;
168 maya 3392 }
169 maya 3227
170 yutakapon 6286 hc = (HCURSOR)LoadImage(NULL, name, IMAGE_CURSOR,
171 maya 3227 0, 0, LR_DEFAULTSIZE | LR_SHARED);
172    
173     if (hc != NULL) {
174     SetClassLongPtr(HVTWin, GCLP_HCURSOR, (LONG_PTR)hc);
175     }
176     }
177    
178 zmatsuo 7390 /**
179     * @param[in] alpha 0-255
180     */
181     void CVTWindow::SetWindowAlpha(BYTE alpha)
182 maya 3227 {
183 zmatsuo 7457 if (pSetLayeredWindowAttributes == NULL) {
184     return; // ���C���[�h�E�C���h�E���T�|�[�g����
185     }
186 zmatsuo 7390 if (Alpha == alpha) {
187     return; // ����������������������
188     }
189 zmatsuo 7528 LONG_PTR lp = GetWindowLongPtr(GWL_EXSTYLE);
190 zmatsuo 7390 if (lp == 0) {
191     return;
192     }
193 maya 3227
194     // 2006/03/16 by 337: BGUseAlphaBlendAPI��On������Layered����������
195     //if (ts->EtermLookfeel.BGUseAlphaBlendAPI) {
196     // �A���t�@�l��255�������A�����������������}�����������������������������B(2006.4.1 yutaka)
197     // �����o�������A�l�����X�����������������������f�����B(2007.10.19 maya)
198 zmatsuo 7390 if (alpha < 255) {
199     ::SetWindowLongPtr(HVTWin, GWL_EXSTYLE, lp | WS_EX_LAYERED);
200 zmatsuo 7457 pSetLayeredWindowAttributes(HVTWin, 0, alpha, LWA_ALPHA);
201 maya 3227 }
202     else {
203 zmatsuo 7390 // �A���t�@�l�� 255 �������A�����������������������`�������B(2007.10.22 maya)
204     ::SetWindowLongPtr(HVTWin, GWL_EXSTYLE, lp & ~WS_EX_LAYERED);
205     ::RedrawWindow(HVTWin, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME);
206 maya 3227 }
207 zmatsuo 7390 Alpha = alpha;
208 maya 3227 }
209    
210 salarm 6100 void RegDeviceNotify(HWND hWnd)
211     {
212     typedef HDEVNOTIFY (WINAPI *PRegisterDeviceNotification)(HANDLE hRecipient, LPVOID NotificationFilter, DWORD Flags);
213     HMODULE h;
214     PRegisterDeviceNotification pRegisterDeviceNotification;
215     DEV_BROADCAST_DEVICEINTERFACE filter;
216 maya 3227
217 salarm 6100 if (((h = GetModuleHandle("user32.dll")) == NULL) ||
218     ((pRegisterDeviceNotification = (PRegisterDeviceNotification)GetProcAddress(h, "RegisterDeviceNotificationA")) == NULL)) {
219     return;
220     }
221    
222     ZeroMemory(&filter, sizeof(filter));
223     filter.dbcc_size = sizeof(filter);
224     filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
225     filter.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
226     hDevNotify = pRegisterDeviceNotification(hWnd, &filter, DEVICE_NOTIFY_WINDOW_HANDLE);
227     }
228    
229     void UnRegDeviceNotify(HWND hWnd)
230     {
231     typedef BOOL (WINAPI *PUnregisterDeviceNotification)(HDEVNOTIFY Handle);
232     HMODULE h;
233     PUnregisterDeviceNotification pUnregisterDeviceNotification;
234    
235     if (((h = GetModuleHandle("user32.dll")) == NULL) ||
236     ((pUnregisterDeviceNotification = (PUnregisterDeviceNotification)GetProcAddress(h, "UnregisterDeviceNotification")) == NULL)) {
237     return;
238     }
239    
240     pUnregisterDeviceNotification(hDevNotify);
241     }
242    
243 salarm 6347 void SetAutoConnectPort(int port)
244     {
245     AutoDisconnectedPort = port;
246     }
247    
248 doda 6782 /////////////////////////////////////////////////////////////////////////////
249     // CVTWindow constructor
250    
251 zmatsuo 7916 CVTWindow::CVTWindow(HINSTANCE hInstance)
252 maya 3227 {
253 zmatsuo 8519 WNDCLASSW wc;
254 maya 3227 RECT rect;
255     DWORD Style;
256     int CmdShow;
257 doda 6790 BOOL isFirstInstance;
258 zmatsuo 7916 m_hInst = hInstance;
259 maya 3227
260 doda 6790 CommInit(&cv);
261 nmaya 10009 cv.ts = &ts;
262 zmatsuo 10130 isFirstInstance = StartTeraTerm(m_hInst, &ts);
263 doda 6790
264 maya 3227 TTXInit(&ts, &cv); /* TTPLUG */
265    
266     MsgDlgHelp = RegisterWindowMessage(HELPMSGSTRING);
267    
268 doda 6790 if (isFirstInstance) {
269 maya 3227 /* first instance */
270     if (LoadTTSET()) {
271     /* read setup info from "teraterm.ini" */
272 zmatsuo 9429 (*ReadIniFile)(ts.SetupFNameW, &ts);
273 maya 3227 FreeTTSET();
274     }
275 doda 6783 else {
276     abort();
277     }
278 maya 3227
279     } else {
280     // 2�������~���v���Z�X�����������A�f�B�X�N���� TERATERM.INI �������B(2004.11.4 yutaka)
281     if (LoadTTSET()) {
282     /* read setup info from "teraterm.ini" */
283 zmatsuo 9429 (*ReadIniFile)(ts.SetupFNameW, &ts);
284 maya 3227 FreeTTSET();
285     }
286 doda 6783 else {
287     abort();
288     }
289 maya 3227 }
290    
291     /* Parse command line parameters*/
292     // 256�o�C�g�������R�}���h���C���p�����[�^�w�����������ABOF(Buffer Over Flow)��
293     // �������o�O���C���B(2007.6.12 maya)
294 maya 3392 if (LoadTTSET()) {
295 zmatsuo 10342 // GetCommandLineW() in MSDN remark
296     // The lifetime of the returned value is managed by the
297     // system, applications should not free or modify this value.
298 zmatsuo 9436 wchar_t *ParamW = GetCommandLineW();
299     (*ParseParam)(ParamW, &ts, &(TopicName[0]));
300 maya 3392 }
301 maya 3227 FreeTTSET();
302    
303 zmatsuo 7594 // DPI Aware (��DPI����)
304 zmatsuo 7715 if (pIsValidDpiAwarenessContext != NULL && pSetThreadDpiAwarenessContext != NULL) {
305 zmatsuo 9656 wchar_t Temp[4];
306     GetPrivateProfileStringW(L"Tera Term", L"DPIAware", L"on", Temp, _countof(Temp), ts.SetupFNameW);
307     if (_wcsicmp(Temp, L"on") == 0) {
308 zmatsuo 7715 if (pIsValidDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) == TRUE) {
309 zmatsuo 7594 pSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
310     }
311     }
312     }
313    
314 maya 3227 // duplicate session���w�������������A���L�����������R�s�[���� (2004.12.7 yutaka)
315     if (ts.DuplicateSession == 1) {
316 nmaya 10238 // ���L�����������W�����������������E�B���h�E���W�������B
317     // �������������� TERATERM.INI ���l���g�����������A�������������B
318     POINT VTPos = ts.VTPos;
319     POINT TEKPos = ts.TEKPos;
320    
321 maya 3227 CopyShmemToTTSet(&ts);
322    
323 nmaya 10238 ts.VTPos = VTPos;
324     ts.TEKPos = TEKPos;
325 nmaya 10186 }
326    
327 maya 3227 InitKeyboard();
328     SetKeyMap();
329    
330     /* window status */
331     AdjustSize = TRUE;
332     Minimized = FALSE;
333     LButton = FALSE;
334     MButton = FALSE;
335     RButton = FALSE;
336     DblClk = FALSE;
337     AfterDblClk = FALSE;
338     TplClk = FALSE;
339     Hold = FALSE;
340     FirstPaint = TRUE;
341     ScrollLock = FALSE; // �����l������ (2006.11.14 yutaka)
342 zmatsuo 7390 Alpha = 255;
343 zmatsuo 7717 IgnoreSizeMessage = FALSE;
344 doda 8445 #if UNICODE_DEBUG
345     TipWinCodeDebug = NULL;
346     #endif
347 maya 3227
348 zmatsuo 8771 // UnicodeDebugParam
349     {
350     #if _DEBUG
351     UnicodeDebugParam.CodePopupEnable = TRUE;
352     #else
353     UnicodeDebugParam.CodePopupEnable = FALSE;
354     #endif
355     UnicodeDebugParam.CodePopupKey1 = VK_CONTROL;
356     UnicodeDebugParam.CodePopupKey2 = VK_CONTROL;
357     UnicodeDebugParam.UseUnicodeApi = FALSE;
358 zmatsuo 10055 UnicodeDebugParam.CodePageForANSIDraw = GetACP();
359 zmatsuo 8771 }
360    
361 maya 3227 /* Initialize scroll buffer */
362 zmatsuo 8750 UnicodeDebugParam.UseUnicodeApi = IsWindowsNTKernel() ? TRUE : FALSE;
363     InitBuffer(UnicodeDebugParam.UseUnicodeApi);
364 zmatsuo 8771 BuffSetDispCodePage(UnicodeDebugParam.CodePageForANSIDraw);
365 maya 3227
366     InitDisp();
367 zmatsuo 10134 BGLoadThemeFile(&ts);
368 maya 3227
369     if (ts.HideTitle>0) {
370     Style = WS_VSCROLL | WS_HSCROLL |
371     WS_BORDER | WS_THICKFRAME | WS_POPUP;
372    
373 zmatsuo 9961 if (ts.EtermLookfeel.BGNoFrame)
374 maya 3227 Style &= ~(WS_BORDER | WS_THICKFRAME);
375     }
376     else
377     #ifdef WINDOW_MAXMIMUM_ENABLED
378     Style = WS_VSCROLL | WS_HSCROLL |
379     WS_BORDER | WS_THICKFRAME |
380     WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
381     #else
382     Style = WS_VSCROLL | WS_HSCROLL |
383     WS_BORDER | WS_THICKFRAME |
384     WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
385     #endif
386    
387     wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
388 zmatsuo 7528 wc.lpfnWndProc = (WNDPROC)ProcStub;
389 maya 3227 wc.cbClsExtra = 0;
390     wc.cbWndExtra = 0;
391 zmatsuo 7916 wc.hInstance = hInstance;
392 maya 3227 wc.hIcon = NULL;
393     //wc.hCursor = LoadCursor(NULL,IDC_IBEAM);
394     wc.hCursor = NULL; // �}�E�X�J�[�\�������I�����X���� (2005.4.2 yutaka)
395     wc.hbrBackground = NULL;
396     wc.lpszMenuName = NULL;
397     wc.lpszClassName = VTClassName;
398    
399 zmatsuo 9324 RegisterClassW(&wc);
400 zmatsuo 7916 m_hAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACC));
401 maya 3227
402 maya 3392 if (ts.VTPos.x==CW_USEDEFAULT) {
403 maya 3227 rect = rectDefault;
404 maya 3392 }
405 maya 3227 else {
406     rect.left = ts.VTPos.x;
407     rect.top = ts.VTPos.y;
408     rect.right = rect.left + 100;
409     rect.bottom = rect.top + 100;
410     }
411 zmatsuo 8519 CreateW(hInstance, VTClassName, L"Tera Term", Style, rect, NULL, NULL);
412 maya 3227
413     /*--------- Init2 -----------------*/
414     HVTWin = GetSafeHwnd();
415     if (HVTWin == NULL) return;
416 nmaya 10009 cv.HWin = HVTWin;
417 nmaya 10019
418     // Windows 11 ���E�B���h�E���p������������������������
419 nmaya 10036 if (ts.WindowCornerDontround && pDwmSetWindowAttribute != NULL) {
420 nmaya 10019 DWM_WINDOW_CORNER_PREFERENCE preference = DWMWCP_DONOTROUND;
421     pDwmSetWindowAttribute(HVTWin, DWMWA_WINDOW_CORNER_PREFERENCE, &preference, sizeof(preference));
422     }
423    
424 maya 3227 // register this window to the window list
425     SerialNo = RegWin(HVTWin,NULL);
426    
427     logfile_lock_initialize();
428 zmatsuo 7390 SetMouseCursor(ts.MouseCursorName);
429 maya 3227
430 zmatsuo 9961 if(ts.EtermLookfeel.BGNoFrame && ts.HideTitle > 0) {
431 doda 8445 DWORD ExStyle = (DWORD)::GetWindowLongPtr(HVTWin,GWL_EXSTYLE);
432 maya 3227 ExStyle &= ~WS_EX_CLIENTEDGE;
433 zmatsuo 7528 ::SetWindowLongPtr(HVTWin,GWL_EXSTYLE,ExStyle);
434 maya 3227 }
435    
436 salarm 6100 // USB�f�o�C�X�������m�o�^
437     RegDeviceNotify(HVTWin);
438    
439 nmaya 10009 // ���m����������
440 zmatsuo 10394 NotifyIcon *ni = Notify2Initialize();
441     cv.NotifyIcon = ni;
442     Notify2SetWindow(ni, m_hWnd, WM_USER_NOTIFYICON, m_hInst, (ts.VTIcon != IdIconDefault) ? ts.VTIcon: IDI_VT);
443     Notify2SetSound(ni, ts.NotifySound);
444 maya 3227
445 nmaya 10009 // VT �E�B���h�E���A�C�R��
446     SetVTIconID(&cv, NULL, 0);
447 doda 6690
448 maya 3227 MainMenu = NULL;
449     WinMenu = NULL;
450     if ((ts.HideTitle==0) && (ts.PopupMenu==0)) {
451     InitMenu(&MainMenu);
452     ::SetMenu(HVTWin,MainMenu);
453     }
454    
455     /* Reset Terminal */
456     ResetTerminal();
457    
458 maya 3392 if ((ts.PopupMenu>0) || (ts.HideTitle>0)) {
459 maya 3227 ::PostMessage(HVTWin,WM_USER_CHANGEMENU,0,0);
460 maya 3392 }
461 maya 3227
462     ChangeFont();
463    
464     ResetIME();
465    
466     BuffChangeWinSize(NumOfColumns,NumOfLines);
467    
468     ChangeTitle();
469     /* Enable drag-drop */
470     ::DragAcceptFiles(HVTWin,TRUE);
471    
472     if (ts.HideWindow>0) {
473     if (strlen(TopicName)>0) {
474     InitDDE();
475     SendDDEReady();
476     }
477     FirstPaint = FALSE;
478     Startup();
479     return;
480     }
481 maya 3392 CmdShow = SW_SHOWDEFAULT;
482     if (ts.Minimize>0) {
483 maya 3227 CmdShow = SW_SHOWMINIMIZED;
484 maya 3392 }
485 zmatsuo 7390 SetWindowAlpha(ts.AlphaBlendActive);
486 maya 3227 ShowWindow(CmdShow);
487     ChangeCaret();
488 yutakapon 6130
489 zmatsuo 7148 DropLists = NULL;
490     DropListCount = 0;
491 yasuhide 8143
492 doda 8445 #if UNICODE_DEBUG
493     CtrlKeyState = 0;
494     #endif
495    
496 yasuhide 8143 // TipWin
497 yasuhide 8268 TipWin = new CTipWin(hInstance);
498     TipWin->Create(HVTWin);
499 maya 3227 }
500    
501     /////////////////////////////////////////////////////////////////////////////
502 yasuhide 8268 // CVTWindow destructor
503 maya 3227
504 yasuhide 8268 CVTWindow::~CVTWindow()
505     {
506     TipWin->Destroy();
507     delete TipWin;
508     TipWin = NULL;
509     }
510    
511     /////////////////////////////////////////////////////////////////////////////
512    
513 maya 3227 int CVTWindow::Parse()
514     {
515     // added ScrollLock (2006.11.14 yutaka)
516     if (LButton || MButton || RButton || ScrollLock)
517     return 0;
518     return (VTParse()); // Parse received characters
519     }
520    
521     void CVTWindow::ButtonUp(BOOL Paste)
522     {
523     BOOL disableBuffEndSelect = false;
524    
525     /* disable autoscrolling */
526     ::KillTimer(HVTWin,IdScrollTimer);
527     ReleaseCapture();
528    
529     if (ts.SelectOnlyByLButton &&
530     (MButton || RButton)) {
531     disableBuffEndSelect = true;
532     }
533    
534     LButton = FALSE;
535     MButton = FALSE;
536     RButton = FALSE;
537     DblClk = FALSE;
538     TplClk = FALSE;
539     CaretOn();
540    
541     // SelectOnlyByLButton �� on �� ���E�E�N���b�N����������
542     // �o�b�t�@���I���������������A�I�����e���N���b�v�{�[�h��
543     // �R�s�[�������������������C�� (2007.12.6 maya)
544     if (!disableBuffEndSelect) {
545 zmatsuo 8676 wchar_t *strW = BuffEndSelect();
546     if (strW != NULL) {
547     CBSetTextW(HVTWin, strW, 0);
548     }
549 maya 3227 }
550    
551 doda 6415 if (Paste) {
552 doda 6456 CBStartPaste(HVTWin, FALSE, BracketedPasteMode());
553 doda 8445
554 doda 6456 // �X�N���[�����u�����Z�b�g
555     if (WinOrgY != 0) {
556     DispVScroll(SCROLL_BOTTOM, 0);
557 maya 3227 }
558     }
559     }
560    
561     void CVTWindow::ButtonDown(POINT p, int LMR)
562     {
563     HMENU PopupMenu, PopupBase;
564     BOOL mousereport;
565    
566     if ((LMR==IdLeftButton) && ControlKey() && (MainMenu==NULL) &&
567     ((ts.MenuFlag & MF_NOPOPUP)==0)) {
568     int i, numItems;
569    
570     InitMenu(&PopupMenu);
571    
572     PopupBase = CreatePopupMenu();
573     numItems = GetMenuItemCount(PopupMenu);
574    
575     for (i = 0; i < numItems; i++) {
576 zmatsuo 9358 wchar_t itemText[256];
577 maya 3227 HMENU submenu = GetSubMenu(PopupMenu, i);
578    
579     if (submenu != NULL) {
580     InitMenuPopup(submenu);
581     }
582    
583 zmatsuo 9358 if (GetMenuStringW(PopupMenu, i, itemText, _countof(itemText), MF_BYPOSITION) != 0) {
584 maya 3227 int state = GetMenuState(PopupMenu, i, MF_BYPOSITION) &
585     (MF_CHECKED | MF_DISABLED | MF_GRAYED | MF_HILITE |
586     MF_MENUBARBREAK | MF_MENUBREAK | MF_SEPARATOR);
587    
588 zmatsuo 9358 AppendMenuW(PopupBase,
589     submenu != NULL ? LOBYTE(state) | MF_POPUP : state,
590     submenu != NULL ? (UINT_PTR)submenu : GetMenuItemID(PopupMenu, i),
591     itemText);
592 maya 3227 }
593     }
594    
595     ::ClientToScreen(HVTWin, &p);
596     TrackPopupMenu(PopupBase,TPM_LEFTALIGN | TPM_LEFTBUTTON,
597     p.x,p.y,0,HVTWin,NULL);
598     if (WinMenu!=NULL) {
599     DestroyMenu(WinMenu);
600     WinMenu = NULL;
601     }
602     DestroyMenu(PopupBase);
603     DestroyMenu(PopupMenu);
604     PopupMenu = 0;
605     return;
606     }
607    
608 zmatsuo 7528 mousereport = MouseReport(IdMouseEventBtnDown, LMR, p.x, p.y);
609     if (mousereport) {
610     ::SetCapture(m_hWnd);
611 doda 3987 return;
612     }
613 maya 3227
614     // added ConfirmPasteMouseRButton (2007.3.17 maya)
615     if ((LMR == IdRightButton) &&
616 doda 6594 (ts.PasteFlag & CPF_DISABLE_RBUTTON) == 0 &&
617     (ts.PasteFlag & CPF_CONFIRM_RBUTTON) != 0 &&
618 maya 3227 cv.Ready &&
619     !mousereport &&
620 zmatsuo 8948 IsSendVarNULL() && IsFileVarNULL() &&
621 maya 3227 (cv.PortType!=IdFile) &&
622     (IsClipboardFormatAvailable(CF_TEXT) ||
623     IsClipboardFormatAvailable(CF_OEMTEXT))) {
624    
625     int i, numItems;
626    
627     InitPasteMenu(&PopupMenu);
628     PopupBase = CreatePopupMenu();
629     numItems = GetMenuItemCount(PopupMenu);
630    
631     for (i = 0; i < numItems; i++) {
632 zmatsuo 9358 wchar_t itemText[256];
633     if (GetMenuStringW(PopupMenu, i, itemText, _countof(itemText), MF_BYPOSITION) != 0) {
634 maya 3227 int state = GetMenuState(PopupMenu, i, MF_BYPOSITION) &
635     (MF_CHECKED | MF_DISABLED | MF_GRAYED | MF_HILITE |
636     MF_MENUBARBREAK | MF_MENUBREAK | MF_SEPARATOR);
637    
638 zmatsuo 9358 AppendMenuW(PopupBase, state,
639     GetMenuItemID(PopupMenu, i), itemText);
640 maya 3227 }
641     }
642    
643     ::ClientToScreen(HVTWin, &p);
644     TrackPopupMenu(PopupBase,TPM_LEFTALIGN | TPM_LEFTBUTTON,
645     p.x,p.y,0,HVTWin,NULL);
646     if (WinMenu!=NULL) {
647     DestroyMenu(WinMenu);
648     WinMenu = NULL;
649     }
650     DestroyMenu(PopupBase);
651     DestroyMenu(PopupMenu);
652     PopupMenu = 0;
653     return;
654     }
655    
656     if (AfterDblClk && (LMR==IdLeftButton) &&
657     (abs(p.x-DblClkX)<=GetSystemMetrics(SM_CXDOUBLECLK)) &&
658     (abs(p.y-DblClkY)<=GetSystemMetrics(SM_CYDOUBLECLK))) {
659     /* triple click */
660     ::KillTimer(HVTWin, IdDblClkTimer);
661     AfterDblClk = FALSE;
662     BuffTplClk(p.y);
663     LButton = TRUE;
664     TplClk = TRUE;
665     /* for AutoScrolling */
666     ::SetCapture(HVTWin);
667     ::SetTimer(HVTWin, IdScrollTimer, 100, NULL);
668     }
669     else {
670     if (! (LButton || MButton || RButton)) {
671     BOOL box = FALSE;
672    
673     // select several pages of output from Tera Term window (2005.5.15 yutaka)
674     if (LMR == IdLeftButton && ShiftKey()) {
675     BuffSeveralPagesSelect(p.x, p.y);
676    
677     } else {
678     // Select rectangular block with Alt Key. Delete Shift key.(2005.5.15 yutaka)
679     if (LMR == IdLeftButton && AltKey()) {
680     box = TRUE;
681     }
682    
683     // Starting the selection only by a left button.(2007.11.20 maya)
684     if (!ts.SelectOnlyByLButton ||
685     (ts.SelectOnlyByLButton && LMR == IdLeftButton) ) {
686     BuffStartSelect(p.x,p.y, box);
687     TplClk = FALSE;
688    
689     /* for AutoScrolling */
690     ::SetCapture(HVTWin);
691     ::SetTimer(HVTWin, IdScrollTimer, 100, NULL);
692     }
693     }
694     }
695    
696     switch (LMR) {
697     case IdRightButton:
698     RButton = TRUE;
699     break;
700     case IdMiddleButton:
701     MButton = TRUE;
702     break;
703     case IdLeftButton:
704     LButton = TRUE;
705     break;
706     }
707     }
708     }
709    
710     void CVTWindow::InitMenu(HMENU *Menu)
711     {
712 doda 8445 static const DlgTextInfo MenuTextInfo[] = {
713     { ID_FILE, "MENU_FILE" },
714     { ID_EDIT, "MENU_EDIT" },
715     { ID_SETUP, "MENU_SETUP" },
716     { ID_CONTROL, "MENU_CONTROL" },
717     { ID_HELPMENU, "MENU_HELP" },
718     };
719     static const DlgTextInfo FileMenuTextInfo[] = {
720     { ID_FILE_NEWCONNECTION, "MENU_FILE_NEW" },
721     { ID_FILE_DUPLICATESESSION, "MENU_FILE_DUPLICATE" },
722     { ID_FILE_CYGWINCONNECTION, "MENU_FILE_GYGWIN" },
723     { ID_FILE_LOG, "MENU_FILE_LOG" },
724     { ID_FILE_COMMENTTOLOG, "MENU_FILE_COMMENTLOG" },
725     { ID_FILE_VIEWLOG, "MENU_FILE_VIEWLOG" },
726     { ID_FILE_SHOWLOGDIALOG, "MENU_FILE_SHOWLOGDIALOG" },
727     { ID_FILE_PAUSELOG, "MENU_FILE_PAUSELOG" },
728     { ID_FILE_STOPLOG, "MENU_FILE_STOPLOG" },
729     { ID_FILE_SENDFILE, "MENU_FILE_SENDFILE" },
730     { ID_FILE_REPLAYLOG, "MENU_FILE_REPLAYLOG" },
731     { ID_FILE_CHANGEDIR, "MENU_FILE_CHANGEDIR" },
732     { ID_FILE_PRINT2, "MENU_FILE_PRINT" },
733     { ID_FILE_DISCONNECT, "MENU_FILE_DISCONNECT" },
734     { ID_FILE_EXIT, "MENU_FILE_EXIT" },
735     { ID_FILE_EXITALL, "MENU_FILE_EXITALL" },
736     { 11, "MENU_TRANS" },
737     { ID_FILE_KERMITRCV, "MENU_TRANS_KERMIT_RCV" },
738     { ID_FILE_KERMITGET, "MENU_TRANS_KERMIT_GET" },
739     { ID_FILE_KERMITSEND, "MENU_TRANS_KERMIT_SEND" },
740     { ID_FILE_KERMITFINISH, "MENU_TRANS_KERMIT_FINISH" },
741     { ID_FILE_XRCV, "MENU_TRANS_X_RCV" },
742     { ID_FILE_XSEND, "MENU_TRANS_X_SEND" },
743     { ID_FILE_YRCV, "MENU_TRANS_Y_RCV" },
744     { ID_FILE_YSEND, "MENU_TRANS_Y_SEND" },
745     { ID_FILE_ZRCV, "MENU_TRANS_Z_RCV" },
746     { ID_FILE_ZSEND, "MENU_TRANS_Z_SEND" },
747     { ID_FILE_BPRCV, "MENU_TRANS_BP_RCV" },
748     { ID_FILE_BPSEND, "MENU_TRANS_BP_SEND" },
749     { ID_FILE_QVRCV, "MENU_TRANS_QV_RCV" },
750     { ID_FILE_QVSEND, "MENU_TRANS_QV_SEND" },
751     };
752     static const DlgTextInfo EditMenuTextInfo[] = {
753     { ID_EDIT_COPY2, "MENU_EDIT_COPY" },
754     { ID_EDIT_COPYTABLE, "MENU_EDIT_COPYTABLE" },
755     { ID_EDIT_PASTE2, "MENU_EDIT_PASTE" },
756     { ID_EDIT_PASTECR, "MENU_EDIT_PASTECR" },
757     { ID_EDIT_CLEARSCREEN, "MENU_EDIT_CLSCREEN" },
758     { ID_EDIT_CLEARBUFFER, "MENU_EDIT_CLBUFFER" },
759     { ID_EDIT_CANCELSELECT, "MENU_EDIT_CANCELSELECT" },
760     { ID_EDIT_SELECTSCREEN, "MENU_EDIT_SELECTSCREEN" },
761     { ID_EDIT_SELECTALL, "MENU_EDIT_SELECTALL" },
762     };
763     static const DlgTextInfo SetupMenuTextInfo[] = {
764     { ID_SETUP_TERMINAL, "MENU_SETUP_TERMINAL" },
765     { ID_SETUP_WINDOW, "MENU_SETUP_WINDOW" },
766     { ID_SETUP_FONT, "MENU_SETUP_FONT" },
767     { ID_SETUP_DLG_FONT, "MENU_SETUP_DIALOG_FONT" },
768     { 2, "MENU_SETUP_FONT_SUBMENU" },
769     { ID_SETUP_KEYBOARD, "MENU_SETUP_KEYBOARD" },
770     { ID_SETUP_SERIALPORT, "MENU_SETUP_SERIALPORT" },
771     { ID_SETUP_TCPIP, "MENU_SETUP_TCPIP" },
772     { ID_SETUP_GENERAL, "MENU_SETUP_GENERAL" },
773     { ID_SETUP_ADDITIONALSETTINGS, "MENU_SETUP_ADDITION" },
774     { ID_SETUP_SAVE, "MENU_SETUP_SAVE" },
775     { ID_SETUP_RESTORE, "MENU_SETUP_RESTORE" },
776     { ID_OPEN_SETUP, "MENU_SETUP_OPENSETUP" },
777     { ID_SETUP_LOADKEYMAP, "MENU_SETUP_LOADKEYMAP" },
778     };
779     static const DlgTextInfo ControlMenuTextInfo[] = {
780     { ID_CONTROL_RESETTERMINAL, "MENU_CONTROL_RESET" },
781     { ID_CONTROL_RESETREMOTETITLE, "MENU_CONTROL_RESETTITLE" },
782     { ID_CONTROL_AREYOUTHERE, "MENU_CONTROL_AREYOUTHERE" },
783     { ID_CONTROL_SENDBREAK, "MENU_CONTROL_SENDBREAK" },
784     { ID_CONTROL_RESETPORT, "MENU_CONTROL_RESETPORT" },
785     { ID_CONTROL_BROADCASTCOMMAND, "MENU_CONTROL_BROADCAST" },
786     { ID_CONTROL_OPENTEK, "MENU_CONTROL_OPENTEK" },
787     { ID_CONTROL_CLOSETEK, "MENU_CONTROL_CLOSETEK" },
788     { ID_CONTROL_MACRO, "MENU_CONTROL_MACRO" },
789     { ID_CONTROL_SHOW_MACRO, "MENU_CONTROL_SHOW_MACRO" },
790     };
791     static const DlgTextInfo HelpMenuTextInfo[] = {
792     { ID_HELP_INDEX2, "MENU_HELP_INDEX" },
793     { ID_HELP_ABOUT, "MENU_HELP_ABOUT" },
794     };
795 maya 3227
796 doda 8445 HMENU hMenu = LoadMenu(m_hInst, MAKEINTRESOURCE(IDR_MENU));
797     *Menu = hMenu;
798    
799     FileMenu = GetSubMenu(hMenu,ID_FILE);
800 maya 3227 TransMenu = GetSubMenu(FileMenu,ID_TRANSFER);
801 doda 8445 EditMenu = GetSubMenu(hMenu,ID_EDIT);
802     SetupMenu = GetSubMenu(hMenu,ID_SETUP);
803     ControlMenu = GetSubMenu(hMenu,ID_CONTROL);
804     HelpMenu = GetSubMenu(hMenu,ID_HELPMENU);
805 maya 3227
806 zmatsuo 9350 SetDlgMenuTextsW(hMenu, MenuTextInfo, _countof(MenuTextInfo), ts.UILanguageFileW);
807 doda 8445
808 zmatsuo 9350 SetDlgMenuTextsW(FileMenu, FileMenuTextInfo, _countof(FileMenuTextInfo), ts.UILanguageFileW);
809     SetDlgMenuTextsW(EditMenu, EditMenuTextInfo, _countof(EditMenuTextInfo), ts.UILanguageFileW);
810     SetDlgMenuTextsW(SetupMenu, SetupMenuTextInfo, _countof(SetupMenuTextInfo), ts.UILanguageFileW);
811     SetDlgMenuTextsW(ControlMenu, ControlMenuTextInfo, _countof(ControlMenuTextInfo), ts.UILanguageFileW);
812     SetDlgMenuTextsW(HelpMenu, HelpMenuTextInfo, _countof(HelpMenuTextInfo), ts.UILanguageFileW);
813 maya 3227
814     if ((ts.MenuFlag & MF_SHOWWINMENU) !=0) {
815 zmatsuo 8490 wchar_t uimsg[MAX_UIMSG];
816 maya 3227 WinMenu = CreatePopupMenu();
817 zmatsuo 8490 get_lang_msgW("MENU_WINDOW", uimsg, _countof(uimsg),
818     L"&Window", ts.UILanguageFile);
819 zmatsuo 9324 InsertMenuW(hMenu, ID_HELPMENU,
820     MF_STRING | MF_ENABLED | MF_POPUP | MF_BYPOSITION,
821     (UINT_PTR)WinMenu, uimsg);
822 maya 3227 }
823    
824 doda 8445 TTXModifyMenu(hMenu); /* TTPLUG */
825 maya 3227 }
826    
827     void CVTWindow::InitMenuPopup(HMENU SubMenu)
828     {
829     if ( SubMenu == FileMenu )
830     {
831 maya 3966 if (ts.DisableMenuNewConnection) {
832     if ( Connecting || cv.Open ) {
833 maya 3965 EnableMenuItem(FileMenu,ID_FILE_NEWCONNECTION,MF_BYCOMMAND | MF_GRAYED);
834     }
835     else {
836     EnableMenuItem(FileMenu,ID_FILE_NEWCONNECTION,MF_BYCOMMAND | MF_ENABLED);
837     }
838 maya 3227 }
839 maya 3966 else {
840     if ( Connecting ) {
841     EnableMenuItem(FileMenu,ID_FILE_NEWCONNECTION,MF_BYCOMMAND | MF_GRAYED);
842     }
843     else {
844     EnableMenuItem(FileMenu,ID_FILE_NEWCONNECTION,MF_BYCOMMAND | MF_ENABLED);
845     }
846     }
847 maya 3227
848 zmatsuo 8948 if ( (! cv.Ready) || (!IsSendVarNULL()) ||
849     (!IsFileVarNULL()) || (cv.PortType==IdFile) ) {
850 maya 3227 EnableMenuItem(FileMenu,ID_FILE_SENDFILE,MF_BYCOMMAND | MF_GRAYED);
851     EnableMenuItem(FileMenu,ID_TRANSFER,MF_BYPOSITION | MF_GRAYED); /* Transfer */
852     EnableMenuItem(FileMenu,ID_FILE_CHANGEDIR,MF_BYCOMMAND | MF_GRAYED);
853     EnableMenuItem(FileMenu,ID_FILE_DISCONNECT,MF_BYCOMMAND | MF_GRAYED);
854     EnableMenuItem(FileMenu,ID_FILE_DUPLICATESESSION,MF_BYCOMMAND | MF_GRAYED);
855     }
856     else {
857     EnableMenuItem(FileMenu,ID_FILE_SENDFILE,MF_BYCOMMAND | MF_ENABLED);
858     EnableMenuItem(FileMenu,ID_TRANSFER,MF_BYPOSITION | MF_ENABLED); /* Transfer */
859     EnableMenuItem(FileMenu,ID_FILE_CHANGEDIR,MF_BYCOMMAND | MF_ENABLED);
860     EnableMenuItem(FileMenu,ID_FILE_DISCONNECT,MF_BYCOMMAND | MF_ENABLED);
861 maya 3964 if (ts.DisableMenuDuplicateSession) {
862     EnableMenuItem(FileMenu,ID_FILE_DUPLICATESESSION,MF_BYCOMMAND | MF_GRAYED);
863     }
864     else {
865     EnableMenuItem(FileMenu,ID_FILE_DUPLICATESESSION,MF_BYCOMMAND | MF_ENABLED);
866     }
867 maya 3227 }
868    
869     // �V�K���j���[������ (2004.12.5 yutaka)
870     EnableMenuItem(FileMenu,ID_FILE_CYGWINCONNECTION,MF_BYCOMMAND | MF_ENABLED);
871     EnableMenuItem(FileMenu,ID_FILE_TERATERMMENU,MF_BYCOMMAND | MF_ENABLED);
872    
873     // XXX: �������u�����������Alog���O���C�����������B (2005.2.1 yutaka)
874 zmatsuo 8858 if (FLogIsOpend()) { // ���O�������[�h������
875 maya 3227 EnableMenuItem(FileMenu,ID_FILE_LOG,MF_BYCOMMAND | MF_GRAYED);
876     EnableMenuItem(FileMenu,ID_FILE_COMMENTTOLOG, MF_BYCOMMAND | MF_ENABLED);
877     EnableMenuItem(FileMenu,ID_FILE_VIEWLOG, MF_BYCOMMAND | MF_ENABLED);
878 maya 3709 EnableMenuItem(FileMenu,ID_FILE_SHOWLOGDIALOG, MF_BYCOMMAND | MF_ENABLED);
879 doda 8396 EnableMenuItem(FileMenu,ID_FILE_PAUSELOG, MF_BYCOMMAND | MF_ENABLED);
880     EnableMenuItem(FileMenu,ID_FILE_STOPLOG, MF_BYCOMMAND | MF_ENABLED);
881 zmatsuo 8857 if (FLogIsPause()) {
882 doda 8396 CheckMenuItem(FileMenu,ID_FILE_PAUSELOG, MF_BYCOMMAND | MF_CHECKED);
883     }
884     else {
885     CheckMenuItem(FileMenu,ID_FILE_PAUSELOG, MF_BYCOMMAND | MF_UNCHECKED);
886     }
887 maya 3227 } else {
888     EnableMenuItem(FileMenu,ID_FILE_LOG,MF_BYCOMMAND | MF_ENABLED);
889     EnableMenuItem(FileMenu,ID_FILE_COMMENTTOLOG, MF_BYCOMMAND | MF_GRAYED);
890     EnableMenuItem(FileMenu,ID_FILE_VIEWLOG, MF_BYCOMMAND | MF_GRAYED);
891     EnableMenuItem(FileMenu,ID_FILE_SHOWLOGDIALOG, MF_BYCOMMAND | MF_GRAYED);
892 doda 8396 EnableMenuItem(FileMenu,ID_FILE_PAUSELOG, MF_BYCOMMAND | MF_GRAYED);
893     EnableMenuItem(FileMenu,ID_FILE_STOPLOG, MF_BYCOMMAND | MF_GRAYED);
894    
895     CheckMenuItem(FileMenu,ID_FILE_PAUSELOG, MF_BYCOMMAND | MF_UNCHECKED);
896 maya 3227 }
897    
898     }
899     else if ( SubMenu == TransMenu )
900     {
901     if ((cv.PortType==IdSerial) &&
902     ((ts.DataBit==IdDataBit7) || (ts.Flow==IdFlowX))) {
903     EnableMenuItem(TransMenu,1,MF_BYPOSITION | MF_GRAYED); /* XMODEM */
904     EnableMenuItem(TransMenu,4,MF_BYPOSITION | MF_GRAYED); /* Quick-VAN */
905     }
906     else {
907     EnableMenuItem(TransMenu,1,MF_BYPOSITION | MF_ENABLED); /* XMODEM */
908     EnableMenuItem(TransMenu,4,MF_BYPOSITION | MF_ENABLED); /* Quick-VAN */
909     }
910     if ((cv.PortType==IdSerial) &&
911     (ts.DataBit==IdDataBit7)) {
912     EnableMenuItem(TransMenu,2,MF_BYPOSITION | MF_GRAYED); /* ZMODEM */
913     EnableMenuItem(TransMenu,3,MF_BYPOSITION | MF_GRAYED); /* B-Plus */
914     }
915     else {
916     EnableMenuItem(TransMenu,2,MF_BYPOSITION | MF_ENABLED); /* ZMODEM */
917     EnableMenuItem(TransMenu,3,MF_BYPOSITION | MF_ENABLED); /* B-Plus */
918     }
919     }
920     else if (SubMenu == EditMenu)
921     {
922     if (Selected) {
923     EnableMenuItem(EditMenu,ID_EDIT_COPY2,MF_BYCOMMAND | MF_ENABLED);
924     EnableMenuItem(EditMenu,ID_EDIT_COPYTABLE,MF_BYCOMMAND | MF_ENABLED);
925     }
926     else {
927     EnableMenuItem(EditMenu,ID_EDIT_COPY2,MF_BYCOMMAND | MF_GRAYED);
928     EnableMenuItem(EditMenu,ID_EDIT_COPYTABLE,MF_BYCOMMAND | MF_GRAYED);
929     }
930     if (cv.Ready &&
931 zmatsuo 8948 IsSendVarNULL() && IsFileVarNULL() &&
932 maya 3227 (cv.PortType!=IdFile) &&
933     (IsClipboardFormatAvailable(CF_TEXT) ||
934     IsClipboardFormatAvailable(CF_OEMTEXT))) {
935     EnableMenuItem(EditMenu,ID_EDIT_PASTE2,MF_BYCOMMAND | MF_ENABLED);
936     EnableMenuItem(EditMenu,ID_EDIT_PASTECR,MF_BYCOMMAND | MF_ENABLED);
937     }
938     else {
939     EnableMenuItem(EditMenu,ID_EDIT_PASTE2,MF_BYCOMMAND | MF_GRAYED);
940     EnableMenuItem(EditMenu,ID_EDIT_PASTECR,MF_BYCOMMAND | MF_GRAYED);
941     }
942     }
943     else if (SubMenu == SetupMenu)
944 yutakapon 8179 /*
945     * �l�b�g���[�N������(TCP/IP���I������������������)���V���A���|�[�g
946     * (ID_SETUP_SERIALPORT)�����j���[���I�����������������������������A
947     * �����K�[�h���O���A�V���A���|�[�g�����_�C�A���O�����V���������������������������B
948     */
949 zmatsuo 8948 if (!IsSendVarNULL() || !IsFileVarNULL() || Connecting) {
950 yutakapon 8179 EnableMenuItem(SetupMenu,ID_SETUP_SERIALPORT,MF_BYCOMMAND | MF_GRAYED);
951 maya 3392 }
952     else {
953 yutakapon 8179 EnableMenuItem(SetupMenu,ID_SETUP_SERIALPORT,MF_BYCOMMAND | MF_ENABLED);
954 maya 3392 }
955 maya 3227
956     else if (SubMenu == ControlMenu)
957     {
958     if (cv.Ready &&
959 zmatsuo 8948 IsSendVarNULL() && IsFileVarNULL()) {
960 maya 3283 if (ts.DisableMenuSendBreak) {
961 maya 3279 EnableMenuItem(ControlMenu,ID_CONTROL_SENDBREAK,MF_BYCOMMAND | MF_GRAYED);
962     }
963     else {
964     EnableMenuItem(ControlMenu,ID_CONTROL_SENDBREAK,MF_BYCOMMAND | MF_ENABLED);
965     }
966 maya 3392 if (cv.PortType==IdSerial) {
967 maya 3227 EnableMenuItem(ControlMenu,ID_CONTROL_RESETPORT,MF_BYCOMMAND | MF_ENABLED);
968 maya 3392 }
969     else {
970 maya 3227 EnableMenuItem(ControlMenu,ID_CONTROL_RESETPORT,MF_BYCOMMAND | MF_GRAYED);
971 maya 3392 }
972 maya 3227 }
973     else {
974     EnableMenuItem(ControlMenu,ID_CONTROL_SENDBREAK,MF_BYCOMMAND | MF_GRAYED);
975     EnableMenuItem(ControlMenu,ID_CONTROL_RESETPORT,MF_BYCOMMAND | MF_GRAYED);
976     }
977    
978 zmatsuo 8948 if (cv.Ready && cv.TelFlag && IsFileVarNULL()) {
979 maya 3227 EnableMenuItem(ControlMenu,ID_CONTROL_AREYOUTHERE,MF_BYCOMMAND | MF_ENABLED);
980 maya 3392 }
981     else {
982 maya 3227 EnableMenuItem(ControlMenu,ID_CONTROL_AREYOUTHERE,MF_BYCOMMAND | MF_GRAYED);
983 maya 3392 }
984 maya 3227
985 maya 3392 if (HTEKWin==0) {
986 maya 3227 EnableMenuItem(ControlMenu,ID_CONTROL_CLOSETEK,MF_BYCOMMAND | MF_GRAYED);
987 maya 3392 }
988     else {
989 maya 3227 EnableMenuItem(ControlMenu,ID_CONTROL_CLOSETEK,MF_BYCOMMAND | MF_ENABLED);
990 maya 3392 }
991 maya 3227
992 zmatsuo 8948 if (DDELog || !IsFileVarNULL()) {
993 maya 3227 EnableMenuItem(ControlMenu,ID_CONTROL_MACRO,MF_BYCOMMAND | MF_GRAYED);
994 maya 3842 EnableMenuItem(ControlMenu,ID_CONTROL_SHOW_MACRO,MF_BYCOMMAND | MF_ENABLED);
995 maya 3392 }
996     else {
997 yutakapon 3837 EnableMenuItem(ControlMenu,ID_CONTROL_MACRO,MF_BYCOMMAND | MF_ENABLED);
998 maya 3842 EnableMenuItem(ControlMenu,ID_CONTROL_SHOW_MACRO,MF_BYCOMMAND | MF_GRAYED);
999 maya 3392 }
1000 maya 3227
1001     }
1002     else if (SubMenu == WinMenu)
1003     {
1004 yutakapon 5249 SetWinMenu(WinMenu, ts.UIMsg, sizeof(ts.UIMsg), ts.UILanguageFile, 1);
1005 maya 3227 }
1006    
1007     TTXModifyPopupMenu(SubMenu); /* TTPLUG */
1008     }
1009    
1010     // added ConfirmPasteMouseRButton (2007.3.17 maya)
1011     void CVTWindow::InitPasteMenu(HMENU *Menu)
1012     {
1013 doda 8445 static const DlgTextInfo MenuTextInfo[] = {
1014     { ID_EDIT_PASTE2, "MENU_EDIT_PASTE" },
1015     { ID_EDIT_PASTECR, "MENU_EDIT_PASTECR" },
1016     };
1017 zmatsuo 7916 *Menu = LoadMenu(m_hInst,
1018 maya 3227 MAKEINTRESOURCE(IDR_PASTEMENU));
1019 zmatsuo 9350 SetDlgMenuTextsW(*Menu, MenuTextInfo, _countof(MenuTextInfo), ts.UILanguageFileW);
1020 maya 3227 }
1021    
1022     void CVTWindow::ResetSetup()
1023     {
1024     ChangeFont();
1025     BuffChangeWinSize(WinWidth,WinHeight);
1026     ChangeCaret();
1027    
1028     if (cv.Ready) {
1029     ts.PortType = cv.PortType;
1030     if (cv.PortType==IdSerial) {
1031     /* if serial port, change port parameters */
1032     ts.ComPort = cv.ComPort;
1033     CommResetSerial(&ts, &cv, TRUE);
1034     }
1035     }
1036    
1037     /* setup terminal */
1038     SetupTerm();
1039    
1040     /* background and ANSI color */
1041 zmatsuo 10134
1042     #if 0
1043     // �N�������������������e�[�}����������������������������
1044 yutakapon 8106 BGInitialize(FALSE);
1045 maya 3227 BGSetupPrimary(TRUE);
1046 zmatsuo 10134 #endif
1047    
1048 maya 3227 // 2006/03/17 by 337 : Alpha�l���������X
1049     // Layered��������������������������������
1050 yutakapon 6553 //
1051     // AlphaBlend ���������f�����������������B
1052     // (2016.12.24 yutaka)
1053 zmatsuo 7390 SetWindowAlpha(ts.AlphaBlendActive);
1054 maya 3227
1055     /* setup window */
1056     ChangeWin();
1057    
1058     /* Language & IME */
1059     ResetIME();
1060    
1061     /* change TEK window */
1062     if (pTEKWin != NULL)
1063     ((CTEKWindow *)pTEKWin)->RestoreSetup();
1064     }
1065    
1066     void CVTWindow::RestoreSetup()
1067     {
1068     char TempDir[MAXPATHLEN];
1069 maya 4031 char TempName[MAX_PATH];
1070 maya 3227
1071 maya 3392 if ( strlen(ts.SetupFName)==0 ) {
1072 maya 3227 return;
1073 maya 3392 }
1074 maya 3227
1075     ExtractFileName(ts.SetupFName,TempName,sizeof(TempName));
1076     ExtractDirName(ts.SetupFName,TempDir);
1077     if (TempDir[0]==0)
1078     strncpy_s(TempDir, sizeof(TempDir),ts.HomeDir, _TRUNCATE);
1079     FitFileName(TempName,sizeof(TempName),".INI");
1080    
1081     strncpy_s(ts.SetupFName, sizeof(ts.SetupFName),TempDir, _TRUNCATE);
1082     AppendSlash(ts.SetupFName,sizeof(ts.SetupFName));
1083 maya 3392 strncat_s(ts.SetupFName,sizeof(ts.SetupFName),TempName,_TRUNCATE);
1084 maya 3227
1085 maya 3392 if (LoadTTSET()) {
1086 zmatsuo 9429 (*ReadIniFile)(ts.SetupFNameW, &ts);
1087 maya 3392 }
1088 maya 3227 FreeTTSET();
1089    
1090     ResetSetup();
1091     }
1092    
1093     /* called by the [Setup] Terminal command */
1094     void CVTWindow::SetupTerm()
1095     {
1096 zmatsuo 9314 // if (ts.Language==IdJapanese || ts.Language==IdKorean || ts.Language==IdUtf8) {
1097 maya 3227 ResetCharSet();
1098 zmatsuo 9314 // }
1099 maya 3227 cv.CRSend = ts.CRSend;
1100    
1101 doda 3932 if (cv.Ready) {
1102     if (cv.TelFlag && (ts.TelEcho>0)) {
1103     TelChangeEcho();
1104     }
1105 maya 3392 }
1106 maya 3227
1107     if ((ts.TerminalWidth!=NumOfColumns) ||
1108     (ts.TerminalHeight!=NumOfLines-StatusLine)) {
1109     LockBuffer();
1110     HideStatusLine();
1111     ChangeTerminalSize(ts.TerminalWidth,
1112     ts.TerminalHeight);
1113     UnlockBuffer();
1114     }
1115     else if ((ts.TermIsWin>0) &&
1116     ((ts.TerminalWidth!=WinWidth) ||
1117 maya 3392 (ts.TerminalHeight!=WinHeight-StatusLine))) {
1118 maya 3227 BuffChangeWinSize(ts.TerminalWidth,ts.TerminalHeight+StatusLine);
1119 maya 3392 }
1120 doda 4246
1121     ChangeTerminalID();
1122 maya 3227 }
1123    
1124     void CVTWindow::Startup()
1125     {
1126     /* auto log */
1127     /* OnCommOpen ���J�n�������������������J�n������ (2007.5.14 maya) */
1128    
1129     if ((TopicName[0]==0) && (ts.MacroFN[0]!=0)) {
1130     // start the macro specified in the command line or setup file
1131     RunMacro(ts.MacroFN,TRUE);
1132     ts.MacroFN[0] = 0;
1133     }
1134     else {// start connection
1135 maya 3392 if (TopicName[0]!=0) {
1136 maya 3227 cv.NoMsg=1; /* suppress error messages */
1137 maya 3392 }
1138 maya 3227 ::PostMessage(HVTWin,WM_USER_COMMSTART,0,0);
1139     }
1140     }
1141    
1142     void CVTWindow::OpenTEK()
1143     {
1144     ActiveWin = IdTEK;
1145     if (HTEKWin==NULL) {
1146 zmatsuo 7916 pTEKWin = new CTEKWindow(m_hInst);
1147 maya 3227 }
1148     else {
1149     ::ShowWindow(HTEKWin,SW_SHOWNORMAL);
1150     ::SetFocus(HTEKWin);
1151     }
1152     }
1153    
1154     /////////////////////////////////////////////////////////////////////////////
1155     // CVTWindow message handler
1156    
1157     BOOL CVTWindow::OnCommand(WPARAM wParam, LPARAM lParam)
1158     {
1159     WORD wID = LOWORD(wParam);
1160     WORD wNotifyCode = HIWORD(wParam);
1161    
1162     if (wNotifyCode==1) {
1163     switch (wID) {
1164     case ID_ACC_SENDBREAK:
1165     // added DisableAcceleratorSendBreak (2007.3.17 maya)
1166     if (!ts.DisableAcceleratorSendBreak)
1167     OnControlSendBreak();
1168     return TRUE;
1169     case ID_ACC_AREYOUTHERE:
1170     OnControlAreYouThere();
1171     return TRUE;
1172     }
1173     if (ActiveWin==IdVT) {
1174     switch (wID) {
1175     case ID_ACC_NEWCONNECTION:
1176 maya 5684 if (ts.AcceleratorNewConnection)
1177     OnFileNewConnection();
1178 maya 3227 return TRUE;
1179 maya 5691 case ID_ACC_DUPLICATESESSION:
1180     // added DisableAcceleratorDuplicateSession (2009.4.6 maya)
1181     if (!ts.DisableAcceleratorDuplicateSession)
1182     OnDuplicateSession();
1183     return TRUE;
1184 maya 5684 case ID_ACC_CYGWINCONNECTION:
1185     if (ts.AcceleratorCygwinConnection)
1186     OnCygwinConnection();
1187     return TRUE;
1188 maya 5691 case ID_ACC_DISCONNECT:
1189     Disconnect(TRUE);
1190     return TRUE;
1191 maya 3227 case ID_ACC_COPY:
1192     OnEditCopy();
1193     return TRUE;
1194 doda 6459 case ID_ACC_PASTECR:
1195     OnEditPasteCR();
1196     return TRUE;
1197     case ID_ACC_PASTE:
1198     OnEditPaste();
1199     return TRUE;
1200 maya 3227 case ID_ACC_PRINT:
1201     OnFilePrint();
1202     return TRUE;
1203     case ID_ACC_EXIT:
1204     OnFileExit();
1205     return TRUE;
1206     }
1207     }
1208     else { // transfer accelerator message to TEK win
1209     switch (wID) {
1210     case ID_ACC_COPY:
1211     ::PostMessage(HTEKWin,WM_COMMAND,ID_TEKEDIT_COPY,0);
1212     return TRUE;
1213 doda 6459 case ID_ACC_PASTECR:
1214     ::PostMessage(HTEKWin,WM_COMMAND,ID_TEKEDIT_PASTECR,0);
1215     return TRUE;
1216     case ID_ACC_PASTE:
1217     ::PostMessage(HTEKWin,WM_COMMAND,ID_TEKEDIT_PASTE,0);
1218     return TRUE;
1219 maya 3227 case ID_ACC_PRINT:
1220     ::PostMessage(HTEKWin,WM_COMMAND,ID_TEKFILE_PRINT,0);
1221     return TRUE;
1222     case ID_ACC_EXIT:
1223     ::PostMessage(HTEKWin,WM_COMMAND,ID_TEKFILE_EXIT,0);
1224     return TRUE;
1225     }
1226     }
1227     }
1228    
1229     if ((wID>=ID_WINDOW_1) && (wID<ID_WINDOW_1+9)) {
1230     SelectWin(wID-ID_WINDOW_1);
1231     return TRUE;
1232     }
1233     else {
1234 maya 3392 if (TTXProcessCommand(HVTWin, wID)) {
1235 maya 3227 return TRUE;
1236 maya 3392 }
1237     else { /* TTPLUG */
1238 zmatsuo 7784 return TTCFrameWnd::OnCommand(wParam, lParam);
1239 maya 3392 }
1240 maya 3227 }
1241     }
1242    
1243 zmatsuo 7528 void CVTWindow::OnActivate(UINT nState, HWND pWndOther, BOOL bMinimized)
1244 maya 3227 {
1245     DispSetActive(nState!=WA_INACTIVE);
1246 zmatsuo 7390 if (nState == WA_INACTIVE) {
1247     SetWindowAlpha(ts.AlphaBlendInactive);
1248     } else {
1249     SetWindowAlpha(ts.AlphaBlendActive);
1250     }
1251 maya 3227 }
1252    
1253 zmatsuo 9143 /**
1254     * �L�[�{�[�h����1��������
1255     * @param nChar UTF-16 char(wchar_t) IsWindowUnicode() == TRUE ��
1256     * ANSI char(char) IsWindowUnicode() == FALSE ��
1257     */
1258 zmatsuo 8337 void CVTWindow::OnChar(WPARAM nChar, UINT nRepCnt, UINT nFlags)
1259 maya 3227 {
1260     unsigned int i;
1261    
1262 maya 3392 if (!KeybEnabled || (TalkStatus!=IdTalkKeyb)) {
1263 maya 3227 return;
1264 maya 3392 }
1265 maya 3227
1266 doda 4414 if (MetaKey(ts.MetaKey)) {
1267 maya 3227 ::PostMessage(HVTWin,WM_SYSCHAR,nChar,MAKELONG(nRepCnt,nFlags));
1268     return;
1269     }
1270    
1271 zmatsuo 9143 wchar_t u16;
1272     if (IsWindowUnicode(HVTWin) == TRUE) {
1273     // ������ UTF-16
1274     u16 = (wchar_t)nChar;
1275     } else {
1276 zmatsuo 9150 // ������ ANSI
1277 zmatsuo 9500 if (ts.Language == IdJapanese || ts.Language == IdChinese || ts.Language == IdKorean) {
1278     // CJK (2byte����)
1279     if (vtwin_work.dbcs_lead_byte == 0 && IsDBCSLeadByte(nChar)) {
1280     // ANSI 2�o�C�g������ 1byte��������
1281     // ������ WM_IME_* ���b�Z�[�W������������
1282     // ������������������������
1283     // TERATERM.INI �� IME=off ������
1284     // imm32.dll �����[�h����������������
1285     vtwin_work.dbcs_lead_byte = nChar;
1286     return;
1287     }
1288     else {
1289     // ANSI(ACP) -> UTF-32 -> UTF-16
1290     char mb_str[2];
1291     size_t mb_len;
1292     if (vtwin_work.dbcs_lead_byte == 0) {
1293     // 1�o�C�g����
1294     mb_str[0] = (char)nChar;
1295     mb_len = 1;
1296     }
1297     else {
1298     // 2�o�C�g����
1299     mb_str[0] = (char)vtwin_work.dbcs_lead_byte;
1300     mb_str[1] = (char)nChar;
1301     mb_len = 2;
1302     vtwin_work.dbcs_lead_byte = 0;
1303     }
1304     unsigned int u32;
1305     mb_len = MBCPToUTF32(mb_str, mb_len, CP_ACP, &u32);
1306     if (mb_len == 0) {
1307     return;
1308     }
1309     u16 = (wchar_t)u32;
1310     }
1311 zmatsuo 9143 }
1312 zmatsuo 9500 else if (ts.Language == IdRussian) {
1313     BYTE c;
1314     if (ts.RussKeyb == IdWindows) {
1315     // key = CP1251
1316     c = (char)nChar;
1317 zmatsuo 9383 }
1318     else {
1319 zmatsuo 9500 // key -> CP1251
1320     c = RussConv(ts.RussKeyb, IdWindows, nChar);
1321 zmatsuo 9383 }
1322 zmatsuo 9500 // CP1251 -> UTF-32 -> UTF-16
1323     unsigned long u32 = MBCP_UTF32(c, 1251);
1324 zmatsuo 9383 u16 = (wchar_t)u32;
1325     }
1326 zmatsuo 9500 else {
1327     u16 = (wchar_t)nChar;
1328     }
1329 zmatsuo 9143 }
1330    
1331     // �o�b�t�@���o���A�������o��
1332 maya 3227 for (i=1 ; i<=nRepCnt ; i++) {
1333 doda 8445 CommTextOutW(&cv,&u16,1);
1334 maya 3392 if (ts.LocalEcho>0) {
1335 doda 8445 CommTextEchoW(&cv,&u16,1);
1336 maya 3392 }
1337 maya 3227 }
1338    
1339 doda 6421 // �X�N���[�����u�����Z�b�g
1340     if (WinOrgY != 0) {
1341 maya 3227 DispVScroll(SCROLL_BOTTOM, 0);
1342     }
1343     }
1344    
1345 zmatsuo 8827 LRESULT CVTWindow::OnUniChar(WPARAM wParam, LPARAM lParam)
1346     {
1347     if (wParam == UNICODE_NOCHAR) {
1348     // �������b�Z�[�W���T�|�[�g�����������e�X�g��������������������
1349     return TRUE;
1350     }
1351    
1352     char32_t u32 = (char32_t)wParam;
1353     wchar_t strW[2];
1354     size_t u16_len = UTF32ToUTF16(u32, strW, _countof(strW));
1355     CommTextOutW(&cv, strW, u16_len);
1356     if (ts.LocalEcho > 0) {
1357     CommTextEchoW(&cv, strW, u16_len);
1358     }
1359    
1360     return FALSE;
1361     }
1362    
1363 maya 3227 /* copy from ttset.c*/
1364 zmatsuo 8463 static void WriteInt2(const char *Sect, const char *Key, const char *FName, int i1, int i2)
1365 maya 3227 {
1366     char Temp[32];
1367     _snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%d,%d", i1, i2);
1368     WritePrivateProfileString(Sect, Key, Temp, FName);
1369     }
1370    
1371     static void SaveVTPos()
1372     {
1373     #define Section "Tera Term"
1374     if (ts.SaveVTWinPos) {
1375     /* VT win position */
1376     WriteInt2(Section, "VTPos", ts.SetupFName, ts.VTPos.x, ts.VTPos.y);
1377    
1378     /* VT terminal size */
1379     WriteInt2(Section, "TerminalSize", ts.SetupFName,
1380     ts.TerminalWidth, ts.TerminalHeight);
1381     }
1382     }
1383    
1384     void CVTWindow::OnClose()
1385     {
1386     if ((HTEKWin!=NULL) && ! ::IsWindowEnabled(HTEKWin)) {
1387     MessageBeep(0);
1388     return;
1389     }
1390 zmatsuo 8479
1391 maya 3227 if (cv.Ready && (cv.PortType==IdTCPIP) &&
1392     ((ts.PortFlag & PF_CONFIRMDISCONN) != 0) &&
1393 zmatsuo 8479 ! CloseTT) {
1394 zmatsuo 9351 static const TTMessageBoxInfoW info = {
1395     "Tera Term",
1396     NULL, L"Tera Term",
1397     "MSG_DISCONNECT_CONF", L"Disconnect?",
1398     MB_OKCANCEL | MB_ICONEXCLAMATION | MB_DEFBUTTON2
1399     };
1400     int result = TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
1401 zmatsuo 8479 if (result == IDCANCEL) {
1402     return;
1403     }
1404 maya 3392 }
1405 maya 3227
1406 zmatsuo 8900 FLogClose();
1407 zmatsuo 9067 FileSendEnd();
1408 maya 3227 ProtoEnd();
1409    
1410     SaveVTPos();
1411 zmatsuo 10394 Notify2UnsetWindow((NotifyIcon *)cv.NotifyIcon);
1412 nmaya 10009
1413     // �A�v���P�[�V�����I�������A�C�R�����j���������A�E�B���h�E���������O��
1414     // �^�C�g���o�[���A�C�R���� "Windows �����s�t�@�C�����A�C�R��" ��������
1415     // ���������������j��������
1416     // TTSetIcon(m_hInst, m_hWnd, NULL, 0);
1417    
1418 maya 3227 DestroyWindow();
1419     }
1420    
1421 yutakapon 5232 // �STera Term���I�����w������
1422     void CVTWindow::OnAllClose()
1423     {
1424 yutakapon 5351 // ���R�I���������������������A�����������[�U���������������o�������������B
1425 zmatsuo 9351 static const TTMessageBoxInfoW info = {
1426     "Tera Term",
1427     NULL, L"Tera Term",
1428     "MSG_ALL_TERMINATE_CONF", L"Terminate ALL Tera Term(s)?",
1429     MB_OKCANCEL | MB_ICONERROR | MB_DEFBUTTON2
1430     };
1431     int result = TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
1432     if (result == IDCANCEL)
1433 yutakapon 5351 return;
1434    
1435 yutakapon 5232 BroadcastClosingMessage(HVTWin);
1436     }
1437    
1438     // �I������������������Tera Term���I�������BOnAllClose()���M�p�B
1439 zmatsuo 7896 LRESULT CVTWindow::OnNonConfirmClose(WPARAM wParam, LPARAM lParam)
1440 yutakapon 5232 {
1441     // ������ ts �����e�����}�I���������������A�I�����������Z�[�u�����������������������A�������������B
1442     ts.PortFlag &= ~PF_CONFIRMDISCONN;
1443     OnClose();
1444     return 1;
1445     }
1446    
1447 maya 3227 void CVTWindow::OnDestroy()
1448     {
1449     // remove this window from the window list
1450     UnregWin(HVTWin);
1451    
1452 salarm 6100 // USB�f�o�C�X�������m����
1453     UnRegDeviceNotify(HVTWin);
1454    
1455 maya 3227 EndKeyboard();
1456    
1457     /* Disable drag-drop */
1458     ::DragAcceptFiles(HVTWin,FALSE);
1459 zmatsuo 7148 DropListFree();
1460 maya 3227
1461     EndDDE();
1462    
1463 maya 3392 if (cv.TelFlag) {
1464 maya 3227 EndTelnet();
1465 maya 3392 }
1466 maya 3227 CommClose(&cv);
1467    
1468 zmatsuo 7485 FreeIME(HVTWin);
1469 maya 3227 FreeTTSET();
1470    
1471 zmatsuo 9055 #if 0
1472 maya 3227 do { }
1473 maya 3392 while (FreeTTFILE());
1474 zmatsuo 9055 #endif
1475 maya 3227
1476 maya 3392 if (HTEKWin != NULL) {
1477 maya 3227 ::DestroyWindow(HTEKWin);
1478 maya 3392 }
1479 maya 3227
1480 doda 3450 EndTerm();
1481 maya 3227 EndDisp();
1482    
1483     FreeBuffer();
1484    
1485     TTXEnd(); /* TTPLUG */
1486 doda 6662
1487 zmatsuo 10102 TTSetUnInit(&ts);
1488    
1489 zmatsuo 10394 Notify2Uninitialize((NotifyIcon *)cv.NotifyIcon);
1490     cv.NotifyIcon = NULL;
1491 maya 3227 }
1492    
1493 doda 8445 static void EscapeFilename(const wchar_t *src, wchar_t *dest)
1494 maya 3227 {
1495 doda 8445 #define ESCAPE_CHARS L" ;&()$!`'[]{}#^~"
1496     const wchar_t *s = src;
1497     wchar_t *d = dest;
1498 zmatsuo 7148 while (*s) {
1499 doda 8445 wchar_t c = *s++;
1500     if (c == L'\\') {
1501 zmatsuo 7148 // �p�X���������� \ -> / ��
1502     *d = '/';
1503 doda 8445 } else if (wcschr(ESCAPE_CHARS, c) != NULL) {
1504 zmatsuo 7148 // �G�X�P�[�v���K�v������
1505 doda 8445 *d++ = L'\\';
1506 zmatsuo 7148 *d = c;
1507     } else {
1508     *d = c;
1509     }
1510     d++;
1511     }
1512     *d = '\0'; // null-terminate
1513     }
1514 maya 3227
1515 zmatsuo 9175 static wchar_t *GetPasteString(const wchar_t *str, bool escape)
1516 zmatsuo 7148 {
1517 doda 8445 wchar_t *tmpbuf;
1518     if (!escape) {
1519     tmpbuf = _wcsdup(str);
1520     }
1521     else {
1522     const size_t len = wcslen(str) * sizeof(wchar_t) * 2;
1523     tmpbuf = (wchar_t *)malloc(len);
1524 zmatsuo 7148 EscapeFilename(str, tmpbuf);
1525     }
1526 zmatsuo 9175 return tmpbuf;
1527 zmatsuo 7148 }
1528 yutakapon 4891
1529 zmatsuo 7148 /* �������t�@�C������(�t�H���_������������) */
1530 doda 8445 static bool SendScp(wchar_t *Filenames[], int FileCount, const char *SendDir)
1531 zmatsuo 7148 {
1532     typedef int (CALLBACK *PSSH_start_scp)(char *, char *);
1533 youlab 9554 typedef int(CALLBACK * PSSH_scp_sending_status)(void);
1534 zmatsuo 7148 static PSSH_start_scp func = NULL;
1535 youlab 9554 static PSSH_scp_sending_status func_status = NULL;
1536 zmatsuo 7148 static HMODULE h = NULL;
1537     char msg[128];
1538 youlab 9554 char *FileName;
1539 yutakapon 4891
1540 zmatsuo 7148 if (h == NULL) {
1541     if ( ((h = GetModuleHandle("ttxssh.dll")) == NULL) ) {
1542     _snprintf_s(msg, sizeof(msg), _TRUNCATE, "GetModuleHandle(\"ttxssh.dll\")) %d", GetLastError());
1543     scp_send_error:
1544     ::MessageBox(NULL, msg, "Tera Term: scpsend command error", MB_OK | MB_ICONERROR);
1545     return false;
1546     }
1547     }
1548     if (func == NULL) {
1549     func = (PSSH_start_scp)GetProcAddress(h, "TTXScpSendfile");
1550     if (func == NULL) {
1551     _snprintf_s(msg, sizeof(msg), _TRUNCATE, "GetProcAddress(\"TTXScpSendfile\")) %d", GetLastError());
1552     goto scp_send_error;
1553     }
1554     }
1555 youlab 9554 if (func_status == NULL) {
1556     func_status = (PSSH_scp_sending_status)GetProcAddress(h, "TTXScpSendingStatus");
1557     if (func_status == NULL) {
1558     _snprintf_s(msg, sizeof(msg), _TRUNCATE, "GetProcAddress(\"TTXScpSendingStatus\")) %d", GetLastError());
1559     goto scp_send_error;
1560     }
1561     }
1562 yutakapon 4891
1563 youlab 9554 if (SendScpDoing) {
1564     if (func_status()) {
1565     return false;
1566     }
1567     else {
1568     DropListsSendScpIndex++;
1569     }
1570 zmatsuo 7148 }
1571 youlab 9554
1572     FileName = ToU8W(Filenames[0]);
1573     func(FileName, ts.ScpSendDir);
1574     free(FileName);
1575    
1576 zmatsuo 7148 return true;
1577     }
1578 doda 6620
1579 youlab 9554 static void StartSendScpTimer(void)
1580     {
1581     DropListsSendScpIndex = 0;
1582     SetTimer(HVTWin, IdScpSendingTimer, 100, NULL);
1583     }
1584    
1585 zmatsuo 7148 void CVTWindow::DropListFree()
1586     {
1587     if (DropListCount > 0) {
1588     for (int i = 0; i < DropListCount; i++) {
1589     free(DropLists[i]);
1590     DropLists[i] = NULL;
1591     }
1592     free(DropLists);
1593     DropLists = NULL;
1594     DropListCount = 0;
1595     }
1596     }
1597 yutakapon 4891
1598 nmaya 10093 /**
1599     * �t�@�C�����h���b�v������
1600     * @param ShowDialog 0 �\���������\����������������
1601     * 1 �K���\������
1602     */
1603     LRESULT CVTWindow::OnDropNotify(WPARAM ShowDialog, LPARAM)
1604 zmatsuo 7148 {
1605     // ini���������������A�����s��������Tera Term�������L��������
1606     static enum drop_type DefaultDropType = DROP_TYPE_CANCEL;
1607     static unsigned char DefaultDropTypePaste = DROP_TYPE_PASTE_ESCAPE;
1608     static bool DefaultShowDialog = ts.ConfirmFileDragAndDrop ? true : false;
1609 nmaya 10093 static bool TransBin;
1610 doda 6620
1611 zmatsuo 7148 int FileCount = 0;
1612     int DirectoryCount = 0;
1613     for (int i = 0; i < DropListCount; i++) {
1614 doda 8445 const wchar_t *FileName = DropLists[i];
1615 zmatsuo 9324 const DWORD attr = GetFileAttributesW(FileName);
1616 zmatsuo 7650 if (attr == INVALID_FILE_ATTRIBUTES) {
1617 zmatsuo 7536 FileCount++;
1618     } else if (attr & FILE_ATTRIBUTE_DIRECTORY) {
1619 zmatsuo 7148 DirectoryCount++;
1620     } else {
1621     FileCount++;
1622     }
1623     }
1624 yutakapon 4891
1625 zmatsuo 7148 bool DoSameProcess = false;
1626     const bool isSSH = (cv.isSSH == 2);
1627     enum drop_type DropType;
1628     unsigned char DropTypePaste = DROP_TYPE_PASTE_ESCAPE;
1629     if (DefaultDropType == DROP_TYPE_CANCEL) {
1630     // default is not set
1631 nmaya 10093 TransBin = ts.TransBin == 0 ? false : true;
1632 zmatsuo 7148 if (!ShowDialog) {
1633     if (FileCount == 1 && DirectoryCount == 0) {
1634     if (ts.ConfirmFileDragAndDrop) {
1635     if (isSSH) {
1636     DropType = DROP_TYPE_SCP;
1637     } else {
1638     DropType = DROP_TYPE_SEND_FILE;
1639 yutakapon 4891 }
1640 zmatsuo 7148 DoSameProcess = false;
1641     } else {
1642     DropType = DROP_TYPE_SEND_FILE;
1643     DoSameProcess = DefaultShowDialog ? false : true;
1644     }
1645     } else if (FileCount == 0 && DirectoryCount == 1) {
1646     DropType = DROP_TYPE_PASTE_FILENAME;
1647     DoSameProcess = DefaultShowDialog ? false : true;
1648     } else if (FileCount > 0 && DirectoryCount > 0) {
1649     DropType = DROP_TYPE_PASTE_FILENAME;
1650     DoSameProcess = false;
1651     } else if (FileCount > 0 && DirectoryCount == 0) {
1652     // filename only
1653     if (isSSH) {
1654     DropType = DROP_TYPE_SCP;
1655     } else {
1656     DropType = DROP_TYPE_SEND_FILE;
1657     }
1658     DoSameProcess = false;
1659     } else {
1660     // directory only
1661     DropType = DROP_TYPE_PASTE_FILENAME;
1662     DoSameProcess = ts.ConfirmFileDragAndDrop ? false : true;
1663     }
1664     } else {
1665     // show dialog
1666     if (DirectoryCount > 0) {
1667     DropType = DROP_TYPE_PASTE_FILENAME;
1668     } else {
1669     if (isSSH) {
1670     DropType = DROP_TYPE_SCP;
1671     } else {
1672     DropType = DROP_TYPE_SEND_FILE;
1673     }
1674     }
1675     DoSameProcess = false;
1676     }
1677     } else {
1678     if (DirectoryCount > 0 &&
1679     (DefaultDropType == DROP_TYPE_SEND_FILE ||
1680     DefaultDropType == DROP_TYPE_SCP))
1681     { // �f�t�H���g�����������������������g��������
1682     DropType = DROP_TYPE_PASTE_FILENAME;
1683     DropTypePaste = DefaultDropTypePaste;
1684     DoSameProcess = false;
1685     } else {
1686     DropType = DefaultDropType;
1687     DropTypePaste = DefaultDropTypePaste;
1688     DoSameProcess = (ShowDialog || DefaultShowDialog) ? false : true;
1689     }
1690     }
1691 yutakapon 4891
1692 zmatsuo 7148 for (int i = 0; i < DropListCount; i++) {
1693 doda 8445 const wchar_t *FileName = DropLists[i];
1694 yutakapon 4891
1695 zmatsuo 7148 if (!DoSameProcess) {
1696     bool DoSameProcessNextDrop;
1697     bool DoNotShowDialog = !DefaultShowDialog;
1698 zmatsuo 10150 SetDialogFont(ts.DialogFontNameW, ts.DialogFontPoint, ts.DialogFontCharSet,
1699     ts.UILanguageFileW, "Tera Term", "DLG_SYSTEM_FONT");
1700 zmatsuo 7148 DropType =
1701 zmatsuo 7916 ShowDropDialogBox(m_hInst, HVTWin,
1702 zmatsuo 7148 FileName, DropType,
1703     DropListCount - i,
1704     (DirectoryCount == 0 && isSSH) ? true : false,
1705     DirectoryCount == 0 ? true : false,
1706 nmaya 10093 &TransBin,
1707 zmatsuo 7172 &ts,
1708 zmatsuo 7148 &DropTypePaste,
1709     &DoSameProcess,
1710     &DoSameProcessNextDrop,
1711     &DoNotShowDialog);
1712     if (DropType == DROP_TYPE_CANCEL) {
1713     goto finish;
1714     }
1715     if (DoSameProcessNextDrop) {
1716     DefaultDropType = DropType;
1717     }
1718     if (!ts.ConfirmFileDragAndDrop) {
1719     DefaultShowDialog = !DoNotShowDialog;
1720     }
1721     }
1722 zmatsuo 7322
1723 zmatsuo 7148 switch (DropType) {
1724     case DROP_TYPE_CANCEL:
1725     default:
1726     // cancel
1727     break;
1728     case DROP_TYPE_SEND_FILE:
1729 nmaya 10093 if (!TransBin) {
1730     SendMemSendFile(FileName, FALSE, SENDMEM_DELAYTYPE_NO_DELAY, 0, 0);
1731     }
1732     else {
1733     SendMemSendFile(FileName, TRUE, SENDMEM_DELAYTYPE_NO_DELAY, 0, 0);
1734     }
1735 zmatsuo 8449 break;
1736 zmatsuo 7148 case DROP_TYPE_PASTE_FILENAME:
1737     {
1738     const bool escape = (DropTypePaste & DROP_TYPE_PASTE_ESCAPE) ? true : false;
1739 doda 7195
1740 nmaya 10093 DefaultDropTypePaste = DropTypePaste;
1741    
1742 doda 7195 TermSendStartBracket();
1743    
1744 zmatsuo 9175 wchar_t *str = GetPasteString(FileName, escape);
1745     TermPasteStringNoBracket(str, wcslen(str));
1746     free(str);
1747 zmatsuo 7148 if (DropListCount > 1 && i < DropListCount - 1) {
1748 zmatsuo 9175 if (DropTypePaste & DROP_TYPE_PASTE_NEWLINE) {
1749     TermPasteStringNoBracket(L"\x0d", 1); // ���s(CR,0x0d)
1750     }
1751     else {
1752     TermPasteStringNoBracket(L" ", 1); // space
1753     }
1754 zmatsuo 7148 }
1755 doda 7195
1756     TermSendEndBracket();
1757    
1758 zmatsuo 7148 break;
1759     }
1760     case DROP_TYPE_SCP:
1761     {
1762 youlab 9554 // ������SCP���M�����������������B
1763     if (SendScpDoing) {
1764     // do nothing.
1765 zmatsuo 7148 goto finish;
1766     }
1767 youlab 9554 else {
1768     // �������M���������^�C�}�[�������s���������A�A�����M������
1769     // �G���[���N�������������������B
1770     if (DoSameProcess) {
1771     int j;
1772    
1773     DropListCountSendScp = DropListCount - i;
1774     DropListsSendScp = (wchar_t **)malloc(sizeof(wchar_t *) * DropListCountSendScp);
1775    
1776     for (j = 0; j < DropListCountSendScp; j++) {
1777     DropListsSendScp[j] = _wcsdup(DropLists[j]);
1778     }
1779     SendScpDoing = TRUE;
1780    
1781     StartSendScpTimer();
1782     goto finish;
1783     }
1784     else {
1785     // send by scp
1786     wchar_t **FileNames = &DropLists[i];
1787     int FileCount = 1;
1788     if (!SendScp(FileNames, FileCount, ts.ScpSendDir)) {
1789     goto finish;
1790     }
1791     i += FileCount - 1;
1792     break;
1793     }
1794     }
1795    
1796 zmatsuo 7148 }
1797     }
1798     }
1799 yutakapon 4891
1800 zmatsuo 7148 finish:
1801     DropListFree();
1802     return 0;
1803 maya 3227 }
1804    
1805     void CVTWindow::OnDropFiles(HDROP hDropInfo)
1806     {
1807     ::SetForegroundWindow(HVTWin);
1808 zmatsuo 8948 if (cv.Ready && IsSendVarNULL())
1809 maya 3227 {
1810 zmatsuo 7148 const UINT ShowDialog =
1811     ((GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0) ? 1 : 0;
1812 zmatsuo 9324 DropListCount = DragQueryFileW(hDropInfo, -1, NULL, 0);
1813 doda 8445 DropLists = (wchar_t **)malloc(sizeof(wchar_t *) * DropListCount);
1814 maya 3227
1815 zmatsuo 7148 for (int i = 0; i < DropListCount; i++) {
1816 zmatsuo 9324 const UINT cch = DragQueryFileW(hDropInfo, i, NULL, 0);
1817 doda 8445 if (cch == 0) {
1818     continue;
1819     }
1820     wchar_t *FileName = (wchar_t *)malloc(sizeof(wchar_t) * (cch + 1));
1821 zmatsuo 9324 DragQueryFileW(hDropInfo,i,FileName,cch + 1);
1822 doda 8445 FileName[cch] = '\0';
1823 zmatsuo 7148 DropLists[i] = FileName;
1824     }
1825 maya 3227
1826 zmatsuo 7148 ::PostMessage(HVTWin, WM_USER_DROPNOTIFY, ShowDialog, 0);
1827 maya 3227 }
1828     DragFinish(hDropInfo);
1829     }
1830    
1831 doda 6801 void CVTWindow::OnGetMinMaxInfo(MINMAXINFO *lpMMI)
1832 maya 3227 {
1833     #ifndef WINDOW_MAXMIMUM_ENABLED
1834     lpMMI->ptMaxSize.x = 10000;
1835     lpMMI->ptMaxSize.y = 10000;
1836     lpMMI->ptMaxTrackSize.x = 10000;
1837     lpMMI->ptMaxTrackSize.y = 10000;
1838     #endif
1839     }
1840    
1841 zmatsuo 7528 void CVTWindow::OnHScroll(UINT nSBCode, UINT nPos, HWND pScrollBar)
1842 maya 3227 {
1843     int Func;
1844    
1845     switch (nSBCode) {
1846     case SB_BOTTOM:
1847     Func = SCROLL_BOTTOM;
1848     break;
1849     case SB_ENDSCROLL:
1850     return;
1851     case SB_LINEDOWN:
1852     Func = SCROLL_LINEDOWN;
1853     break;
1854     case SB_LINEUP:
1855     Func = SCROLL_LINEUP;
1856     break;
1857     case SB_PAGEDOWN:
1858     Func = SCROLL_PAGEDOWN;
1859     break;
1860 doda 6435 case SB_PAGEUP:
1861 maya 3227 Func = SCROLL_PAGEUP;
1862     break;
1863     case SB_THUMBPOSITION:
1864     case SB_THUMBTRACK:
1865     Func = SCROLL_POS;
1866     break;
1867     case SB_TOP:
1868     Func = SCROLL_TOP;
1869     break;
1870     default:
1871     return;
1872     }
1873     DispHScroll(Func,nPos);
1874     }
1875    
1876 zmatsuo 7528 void CVTWindow::OnInitMenuPopup(HMENU hPopupMenu, UINT nIndex, BOOL bSysMenu)
1877 maya 3227 {
1878 zmatsuo 7528 InitMenuPopup(hPopupMenu);
1879 maya 3227 }
1880    
1881 zmatsuo 8337 void CVTWindow::OnKeyDown(WPARAM nChar, UINT nRepCnt, UINT nFlags)
1882 maya 3227 {
1883 doda 8445 #if UNICODE_DEBUG
1884     if (UnicodeDebugParam.CodePopupEnable)
1885     {
1886     const DWORD now = GetTickCount();
1887     switch(CtrlKeyState) {
1888     case 0:
1889     if (nChar == UnicodeDebugParam.CodePopupKey1) {
1890     CtrlKeyDownTick = now;
1891     CtrlKeyState = 1;
1892     }
1893     break;
1894     case 2:
1895     if (nChar != UnicodeDebugParam.CodePopupKey2) {
1896     CtrlKeyState = 0;
1897     break;
1898     }
1899     if (now - CtrlKeyDownTick < 500 && TipWinCodeDebug == NULL) {
1900     POINT pos;
1901     GetCursorPos(&pos);
1902     ScreenToClient(m_hWnd, &pos);
1903     CodePopup(pos.x, pos.y);
1904     CtrlKeyState = 3;
1905     } else {
1906     CtrlKeyDownTick = now;
1907     CtrlKeyState = 1;
1908     }
1909     break;
1910     case 3:
1911     break;
1912     default:
1913     CtrlKeyState = 0;
1914     break;
1915     }
1916     }
1917     if (TipWinCodeDebug != NULL && nChar == VK_SHIFT) {
1918     POINT pos;
1919     GetCursorPos(&pos);
1920     ScreenToClient(m_hWnd, &pos);
1921     wchar_t *buf = BuffGetCharInfo(pos.x, pos.y);
1922     CBSetTextW(HVTWin, buf, 0);
1923     free(buf);
1924 zmatsuo 8745 MessageBeep(MB_OK);
1925     TipWinDestroy(TipWinCodeDebug);
1926     TipWinCodeDebug = NULL;
1927     CtrlKeyState = 0;
1928 doda 8445 }
1929     #endif
1930 maya 3227 switch (KeyDown(HVTWin,nChar,nRepCnt,nFlags & 0x1ff)) {
1931     case KEYDOWN_OTHER:
1932     break;
1933     case KEYDOWN_CONTROL:
1934     return;
1935     case KEYDOWN_COMMOUT:
1936 doda 6421 // �X�N���[�����u�����Z�b�g
1937     if (WinOrgY != 0) {
1938 maya 3227 DispVScroll(SCROLL_BOTTOM, 0);
1939     }
1940     return;
1941     }
1942    
1943 doda 4519 if (MetaKey(ts.MetaKey) && (nFlags & 0x2000) != 0)
1944 doda 4414 {
1945 zmatsuo 9150 BYTE KeyState[256];
1946     MSG M;
1947    
1948 doda 4712 PeekMessage((LPMSG)&M,HVTWin,WM_CHAR,WM_CHAR,PM_REMOVE);
1949 maya 3227 /* for Ctrl+Alt+Key combination */
1950 zmatsuo 9150 GetKeyboardState(KeyState);
1951 maya 3227 KeyState[VK_MENU] = 0;
1952 zmatsuo 9150 SetKeyboardState(KeyState);
1953 maya 3227 M.hwnd = HVTWin;
1954     M.message = WM_KEYDOWN;
1955     M.wParam = nChar;
1956     M.lParam = MAKELONG(nRepCnt,nFlags & 0xdfff);
1957     TranslateMessage(&M);
1958     }
1959    
1960     }
1961    
1962 zmatsuo 8337 void CVTWindow::OnKeyUp(WPARAM nChar, UINT nRepCnt, UINT nFlags)
1963 maya 3227 {
1964     KeyUp(nChar);
1965 doda 8445 #if UNICODE_DEBUG
1966     if (CtrlKeyState == 1 && nChar == UnicodeDebugParam.CodePopupKey1) {
1967     CtrlKeyState++;
1968     } else {
1969     CtrlKeyState = 0;
1970     }
1971     if (nChar == UnicodeDebugParam.CodePopupKey2) {
1972     if (TipWinCodeDebug != NULL) {
1973     TipWinDestroy(TipWinCodeDebug);
1974     TipWinCodeDebug = NULL;
1975     CtrlKeyState = 0;
1976     }
1977     }
1978     #endif
1979 maya 3227 }
1980    
1981 zmatsuo 7528 void CVTWindow::OnKillFocus(HWND hNewWnd)
1982 maya 3227 {
1983     DispDestroyCaret();
1984     FocusReport(FALSE);
1985 zmatsuo 7784 // TTCFrameWnd::OnKillFocus(hNewWnd); // TODO
1986 maya 3227
1987 maya 3392 if (IsCaretOn()) {
1988 maya 3227 CaretKillFocus(TRUE);
1989 maya 3392 }
1990 maya 3227 }
1991    
1992 zmatsuo 8337 void CVTWindow::OnLButtonDblClk(WPARAM nFlags, POINTS point)
1993 maya 3227 {
1994 maya 3392 if (LButton || MButton || RButton) {
1995 maya 3227 return;
1996 maya 3392 }
1997 maya 3227
1998     DblClkX = point.x;
1999     DblClkY = point.y;
2000    
2001 doda 3992 if (MouseReport(IdMouseEventBtnDown, IdLeftButton, DblClkX, DblClkY)) {
2002 maya 3227 return;
2003 maya 3392 }
2004 maya 3227
2005 doda 3992 if (BuffUrlDblClk(DblClkX, DblClkY)) { // �u���E�U�����o���������������������B (2005.4.3 yutaka)
2006     return;
2007     }
2008    
2009 maya 3227 BuffDblClk(DblClkX, DblClkY);
2010    
2011     LButton = TRUE;
2012     DblClk = TRUE;
2013     AfterDblClk = TRUE;
2014     ::SetTimer(HVTWin, IdDblClkTimer, GetDoubleClickTime(), NULL);
2015    
2016     /* for AutoScrolling */
2017     ::SetCapture(HVTWin);
2018     ::SetTimer(HVTWin, IdScrollTimer, 100, NULL);
2019     }
2020    
2021 zmatsuo 8337 void CVTWindow::OnLButtonDown(WPARAM nFlags, POINTS point)
2022 maya 3227 {
2023     POINT p;
2024    
2025     p.x = point.x;
2026     p.y = point.y;
2027     ButtonDown(p,IdLeftButton);
2028     }
2029    
2030 zmatsuo 8337 void CVTWindow::OnLButtonUp(WPARAM nFlags, POINTS point)
2031 maya 3227 {
2032 doda 5341 if (IgnoreRelease)
2033     IgnoreRelease = FALSE;
2034 doda 7078 else if (MouseReport(IdMouseEventBtnUp, IdLeftButton, point.x, point.y)) {
2035     ReleaseCapture();
2036     }
2037 maya 3227
2038 maya 3392 if (! LButton) {
2039 maya 3227 return;
2040 maya 3392 }
2041 maya 3227
2042     ButtonUp(FALSE);
2043     }
2044    
2045 zmatsuo 8337 void CVTWindow::OnMButtonDown(WPARAM nFlags, POINTS point)
2046 maya 3227 {
2047     POINT p;
2048    
2049     p.x = point.x;
2050     p.y = point.y;
2051     ButtonDown(p,IdMiddleButton);
2052     }
2053    
2054 zmatsuo 8337 void CVTWindow::OnMButtonUp(WPARAM nFlags, POINTS point)
2055 maya 3227 {
2056 doda 5341 if (IgnoreRelease)
2057     IgnoreRelease = FALSE;
2058 doda 7078 else if (MouseReport(IdMouseEventBtnUp, IdMiddleButton, point.x, point.y)) {
2059     ReleaseCapture();
2060     }
2061 maya 3227
2062 maya 3392 if (! MButton) {
2063 maya 3227 return;
2064 maya 3392 }
2065 maya 3227
2066     // added DisablePasteMouseMButton (2008.3.2 maya)
2067 doda 7078 if (ts.PasteFlag & CPF_DISABLE_MBUTTON) {
2068 maya 3227 ButtonUp(FALSE);
2069 maya 3392 }
2070     else {
2071 maya 3227 ButtonUp(TRUE);
2072 maya 3392 }
2073 maya 3227 }
2074    
2075 zmatsuo 8677 LRESULT CVTWindow::OnMouseActivate(HWND pDesktopWnd, UINT nHitTest, UINT message)
2076 maya 3227 {
2077 doda 5341 if ((ts.SelOnActive==0) && (nHitTest==HTCLIENT)) { //disable mouse event for text selection
2078     IgnoreRelease = TRUE;
2079 maya 3227 return MA_ACTIVATEANDEAT; // when window is activated
2080 doda 5341 }
2081     else {
2082 maya 3227 return MA_ACTIVATE;
2083 doda 5341 }
2084 maya 3227 }
2085    
2086 doda 8445
2087     void CVTWindow::CodePopup(int client_x, int client_y)
2088     {
2089     wchar_t *buf = BuffGetCharInfo(client_x, client_y);
2090     if (TipWinCodeDebug == NULL) {
2091     TipWinCodeDebug = TipWinCreate(m_hInst, m_hWnd);
2092     }
2093     POINT pos = { client_x, client_y };
2094     ClientToScreen(m_hWnd, &pos);
2095     TipWinSetPos(TipWinCodeDebug, pos.x, pos.y);
2096     TipWinSetTextW(TipWinCodeDebug, buf);
2097     TipWinSetVisible(TipWinCodeDebug, TRUE);
2098     free(buf);
2099     }
2100    
2101 zmatsuo 8337 void CVTWindow::OnMouseMove(WPARAM nFlags, POINTS point)
2102 maya 3227 {
2103     int i;
2104 zmatsuo 9157 BOOL mousereport = FALSE;
2105 maya 3227
2106 doda 8445 #if UNICODE_DEBUG
2107     if (TipWinCodeDebug != NULL) {
2108     CodePopup(point.x, point.y);
2109     }
2110     #endif
2111    
2112 doda 5341 if (!IgnoreRelease)
2113     mousereport = MouseReport(IdMouseEventMove, 0, point.x, point.y);
2114 doda 3987
2115 maya 3227 if (! (LButton || MButton || RButton)) {
2116 doda 5279 if (BuffCheckMouseOnURL(point.x, point.y))
2117     SetMouseCursor("HAND");
2118     else
2119     SetMouseCursor(ts.MouseCursorName);
2120 maya 3227 return;
2121     }
2122    
2123 doda 3987 if (mousereport) {
2124     return;
2125     }
2126    
2127 maya 3392 if (DblClk) {
2128 maya 3227 i = 2;
2129 maya 3392 }
2130     else if (TplClk) {
2131 maya 3227 i = 3;
2132 maya 3392 }
2133     else {
2134 maya 3227 i = 1;
2135 maya 3392 }
2136 maya 3227
2137     if (!ts.SelectOnlyByLButton ||
2138 maya 3392 (ts.SelectOnlyByLButton && LButton) ) {
2139 maya 3227 // SelectOnlyByLButton == TRUE ���������A���{�^���_�E���������I������ (2007.11.21 maya)
2140     BuffChangeSelect(point.x, point.y,i);
2141     }
2142     }
2143    
2144     void CVTWindow::OnMove(int x, int y)
2145     {
2146 zmatsuo 10391 // �E�B���h�E���u������
2147     // �� x,y ���N���C�A���g���������������W
2148     RECT R;
2149     ::GetWindowRect(HVTWin,&R);
2150     ts.VTPos.x = R.left;
2151     ts.VTPos.y = R.top;
2152    
2153 maya 3227 DispSetWinPos();
2154     }
2155    
2156     // �}�E�X�z�C�[�������]
2157     BOOL CVTWindow::OnMouseWheel(
2158     UINT nFlags, // ���z�L�[
2159     short zDelta, // ���]����
2160 zmatsuo 7528 POINTS pts // �J�[�\�����u
2161 maya 3227 )
2162     {
2163 zmatsuo 7528 POINT pt;
2164     pt.x = pts.x;
2165     pt.y = pts.y;
2166    
2167 maya 3227 int line, i;
2168    
2169 zmatsuo 7457 if (pSetLayeredWindowAttributes != NULL) {
2170 zmatsuo 7390 BOOL InTitleBar;
2171     POINT point = pt;
2172     GetPositionOnWindow(HVTWin, &point,
2173     NULL, NULL, &InTitleBar);
2174     if (InTitleBar) {
2175     int delta = zDelta < 0 ? -1 : 1;
2176     int newAlpha = Alpha;
2177 yasuhide 8143 POINT tippos;
2178 yasuhide 8091
2179 zmatsuo 7390 newAlpha += delta * ts.MouseWheelScrollLine;
2180     if (newAlpha > 255)
2181     newAlpha = 255;
2182     else if (newAlpha < 0)
2183     newAlpha = 0;
2184     SetWindowAlpha(newAlpha);
2185 yasuhide 8091
2186 zmatsuo 9355 wchar_t *uimsg;
2187     GetI18nStrWA("Tera Term", "TOOLTIP_TITLEBAR_OPACITY", L"Opacity %.1f %%", ts.UILanguageFile, &uimsg);
2188     wchar_t *tipbuf;
2189     aswprintf(&tipbuf, uimsg, (newAlpha / 255.0) * 100);
2190     free(uimsg);
2191 yasuhide 8091
2192 yasuhide 8143 tippos = TipWin->GetPos();
2193     if (tippos.x != pt.x ||
2194     tippos.y != pt.y) {
2195     TipWin->SetVisible(FALSE);
2196 yasuhide 8091 }
2197    
2198 yasuhide 8143 TipWin->SetText(tipbuf);
2199     TipWin->SetPos(pt.x, pt.y);
2200     TipWin->SetHideTimer(1000);
2201    
2202     if(! TipWin->IsVisible()) {
2203     TipWin->SetVisible(TRUE);
2204 yasuhide 8091 }
2205    
2206 zmatsuo 9355 free(tipbuf);
2207    
2208 zmatsuo 7390 return TRUE;
2209     }
2210     }
2211    
2212 maya 3227 ::ScreenToClient(HVTWin, &pt);
2213    
2214     line = abs(zDelta) / WHEEL_DELTA; // ���C����
2215     if (line < 1) line = 1;
2216    
2217     // ���X�N���[�����������s������������ (2008.4.6 yutaka)
2218     if (line == 1 && ts.MouseWheelScrollLine > 0)
2219     line *= ts.MouseWheelScrollLine;
2220    
2221     if (MouseReport(IdMouseEventWheel, zDelta<0, pt.x, pt.y))
2222     return TRUE;
2223    
2224 doda 4293 if (WheelToCursorMode()) {
2225 maya 3227 if (zDelta < 0) {
2226     KeyDown(HVTWin, VK_DOWN, line, MapVirtualKey(VK_DOWN, 0) | 0x100);
2227     KeyUp(VK_DOWN);
2228     } else {
2229     KeyDown(HVTWin, VK_UP, line, MapVirtualKey(VK_UP, 0) | 0x100);
2230     KeyUp(VK_UP);
2231     }
2232     } else {
2233     for (i = 0 ; i < line ; i++) {
2234     if (zDelta < 0) {
2235     OnVScroll(SB_LINEDOWN, 0, NULL);
2236     } else {
2237     OnVScroll(SB_LINEUP, 0, NULL);
2238     }
2239     }
2240     }
2241    
2242     return (TRUE);
2243     }
2244    
2245 zmatsuo 7528 void CVTWindow::OnNcLButtonDblClk(UINT nHitTest, POINTS point)
2246 maya 3227 {
2247 doda 7132 if (! Minimized && !ts.TermIsWin && (nHitTest == HTCAPTION)) {
2248 maya 3227 DispRestoreWinSize();
2249 maya 3392 }
2250 maya 3227 }
2251    
2252 zmatsuo 7528 void CVTWindow::OnNcRButtonDown(UINT nHitTest, POINTS point)
2253 maya 3227 {
2254     if ((nHitTest==HTCAPTION) &&
2255     (ts.HideTitle>0) &&
2256 maya 3392 AltKey()) {
2257 maya 3227 ::CloseWindow(HVTWin); /* iconize */
2258 maya 3392 }
2259 maya 3227 }
2260    
2261     void CVTWindow::OnPaint()
2262     {
2263     PAINTSTRUCT ps;
2264     HDC PaintDC;
2265     int Xs, Ys, Xe, Ye;
2266    
2267 zmatsuo 7322 // �\������������������WM_PAINT�����������P�[�X����
2268 zmatsuo 7528 if (::IsWindowVisible(m_hWnd) == 0) {
2269 zmatsuo 7322 return;
2270     }
2271    
2272 maya 3227 BGSetupPrimary(FALSE);
2273    
2274 zmatsuo 7528 PaintDC = BeginPaint(&ps);
2275 maya 3227
2276     PaintWindow(PaintDC,ps.rcPaint,ps.fErase, &Xs,&Ys,&Xe,&Ye);
2277     LockBuffer();
2278 zmatsuo 7499 BuffUpdateRect(Xs,Ys,Xe,Ye);
2279 maya 3227 UnlockBuffer();
2280     DispEndPaint();
2281    
2282     EndPaint(&ps);
2283    
2284     if (FirstPaint) {
2285     if (strlen(TopicName)>0) {
2286     InitDDE();
2287     SendDDEReady();
2288     }
2289     FirstPaint = FALSE;
2290     Startup();
2291     }
2292     }
2293    
2294 zmatsuo 7528 void CVTWindow::OnRButtonDown(UINT nFlags, POINTS point)
2295 maya 3227 {
2296     POINT p;
2297    
2298     p.x = point.x;
2299     p.y = point.y;
2300     ButtonDown(p,IdRightButton);
2301     }
2302    
2303 zmatsuo 7528 void CVTWindow::OnRButtonUp(UINT nFlags, POINTS point)
2304 maya 3227 {
2305 doda 5341 if (IgnoreRelease)
2306     IgnoreRelease = FALSE;
2307 doda 7078 else if (MouseReport(IdMouseEventBtnUp, IdRightButton, point.x, point.y)) {
2308     ReleaseCapture();
2309     }
2310 maya 3227
2311 maya 3392 if (! RButton) {
2312     return;
2313     }
2314 maya 3227
2315 doda 6415 /*
2316     * �y�[�X�g����:
2317 doda 6594 * �Ets.PasteFlag & CPF_DISABLE_RBUTTON -> �E�{�^���������y�[�X�g����
2318     * �Ets.PasteFlag & CPF_CONFIRM_RBUTTON -> �\�����������j���[�����y�[�X�g���s�������A
2319     * �E�{�^���A�b�v�������y�[�X�g���s������
2320 doda 6415 */
2321 doda 7078 if ((ts.PasteFlag & CPF_DISABLE_RBUTTON) || (ts.PasteFlag & CPF_CONFIRM_RBUTTON)) {
2322 maya 3227 ButtonUp(FALSE);
2323     } else {
2324     ButtonUp(TRUE);
2325     }
2326     }
2327    
2328 zmatsuo 7528 void CVTWindow::OnSetFocus(HWND hOldWnd)
2329 maya 3227 {
2330     ChangeCaret();
2331     FocusReport(TRUE);
2332     }
2333    
2334 zmatsuo 8337 void CVTWindow::OnSize(WPARAM nType, int cx, int cy)
2335 maya 3227 {
2336 zmatsuo 7717 if (IgnoreSizeMessage) {
2337     return;
2338     }
2339 maya 3227 RECT R;
2340     int w, h;
2341    
2342     Minimized = (nType==SIZE_MINIMIZED);
2343    
2344     if (FirstPaint && Minimized)
2345     {
2346     if (strlen(TopicName)>0)
2347     {
2348     InitDDE();
2349     SendDDEReady();
2350     }
2351     FirstPaint = FALSE;
2352     Startup();
2353     return;
2354     }
2355 maya 3392 if (Minimized || DontChangeSize) {
2356     return;
2357     }
2358 maya 3227
2359     if (nType == SIZE_MAXIMIZED) {
2360     ts.TerminalOldWidth = ts.TerminalWidth;
2361     ts.TerminalOldHeight = ts.TerminalHeight;
2362     }
2363    
2364     ::GetWindowRect