Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9048 - (hide annotations) (download) (as text)
Wed Dec 16 12:24:13 2020 UTC (3 years, 3 months ago) by nmaya
Original Path: trunk/teraterm/teraterm/ftdlg_lite.cpp
File MIME type: text/x-c++src
File size: 8835 byte(s)
ソースファイルの著作権表記の "最後の発行の年" を削除

ticket #40996
1 doda 8445 /*
2 nmaya 9048 * (C) 2019- TeraTerm Project
3 doda 8445 * 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     #include "teraterm_conf.h"
31    
32     #include <stdio.h>
33     #include <windows.h>
34     #include <commctrl.h>
35     #define _CRTDBG_MAP_ALLOC
36     #include <crtdbg.h>
37    
38     #include "teraterm.h"
39     #include "tttypes.h"
40     #include "ttlib.h"
41     #include "dlglib.h"
42     #include "tt_res.h"
43     #include "teraterml.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     SmallIcon = NULL;
58     BigIcon = NULL;
59     check_2sec = NULL;
60     show = FALSE;
61     UILanguageFile_ = NULL;
62     Pause = FALSE;
63     observer_ = NULL;
64     }
65    
66     BOOL Create(HINSTANCE hInstance, HWND hParent) {
67     return TTCDialog::Create(hInstance, hParent, IDD_FILETRANSDLG);
68     }
69     void SetUILanguageFile(const char *UILanguageFile) {
70     static const DlgTextInfo TextInfos[] = {
71     { IDC_TRANS_FILENAME, "DLG_FILETRANS_FILENAME" },
72     { IDC_FULLPATH_LABEL, "DLG_FILETRANS_FULLPATH" },
73     { IDC_TRANS_TRANS, "DLG_FILETRANS_TRNAS" },
74     { IDC_TRANS_ELAPSED, "DLG_FILETRANS_ELAPSED" },
75     { IDCANCEL, "DLG_FILETRANS_CLOSE" },
76     { IDC_TRANSPAUSESTART, "DLG_FILETRANS_PAUSE" },
77     { IDC_TRANSHELP, "BTN_HELP" },
78     };
79     UILanguageFile_ = UILanguageFile;
80     SetDlgTexts(m_hWnd, TextInfos, _countof(TextInfos), UILanguageFile_);
81     }
82    
83     void ChangeButton(BOOL PauseFlag)
84     {
85     wchar_t UIMsg[MAX_UIMSG];
86     Pause = PauseFlag;
87     if (Pause) {
88     get_lang_msgW("DLG_FILETRANS_START", UIMsg, _countof(UIMsg), L"&Start", UILanguageFile_);
89     }
90     else {
91     get_lang_msgW("DLG_FILETRANS_PAUSE", UIMsg, _countof(UIMsg), L"Pau&se", UILanguageFile_);
92    
93     }
94     SetDlgItemTextW(IDC_TRANSPAUSESTART, UIMsg);
95     if (observer_ != NULL) {
96     observer_->OnPause(PauseFlag);
97     }
98     }
99    
100     private:
101     virtual BOOL OnInitDialog() {
102     int fuLoad = LR_DEFAULTCOLOR;
103    
104     if (HideDialog) {
105     // Visible = False �����t�H�A�O���E���h�����������������A������������
106     // �������g���X�^�C�� WS_EX_NOACTIVATE ���w�������B
107     // (Windows 2000 �������L��)
108     // WS_EX_NOACTIVATE ���w���������\�����������������^�X�N�o�[����������
109     // ���� WS_EX_APPWINDOW ���w�������B
110     ModifyStyleEx(0, WS_EX_NOACTIVATE | WS_EX_APPWINDOW);
111     }
112    
113     if (IsWindowsNT4()) {
114     fuLoad = LR_VGACOLOR;
115     }
116     SmallIcon = LoadImage(m_hInst,
117     MAKEINTRESOURCE(IDI_TTERM),
118     IMAGE_ICON, 16, 16, fuLoad);
119     ::PostMessage(m_hWnd, WM_SETICON, ICON_SMALL,
120     (LPARAM)SmallIcon);
121    
122     BigIcon = LoadImage(m_hInst,
123     MAKEINTRESOURCE(IDI_TTERM),
124     IMAGE_ICON, 0, 0, fuLoad);
125     ::PostMessage(m_hWnd, WM_SETICON, ICON_BIG,
126     (LPARAM)BigIcon);
127    
128     AddModelessHandle(m_hWnd);
129    
130     if (observer_ == NULL){
131     EnableDlgItem(IDCANCEL, FALSE);
132     EnableDlgItem(IDC_TRANSPAUSESTART, FALSE);
133     EnableDlgItem(IDC_TRANSHELP, FALSE);
134     }
135     return TRUE;
136     }
137    
138     virtual BOOL OnClose()
139     {
140     if (observer_ != NULL) {
141     observer_->OnClose();
142     }
143     return TRUE;
144     }
145    
146     virtual BOOL OnCancel()
147     {
148     return OnClose();
149     }
150    
151     virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam)
152     {
153     switch (LOWORD(wParam)) {
154     case IDC_TRANSPAUSESTART:
155     ChangeButton(!Pause);
156     return TRUE;
157     case IDC_TRANSHELP:
158     observer_->OnHelp();
159     return TRUE;
160     default:
161     return (TTCDialog::OnCommand(wParam, lParam));
162     }
163     }
164    
165     virtual BOOL PostNcDestroy() {
166     if (SmallIcon) {
167     DestroyIcon((HICON)SmallIcon);
168     SmallIcon = NULL;
169     }
170    
171     if (BigIcon) {
172     DestroyIcon((HICON)BigIcon);
173     BigIcon = NULL;
174     }
175    
176     RemoveModelessHandle(m_hWnd);
177    
178     delete this;
179     return TRUE;
180     }
181    
182     private:
183     HANDLE SmallIcon;
184     HANDLE BigIcon;
185     const char *UILanguageFile_;
186    
187     public:
188     BOOL Pause;
189     BOOL check_2sec;
190     BOOL show;
191     DWORD prev_elapsed;
192     DWORD StartTime;
193     BOOL HideDialog;
194    
195     CFileTransLiteDlg::Observer *observer_;
196     };
197    
198     CFileTransLiteDlg::CFileTransLiteDlg()
199     {
200     pData = NULL;
201     }
202    
203     CFileTransLiteDlg::~CFileTransLiteDlg()
204     {
205     if (pData == NULL) {
206     return;
207     }
208    
209     Destroy();
210     }
211    
212     BOOL CFileTransLiteDlg::Create(HINSTANCE hInstance, HWND hParent, const char *UILanguageFile)
213     {
214     pData = new PrivateData();
215     pData->check_2sec = FALSE;
216     pData->show = FALSE;
217     pData->Pause = FALSE;
218     pData->HideDialog = FALSE;
219    
220     BOOL Ok = pData->Create(hInstance, hParent);
221     pData->SetUILanguageFile(UILanguageFile);
222    
223     HWND hWnd = ::GetDlgItem(pData->m_hWnd, IDC_TRANSPROGRESS);
224     ::SendMessage(hWnd, PBM_SETRANGE, (WPARAM)0, MAKELPARAM(0, 100));
225     ::SendMessage(hWnd, PBM_SETSTEP, (WPARAM)1, 0);
226     ::SendMessage(hWnd, PBM_SETPOS, (WPARAM)0, 0);
227     ::ShowWindow(hWnd, SW_SHOW);
228    
229     pData->SetDlgItemTextA(IDC_TRANS_ETIME, "0:00");
230     pData->StartTime = GetTickCount();
231     pData->prev_elapsed = 0;
232    
233     return Ok;
234     }
235    
236     void CFileTransLiteDlg::ChangeButton(BOOL PauseFlag)
237     {
238     pData->ChangeButton(PauseFlag);
239     }
240    
241     void CFileTransLiteDlg::RefreshNum(size_t ByteCount, size_t FileSize)
242     {
243     const DWORD now = GetTickCount();
244    
245     if (!pData->check_2sec) {
246     DWORD elapsed_ms = now - pData->StartTime;
247     if (elapsed_ms > 2 * 1000) {
248     // 2sec�o��
249     pData->check_2sec = TRUE;
250     if ((100.0 * (double)ByteCount / (double)FileSize) < 50) {
251     // 50%����������
252     pData->ShowWindow(SW_SHOWNORMAL);
253     }
254     }
255     }
256    
257     char NumStr[24];
258     DWORD elapsed = (now - pData->StartTime) / 1000;
259     if (elapsed != pData->prev_elapsed && elapsed != 0) {
260     char elapsed_str[24];
261     _snprintf_s(elapsed_str, sizeof(elapsed_str), _TRUNCATE, "%ld:%02ld",
262     elapsed / 60, elapsed % 60);
263    
264     char speed_str[24];
265     size_t rate2 = ByteCount / elapsed;
266     if (rate2 < 1200) {
267     _snprintf_s(speed_str, sizeof(speed_str), _TRUNCATE, "%lldBytes/s", (unsigned long long)rate2);
268     }
269     else if (rate2 < 1200000) {
270     _snprintf_s(speed_str, sizeof(speed_str), _TRUNCATE, "%lld.%02lldKB/s",
271     (unsigned long long)(rate2 / 1000), (unsigned long long)(rate2 / 10 % 100));
272     }
273     else {
274     _snprintf_s(speed_str, sizeof(speed_str), _TRUNCATE, "%lld.%02lldMB/s",
275     (unsigned long long)(rate2 / (1000*1000)), (unsigned long long)(rate2 / 10000 % 100));
276     }
277     _snprintf_s(NumStr, sizeof(NumStr), _TRUNCATE, "%s (%s)", elapsed_str, speed_str);
278     pData->SetDlgItemTextA(IDC_TRANS_ETIME, NumStr);
279     pData->prev_elapsed = elapsed;
280     }
281    
282     if (FileSize > 0) {
283     double rate = 100.0 * (double)ByteCount / (double)FileSize;
284     pData->SendDlgItemMessage(IDC_TRANSPROGRESS, PBM_SETPOS, (WPARAM)rate, 0);
285     _snprintf_s(NumStr,sizeof(NumStr),_TRUNCATE,"%u (%3.1f%%)", (int)ByteCount, rate);
286     }
287     else {
288     _snprintf_s(NumStr,sizeof(NumStr),_TRUNCATE,"%u", (int)ByteCount);
289     }
290     pData->SetDlgItemTextA(IDC_TRANSBYTES, NumStr);
291     }
292    
293     void CFileTransLiteDlg::SetCaption(const wchar_t *caption)
294     {
295     pData->SetWindowTextW(caption);
296     }
297    
298     void CFileTransLiteDlg::SetFilename(const wchar_t *filename)
299     {
300     pData->SetDlgItemTextW(IDC_TRANSFNAME, filename);
301     pData->SetDlgItemTextW(IDC_EDIT_FULLPATH, filename);
302     }
303    
304     void CFileTransLiteDlg::SetObserver(CFileTransLiteDlg::Observer *observer)
305     {
306     pData->observer_ = observer;
307     BOOL enable = observer != NULL;
308     pData->EnableDlgItem(IDCANCEL, enable);
309     pData->EnableDlgItem(IDC_TRANSPAUSESTART, enable);
310     pData->EnableDlgItem(IDC_TRANSHELP, enable);
311     }
312    
313     void CFileTransLiteDlg::Destroy()
314     {
315     pData->EndDialog(IDOK);
316     pData = NULL;
317     }

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