blob: e6cc952ffe81fbf23cb9c304eac4b844705d9b9c [file] [log] [blame]
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +00001/* Copyright (C) 2005 TightVNC Team. All Rights Reserved.
Dennis Syrovatskyf72f9fd2006-04-17 08:56:48 +00002 *
3 * Developed by Dennis Syrovatsky
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +00004 *
5 * This is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this software; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 * USA.
19 *
20 * TightVNC distribution homepage on the Web: http://www.tightvnc.com/
21 *
22 */
23
24// -=- FTProgress.cxx
25
26#include <vncviewer/FTProgress.h>
27
28using namespace rfb;
29using namespace rfb::win32;
30
Dennis Syrovatsky93196042005-11-07 08:09:54 +000031FTProgress::FTProgress(HWND hwndParent)
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000032{
Dennis Syrovatsky93196042005-11-07 08:09:54 +000033 m_bInitialized = false;
34 m_hwndParent = hwndParent;
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000035
Dennis Syrovatsky93196042005-11-07 08:09:54 +000036 m_pSingleProgress = NULL;
37 m_pGeneralProgress = NULL;
Dennis Syrovatsky6806fec2005-11-28 06:12:44 +000038
39 m_hwndSinglePercent = GetDlgItem(m_hwndParent, IDC_FTSINGLEPERCENT);
40 m_hwndGeneralPercent = GetDlgItem(m_hwndParent, IDC_FTGENERALPERCENT);
41
42 m_bInitialized = createProgressBarObjects();
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000043}
44
45FTProgress::~FTProgress()
46{
Dennis Syrovatsky2d350412005-11-07 08:21:03 +000047 destroyProgressBarObjects();
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000048}
49
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000050void
51FTProgress::increase(DWORD value)
52{
Dennis Syrovatsky2d350412005-11-07 08:21:03 +000053 if (!m_bInitialized) return;
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000054
Dennis Syrovatsky2d350412005-11-07 08:21:03 +000055 m_pSingleProgress->increase(value);
56 m_pGeneralProgress->increase(value);
57
58 setProgressText();
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000059}
60
61void
Dennis Syrovatsky6806fec2005-11-28 06:12:44 +000062FTProgress::clearAndInitGeneral(DWORD64 dw64MaxValue, DWORD64 dw64Position)
63{
64 if (!m_bInitialized) return;
65
66 m_pGeneralProgress->clear();
67 m_pGeneralProgress->init(dw64MaxValue, dw64Position);
68
69 setProgressText();
70}
71
72void
73FTProgress::clearAndInitSingle(DWORD dwMaxValue, DWORD dwPosition)
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000074{
Dennis Syrovatsky2d350412005-11-07 08:21:03 +000075 if (!m_bInitialized) return;
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +000076
Dennis Syrovatsky2d350412005-11-07 08:21:03 +000077 m_pSingleProgress->clear();
Dennis Syrovatsky6806fec2005-11-28 06:12:44 +000078 m_pSingleProgress->init(dwMaxValue, dwPosition);
Dennis Syrovatsky2d350412005-11-07 08:21:03 +000079
80 setProgressText();
81}
82
83void
84FTProgress::clearAll()
85{
86 if (!m_bInitialized) return;
87
88 m_pSingleProgress->clear();
89 m_pGeneralProgress->clear();
90
91 setProgressText();
Dennis Syrovatsky93196042005-11-07 08:09:54 +000092}
93
94bool
95FTProgress::createProgressBarObjects()
96{
97 if ((m_pSingleProgress != NULL) || (m_pGeneralProgress != NULL)) {
98 return false;
99 } else {
100 HWND hwndSingleProgr = GetDlgItem(m_hwndParent, IDC_FTSINGLEPROGRESS);
101 HWND hwndGeneralProgr = GetDlgItem(m_hwndParent, IDC_FTGENERALPROGRESS);
102
103 m_pSingleProgress = new ProgressControl(hwndSingleProgr);
104 if (m_pSingleProgress == NULL) return false;
105
106 m_pGeneralProgress = new ProgressControl(hwndGeneralProgr);
107 if (m_pGeneralProgress == NULL) {
108 delete m_pSingleProgress;
109 m_pSingleProgress = NULL;
110 return false;
111 }
112 }
113 return true;
114}
115
116bool
117FTProgress::destroyProgressBarObjects()
118{
Dennis Syrovatsky2d350412005-11-07 08:21:03 +0000119 clearAll();
120
Dennis Syrovatsky93196042005-11-07 08:09:54 +0000121 if (m_pSingleProgress != NULL) {
122 delete m_pSingleProgress;
Dennis Syrovatsky1f868512005-12-14 07:38:19 +0000123 m_pSingleProgress = NULL;
Dennis Syrovatsky93196042005-11-07 08:09:54 +0000124 }
125
126 if (m_pGeneralProgress != NULL) {
127 delete m_pGeneralProgress;
Dennis Syrovatsky1f868512005-12-14 07:38:19 +0000128 m_pGeneralProgress = NULL;
Dennis Syrovatsky93196042005-11-07 08:09:54 +0000129 }
130
131 return true;
132}
133
Dennis Syrovatsky93196042005-11-07 08:09:54 +0000134void
135FTProgress::setProgressText()
136{
Dennis Syrovatskyf72f9fd2006-04-17 08:56:48 +0000137 char buf[16] = {0};
138 char buf2[16] = {0};
139
140 int percent = m_pSingleProgress->getCurrentPercent();
141 sprintf(buf, "%d%%", percent);
142 GetWindowText(m_hwndSinglePercent, buf2, 16);
143 if (strcmp(buf, buf2) != 0)
144 SetWindowText(m_hwndSinglePercent, buf);
145
146 percent = m_pGeneralProgress->getCurrentPercent();
147 sprintf(buf, "%d%%", percent);
148 GetWindowText(m_hwndGeneralPercent, buf2, 16);
149 if (strcmp(buf, buf2) != 0)
150 SetWindowText(m_hwndGeneralPercent, buf);
Dennis Syrovatsky803e02c2005-11-06 05:35:27 +0000151}