Home | History | Annotate | Line # | Download | only in menu
rootwindow.cpp revision 1.1.2.2
      1 /* -*-C++-*-	$NetBSD: rootwindow.cpp,v 1.1.2.2 2001/02/11 19:10:03 bouyer 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 			menu.print(TEXT("BOOT START\n"));
    156 			// inquire current options.
    157 			menu.get_options();
    158 			// save options to `hpcboot.cnf'
    159 			menu.save();
    160 			// atart boot sequence.
    161 			menu.boot();
    162 			// NOTREACHED
    163 			break;
    164 		case IDC_PROGRESSBAR:
    165 			break;
    166 		case IDC_CANCELBUTTON:
    167 			PostQuitMessage(0);
    168 			break;
    169 		}
    170 		break;
    171 	case WM_DESTROY:
    172 		PostQuitMessage(0);
    173 		break;
    174 	}
    175 	return TRUE;
    176 }
    177 
    178 void
    179 RootWindow::WMPaint(HWND w, LPCREATESTRUCT aux)
    180 {
    181 	PAINTSTRUCT ps;
    182 	BeginPaint(w, &ps);
    183 	EndPaint(w, &ps);
    184 }
    185 
    186 void
    187 RootWindow::WMCreate(HWND w, LPCREATESTRUCT aux)
    188 {
    189 	int cmdbar_height;
    190 
    191 	_window = w;
    192 	// Command bar.
    193 	_app._cmdbar = CommandBar_Create(aux->hInstance, w, IDC_CMDBAR);
    194 	CommandBar_AddAdornments(_app._cmdbar, 0, 0);
    195 	cmdbar_height = CommandBar_Height(_app._cmdbar);
    196 	_button_height = cmdbar_height;
    197 
    198 	RECT rect;
    199 	GetClientRect(w, &rect);
    200 	rect.top += cmdbar_height;
    201 
    202 	// BOOT button.
    203 	_boot_button = new BootButton(_app, *this, rect);
    204 	_boot_button->create(aux);
    205 	// CANCEL button.
    206 	_cancel_button = new CancelButton(_app, *this, rect);
    207 	_cancel_button->create(aux);
    208 	// Progress bar
    209 	_progress_bar = new ProgressBar(_app, *this, rect);
    210 	_progress_bar->create(aux);
    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 	SendMessage(_window, PBM_SETSTEP, 1, 0);
    305 
    306 	return IsWindow(_window) ? TRUE : FALSE;
    307 }
    308