xref: /netbsd-src/sys/arch/hpc/stand/hpcboot/menu/rootwindow.cpp (revision 3cec974c61d7fac0a37c0377723a33214a458c8b)
1 /* -*-C++-*-	$NetBSD: rootwindow.cpp,v 1.2 2001/03/02 18:26:38 uch Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by UCHIYAMA Yasushi.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include <hpcmenu.h>
40 #include <menu/window.h>
41 #include <menu/tabwindow.h>
42 #include <menu/rootwindow.h>
43 #include <res/resource.h>
44 
45 //
46 // root window
47 //
48 RootWindow::RootWindow(HpcBootApp &app)
49 	: Window(app)
50 {
51 	_boot_button	= 0;
52 	_base		= 0;
53 	_main		= 0;
54 	_option	= 0;
55 	_console	= 0;
56 }
57 
58 RootWindow::~RootWindow()
59 {
60 	if (_boot_button)
61 		delete _boot_button;
62 	if (_cancel_button)
63 		delete _cancel_button;
64 	if (_progress_bar)
65 		delete _progress_bar;
66 	if (_main)
67 		delete _main;
68 	if (_option)
69 		delete _option;
70 	if (_console)
71 		delete _console;
72 	if (_base)
73 		delete _base;
74 }
75 
76 BOOL
77 RootWindow::create(LPCREATESTRUCT aux)
78 {
79 	// Root window's create don't called by Window Procedure.
80 	// so aux is NULL
81 	HINSTANCE inst = _app._instance;
82 	TCHAR *wc_name = reinterpret_cast <TCHAR *>
83 		(LoadString(inst, IDS_HPCMENU, 0, 0));
84 
85 	_window = CreateWindow(wc_name, wc_name, WS_VISIBLE,
86 			       CW_USEDEFAULT, CW_USEDEFAULT,
87 			       CW_USEDEFAULT, CW_USEDEFAULT,
88 			       0, 0, inst, this);
89 	if (!_window)
90 		return FALSE;
91 
92 	HpcMenuInterface &menu = HpcMenuInterface::Instance();
93 	if (menu._pref.auto_boot > 0)
94 		SetTimer(_window, IDD_TIMER, menu._pref.auto_boot * 1000, 0);
95 
96 	ShowWindow(_window, SW_SHOW);
97 	UpdateWindow(_window);
98 
99 	return TRUE;
100 }
101 
102 BOOL
103 RootWindow::proc(HWND w, UINT msg, WPARAM wparam, LPARAM lparam)
104 {
105 	LPCREATESTRUCT aux = reinterpret_cast <LPCREATESTRUCT>(lparam);
106 	HpcMenuInterface &menu = HpcMenuInterface::Instance();
107 
108 	switch(msg) {
109 	default: // message can't handle.
110 		return FALSE;
111 	case WM_CREATE:
112 		WMCreate(w, aux);
113 		break;
114 	case WM_PAINT:
115 		WMPaint(w, aux);
116 		break;
117 	case WM_NOTIFY:
118 	{
119 		NMHDR *notify = reinterpret_cast <NMHDR *>(lparam);
120 		// get current selected tab id
121 		int tab_id = TabCtrl_GetCurSel(_base->_window);
122 		// get context
123 		TC_ITEM tc_item;
124 		tc_item.mask = TCIF_PARAM;
125 		TabCtrl_GetItem(_base->_window, tab_id, &tc_item);
126 		TabWindow *tab = reinterpret_cast <TabWindow *>
127 			(tc_item.lParam);
128 		switch(notify->code) {
129 		case TCN_SELCHANGING:
130 			tab->hide();
131 			break;
132 		case TCN_SELCHANGE:
133 			tab->show();
134 			break;
135 		}
136 	}
137 	break;
138 	case WM_TIMER:
139 		disableTimer();
140 		goto boot;
141 	case WM_COMMAND:
142 		switch(wparam)
143 		{
144 		case IDC_BOOTBUTTON:
145 			// inquire current options.
146 			menu.get_options();
147 			if (menu._pref.safety_message) {
148 				if (MessageBox
149 				    (_window,
150 				     TEXT("Data in memory will be lost.\n Are you sure?"),
151 				     TEXT("WARNING"), MB_YESNO) != IDYES)
152 					break;
153 			}
154 		boot:
155 			SendMessage(_progress_bar->_window, PBM_SETPOS, 0, 0);
156 			menu.print(TEXT("BOOT START\n"));
157 			// inquire current options.
158 			menu.get_options();
159 			// save options to `hpcboot.cnf'
160 			menu.save();
161 			// atart boot sequence.
162 			menu.boot();
163 			// NOTREACHED
164 			break;
165 		case IDC_PROGRESSBAR:
166 			break;
167 		case IDC_CANCELBUTTON:
168 			PostQuitMessage(0);
169 			break;
170 		}
171 		break;
172 	case WM_DESTROY:
173 		PostQuitMessage(0);
174 		break;
175 	}
176 	return TRUE;
177 }
178 
179 void
180 RootWindow::WMPaint(HWND w, LPCREATESTRUCT aux)
181 {
182 	PAINTSTRUCT ps;
183 	BeginPaint(w, &ps);
184 	EndPaint(w, &ps);
185 }
186 
187 void
188 RootWindow::WMCreate(HWND w, LPCREATESTRUCT aux)
189 {
190 	int cmdbar_height;
191 
192 	_window = w;
193 	// Command bar.
194 	_app._cmdbar = CommandBar_Create(aux->hInstance, w, IDC_CMDBAR);
195 	CommandBar_AddAdornments(_app._cmdbar, 0, 0);
196 	cmdbar_height = CommandBar_Height(_app._cmdbar);
197 	_button_height = cmdbar_height;
198 
199 	RECT rect;
200 	GetClientRect(w, &rect);
201 	rect.top += cmdbar_height;
202 
203 	// BOOT button.
204 	_boot_button = new BootButton(_app, *this, rect);
205 	_boot_button->create(aux);
206 	// CANCEL button.
207 	_cancel_button = new CancelButton(_app, *this, rect);
208 	_cancel_button->create(aux);
209 	// Progress bar
210 	_progress_bar = new ProgressBar(_app, *this, rect);
211 	_progress_bar->create(aux);
212 	SendMessage(_progress_bar->_window, PBM_SETSTEP, 1, 0);
213 	SendMessage(_progress_bar->_window, PBM_SETPOS, 0, 0);
214 
215  	// regsiter myself to menu
216 	HpcMenuInterface::Instance()._root = this;
217 
218 	rect.top += cmdbar_height;
219 	// Tab control.
220 	_base =  new TabWindowBase(_app, w, rect, IDC_BASE);
221 	_base->create(aux);
222 	// main/option/console dialog.(register to Menu)
223 	_main = _base->boot(IDC_BASE_MAIN);
224 	_option = _base->boot(IDC_BASE_OPTION);
225 	_console = _base->boot(IDC_BASE_CONSOLE);
226 
227 	_main->show();
228 
229 	return;
230 }
231 
232 void
233 RootWindow::disableTimer()
234 {
235 	KillTimer(_window, IDD_TIMER);
236 }
237 
238 BOOL
239 RootWindow::isDialogMessage(MSG &msg)
240 {
241 	if (_main && IsWindowVisible(_main->_window))
242 		return IsDialogMessage(_main->_window, &msg);
243 	if (_option && IsWindowVisible(_option->_window))
244 		return IsDialogMessage(_option->_window, &msg);
245 	if (_console && IsWindowVisible(_console->_window))
246 		return IsDialogMessage(_console->_window, &msg);
247 	return FALSE;
248 }
249 
250 //
251 // BOOT button
252 //
253 BOOL
254 BootButton::create(LPCREATESTRUCT aux)
255 {
256 	int cx = BOOT_BUTTON_WIDTH;
257 	int cy = _root._button_height;
258 
259 	_window = CreateWindow(TEXT("BUTTON"), TEXT("BOOT"),
260 			       BS_PUSHBUTTON | BS_NOTIFY |
261 			       WS_VISIBLE | WS_CHILD | WS_TABSTOP,
262 			       _rect.left, _rect.top, cx, cy, _parent_window,
263 			       reinterpret_cast <HMENU>(IDC_BOOTBUTTON),
264 			       aux->hInstance,
265 			       NULL);
266 
267 	return IsWindow(_window) ? TRUE : FALSE;
268 }
269 
270 //
271 // CANCEL button
272 //
273 BOOL
274 CancelButton::create(LPCREATESTRUCT aux)
275 {
276 	int cx = BOOT_BUTTON_WIDTH;
277 	int cy = _root._button_height;
278 	int x = _rect.right - BOOT_BUTTON_WIDTH;
279 
280 	_window = CreateWindow(TEXT("BUTTON"), TEXT("CANCEL"),
281 			       BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP |
282 			       WS_VISIBLE | WS_CHILD,
283 			       x, _rect.top, cx, cy, _parent_window,
284 			       reinterpret_cast <HMENU>(IDC_CANCELBUTTON),
285 			       aux->hInstance,
286 			       NULL);
287 	return IsWindow(_window) ? TRUE : FALSE;
288 }
289 
290 //
291 // PROGRESS BAR
292 //
293 BOOL
294 ProgressBar::create(LPCREATESTRUCT aux)
295 {
296 	int cx = _rect.right - _rect.left
297 		- TABCTRL_TAB_WIDTH - BOOT_BUTTON_WIDTH * 2;
298 	int cy = _root._button_height;
299 	int x = _rect.left + BOOT_BUTTON_WIDTH;
300 	_window = CreateWindow(PROGRESS_CLASS, TEXT(""),
301 			       WS_VISIBLE | WS_CHILD,
302 			       x, _rect.top, cx, cy, _parent_window,
303 			       reinterpret_cast <HMENU>(IDC_PROGRESSBAR),
304 			       aux->hInstance, NULL);
305 	SendMessage(_window, PBM_SETRANGE, 0, MAKELPARAM(0, 12));
306 
307 	return IsWindow(_window) ? TRUE : FALSE;
308 }
309