blob: 04f0186b40b69987611285780be262897791d1a2 [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* Copyright (C) 2005 TightVNC Team. All Rights Reserved.
2 *
3 * Developed by Dennis Syrovatsky
4 *
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 *
Peter Åstrand7877cd62009-02-25 16:15:48 +000020 *
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000021 *
22 */
23
24// -=- FTProgress.cxx
25
26#include <vncviewer/FTProgress.h>
27
28using namespace rfb;
29using namespace rfb::win32;
30
31FTProgress::FTProgress(HWND hwndParent)
32{
33 m_bInitialized = false;
34 m_hwndParent = hwndParent;
35
36 m_pSingleProgress = NULL;
37 m_pGeneralProgress = NULL;
38
39 m_hwndSinglePercent = GetDlgItem(m_hwndParent, IDC_FTSINGLEPERCENT);
40 m_hwndGeneralPercent = GetDlgItem(m_hwndParent, IDC_FTGENERALPERCENT);
41
42 m_bInitialized = createProgressBarObjects();
43}
44
45FTProgress::~FTProgress()
46{
47 destroyProgressBarObjects();
48}
49
50void
51FTProgress::increase(DWORD value)
52{
53 if (!m_bInitialized) return;
54
55 m_pSingleProgress->increase(value);
56 m_pGeneralProgress->increase(value);
57
58 setProgressText();
59}
60
61void
62FTProgress::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)
74{
75 if (!m_bInitialized) return;
76
77 m_pSingleProgress->clear();
78 m_pSingleProgress->init(dwMaxValue, dwPosition);
79
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();
92}
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{
119 clearAll();
120
121 if (m_pSingleProgress != NULL) {
122 delete m_pSingleProgress;
123 m_pSingleProgress = NULL;
124 }
125
126 if (m_pGeneralProgress != NULL) {
127 delete m_pGeneralProgress;
128 m_pGeneralProgress = NULL;
129 }
130
131 return true;
132}
133
134void
135FTProgress::setProgressText()
136{
137 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);
Peter Åstrand310b30c2008-12-10 10:37:25 +0000151}