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 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/ftdlg_lite.cpp
File MIME type: text/x-c++src
File size: 8874 byte(s)
Merge branch 'unicode_buf'
1 doda 8445 /*
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     #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     wchar_t *Cation;
187     wchar_t *Filename;
188    
189     public:
190     BOOL Pause;
191     BOOL check_2sec;
192     BOOL show;
193     DWORD prev_elapsed;
194     DWORD StartTime;
195     BOOL HideDialog;
196    
197     CFileTransLiteDlg::Observer *observer_;
198     };
199    
200     CFileTransLiteDlg::CFileTransLiteDlg()
201     {
202     pData = NULL;
203     }
204    
205     CFileTransLiteDlg::~CFileTransLiteDlg()
206     {
207     if (pData == NULL) {
208     return;
209     }
210    
211     Destroy();
212     }
213    
214     BOOL CFileTransLiteDlg::Create(HINSTANCE hInstance, HWND hParent, const char *UILanguageFile)
215     {
216     pData = new PrivateData();
217     pData->check_2sec = FALSE;
218     pData->show = FALSE;
219     pData->Pause = FALSE;
220     pData->HideDialog = FALSE;
221    
222     BOOL Ok = pData->Create(hInstance, hParent);
223     pData->SetUILanguageFile(UILanguageFile);
224    
225     HWND hWnd = ::GetDlgItem(pData->m_hWnd, IDC_TRANSPROGRESS);
226     ::SendMessage(hWnd, PBM_SETRANGE, (WPARAM)0, MAKELPARAM(0, 100));
227     ::SendMessage(hWnd, PBM_SETSTEP, (WPARAM)1, 0);
228     ::SendMessage(hWnd, PBM_SETPOS, (WPARAM)0, 0);
229     ::ShowWindow(hWnd, SW_SHOW);
230    
231     pData->SetDlgItemTextA(IDC_TRANS_ETIME, "0:00");
232     pData->StartTime = GetTickCount();
233     pData->prev_elapsed = 0;
234    
235     return Ok;
236     }
237    
238     void CFileTransLiteDlg::ChangeButton(BOOL PauseFlag)
239     {
240     pData->ChangeButton(PauseFlag);
241     }
242    
243     void CFileTransLiteDlg::RefreshNum(size_t ByteCount, size_t FileSize)
244     {
245     const DWORD now = GetTickCount();
246    
247     if (!pData->check_2sec) {
248     DWORD elapsed_ms = now - pData->StartTime;
249     if (elapsed_ms > 2 * 1000) {
250     // 2sec�o��
251     pData->check_2sec = TRUE;
252     if ((100.0 * (double)ByteCount / (double)FileSize) < 50) {
253     // 50%����������
254     pData->ShowWindow(SW_SHOWNORMAL);
255     }
256     }
257     }
258    
259     char NumStr[24];
260     DWORD elapsed = (now - pData->StartTime) / 1000;
261     if (elapsed != pData->prev_elapsed && elapsed != 0) {
262     char elapsed_str[24];
263     _snprintf_s(elapsed_str, sizeof(elapsed_str), _TRUNCATE, "%ld:%02ld",
264     elapsed / 60, elapsed % 60);
265    
266     char speed_str[24];
267     size_t rate2 = ByteCount / elapsed;
268     if (rate2 < 1200) {
269     _snprintf_s(speed_str, sizeof(speed_str), _TRUNCATE, "%lldBytes/s", (unsigned long long)rate2);
270     }
271     else if (rate2 < 1200000) {
272     _snprintf_s(speed_str, sizeof(speed_str), _TRUNCATE, "%lld.%02lldKB/s",
273     (unsigned long long)(rate2 / 1000), (unsigned long long)(rate2 / 10 % 100));
274     }
275     else {
276     _snprintf_s(speed_str, sizeof(speed_str), _TRUNCATE, "%lld.%02lldMB/s",
277     (unsigned long long)(rate2 / (1000*1000)), (unsigned long long)(rate2 / 10000 % 100));
278     }
279     _snprintf_s(NumStr, sizeof(NumStr), _TRUNCATE, "%s (%s)", elapsed_str, speed_str);
280     pData->SetDlgItemTextA(IDC_TRANS_ETIME, NumStr);
281     pData->prev_elapsed = elapsed;
282     }
283    
284     if (FileSize > 0) {
285     double rate = 100.0 * (double)ByteCount / (double)FileSize;
286     pData->SendDlgItemMessage(IDC_TRANSPROGRESS, PBM_SETPOS, (WPARAM)rate, 0);
287     _snprintf_s(NumStr,sizeof(NumStr),_TRUNCATE,"%u (%3.1f%%)", (int)ByteCount, rate);
288     }
289     else {
290     _snprintf_s(NumStr,sizeof(NumStr),_TRUNCATE,"%u", (int)ByteCount);
291     }
292     pData->SetDlgItemTextA(IDC_TRANSBYTES, NumStr);
293     }
294    
295     void CFileTransLiteDlg::SetCaption(const wchar_t *caption)
296     {
297     pData->SetWindowTextW(caption);
298     }
299    
300     void CFileTransLiteDlg::SetFilename(const wchar_t *filename)
301     {
302     pData->SetDlgItemTextW(IDC_TRANSFNAME, filename);
303     pData->SetDlgItemTextW(IDC_EDIT_FULLPATH, filename);
304     }
305    
306     void CFileTransLiteDlg::SetObserver(CFileTransLiteDlg::Observer *observer)
307     {
308     pData->observer_ = observer;
309     BOOL enable = observer != NULL;
310     pData->EnableDlgItem(IDCANCEL, enable);
311     pData->EnableDlgItem(IDC_TRANSPAUSESTART, enable);
312     pData->EnableDlgItem(IDC_TRANSHELP, enable);
313     }
314    
315     void CFileTransLiteDlg::Destroy()
316     {
317     pData->EndDialog(IDOK);
318     pData = NULL;
319     }

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