]> cygwin.com Git - cygwin-apps/setup.git/blame - threebar.cc
2002-04-27 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / threebar.cc
CommitLineData
b7301c43
RC
1/*
2 * Copyright (c) 2001, Gary R. Van Sickle.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by Gary R. Van Sickle <g.r.vansickle@worldnet.att.net>
13 *
14 */
15
16// This is the implementation of the ThreeBarProgressPage class. It is a fairly generic
17// progress indicator property page with three progress bars.
18
19#include "win32.h"
20#include "commctrl.h"
21#include "resource.h"
22
23#include "dialog.h"
24#include "site.h"
25
26#include "propsheet.h"
27#include "threebar.h"
58db1046 28#include "cistring.h"
b7301c43 29
58db1046 30bool ThreeBarProgressPage::Create ()
b7301c43
RC
31{
32 return PropertyPage::Create (IDD_INSTATUS);
33}
34
35void
36ThreeBarProgressPage::OnInit ()
37{
38 // Get HWNDs to the dialog controls
39 ins_action = GetDlgItem (IDC_INS_ACTION);
40 ins_pkgname = GetDlgItem (IDC_INS_PKG);
41 ins_filename = GetDlgItem (IDC_INS_FILE);
42 // Bars
43 ins_pprogress = GetDlgItem (IDC_INS_PPROGRESS);
44 ins_iprogress = GetDlgItem (IDC_INS_IPROGRESS);
45 ins_diskfull = GetDlgItem (IDC_INS_DISKFULL);
46 // Bar labels
47 ins_bl_package = GetDlgItem (IDC_INS_BL_PACKAGE);
48 ins_bl_total = GetDlgItem (IDC_INS_BL_TOTAL);
49 ins_bl_disk = GetDlgItem (IDC_INS_BL_DISK);
50}
51
52void
53ThreeBarProgressPage::SetText1 (const TCHAR * t)
54{
58db1046 55 ::SetWindowText (ins_action, t);
b7301c43
RC
56}
57
58void
59ThreeBarProgressPage::SetText2 (const TCHAR * t)
60{
58db1046 61 ::SetWindowText (ins_pkgname, t);
b7301c43
RC
62}
63
64void
65ThreeBarProgressPage::SetText3 (const TCHAR * t)
66{
58db1046 67 ::SetWindowText (ins_filename, t);
b7301c43
RC
68}
69
70void
71ThreeBarProgressPage::SetBar1 (long progress, long max)
72{
73 int percent = (int) (100.0 * ((double) progress) / (double) max);
74 SendMessage (ins_pprogress, PBM_SETPOS, (WPARAM) percent, 0);
75}
76
77void
78ThreeBarProgressPage::SetBar2 (long progress, long max)
79{
80 int percent = (int) (100.0 * ((double) progress) / (double) max);
81 SendMessage (ins_iprogress, PBM_SETPOS, (WPARAM) percent, 0);
58db1046
RC
82 cistring s;
83 s.Format (IDS_CYGWIN_SETUP_WITH_PROGRESS, percent);
84 GetOwner ()->SetWindowText (s.c_str ());
b7301c43
RC
85}
86
87void
88ThreeBarProgressPage::SetBar3 (long progress, long max)
89{
90 int percent = (int) (100.0 * ((double) progress) / (double) max);
91 SendMessage (ins_diskfull, PBM_SETPOS, (WPARAM) percent, 0);
92}
93
94void
95ThreeBarProgressPage::EnableSingleBar (bool enable)
96{
97 // Switch to/from single bar mode
98 ShowWindow (ins_bl_total, enable ? SW_HIDE : SW_SHOW);
99 ShowWindow (ins_bl_disk, enable ? SW_HIDE : SW_SHOW);
100 ShowWindow (ins_iprogress, enable ? SW_HIDE : SW_SHOW);
101 ShowWindow (ins_diskfull, enable ? SW_HIDE : SW_SHOW);
102}
103
104void
105ThreeBarProgressPage::OnActivate ()
106{
107 // Disable back and next buttons
108 GetOwner ()->SetButtons (0);
109
110 // Set all bars to 0
111 SetBar1 (0);
112 SetBar2 (0);
113 SetBar3 (0);
114
115 switch (task)
116 {
117 case WM_APP_START_SITE_INFO_DOWNLOAD:
118 case WM_APP_START_SETUP_INI_DOWNLOAD:
119 // For these tasks, show only a single progress bar.
120 EnableSingleBar ();
121 break;
122 default:
123 // Show the normal 3-bar view by default
124 EnableSingleBar (false);
125 break;
126 }
127
128 Window::PostMessage (task);
129}
130
131bool
58db1046 132 ThreeBarProgressPage::OnMessageApp (UINT uMsg, WPARAM wParam, LPARAM lParam)
b7301c43
RC
133{
134 switch (uMsg)
135 {
136 case WM_APP_START_DOWNLOAD:
137 {
138 // Start the package download thread.
139 do_download (GetInstance (), GetHWND ());
140 break;
141 }
142 case WM_APP_DOWNLOAD_THREAD_COMPLETE:
143 {
144 if (lParam == IDD_S_INSTALL)
145 {
146 // Download is complete and we want to go on to the install.
147 Window::PostMessage (WM_APP_START_INSTALL);
148 }
149 else if (lParam != 0)
150 {
151 // Download failed for some reason, go back to site selection page
152 GetOwner ()->SetActivePageByID (lParam);
153 }
154 else
155 {
156 // Was a download-only, and is complete or failed.
157 GetOwner ()->PressButton (PSBTN_CANCEL);
158 }
159 break;
160 }
161 case WM_APP_START_INSTALL:
162 {
163 // Start the install thread.
164 do_install (GetInstance (), GetHWND ());
165 break;
166 }
167 case WM_APP_INSTALL_THREAD_COMPLETE:
168 {
169 // Re-enable and "Push" the Next button
170 GetOwner ()->SetButtons (PSWIZB_NEXT);
171 GetOwner ()->PressButton (PSBTN_NEXT);
172 break;
173 }
174 case WM_APP_START_SITE_INFO_DOWNLOAD:
175 {
176 do_download_site_info (GetInstance (), GetHWND ());
177 break;
178 }
179 case WM_APP_SITE_INFO_DOWNLOAD_COMPLETE:
180 {
181 GetOwner ()->SetActivePageByID (lParam);
182 break;
183 }
184 case WM_APP_START_SETUP_INI_DOWNLOAD:
185 {
186 do_ini (GetInstance (), GetHWND ());
187 break;
188 }
189 case WM_APP_SETUP_INI_DOWNLOAD_COMPLETE:
190 {
191 if (lParam == IDD_S_FROM_CWD)
192 {
193 // There isn't actually a dialog template named this
194 do_fromcwd (GetInstance (), GetHWND ());
195 }
196 else
197 {
198 GetOwner ()->SetActivePageByID (lParam);
199 }
200 break;
201 }
202 default:
203 {
204 // Not handled
205 return false;
206 }
207 }
208
209 return true;
210}
This page took 0.043439 seconds and 5 git commands to generate.