blob: 95b4dd4d232eb3f701d561ffd8019517476442ed [file] [log] [blame]
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +00001/* Copyright (C) 2005 TightVNC Team. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 *
18 * TightVNC distribution homepage on the Web: http://www.tightvnc.com/
19 *
20 */
21
22// -=- FTProgress.cxx
23
24#include <vncviewer/FTProgress.h>
25
26using namespace rfb;
27using namespace rfb::win32;
28
Dennis Syrovatsky93196042005-11-07 08:09:54 +000029FTProgress::FTProgress(HWND hwndParent)
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000030{
Dennis Syrovatsky93196042005-11-07 08:09:54 +000031 m_bInitialized = false;
32 m_hwndParent = hwndParent;
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000033
Dennis Syrovatsky93196042005-11-07 08:09:54 +000034 m_pSingleProgress = NULL;
35 m_pGeneralProgress = NULL;
Dennis Syrovatsky6806fec2005-11-28 06:12:44 +000036
37 m_hwndSinglePercent = GetDlgItem(m_hwndParent, IDC_FTSINGLEPERCENT);
38 m_hwndGeneralPercent = GetDlgItem(m_hwndParent, IDC_FTGENERALPERCENT);
39
40 m_bInitialized = createProgressBarObjects();
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000041}
42
43FTProgress::~FTProgress()
44{
Dennis Syrovatsky2d350412005-11-07 08:21:03 +000045 destroyProgressBarObjects();
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000046}
47
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000048void
49FTProgress::increase(DWORD value)
50{
Dennis Syrovatsky2d350412005-11-07 08:21:03 +000051 if (!m_bInitialized) return;
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000052
Dennis Syrovatsky2d350412005-11-07 08:21:03 +000053 m_pSingleProgress->increase(value);
54 m_pGeneralProgress->increase(value);
55
56 setProgressText();
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000057}
58
59void
Dennis Syrovatsky6806fec2005-11-28 06:12:44 +000060FTProgress::clearAndInitGeneral(DWORD64 dw64MaxValue, DWORD64 dw64Position)
61{
62 if (!m_bInitialized) return;
63
64 m_pGeneralProgress->clear();
65 m_pGeneralProgress->init(dw64MaxValue, dw64Position);
66
67 setProgressText();
68}
69
70void
71FTProgress::clearAndInitSingle(DWORD dwMaxValue, DWORD dwPosition)
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000072{
Dennis Syrovatsky2d350412005-11-07 08:21:03 +000073 if (!m_bInitialized) return;
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000074
Dennis Syrovatsky2d350412005-11-07 08:21:03 +000075 m_pSingleProgress->clear();
Dennis Syrovatsky6806fec2005-11-28 06:12:44 +000076 m_pSingleProgress->init(dwMaxValue, dwPosition);
Dennis Syrovatsky2d350412005-11-07 08:21:03 +000077
78 setProgressText();
79}
80
81void
82FTProgress::clearAll()
83{
84 if (!m_bInitialized) return;
85
86 m_pSingleProgress->clear();
87 m_pGeneralProgress->clear();
88
89 setProgressText();
Dennis Syrovatsky93196042005-11-07 08:09:54 +000090}
91
92bool
93FTProgress::createProgressBarObjects()
94{
95 if ((m_pSingleProgress != NULL) || (m_pGeneralProgress != NULL)) {
96 return false;
97 } else {
98 HWND hwndSingleProgr = GetDlgItem(m_hwndParent, IDC_FTSINGLEPROGRESS);
99 HWND hwndGeneralProgr = GetDlgItem(m_hwndParent, IDC_FTGENERALPROGRESS);
100
101 m_pSingleProgress = new ProgressControl(hwndSingleProgr);
102 if (m_pSingleProgress == NULL) return false;
103
104 m_pGeneralProgress = new ProgressControl(hwndGeneralProgr);
105 if (m_pGeneralProgress == NULL) {
106 delete m_pSingleProgress;
107 m_pSingleProgress = NULL;
108 return false;
109 }
110 }
111 return true;
112}
113
114bool
115FTProgress::destroyProgressBarObjects()
116{
Dennis Syrovatsky2d350412005-11-07 08:21:03 +0000117 clearAll();
118
Dennis Syrovatsky93196042005-11-07 08:09:54 +0000119 if (m_pSingleProgress != NULL) {
120 delete m_pSingleProgress;
121 }
122
123 if (m_pGeneralProgress != NULL) {
124 delete m_pGeneralProgress;
125 }
126
127 return true;
128}
129
Dennis Syrovatsky93196042005-11-07 08:09:54 +0000130void
131FTProgress::setProgressText()
132{
133 char buf[16];
134
135 int percent = m_pSingleProgress->getCurrentPercent();
136 sprintf(buf, "%d%%", percent);
137 SetWindowText(m_hwndSinglePercent, buf);
138
139 percent = m_pGeneralProgress->getCurrentPercent();
140 sprintf(buf, "%d%%", percent);
141 SetWindowText(m_hwndGeneralPercent, buf);
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +0000142}