blob: 85bd15f33db730d3fb2784792a2769ffd8dc8c83 [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +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// -=- ProgressControl.cxx
23
24#include <rfb_win32/ProgressControl.h>
25
26using namespace rfb;
27using namespace rfb::win32;
28
29#define MAX_RANGE 0xFFFF
30
31ProgressControl::ProgressControl(HWND hwndProgress)
32{
33 m_hwndProgress = hwndProgress;
34
35 m_dw64MaxValue = 0;
36 m_dw64CurrentValue = 0;
37}
38
39ProgressControl::~ProgressControl()
40{
41}
42
43bool
44ProgressControl::init(DWORD64 maxValue, DWORD64 position)
45{
46 if (m_dw64CurrentValue > m_dw64MaxValue) return false;
47
48 m_dw64CurrentValue = position;
49 m_dw64MaxValue = maxValue;
50
51 if (!SendMessage(m_hwndProgress, PBM_SETRANGE, (WPARAM) 0, MAKELPARAM(0, MAX_RANGE)))
52 return false;
53
54 return true;
55}
56
57bool
58ProgressControl::clear()
59{
60 m_dw64CurrentValue = 0;
61 return show();
62}
63
64bool
65ProgressControl::increase(DWORD64 value)
66{
67 if ((m_dw64MaxValue - m_dw64CurrentValue) > value) {
68 m_dw64CurrentValue += value;
69 } else {
70 m_dw64CurrentValue = m_dw64MaxValue;
71 }
72 return show();
73}
74
75bool
76ProgressControl::show()
77{
78 DWORD curPos;
79 if (m_dw64MaxValue != 0) {
80 curPos = (DWORD) ((m_dw64CurrentValue * MAX_RANGE) / m_dw64MaxValue);
81 } else {
82 curPos = 0;
83 }
84
85 if (!SendMessage(m_hwndProgress, PBM_SETPOS, (WPARAM) curPos, (LPARAM) 0))
86 return false;
87
88 return true;
89}
90
91int
92ProgressControl::getCurrentPercent()
93{
94 if (m_dw64MaxValue == 0) return 0;
95
96 return ((int) ((m_dw64CurrentValue * 100) / m_dw64MaxValue));
97}