Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/teraterm/teraterm/ftdlg_lite.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

- tttset.UILanguageFile 参照部分を tttset.UILanguageFileW へ変更
- SetI18nMenuStrs() -> SetI18nMenuStrsW()
- GetI18nStrWA() -> GetI18nStrWW()
- MessageBox() -> MessageBoxW()
- GetCommonDialogFilterW() -> GetCommonDialogFilterWW()
  - GetCommonDialogFilterW() は ANSI版lngファイル名を参照
  - GetCommonDialogFilterW() 削除
1 /*
2 * (C) 2019- TeraTerm Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /* TERATERM.EXE, file transfer dialog box lite */
30
31 #include <stdio.h>
32 #include <windows.h>
33 #include <commctrl.h>
34 #define _CRTDBG_MAP_ALLOC
35 #include <crtdbg.h>
36
37 #include "teraterm.h"
38 #include "tttypes.h"
39 #include "ttlib.h"
40 #include "dlglib.h"
41 #include "tt_res.h"
42 #include "teraterml.h"
43 #include "compat_win.h"
44
45 #include "ftdlg_lite.h"
46
47 // ���� �\�����e
48 // 0-2sec �����v�J�[�\��
49 // 2sec �i��50%���������_�C�A���O���o��/�����������������v������
50
51 #include "tmfc.h"
52
53 class PrivateData : public TTCDialog
54 {
55 public:
56 PrivateData() {
57 check_2sec = NULL;
58 show = FALSE;
59 UILanguageFile_ = NULL;
60 Pause = FALSE;
61 observer_ = NULL;
62 }
63
64 BOOL Create(HINSTANCE hInstance, HWND hParent) {
65 return TTCDialog::Create(hInstance, hParent, IDD_FILETRANSDLG);
66 }
67 void SetUILanguageFile(const wchar_t *UILanguageFile) {
68 static const DlgTextInfo TextInfos[] = {
69 { IDC_TRANS_FILENAME, "DLG_FILETRANS_FILENAME" },
70 { IDC_FULLPATH_LABEL, "DLG_FILETRANS_FULLPATH" },
71 { IDC_TRANS_TRANS, "DLG_FILETRANS_TRNAS" },
72 { IDC_TRANS_ELAPSED, "DLG_FILETRANS_ELAPSED" },
73 { IDCANCEL, "DLG_FILETRANS_CLOSE" },
74 { IDC_TRANSPAUSESTART, "DLG_FILETRANS_PAUSE" },
75 { IDC_TRANSHELP, "BTN_HELP" },
76 };
77 UILanguageFile_ = UILanguageFile;
78 SetDlgTextsW(m_hWnd, TextInfos, _countof(TextInfos), UILanguageFile_);
79 }
80
81 void ChangeButton(BOOL PauseFlag)
82 {
83 wchar_t *UIMsg;
84 Pause = PauseFlag;
85 if (Pause) {
86 GetI18nStrWW("Tera Term", "DLG_FILETRANS_START", L"&Start", UILanguageFile_, &UIMsg);
87 }
88 else {
89 GetI18nStrWW("Tera Term", "DLG_FILETRANS_PAUSE", L"Pau&se", UILanguageFile_, &UIMsg);
90 }
91 SetDlgItemTextW(IDC_TRANSPAUSESTART, UIMsg);
92 free(UIMsg);
93 if (observer_ != NULL) {
94 observer_->OnPause(PauseFlag);
95 }
96 }
97
98 private:
99 virtual BOOL OnInitDialog() {
100 if (HideDialog) {
101 // Visible = False �����t�H�A�O���E���h�����������������A������������
102 // �������g���X�^�C�� WS_EX_NOACTIVATE ���w�������B
103 // (Windows 2000 �������L��)
104 // WS_EX_NOACTIVATE ���w���������\�����������������^�X�N�o�[����������
105 // ���� WS_EX_APPWINDOW ���w�������B
106 ModifyStyleEx(0, WS_EX_NOACTIVATE | WS_EX_APPWINDOW);
107 }
108
109 TTSetIcon(m_hInst, m_hWnd, MAKEINTRESOURCEW(IDI_TTERM), 0);
110
111 AddModelessHandle(m_hWnd);
112
113 if (observer_ == NULL){
114 EnableDlgItem(IDCANCEL, FALSE);
115 EnableDlgItem(IDC_TRANSPAUSESTART, FALSE);
116 EnableDlgItem(IDC_TRANSHELP, FALSE);
117 }
118 return TRUE;
119 }
120
121 virtual BOOL OnClose()
122 {
123 TTSetIcon(m_hInst, m_hWnd, NULL, 0);
124 if (observer_ != NULL) {
125 observer_->OnClose();
126 }
127 return TRUE;
128 }
129
130 virtual BOOL OnCancel()
131 {
132 return OnClose();
133 }
134
135 virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam)
136 {
137 switch (LOWORD(wParam)) {
138 case IDC_TRANSPAUSESTART:
139 ChangeButton(!Pause);
140 return TRUE;
141 case IDC_TRANSHELP:
142 observer_->OnHelp();
143 return TRUE;
144 default:
145 return (TTCDialog::OnCommand(wParam, lParam));
146 }
147 }
148
149 virtual BOOL PostNcDestroy() {
150 RemoveModelessHandle(m_hWnd);
151
152 delete this;
153 return TRUE;
154 }
155
156 virtual LRESULT DlgProc(UINT msg, WPARAM wp, LPARAM) {
157 switch (msg) {
158 case WM_DPICHANGED: {
159 const UINT NewDPI = LOWORD(wp);
160 TTSetIcon(m_hInst, m_hWnd, MAKEINTRESOURCEW(IDI_TTERM), NewDPI);
161 return (LRESULT)TRUE;
162 }
163 default:
164 return (LRESULT)FALSE;
165 }
166 }
167
168 private:
169 const wchar_t *UILanguageFile_;
170
171 public:
172 BOOL Pause;
173 BOOL check_2sec;
174 BOOL show;
175 DWORD prev_elapsed;
176 DWORD StartTime;
177 BOOL HideDialog;
178
179 CFileTransLiteDlg::Observer *observer_;
180 };
181
182 CFileTransLiteDlg::CFileTransLiteDlg()
183 {
184 pData = NULL;
185 }
186
187 CFileTransLiteDlg::~CFileTransLiteDlg()
188 {
189 if (pData == NULL) {
190 return;
191 }
192
193 Destroy();
194 }
195
196 BOOL CFileTransLiteDlg::Create(HINSTANCE hInstance, HWND hParent, const wchar_t *UILanguageFile)
197 {
198 pData = new PrivateData();
199 pData->check_2sec = FALSE;
200 pData->show = FALSE;
201 pData->Pause = FALSE;
202 pData->HideDialog = FALSE;
203
204 BOOL Ok = pData->Create(hInstance, hParent);
205 pData->SetUILanguageFile(UILanguageFile);
206
207 HWND hWnd = ::GetDlgItem(pData->m_hWnd, IDC_TRANSPROGRESS);
208 ::SendMessage(hWnd, PBM_SETRANGE, (WPARAM)0, MAKELPARAM(0, 100));
209 ::SendMessage(hWnd, PBM_SETSTEP, (WPARAM)1, 0);
210 ::SendMessage(hWnd, PBM_SETPOS, (WPARAM)0, 0);
211 ::ShowWindow(hWnd, SW_SHOW);
212
213 pData->SetDlgItemTextA(IDC_TRANS_ETIME, "0:00");
214 pData->StartTime = GetTickCount();
215 pData->prev_elapsed = 0;
216
217 return Ok;
218 }
219
220 void CFileTransLiteDlg::ChangeButton(BOOL PauseFlag)
221 {
222 pData->ChangeButton(PauseFlag);
223 }
224
225 void CFileTransLiteDlg::RefreshNum(size_t ByteCount, size_t FileSize)
226 {
227 const DWORD now = GetTickCount();
228
229 if (!pData->check_2sec) {
230 DWORD elapsed_ms = now - pData->StartTime;
231 if (elapsed_ms > 2 * 1000) {
232 // 2sec�o��
233 pData->check_2sec = TRUE;
234 if ((100.0 * (double)ByteCount / (double)FileSize) < 50) {
235 // 50%����������
236 pData->ShowWindow(SW_SHOWNORMAL);
237 }
238 }
239 }
240
241 char NumStr[24];
242 DWORD elapsed = (now - pData->StartTime) / 1000;
243 if (elapsed != pData->prev_elapsed && elapsed != 0) {
244 char elapsed_str[24];
245 _snprintf_s(elapsed_str, sizeof(elapsed_str), _TRUNCATE, "%ld:%02ld",
246 elapsed / 60, elapsed % 60);
247
248 char speed_str[24];
249 size_t rate2 = ByteCount / elapsed;
250 if (rate2 < 1200) {
251 _snprintf_s(speed_str, sizeof(speed_str), _TRUNCATE, "%lldBytes/s", (unsigned long long)rate2);
252 }
253 else if (rate2 < 1200000) {
254 _snprintf_s(speed_str, sizeof(speed_str), _TRUNCATE, "%lld.%02lldKB/s",
255 (unsigned long long)(rate2 / 1000), (unsigned long long)(rate2 / 10 % 100));
256 }
257 else {
258 _snprintf_s(speed_str, sizeof(speed_str), _TRUNCATE, "%lld.%02lldMB/s",
259 (unsigned long long)(rate2 / (1000*1000)), (unsigned long long)(rate2 / 10000 % 100));
260 }
261 _snprintf_s(NumStr, sizeof(NumStr), _TRUNCATE, "%s (%s)", elapsed_str, speed_str);
262 pData->SetDlgItemTextA(IDC_TRANS_ETIME, NumStr);
263 pData->prev_elapsed = elapsed;
264 }
265
266 if (FileSize > 0) {
267 double rate = 100.0 * (double)ByteCount / (double)FileSize;
268 pData->SendDlgItemMessage(IDC_TRANSPROGRESS, PBM_SETPOS, (WPARAM)rate, 0);
269 _snprintf_s(NumStr,sizeof(NumStr),_TRUNCATE,"%u (%3.1f%%)", (int)ByteCount, rate);
270 }
271 else {
272 _snprintf_s(NumStr,sizeof(NumStr),_TRUNCATE,"%u", (int)ByteCount);
273 }
274 pData->SetDlgItemTextA(IDC_TRANSBYTES, NumStr);
275 }
276
277 void CFileTransLiteDlg::SetCaption(const wchar_t *caption)
278 {
279 pData->SetWindowTextW(caption);
280 }
281
282 void CFileTransLiteDlg::SetFilename(const wchar_t *filename)
283 {
284 pData->SetDlgItemTextW(IDC_TRANSFNAME, filename);
285 pData->SetDlgItemTextW(IDC_EDIT_FULLPATH, filename);
286 }
287
288 void CFileTransLiteDlg::SetObserver(CFileTransLiteDlg::Observer *observer)
289 {
290 pData->observer_ = observer;
291 BOOL enable = observer != NULL;
292 pData->EnableDlgItem(IDCANCEL, enable);
293 pData->EnableDlgItem(IDC_TRANSPAUSESTART, enable);
294 pData->EnableDlgItem(IDC_TRANSHELP, enable);
295 }
296
297 void CFileTransLiteDlg::Destroy()
298 {
299 pData->EndDialog(IDOK);
300 pData = NULL;
301 }

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