]>
Commit | Line | Data |
---|---|---|
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" | |
28 | ||
29 | bool | |
30 | 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::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 | ||
77 | void | |
78 | ThreeBarProgressPage::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); | |
82 | } | |
83 | ||
84 | void | |
85 | ThreeBarProgressPage::SetBar3 (long progress, long max) | |
86 | { | |
87 | int percent = (int) (100.0 * ((double) progress) / (double) max); | |
88 | SendMessage (ins_diskfull, PBM_SETPOS, (WPARAM) percent, 0); | |
89 | } | |
90 | ||
91 | void | |
92 | ThreeBarProgressPage::EnableSingleBar (bool enable) | |
93 | { | |
94 | // Switch to/from single bar mode | |
95 | ShowWindow (ins_bl_total, enable ? SW_HIDE : SW_SHOW); | |
96 | ShowWindow (ins_bl_disk, enable ? SW_HIDE : SW_SHOW); | |
97 | ShowWindow (ins_iprogress, enable ? SW_HIDE : SW_SHOW); | |
98 | ShowWindow (ins_diskfull, enable ? SW_HIDE : SW_SHOW); | |
99 | } | |
100 | ||
101 | void | |
102 | ThreeBarProgressPage::OnActivate () | |
103 | { | |
104 | // Disable back and next buttons | |
105 | GetOwner ()->SetButtons (0); | |
106 | ||
107 | // Set all bars to 0 | |
108 | SetBar1 (0); | |
109 | SetBar2 (0); | |
110 | SetBar3 (0); | |
111 | ||
112 | switch (task) | |
113 | { | |
114 | case WM_APP_START_SITE_INFO_DOWNLOAD: | |
115 | case WM_APP_START_SETUP_INI_DOWNLOAD: | |
116 | // For these tasks, show only a single progress bar. | |
117 | EnableSingleBar (); | |
118 | break; | |
119 | default: | |
120 | // Show the normal 3-bar view by default | |
121 | EnableSingleBar (false); | |
122 | break; | |
123 | } | |
124 | ||
125 | Window::PostMessage (task); | |
126 | } | |
127 | ||
128 | bool | |
129 | ThreeBarProgressPage::OnMessageApp (UINT uMsg, WPARAM wParam, LPARAM lParam) | |
130 | { | |
131 | switch (uMsg) | |
132 | { | |
133 | case WM_APP_START_DOWNLOAD: | |
134 | { | |
135 | // Start the package download thread. | |
136 | do_download (GetInstance (), GetHWND ()); | |
137 | break; | |
138 | } | |
139 | case WM_APP_DOWNLOAD_THREAD_COMPLETE: | |
140 | { | |
141 | if (lParam == IDD_S_INSTALL) | |
142 | { | |
143 | // Download is complete and we want to go on to the install. | |
144 | Window::PostMessage (WM_APP_START_INSTALL); | |
145 | } | |
146 | else if (lParam != 0) | |
147 | { | |
148 | // Download failed for some reason, go back to site selection page | |
149 | GetOwner ()->SetActivePageByID (lParam); | |
150 | } | |
151 | else | |
152 | { | |
153 | // Was a download-only, and is complete or failed. | |
154 | GetOwner ()->PressButton (PSBTN_CANCEL); | |
155 | } | |
156 | break; | |
157 | } | |
158 | case WM_APP_START_INSTALL: | |
159 | { | |
160 | // Start the install thread. | |
161 | do_install (GetInstance (), GetHWND ()); | |
162 | break; | |
163 | } | |
164 | case WM_APP_INSTALL_THREAD_COMPLETE: | |
165 | { | |
166 | // Re-enable and "Push" the Next button | |
167 | GetOwner ()->SetButtons (PSWIZB_NEXT); | |
168 | GetOwner ()->PressButton (PSBTN_NEXT); | |
169 | break; | |
170 | } | |
171 | case WM_APP_START_SITE_INFO_DOWNLOAD: | |
172 | { | |
173 | do_download_site_info (GetInstance (), GetHWND ()); | |
174 | break; | |
175 | } | |
176 | case WM_APP_SITE_INFO_DOWNLOAD_COMPLETE: | |
177 | { | |
178 | GetOwner ()->SetActivePageByID (lParam); | |
179 | break; | |
180 | } | |
181 | case WM_APP_START_SETUP_INI_DOWNLOAD: | |
182 | { | |
183 | do_ini (GetInstance (), GetHWND ()); | |
184 | break; | |
185 | } | |
186 | case WM_APP_SETUP_INI_DOWNLOAD_COMPLETE: | |
187 | { | |
188 | if (lParam == IDD_S_FROM_CWD) | |
189 | { | |
190 | // There isn't actually a dialog template named this | |
191 | do_fromcwd (GetInstance (), GetHWND ()); | |
192 | } | |
193 | else | |
194 | { | |
195 | GetOwner ()->SetActivePageByID (lParam); | |
196 | } | |
197 | break; | |
198 | } | |
199 | default: | |
200 | { | |
201 | // Not handled | |
202 | return false; | |
203 | } | |
204 | } | |
205 | ||
206 | return true; | |
207 | } |