xref: /netbsd-src/sys/arch/hpc/stand/hpcboot/menu/rootwindow.cpp (revision b19e9f6776dfba359eaedbfd67d0367bca2f732e)
1 /* -*-C++-*-	$NetBSD: rootwindow.cpp,v 1.3 2001/05/08 18:51:24 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, CW_USEDEFAULT, CW_USEDEFAULT,
87 	    0, 0, inst, this);
88 	if (!_window)
89 		return FALSE;
90 
91 	HpcMenuInterface &menu = HpcMenuInterface::Instance();
92 	if (menu._pref.auto_boot > 0)
93 		SetTimer(_window, IDD_TIMER, menu._pref.auto_boot * 1000, 0);
94 
95 	ShowWindow(_window, SW_SHOW);
96 	UpdateWindow(_window);
97 
98 	return TRUE;
99 }
100 
101 BOOL
102 RootWindow::proc(HWND w, UINT msg, WPARAM wparam, LPARAM lparam)
103 {
104 	LPCREATESTRUCT aux = reinterpret_cast <LPCREATESTRUCT>(lparam);
105 	HpcMenuInterface &menu = HpcMenuInterface::Instance();
106 
107 	switch(msg) {
108 	default: // message can't handle.
109 		return FALSE;
110 	case WM_CREATE:
111 		WMCreate(w, aux);
112 		break;
113 	case WM_PAINT:
114 		WMPaint(w, aux);
115 		break;
116 	case WM_NOTIFY:
117 	{
118 		NMHDR *notify = reinterpret_cast <NMHDR *>(lparam);
119 		// get current selected tab id
120 		int tab_id = TabCtrl_GetCurSel(_base->_window);
121 		// get context
122 		TC_ITEM tc_item;
123 		tc_item.mask = TCIF_PARAM;
124 		TabCtrl_GetItem(_base->_window, tab_id, &tc_item);
125 		TabWindow *tab = reinterpret_cast <TabWindow *>
126 		    (tc_item.lParam);
127 		switch(notify->code) {
128 		case TCN_SELCHANGING:
129 			tab->hide();
130 			break;
131 		case TCN_SELCHANGE:
132 			tab->show();
133 			break;
134 		}
135 	}
136 	break;
137 	case WM_TIMER:
138 		disableTimer();
139 		goto boot;
140 	case WM_COMMAND:
141 		switch(wparam)
142 		{
143 		case IDC_BOOTBUTTON:
144 			// inquire current options.
145 			menu.get_options();
146 			if (menu._pref.safety_message) {
147 				if (MessageBox(_window,
148 				    TEXT("Data in memory will be lost.\n Are you sure?"),
149 				    TEXT("WARNING"), MB_YESNO) != IDYES)
150 					break;
151 			}
152 		boot:
153 			SendMessage(_progress_bar->_window, PBM_SETPOS, 0, 0);
154 			menu.print(TEXT("BOOT START\n"));
155 			// inquire current options.
156 			menu.get_options();
157 			// save options to `hpcboot.cnf'
158 			menu.save();
159 			// atart boot sequence.
160 			menu.boot();
161 			// NOTREACHED
162 			break;
163 		case IDC_PROGRESSBAR:
164 			break;
165 		case IDC_CANCELBUTTON:
166 			PostQuitMessage(0);
167 			break;
168 		}
169 		break;
170 	case WM_DESTROY:
171 		PostQuitMessage(0);
172 		break;
173 	}
174 	return TRUE;
175 }
176 
177 void
178 RootWindow::WMPaint(HWND w, LPCREATESTRUCT aux)
179 {
180 	PAINTSTRUCT ps;
181 	BeginPaint(w, &ps);
182 	EndPaint(w, &ps);
183 }
184 
185 void
186 RootWindow::WMCreate(HWND w, LPCREATESTRUCT aux)
187 {
188 	int cmdbar_height;
189 
190 	_window = w;
191 	// Command bar.
192 	_app._cmdbar = CommandBar_Create(aux->hInstance, w, IDC_CMDBAR);
193 	CommandBar_AddAdornments(_app._cmdbar, 0, 0);
194 	cmdbar_height = CommandBar_Height(_app._cmdbar);
195 	_button_height = cmdbar_height;
196 
197 	RECT rect;
198 	GetClientRect(w, &rect);
199 	rect.top += cmdbar_height;
200 
201 	// BOOT button.
202 	_boot_button = new BootButton(_app, *this, rect);
203 	_boot_button->create(aux);
204 	// CANCEL button.
205 	_cancel_button = new CancelButton(_app, *this, rect);
206 	_cancel_button->create(aux);
207 	// Progress bar
208 	_progress_bar = new ProgressBar(_app, *this, rect);
209 	_progress_bar->create(aux);
210 	SendMessage(_progress_bar->_window, PBM_SETSTEP, 1, 0);
211 	SendMessage(_progress_bar->_window, PBM_SETPOS, 0, 0);
212 
213  	// regsiter myself to menu
214 	HpcMenuInterface::Instance()._root = this;
215 
216 	rect.top += cmdbar_height;
217 	// Tab control.
218 	_base =  new TabWindowBase(_app, w, rect, IDC_BASE);
219 	_base->create(aux);
220 	// main/option/console dialog.(register to Menu)
221 	_main = _base->boot(IDC_BASE_MAIN);
222 	_option = _base->boot(IDC_BASE_OPTION);
223 	_console = _base->boot(IDC_BASE_CONSOLE);
224 
225 	_main->show();
226 
227 	return;
228 }
229 
230 void
231 RootWindow::disableTimer()
232 {
233 	KillTimer(_window, IDD_TIMER);
234 }
235 
236 BOOL
237 RootWindow::isDialogMessage(MSG &msg)
238 {
239 	if (_main && IsWindowVisible(_main->_window))
240 		return IsDialogMessage(_main->_window, &msg);
241 	if (_option && IsWindowVisible(_option->_window))
242 		return IsDialogMessage(_option->_window, &msg);
243 	if (_console && IsWindowVisible(_console->_window))
244 		return IsDialogMessage(_console->_window, &msg);
245 	return FALSE;
246 }
247 
248 //
249 // BOOT button
250 //
251 BOOL
252 BootButton::create(LPCREATESTRUCT aux)
253 {
254 	int cx = BOOT_BUTTON_WIDTH;
255 	int cy = _root._button_height;
256 
257 	_window = CreateWindow(TEXT("BUTTON"), TEXT("BOOT"),
258 	    BS_PUSHBUTTON | BS_NOTIFY |
259 	    WS_VISIBLE | WS_CHILD | WS_TABSTOP,
260 	    _rect.left, _rect.top, cx, cy, _parent_window,
261 	    reinterpret_cast <HMENU>(IDC_BOOTBUTTON),
262 	    aux->hInstance,
263 	    NULL);
264 
265 	return IsWindow(_window) ? TRUE : FALSE;
266 }
267 
268 //
269 // CANCEL button
270 //
271 BOOL
272 CancelButton::create(LPCREATESTRUCT aux)
273 {
274 	int cx = BOOT_BUTTON_WIDTH;
275 	int cy = _root._button_height;
276 	int x = _rect.right - BOOT_BUTTON_WIDTH;
277 
278 	_window = CreateWindow(TEXT("BUTTON"), TEXT("CANCEL"),
279 	    BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP |
280 	    WS_VISIBLE | WS_CHILD,
281 	    x, _rect.top, cx, cy, _parent_window,
282 	    reinterpret_cast <HMENU>(IDC_CANCELBUTTON),
283 	    aux->hInstance,
284 	    NULL);
285 	return IsWindow(_window) ? TRUE : FALSE;
286 }
287 
288 //
289 // PROGRESS BAR
290 //
291 BOOL
292 ProgressBar::create(LPCREATESTRUCT aux)
293 {
294 	int cx = _rect.right - _rect.left
295 	    - TABCTRL_TAB_WIDTH - BOOT_BUTTON_WIDTH * 2;
296 	int cy = _root._button_height;
297 	int x = _rect.left + BOOT_BUTTON_WIDTH;
298 	_window = CreateWindow(PROGRESS_CLASS, TEXT(""),
299 	    WS_VISIBLE | WS_CHILD,
300 	    x, _rect.top, cx, cy, _parent_window,
301 	    reinterpret_cast <HMENU>(IDC_PROGRESSBAR),
302 	    aux->hInstance, NULL);
303 	SendMessage(_window, PBM_SETRANGE, 0, MAKELPARAM(0, 12));
304 
305 	return IsWindow(_window) ? TRUE : FALSE;
306 }
307