Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/teraterm/teraterm/ftdlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10614 - (show annotations) (download) (as text)
Wed Mar 1 14:18:19 2023 UTC (12 months, 1 week ago) by zmatsuo
File MIME type: text/x-c++src
File size: 8299 byte(s)
lngファイル名変数を ANSI版から Unicode 版へ切り替え

- tttset.UILanguageFile 参照部分を tttset.UILanguageFileW へ変更
- SetI18nMenuStrs() -> SetI18nMenuStrsW()
- GetI18nStrWA() -> GetI18nStrWW()
- MessageBox() -> MessageBoxW()
- GetCommonDialogFilterW() -> GetCommonDialogFilterWW()
  - GetCommonDialogFilterW() は ANSI版lngファイル名を参照
  - GetCommonDialogFilterW() 削除
1 /*
2 * Copyright (C) 1994-1998 T. Teranishi
3 * (C) 2007- TeraTerm Project
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 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 *
18 * 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 */
29
30 /* TERATERM.EXE, file transfer dialog box */
31
32 #include <stdio.h>
33 #include <windows.h>
34 #include <commctrl.h>
35
36 #include "teraterm.h"
37 #include "tttypes.h"
38 #include "ttlib.h"
39 #include "dlglib.h"
40 #include "tt_res.h"
41 #include "ftdlg.h"
42 #include "teraterml.h"
43 #include "helpid.h"
44 #include "filesys.h"
45 #include "codeconv.h"
46 #include "compat_win.h"
47
48 /////////////////////////////////////////////////////////////////////////////
49 // CFileTransDlg dialog
50
51 CFileTransDlg::CFileTransDlg()
52 {
53 DlgCaption = NULL;
54 FileName = NULL;
55 FullName = NULL;
56 ProgStat = 0;
57 }
58
59 CFileTransDlg::~CFileTransDlg()
60 {
61 free(DlgCaption);
62 free(FileName);
63 free(FullName);
64 }
65
66 BOOL CFileTransDlg::Create(HINSTANCE hInstance, CFileTransDlg::Info *info)
67 {
68 BOOL Ok;
69 HWND hwnd;
70
71 UILanguageFile = info->UILanguageFileW;
72 OpId = info->OpId; // OpLog or OpSendFile ����
73 DlgCaption = _wcsdup(info->DlgCaption);
74 FullName = _wcsdup(info->FullName);
75 if (info->FileName != NULL) {
76 FileName = _wcsdup(info->FileName);
77 }
78 else {
79 const wchar_t *fullname = info->FullName;
80 const wchar_t *p = wcsrchr(fullname, L'\\');
81 if (p == NULL) {
82 p = wcsrchr(fullname, L'/');
83 }
84 if (p == NULL) {
85 FileName = _wcsdup(fullname);
86 }
87 else {
88 FileName = _wcsdup(p + 1);
89 }
90 }
91 HideDialog = info->HideDialog;
92 HMainWin = info->HMainWin;
93
94 Pause = FALSE;
95 hwnd = GetForegroundWindow();
96 if (OpId == OpLog) { // parent window is desktop
97 Ok = TTCDialog::Create(hInstance, GetDesktopWindow(), IDD_FILETRANSDLG);
98 }
99 else { // parent window is VT window
100 Ok = TTCDialog::Create(hInstance, NULL, IDD_FILETRANSDLG);
101 }
102 if (OpId == OpSendFile) {
103 HWND HProg = ::GetDlgItem(m_hWnd, IDC_TRANSPROGRESS);
104
105 ProgStat = 0;
106
107 ::SendMessage(HProg, PBM_SETRANGE, (WPARAM)0, MAKELPARAM(0, 100));
108 ::SendMessage(HProg, PBM_SETSTEP, (WPARAM)1, 0);
109 ::SendMessage(HProg, PBM_SETPOS, (WPARAM)0, 0);
110
111 ::ShowWindow(HProg, SW_SHOW);
112
113 ::ShowWindow(GetDlgItem(IDC_TRANS_ELAPSED), SW_SHOW);
114 }
115
116 if (!HideDialog) {
117 // Visible = False ���_�C�A���O���\������
118 ShowWindow(SW_SHOWNORMAL);
119 if (OpId == OpLog) {
120 ShowWindow(SW_MINIMIZE);
121 }
122 }
123 else {
124 // ���O���t�H�A�O���E���h�������E�B���h�E���t�H�[�J�X�������B
125 // ���j���[�������O���X�^�[�g�������� VTWin ���t�H�[�J�X���������������K�v�������B
126 ::SetForegroundWindow(hwnd);
127 }
128
129 return Ok;
130 }
131
132 /**
133 * �e�L�X�g�����X����
134 */
135 void CFileTransDlg::ChangeButton(BOOL PauseFlag)
136 {
137 Pause = PauseFlag;
138 if (Pause) {
139 static const DlgTextInfo TextInfos[] = {
140 { IDC_TRANSPAUSESTART, "DLG_FILETRANS_START" },
141 };
142 SetDlgTextsW(m_hWnd, TextInfos, _countof(TextInfos), UILanguageFile);
143 }
144 else {
145 static const DlgTextInfo TextInfos[] = {
146 { IDC_TRANSPAUSESTART, "DLG_FILETRANS_PAUSE" },
147 };
148 SetDlgTextsW(m_hWnd, TextInfos, _countof(TextInfos), UILanguageFile);
149 }
150 }
151
152 void CFileTransDlg::RefreshNum(DWORD StartTime, LONG FileSize, LONG ByteCount)
153 {
154 char NumStr[24];
155 double rate;
156 int rate2;
157 static DWORD prev_elapsed;
158 DWORD elapsed;
159
160 if (OpId == OpSendFile) {
161 if (StartTime == 0) {
162 SetDlgItemText(IDC_TRANS_ETIME, "0:00");
163 prev_elapsed = 0;
164 }
165 else {
166 elapsed = (GetTickCount() - StartTime) / 1000;
167 if (elapsed != prev_elapsed && elapsed != 0) {
168 rate2 = ByteCount / elapsed;
169 if (rate2 < 1200) {
170 _snprintf_s(NumStr, sizeof(NumStr), _TRUNCATE, "%d:%02d (%dBytes/s)", elapsed / 60, elapsed % 60, rate2);
171 }
172 else if (rate2 < 1200000) {
173 _snprintf_s(NumStr, sizeof(NumStr), _TRUNCATE, "%d:%02d (%d.%02dKB/s)", elapsed / 60, elapsed % 60, rate2 / 1000, rate2 / 10 % 100);
174 }
175 else {
176 _snprintf_s(NumStr, sizeof(NumStr), _TRUNCATE, "%d:%02d (%d.%02dMB/s)", elapsed / 60, elapsed % 60, rate2 / (1000*1000), rate2 / 10000 % 100);
177 }
178 SetDlgItemText(IDC_TRANS_ETIME, NumStr);
179 prev_elapsed = elapsed;
180 }
181 }
182
183 if (FileSize > 0) {
184 rate = 100.0 * (double)ByteCount / (double)FileSize;
185 if (ProgStat < (int)rate) {
186 ProgStat = (int)rate;
187 SendDlgItemMessage(IDC_TRANSPROGRESS, PBM_SETPOS, (WPARAM)ProgStat, 0);
188 }
189 _snprintf_s(NumStr,sizeof(NumStr),_TRUNCATE,"%u (%3.1f%%)",ByteCount, rate);
190 }
191 SetDlgItemText(IDC_TRANSBYTES, NumStr);
192 }
193 else {
194 _snprintf_s(NumStr,sizeof(NumStr),_TRUNCATE,"%u",ByteCount);
195 SetDlgItemText(IDC_TRANSBYTES, NumStr);
196 }
197 }
198
199 /////////////////////////////////////////////////////////////////////////////
200 // CFileTransDlg message handler
201
202 BOOL CFileTransDlg::OnInitDialog()
203 {
204 static const DlgTextInfo TextInfos[] = {
205 { IDC_TRANS_FILENAME, "DLG_FILETRANS_FILENAME" },
206 { IDC_FULLPATH_LABEL, "DLG_FILETRANS_FULLPATH" },
207 { IDC_TRANS_TRANS, "DLG_FILETRANS_TRNAS" },
208 { IDC_TRANS_ELAPSED, "DLG_FILETRANS_ELAPSED" },
209 { IDCANCEL, "DLG_FILETRANS_CLOSE" },
210 { IDC_TRANSPAUSESTART, "DLG_FILETRANS_PAUSE" },
211 { IDC_TRANSHELP, "BTN_HELP" },
212 };
213
214 if (HideDialog) {
215 // Visible = False �����t�H�A�O���E���h�����������������A������������
216 // �������g���X�^�C�� WS_EX_NOACTIVATE ���w�������B
217 // (Windows 2000 �������L��)
218 // WS_EX_NOACTIVATE ���w���������\�����������������^�X�N�o�[����������
219 // ���� WS_EX_APPWINDOW ���w�������B
220 ModifyStyleEx(0, WS_EX_NOACTIVATE | WS_EX_APPWINDOW);
221 }
222
223 SetWindowTextW(DlgCaption);
224 SetDlgItemTextW(IDC_TRANSFNAME, FileName);
225 SetDlgItemTextW(IDC_EDIT_FULLPATH, FullName);
226
227 SetDlgTextsW(m_hWnd, TextInfos, _countof(TextInfos), UILanguageFile);
228
229 TTSetIcon(m_hInst, m_hWnd, MAKEINTRESOURCEW(IDI_TTERM), 0);
230
231 AddModelessHandle(m_hWnd);
232
233 return TRUE;
234 }
235
236 BOOL CFileTransDlg::OnCancel( )
237 {
238 if (OpId == OpLog) {
239 FLogClose();
240 }
241 else {
242 FileSendEnd();
243 }
244 return TRUE;
245 }
246
247 BOOL CFileTransDlg::OnCommand(WPARAM wParam, LPARAM lParam)
248 {
249 switch (LOWORD(wParam)) {
250 case IDC_TRANSPAUSESTART:
251 ChangeButton(! Pause);
252 if (OpId == OpLog) {
253 FLogPause(Pause);
254 }
255 else {
256 FileSendPause(Pause);
257 }
258 return TRUE;
259 case IDC_TRANSHELP:
260 if (OpId == OpLog) {
261 ::PostMessage(HMainWin, WM_USER_DLGHELP2, HlpFileLog, 0);
262 }
263 else {
264 ::PostMessage(HMainWin, WM_USER_DLGHELP2, HlpFileSend, 0);
265 }
266 return TRUE;
267 default:
268 return (TTCDialog::OnCommand(wParam,lParam));
269 }
270 }
271
272 BOOL CFileTransDlg::OnClose()
273 {
274 TTSetIcon(m_hInst, m_hWnd, NULL, 0);
275 return TRUE;
276 }
277
278 BOOL CFileTransDlg::PostNcDestroy()
279 {
280 RemoveModelessHandle(m_hWnd);
281
282 delete this;
283 return TRUE;
284 }
285
286 LRESULT CFileTransDlg::DlgProc(UINT msg, WPARAM wp, LPARAM)
287 {
288 switch (msg) {
289 case WM_DPICHANGED: {
290 const UINT NewDPI = LOWORD(wp);
291 TTSetIcon(m_hInst, m_hWnd, MAKEINTRESOURCEW(IDI_TTERM), NewDPI);
292 break;
293 }
294 default:
295 break;
296 }
297 return (LRESULT)FALSE;
298 }

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