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

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