Dennis Syrovatsky | 803e02c | 2005-11-06 05:35:27 +0000 | [diff] [blame] | 1 | /* 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 | |
| 26 | using namespace rfb; |
| 27 | using namespace rfb::win32; |
| 28 | |
Dennis Syrovatsky | 9319604 | 2005-11-07 08:09:54 +0000 | [diff] [blame] | 29 | FTProgress::FTProgress(HWND hwndParent) |
Dennis Syrovatsky | 803e02c | 2005-11-06 05:35:27 +0000 | [diff] [blame] | 30 | { |
Dennis Syrovatsky | 9319604 | 2005-11-07 08:09:54 +0000 | [diff] [blame] | 31 | m_bInitialized = false; |
| 32 | m_hwndParent = hwndParent; |
Dennis Syrovatsky | 803e02c | 2005-11-06 05:35:27 +0000 | [diff] [blame] | 33 | |
Dennis Syrovatsky | 9319604 | 2005-11-07 08:09:54 +0000 | [diff] [blame] | 34 | m_pSingleProgress = NULL; |
| 35 | m_pGeneralProgress = NULL; |
Dennis Syrovatsky | 803e02c | 2005-11-06 05:35:27 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | FTProgress::~FTProgress() |
| 39 | { |
Dennis Syrovatsky | 2d35041 | 2005-11-07 08:21:03 +0000 | [diff] [blame] | 40 | destroyProgressBarObjects(); |
Dennis Syrovatsky | 803e02c | 2005-11-06 05:35:27 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | bool |
| 44 | FTProgress::initialize(DWORD64 totalMaxValue, DWORD maxValue) |
| 45 | { |
Dennis Syrovatsky | 9319604 | 2005-11-07 08:09:54 +0000 | [diff] [blame] | 46 | m_bInitialized = false; |
| 47 | |
| 48 | m_hwndSinglePercent = GetDlgItem(m_hwndParent, IDC_FTSINGLEPERCENT); |
| 49 | m_hwndGeneralPercent = GetDlgItem(m_hwndParent, IDC_FTGENERALPERCENT); |
| 50 | |
| 51 | if ((m_hwndSinglePercent == NULL) || (m_hwndGeneralPercent == NULL)) return false; |
| 52 | |
| 53 | if (!createProgressBarObjects()) return false; |
| 54 | |
| 55 | if (!initProgressControls(totalMaxValue, maxValue)) return false; |
| 56 | |
Dennis Syrovatsky | 4ab4185 | 2005-11-07 09:52:36 +0000 | [diff] [blame] | 57 | setProgressText(); |
| 58 | |
Dennis Syrovatsky | 9319604 | 2005-11-07 08:09:54 +0000 | [diff] [blame] | 59 | m_bInitialized = true; |
| 60 | return true; |
Dennis Syrovatsky | 803e02c | 2005-11-06 05:35:27 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void |
| 64 | FTProgress::increase(DWORD value) |
| 65 | { |
Dennis Syrovatsky | 2d35041 | 2005-11-07 08:21:03 +0000 | [diff] [blame] | 66 | if (!m_bInitialized) return; |
Dennis Syrovatsky | 803e02c | 2005-11-06 05:35:27 +0000 | [diff] [blame] | 67 | |
Dennis Syrovatsky | 2d35041 | 2005-11-07 08:21:03 +0000 | [diff] [blame] | 68 | m_pSingleProgress->increase(value); |
| 69 | m_pGeneralProgress->increase(value); |
| 70 | |
| 71 | setProgressText(); |
Dennis Syrovatsky | 803e02c | 2005-11-06 05:35:27 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void |
Dennis Syrovatsky | 2d35041 | 2005-11-07 08:21:03 +0000 | [diff] [blame] | 75 | FTProgress::clearSingle() |
Dennis Syrovatsky | 803e02c | 2005-11-06 05:35:27 +0000 | [diff] [blame] | 76 | { |
Dennis Syrovatsky | 2d35041 | 2005-11-07 08:21:03 +0000 | [diff] [blame] | 77 | if (!m_bInitialized) return; |
Dennis Syrovatsky | 803e02c | 2005-11-06 05:35:27 +0000 | [diff] [blame] | 78 | |
Dennis Syrovatsky | 2d35041 | 2005-11-07 08:21:03 +0000 | [diff] [blame] | 79 | m_pSingleProgress->clear(); |
| 80 | |
| 81 | setProgressText(); |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | FTProgress::clearAll() |
| 86 | { |
| 87 | if (!m_bInitialized) return; |
| 88 | |
| 89 | m_pSingleProgress->clear(); |
| 90 | m_pGeneralProgress->clear(); |
| 91 | |
| 92 | setProgressText(); |
Dennis Syrovatsky | 9319604 | 2005-11-07 08:09:54 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | bool |
| 96 | FTProgress::createProgressBarObjects() |
| 97 | { |
| 98 | if ((m_pSingleProgress != NULL) || (m_pGeneralProgress != NULL)) { |
| 99 | return false; |
| 100 | } else { |
| 101 | HWND hwndSingleProgr = GetDlgItem(m_hwndParent, IDC_FTSINGLEPROGRESS); |
| 102 | HWND hwndGeneralProgr = GetDlgItem(m_hwndParent, IDC_FTGENERALPROGRESS); |
| 103 | |
| 104 | m_pSingleProgress = new ProgressControl(hwndSingleProgr); |
| 105 | if (m_pSingleProgress == NULL) return false; |
| 106 | |
| 107 | m_pGeneralProgress = new ProgressControl(hwndGeneralProgr); |
| 108 | if (m_pGeneralProgress == NULL) { |
| 109 | delete m_pSingleProgress; |
| 110 | m_pSingleProgress = NULL; |
| 111 | return false; |
| 112 | } |
| 113 | } |
| 114 | return true; |
| 115 | } |
| 116 | |
| 117 | bool |
| 118 | FTProgress::destroyProgressBarObjects() |
| 119 | { |
Dennis Syrovatsky | 2d35041 | 2005-11-07 08:21:03 +0000 | [diff] [blame] | 120 | clearAll(); |
| 121 | |
Dennis Syrovatsky | 9319604 | 2005-11-07 08:09:54 +0000 | [diff] [blame] | 122 | if (m_pSingleProgress != NULL) { |
| 123 | delete m_pSingleProgress; |
| 124 | } |
| 125 | |
| 126 | if (m_pGeneralProgress != NULL) { |
| 127 | delete m_pGeneralProgress; |
| 128 | } |
| 129 | |
| 130 | return true; |
| 131 | } |
| 132 | |
| 133 | bool |
| 134 | FTProgress::initProgressControls(DWORD64 totalMaxValue, DWORD maxValue) |
| 135 | { |
| 136 | bool bResult = true; |
| 137 | |
| 138 | if ((m_pSingleProgress != NULL) && (m_pGeneralProgress != NULL)) { |
| 139 | if (!m_pSingleProgress->init(totalMaxValue, 0)) return false; |
| 140 | if (!m_pGeneralProgress->init(maxValue, 0)) return false; |
| 141 | } else { |
| 142 | return false; |
| 143 | } |
| 144 | |
| 145 | setProgressText(); |
| 146 | return true; |
| 147 | } |
| 148 | |
| 149 | void |
| 150 | FTProgress::setProgressText() |
| 151 | { |
| 152 | char buf[16]; |
| 153 | |
| 154 | int percent = m_pSingleProgress->getCurrentPercent(); |
| 155 | sprintf(buf, "%d%%", percent); |
| 156 | SetWindowText(m_hwndSinglePercent, buf); |
| 157 | |
| 158 | percent = m_pGeneralProgress->getCurrentPercent(); |
| 159 | sprintf(buf, "%d%%", percent); |
| 160 | SetWindowText(m_hwndGeneralPercent, buf); |
Dennis Syrovatsky | 803e02c | 2005-11-06 05:35:27 +0000 | [diff] [blame] | 161 | } |