Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8445 - (hide annotations) (download) (as text)
Tue Dec 17 12:15:31 2019 UTC (4 years, 3 months ago) by doda
Original Path: trunk/teraterm/teraterm/teraterm.cpp
File MIME type: text/x-c++src
File size: 9115 byte(s)
Merge branch 'unicode_buf'
1 doda 6806 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3 zmatsuo 7528 * (C) 2006-2019 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
30     /* TERATERM.EXE, main */
31    
32 zmatsuo 7554 #include "teraterm_conf.h"
33    
34 doda 8445 #include <stdio.h>
35 zmatsuo 7528 #include <crtdbg.h>
36     #include <tchar.h>
37 doda 8445 #include <io.h> // for access()
38 maya 3227 #include "teraterm.h"
39     #include "tttypes.h"
40     #include "commlib.h"
41     #include "ttwinman.h"
42     #include "buffer.h"
43     #include "vtterm.h"
44     #include "vtwin.h"
45     #include "clipboar.h"
46     #include "ttftypes.h"
47     #include "filesys.h"
48     #include "telnet.h"
49     #include "tektypes.h"
50     #include "tekwin.h"
51     #include "ttdde.h"
52 doda 4414 #include "keyboard.h"
53 zmatsuo 7457 #include "dllutil.h"
54     #include "compat_win.h"
55 maya 3227 #include "compat_w95.h"
56 zmatsuo 7509 #include "dlglib.h"
57 zmatsuo 7528 #include "teraterml.h"
58 doda 8445 #include "unicode_test.h"
59     #if UNICODE_INTERNAL_BUFF
60     #include "sendmem.h"
61     #endif
62 maya 3227
63 zmatsuo 7656 #if defined(_DEBUG) && defined(_MSC_VER)
64 zmatsuo 7457 #define new ::new(_NORMAL_BLOCK, __FILE__, __LINE__)
65 maya 3227 #endif
66    
67 zmatsuo 7457 static BOOL AddFontFlag;
68     static TCHAR TSpecialFont[MAX_PATH];
69 zmatsuo 7935 static CVTWindow* pVTWin;
70 zmatsuo 7457
71     static void LoadSpecialFont()
72     {
73 zmatsuo 7509 if (!IsExistFontA("Tera Special", SYMBOL_CHARSET, TRUE)) {
74 zmatsuo 7457 int r;
75    
76     if (GetModuleFileName(NULL, TSpecialFont,_countof(TSpecialFont)) == 0) {
77     AddFontFlag = FALSE;
78     return;
79 doda 6793 }
80 zmatsuo 7457 *_tcsrchr(TSpecialFont, _T('\\')) = 0;
81     _tcscat_s(TSpecialFont, _T("\\TSPECIAL1.TTF"));
82    
83     if (pAddFontResourceEx != NULL) {
84     // teraterm.exe�������L�����t�H���g�������B
85     // remove�����������I��������OS������������
86     r = pAddFontResourceEx(TSpecialFont, FR_PRIVATE, NULL);
87     } else {
88     // �V�X�e���S�����g�����t�H���g������
89     // remove��������OS������������������
90     r = AddFontResource(TSpecialFont);
91 doda 6793 }
92 zmatsuo 7457 if (r != 0) {
93     AddFontFlag = TRUE;
94     }
95 doda 6793 }
96 maya 3227 }
97    
98 zmatsuo 7457 static void UnloadSpecialFont()
99     {
100     if (AddFontFlag) {
101     if (pRemoveFontResourceEx != NULL) {
102     pRemoveFontResourceEx(TSpecialFont, FR_PRIVATE, NULL);
103     } else {
104     RemoveFontResource(TSpecialFont);
105     }
106     }
107     }
108    
109 zmatsuo 7509 static void init()
110 zmatsuo 7457 {
111     DLLInit();
112     WinCompatInit();
113 zmatsuo 7509 LoadSpecialFont();
114 zmatsuo 7457 }
115    
116 maya 3227 // Tera Term main engine
117 zmatsuo 7528 static BOOL OnIdle(LONG lCount)
118 maya 3227 {
119     static int Busy = 2;
120     int Change, nx, ny;
121     BOOL Size;
122    
123     if (lCount==0) Busy = 2;
124    
125     if (cv.Ready)
126     {
127     /* Sender */
128     CommSend(&cv);
129    
130     /* Parser */
131     if ((cv.HLogBuf!=NULL) && (cv.LogBuf==NULL))
132     cv.LogBuf = (PCHAR)GlobalLock(cv.HLogBuf);
133    
134     if ((cv.HBinBuf!=NULL) && (cv.BinBuf==NULL))
135     cv.BinBuf = (PCHAR)GlobalLock(cv.HBinBuf);
136    
137     if ((TelStatus==TelIdle) && cv.TelMode)
138     TelStatus = TelIAC;
139    
140     if (TelStatus != TelIdle)
141     {
142     ParseTel(&Size,&nx,&ny);
143     if (Size) {
144     LockBuffer();
145     ChangeTerminalSize(nx,ny);
146     UnlockBuffer();
147     }
148     }
149     else {
150     if (cv.ProtoFlag) Change = ProtoDlgParse();
151     else {
152     switch (ActiveWin) {
153 doda 6435 case IdVT:
154 zmatsuo 7935 Change = pVTWin->Parse();
155 maya 3227 // TEK window���A�N�e�B�u���� pause ���g�����ACPU�g�p��100%������
156     // ���������b�������B(2006.2.6 yutaka)
157     // �����������������A�R���e�L�X�g�X�C�b�`�����������B(2006.3.20 yutaka)
158     Sleep(0);
159     break;
160    
161     case IdTEK:
162     if (pTEKWin != NULL) {
163     Change = ((CTEKWindow*)pTEKWin)->Parse();
164     // TEK window���A�N�e�B�u���� pause ���g�����ACPU�g�p��100%������
165     // ���������b�������B(2006.2.6 yutaka)
166     Sleep(1);
167     }
168 maya 3392 else {
169 maya 3227 Change = IdVT;
170 maya 3392 }
171 maya 3227 break;
172    
173     default:
174     Change = 0;
175     }
176    
177     switch (Change) {
178 maya 3392 case IdVT:
179     VTActivate();
180     break;
181     case IdTEK:
182 zmatsuo 7935 pVTWin->OpenTEK();
183 maya 3392 break;
184 maya 3227 }
185     }
186     }
187    
188     if (cv.LogBuf!=NULL)
189     {
190 maya 3392 if (FileLog) {
191     LogToFile();
192     }
193     if (DDELog && AdvFlag) {
194     DDEAdv();
195     }
196 maya 3227 GlobalUnlock(cv.HLogBuf);
197     cv.LogBuf = NULL;
198     }
199    
200     if (cv.BinBuf!=NULL)
201     {
202 maya 3392 if (BinLog) {
203     LogToFile();
204     }
205 maya 3227 GlobalUnlock(cv.HBinBuf);
206     cv.BinBuf = NULL;
207     }
208    
209     /* Talker */
210     switch (TalkStatus) {
211 maya 3392 case IdTalkCB:
212     CBSend();
213     break; /* clip board */
214     case IdTalkFile:
215     FileSend();
216     break; /* file */
217 doda 8445 case IdTalkSendMem:
218     SendMemContinuously();
219     break;
220     default:
221     break;
222 maya 3227 }
223    
224     /* Receiver */
225     if (DDELog && cv.DCount >0) {
226     // ���O�o�b�t�@������DDE�N���C�A���g�����������������������A
227     // TCP�p�P�b�g�����M���s�������B
228     // �A���������M���s�����A���O�o�b�t�@�����E���h���r�������������M���f�[�^��
229     // �������������������\���������B(2007.6.14 yutaka)
230    
231     } else {
232     CommReceive(&cv);
233     }
234    
235     }
236    
237     if (cv.Ready &&
238 doda 3494 (cv.RRQ || (cv.OutBuffCount>0) || (cv.InBuffCount>0) || (cv.FlushLen>0) || (cv.LCount>0) || (cv.BCount>0) || (cv.DCount>0)) ) {
239 maya 3227 Busy = 2;
240 maya 3392 }
241     else {
242 maya 3227 Busy--;
243 maya 3392 }
244 maya 3227
245     return (Busy>0);
246     }
247    
248 zmatsuo 7528 BOOL CallOnIdle(LONG lCount)
249 maya 3227 {
250 zmatsuo 7528 return OnIdle(lCount);
251     }
252    
253     static HWND main_window;
254     HWND GetHWND()
255     {
256     return main_window;
257     }
258    
259 zmatsuo 7915 static HWND hModelessDlg;
260 zmatsuo 7528
261 zmatsuo 7915 void AddModelessHandle(HWND hWnd)
262 zmatsuo 7528 {
263 zmatsuo 7915 hModelessDlg = hWnd;
264 zmatsuo 7528 }
265    
266 zmatsuo 7915 void RemoveModelessHandle(HWND hWnd)
267 zmatsuo 7528 {
268 zmatsuo 7914 (void)hWnd;
269 zmatsuo 7915 hModelessDlg = 0;
270 zmatsuo 7528 }
271    
272 zmatsuo 7914 static UINT nMsgLast;
273     static POINT ptCursorLast;
274    
275     /**
276     * idle��������������������
277     */
278     static BOOL IsIdleMessage(const MSG* pMsg)
279     {
280     if (pMsg->message == WM_MOUSEMOVE ||
281     pMsg->message == WM_NCMOUSEMOVE)
282     {
283     if (pMsg->message == nMsgLast &&
284     pMsg->pt.x == ptCursorLast.x &&
285     pMsg->pt.y == ptCursorLast.y)
286     { // �������u��������idle������������
287     return FALSE;
288     }
289    
290     ptCursorLast = pMsg->pt;
291     nMsgLast = pMsg->message;
292     return TRUE;
293     }
294    
295     if (pMsg->message == WM_PAINT ||
296     pMsg->message == 0x0118/*WM_SYSTIMER*/)
297     {
298     return FALSE;
299     }
300    
301     return TRUE;
302     }
303    
304 zmatsuo 7528 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst,
305     LPSTR lpszCmdLine, int nCmdShow)
306     {
307 zmatsuo 7914 (void)hPreInst;
308     (void)lpszCmdLine;
309     (void)nCmdShow;
310 zmatsuo 7528 #ifdef _DEBUG
311 zmatsuo 7656 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
312 zmatsuo 7528 #endif
313 doda 8445
314 zmatsuo 7528 init();
315     hInst = hInstance;
316 zmatsuo 7916 CVTWindow *m_pMainWnd = new CVTWindow(hInstance);
317 zmatsuo 7528 pVTWin = m_pMainWnd;
318     main_window = m_pMainWnd->m_hWnd;
319 zmatsuo 7589 // [Tera Term]�Z�N�V������DLG_SYSTEM_FONT�������������Z�b�g����
320 zmatsuo 7706 SetDialogFont(ts.DialogFontName, ts.DialogFontPoint, ts.DialogFontCharSet,
321     ts.UILanguageFile, "Tera Term", "DLG_SYSTEM_FONT");
322 zmatsuo 7528
323 zmatsuo 7914 BOOL bIdle = TRUE; // idle������?
324     LONG lCount = 0;
325 zmatsuo 7528 MSG msg;
326 zmatsuo 7914 for (;;) {
327     // idle���������b�Z�[�W����������
328     while (bIdle) {
329     if (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) != FALSE) {
330     // ���b�Z�[�W����������
331     break;
332 zmatsuo 7528 }
333 zmatsuo 7914
334     const BOOL continue_idle = OnIdle(lCount++);
335     if (!continue_idle) {
336     // FALSE��������������idle�������s�v
337     bIdle = FALSE;
338     break;
339     }
340 zmatsuo 7528 }
341    
342 zmatsuo 7914 // ���b�Z�[�W����������������������
343     for(;;) {
344     // ���b�Z�[�W���������������AGetMessage()���u���b�N��������������
345     if (::GetMessage(&msg, NULL, 0, 0) == FALSE) {
346     // WM_QUIT
347     goto exit_message_loop;
348     }
349 zmatsuo 7528
350 zmatsuo 7915 if (hModelessDlg == 0 ||
351     ::IsDialogMessage(hModelessDlg, &msg) == FALSE)
352 zmatsuo 7914 {
353     bool message_processed = false;
354    
355     if (m_pMainWnd->m_hAccel != NULL) {
356     if (!MetaKey(ts.MetaKey)) {
357     // matakey����������������
358     if (::TranslateAccelerator(m_pMainWnd->m_hWnd , m_pMainWnd->m_hAccel, &msg)) {
359     // �A�N�Z�����[�^�[�L�[����������
360     message_processed = true;
361     }
362     }
363 zmatsuo 7528 }
364 zmatsuo 7914
365     if (!message_processed) {
366     ::TranslateMessage(&msg);
367     ::DispatchMessage(&msg);
368     }
369 zmatsuo 7528 }
370    
371 zmatsuo 7914 // idle������������?
372     if (IsIdleMessage(&msg)) {
373     bIdle = TRUE;
374 zmatsuo 7528 lCount = 0;
375     }
376 zmatsuo 7914
377     if (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) == FALSE) {
378     // ���b�Z�[�W������������
379     break;
380     }
381 zmatsuo 7528 }
382 maya 3392 }
383 zmatsuo 7914 exit_message_loop:
384    
385 zmatsuo 7528 delete m_pMainWnd;
386     m_pMainWnd = NULL;
387    
388     UnloadSpecialFont();
389     DLLExit();
390    
391 zmatsuo 7914 return (int)msg.wParam;
392 maya 3227 }

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