]> cygwin.com Git - cygwin-apps/setup.git/blob - threebar.cc
2003-06-23 Max Bowsher <maxb@ukf.net>
[cygwin-apps/setup.git] / threebar.cc
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"
28 #include "cistring.h"
29
30 bool ThreeBarProgressPage::Create ()
31 {
32 return PropertyPage::Create (IDD_INSTATUS);
33 }
34
35 void
36 ThreeBarProgressPage::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
52 void
53 ThreeBarProgressPage::SetText1 (const TCHAR * t)
54 {
55 ::SetWindowText (ins_action, t);
56 }
57
58 void
59 ThreeBarProgressPage::SetText2 (const TCHAR * t)
60 {
61 ::SetWindowText (ins_pkgname, t);
62 }
63
64 void
65 ThreeBarProgressPage::SetText3 (const TCHAR * t)
66 {
67 ::SetWindowText (ins_filename, t);
68 }
69
70 void
71 ThreeBarProgressPage::SetText4 (const TCHAR * t)
72 {
73 ::SetWindowText (ins_bl_package, t);
74 }
75
76 void
77 ThreeBarProgressPage::SetBar1 (long progress, long max)
78 {
79 int percent = (int) (100.0 * ((double) progress) / (double) max);
80 SendMessage (ins_pprogress, PBM_SETPOS, (WPARAM) percent, 0);
81 }
82
83 void
84 ThreeBarProgressPage::SetBar2 (long progress, long max)
85 {
86 int percent = (int) (100.0 * ((double) progress) / (double) max);
87 SendMessage (ins_iprogress, PBM_SETPOS, (WPARAM) percent, 0);
88 cistring s;
89 s.Format (IDS_CYGWIN_SETUP_WITH_PROGRESS, percent);
90 GetOwner ()->SetWindowText (s.c_str ());
91 }
92
93 void
94 ThreeBarProgressPage::SetBar3 (long progress, long max)
95 {
96 int percent = (int) (100.0 * ((double) progress) / (double) max);
97 SendMessage (ins_diskfull, PBM_SETPOS, (WPARAM) percent, 0);
98 }
99
100 void
101 ThreeBarProgressPage::EnableSingleBar (bool enable)
102 {
103 // Switch to/from single bar mode
104 ShowWindow (ins_bl_total, enable ? SW_HIDE : SW_SHOW);
105 ShowWindow (ins_bl_disk, enable ? SW_HIDE : SW_SHOW);
106 ShowWindow (ins_iprogress, enable ? SW_HIDE : SW_SHOW);
107 ShowWindow (ins_diskfull, enable ? SW_HIDE : SW_SHOW);
108 }
109
110 void
111 ThreeBarProgressPage::OnActivate ()
112 {
113 // Disable back and next buttons
114 GetOwner ()->SetButtons (0);
115
116 // Set all bars to 0
117 SetBar1 (0);
118 SetBar2 (0);
119 SetBar3 (0);
120
121 switch (task)
122 {
123 case WM_APP_START_SITE_INFO_DOWNLOAD:
124 case WM_APP_START_SETUP_INI_DOWNLOAD:
125 // For these tasks, show only a single progress bar.
126 EnableSingleBar ();
127 break;
128 default:
129 // Show the normal 3-bar view by default
130 EnableSingleBar (false);
131 break;
132 }
133
134 Window::PostMessage (task);
135 }
136
137 bool
138 ThreeBarProgressPage::OnMessageApp (UINT uMsg, WPARAM wParam, LPARAM lParam)
139 {
140 switch (uMsg)
141 {
142 case WM_APP_START_DOWNLOAD:
143 {
144 // Start the package download thread.
145 do_download (GetInstance (), GetHWND ());
146 break;
147 }
148 case WM_APP_DOWNLOAD_THREAD_COMPLETE:
149 {
150 if (lParam == IDD_S_INSTALL)
151 {
152 // Download is complete and we want to go on to the install.
153 Window::PostMessage (WM_APP_START_INSTALL);
154 }
155 else if (lParam != 0)
156 {
157 // Download failed for some reason, go back to site selection page
158 GetOwner ()->SetActivePageByID (lParam);
159 }
160 else
161 {
162 // Was a download-only, and is complete or failed.
163 GetOwner ()->PressButton (PSBTN_CANCEL);
164 }
165 break;
166 }
167 case WM_APP_START_INSTALL:
168 {
169 // Start the install thread.
170 do_install (GetInstance (), GetHWND ());
171 break;
172 }
173 case WM_APP_INSTALL_THREAD_COMPLETE:
174 {
175 // Install is complete and we want to go on to the postinstall.
176 Window::PostMessage (WM_APP_START_POSTINSTALL);
177 break;
178 }
179 case WM_APP_START_POSTINSTALL:
180 {
181 // Start the postinstall script thread.
182 do_postinstall (GetInstance (), GetHWND ());
183 break;
184 }
185 case WM_APP_POSTINSTALL_THREAD_COMPLETE:
186 {
187 // Re-enable and "Push" the Next button
188 GetOwner ()->SetButtons (PSWIZB_NEXT);
189 GetOwner ()->PressButton (PSBTN_NEXT);
190 break;
191 }
192 case WM_APP_START_SITE_INFO_DOWNLOAD:
193 {
194 do_download_site_info (GetInstance (), GetHWND ());
195 break;
196 }
197 case WM_APP_SITE_INFO_DOWNLOAD_COMPLETE:
198 {
199 GetOwner ()->SetActivePageByID (lParam);
200 break;
201 }
202 case WM_APP_START_SETUP_INI_DOWNLOAD:
203 {
204 do_ini (GetInstance (), GetHWND ());
205 break;
206 }
207 case WM_APP_SETUP_INI_DOWNLOAD_COMPLETE:
208 {
209 if (lParam == IDD_S_FROM_CWD)
210 {
211 // There isn't actually a dialog template named this
212 do_fromcwd (GetInstance (), GetHWND ());
213 }
214 else
215 {
216 GetOwner ()->SetActivePageByID (lParam);
217 }
218 break;
219 }
220 default:
221 {
222 // Not handled
223 return false;
224 }
225 }
226
227 return true;
228 }
This page took 0.043102 seconds and 5 git commands to generate.