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