Home | History | Annotate | Line # | Download | only in menu
rootwindow.cpp revision 1.11
      1 /* -*-C++-*-	$NetBSD: rootwindow.cpp,v 1.11 2003/12/25 03:19:53 uwe 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 #include "../binary/build_number.h"
     45 
     46 //
     47 // root window
     48 //
     49 RootWindow::RootWindow(HpcBootApp &app)
     50 	: Window(app)
     51 {
     52 	_boot_button	= 0;
     53 	_base		= 0;
     54 	_main		= 0;
     55 	_option	= 0;
     56 	_console	= 0;
     57 }
     58 
     59 RootWindow::~RootWindow()
     60 {
     61 	if (_boot_button)
     62 		delete _boot_button;
     63 	if (_cancel_button)
     64 		delete _cancel_button;
     65 	if (_progress_bar)
     66 		delete _progress_bar;
     67 	if (_main)
     68 		delete _main;
     69 	if (_option)
     70 		delete _option;
     71 	if (_console)
     72 		delete _console;
     73 	if (_base)
     74 		delete _base;
     75 }
     76 
     77 BOOL
     78 RootWindow::create(LPCREATESTRUCT aux)
     79 {
     80 	TCHAR app_name[32];
     81 	// Root window's create don't called by Window Procedure.
     82 	// so aux is NULL
     83 	HINSTANCE inst = _app._instance;
     84 	TCHAR *wc_name = reinterpret_cast <TCHAR *>
     85 	    (LoadString(inst, IDS_HPCMENU, 0, 0));
     86 	wsprintf(app_name, TEXT("%s Build %d"), wc_name, HPCBOOT_BUILD_NUMBER);
     87 
     88 	_window = CreateWindow(wc_name, app_name, WS_VISIBLE,
     89 	    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
     90 	    0, 0, inst, this);
     91 	if (!_window)
     92 		return FALSE;
     93 
     94 	HpcMenuInterface &menu = HpcMenuInterface::Instance();
     95 	if (menu._pref.auto_boot > 0)
     96 		SetTimer(_window, IDD_TIMER, menu._pref.auto_boot * 1000, 0);
     97 
     98 	ShowWindow(_window, SW_SHOW);
     99 	UpdateWindow(_window);
    100 
    101 	return TRUE;
    102 }
    103 
    104 BOOL
    105 RootWindow::proc(HWND w, UINT msg, WPARAM wparam, LPARAM lparam)
    106 {
    107 	LPCREATESTRUCT aux = reinterpret_cast <LPCREATESTRUCT>(lparam);
    108 	HpcMenuInterface &menu = HpcMenuInterface::Instance();
    109 
    110 	switch(msg) {
    111 	default: // message can't handle.
    112 		return FALSE;
    113 	case WM_CREATE:
    114 		WMCreate(w, aux);
    115 		break;
    116 	case WM_PAINT:
    117 		WMPaint(w, aux);
    118 		break;
    119 	case WM_NOTIFY:
    120 	{
    121 		NMHDR *notify = reinterpret_cast <NMHDR *>(lparam);
    122 		// get current selected tab id
    123 		int tab_id = TabCtrl_GetCurSel(_base->_window);
    124 		// get context
    125 		TC_ITEM tc_item;
    126 		tc_item.mask = TCIF_PARAM;
    127 		TabCtrl_GetItem(_base->_window, tab_id, &tc_item);
    128 		TabWindow *tab = reinterpret_cast <TabWindow *>
    129 		    (tc_item.lParam);
    130 		switch(notify->code) {
    131 		case TCN_SELCHANGING:
    132 			tab->hide();
    133 			break;
    134 		case TCN_SELCHANGE:
    135 			tab->show();
    136 			break;
    137 		}
    138 	}
    139 	break;
    140 	case WM_TIMER:
    141 		disableTimer();
    142 		goto boot;
    143 	case WM_COMMAND:
    144 		switch(wparam)
    145 		{
    146 		case IDC_BOOTBUTTON:
    147 			// inquire current options.
    148 			menu.get_options();
    149 			if (menu._pref.safety_message) {
    150 				if (MessageBox(_window,
    151 				    TEXT("Data in memory will be lost.\nAre you sure?"),
    152 				    TEXT("WARNING"),
    153 				    MB_ICONQUESTION | MB_YESNO) != IDYES)
    154 					break;
    155 				UpdateWindow(w);
    156 			}
    157 		boot:
    158 			SendMessage(_progress_bar->_window, PBM_SETPOS, 0, 0);
    159 			menu.print(TEXT("BOOT START\n"));
    160 			// inquire current options.
    161 			menu.get_options();
    162 			// save options to `hpcboot.cnf'
    163 			menu.save();
    164 			// start boot sequence.
    165 			menu.boot();
    166 			// NOTREACHED
    167 			break;
    168 		case IDC_PROGRESSBAR:
    169 			break;
    170 		case IDC_CANCELBUTTON:
    171 			PostQuitMessage(0);
    172 			break;
    173 		}
    174 		break;
    175 	case WM_DESTROY:
    176 		PostQuitMessage(0);
    177 		break;
    178 	}
    179 	return TRUE;
    180 }
    181 
    182 void
    183 RootWindow::WMPaint(HWND w, LPCREATESTRUCT aux)
    184 {
    185 	PAINTSTRUCT ps;
    186 	BeginPaint(w, &ps);
    187 	EndPaint(w, &ps);
    188 }
    189 
    190 void
    191 RootWindow::WMCreate(HWND w, LPCREATESTRUCT aux)
    192 {
    193 	int cmdbar_height;
    194 
    195 	_window = w;
    196 	// Command bar.
    197 	_app._cmdbar = CommandBar_Create(aux->hInstance, w, IDC_CMDBAR);
    198 	CommandBar_AddAdornments(_app._cmdbar, 0, 0);
    199 	cmdbar_height = CommandBar_Height(_app._cmdbar);
    200 	_button_height = cmdbar_height;
    201 
    202 	RECT rect;
    203 	GetClientRect(w, &rect);
    204 	rect.top += cmdbar_height;
    205 
    206 	// BOOT button.
    207 	_boot_button = new BootButton(_app, *this, rect);
    208 	_boot_button->create(aux);
    209 	// CANCEL button.
    210 	_cancel_button = new CancelButton(_app, *this, rect);
    211 	_cancel_button->create(aux);
    212 	// Progress bar
    213 	_progress_bar = new ProgressBar(_app, *this, rect);
    214 	_progress_bar->create(aux);
    215 
    216  	// regsiter myself to menu
    217 	HpcMenuInterface::Instance()._root = this;
    218 
    219 	rect.top += _button_height;
    220 	// Tab control.
    221 	_base =  new TabWindowBase(_app, w, rect, IDC_BASE);
    222 	_base->create(aux);
    223 	// main/option/console dialog.(register to Menu)
    224 	_main = _base->boot(IDC_BASE_MAIN);
    225 	_option = _base->boot(IDC_BASE_OPTION);
    226 	_console = _base->boot(IDC_BASE_CONSOLE);
    227 
    228 	_main->show();
    229 
    230 	return;
    231 }
    232 
    233 void
    234 RootWindow::disableTimer()
    235 {
    236 	KillTimer(_window, IDD_TIMER);
    237 }
    238 
    239 BOOL
    240 RootWindow::isDialogMessage(MSG &msg)
    241 {
    242 	if (_main && IsWindowVisible(_main->_window))
    243 		return IsDialogMessage(_main->_window, &msg);
    244 	if (_option && IsWindowVisible(_option->_window))
    245 		return IsDialogMessage(_option->_window, &msg);
    246 	if (_console && IsWindowVisible(_console->_window))
    247 		return IsDialogMessage(_console->_window, &msg);
    248 	return FALSE;
    249 }
    250 
    251 void
    252 RootWindow::progress()
    253 {
    254 	SendMessage(_progress_bar->_window, PBM_STEPIT, 0, 0);
    255 }
    256 
    257 void
    258 RootWindow::unprogress()
    259 {
    260 	SendMessage(_progress_bar->_window, PBM_SETPOS, 0, 0);
    261 }
    262 
    263 //
    264 // BOOT button
    265 //
    266 BOOL
    267 BootButton::create(LPCREATESTRUCT aux)
    268 {
    269 	int cx = BOOT_BUTTON_WIDTH;
    270 	int cy = _root._button_height;
    271 
    272 	_window = CreateWindow(TEXT("BUTTON"), TEXT("Boot"),
    273 	    BS_PUSHBUTTON | BS_NOTIFY |
    274 	    WS_VISIBLE | WS_CHILD | WS_TABSTOP,
    275 	    _rect.left, _rect.top, cx, cy, _parent_window,
    276 	    reinterpret_cast <HMENU>(IDC_BOOTBUTTON),
    277 	    aux->hInstance,
    278 	    NULL);
    279 
    280 	return IsWindow(_window) ? TRUE : FALSE;
    281 }
    282 
    283 //
    284 // CANCEL button
    285 //
    286 BOOL
    287 CancelButton::create(LPCREATESTRUCT aux)
    288 {
    289 	int cx = BOOT_BUTTON_WIDTH;
    290 	int cy = _root._button_height;
    291 	int x = _rect.right - BOOT_BUTTON_WIDTH;
    292 
    293 	_window = CreateWindow(TEXT("BUTTON"), TEXT("Cancel"),
    294 	    BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP |
    295 	    WS_VISIBLE | WS_CHILD,
    296 	    x, _rect.top, cx, cy, _parent_window,
    297 	    reinterpret_cast <HMENU>(IDC_CANCELBUTTON),
    298 	    aux->hInstance,
    299 	    NULL);
    300 	return IsWindow(_window) ? TRUE : FALSE;
    301 }
    302 
    303 //
    304 // PROGRESS BAR
    305 //
    306 BOOL
    307 ProgressBar::create(LPCREATESTRUCT aux)
    308 {
    309 	int cx = _rect.right - _rect.left - BOOT_BUTTON_WIDTH * 2;
    310 	int cy = _root._button_height;
    311 	int x = _rect.left + BOOT_BUTTON_WIDTH;
    312 	_window = CreateWindowEx(WS_EX_CLIENTEDGE,
    313 	    PROGRESS_CLASS, TEXT(""),
    314 	    PBS_SMOOTH | WS_VISIBLE | WS_CHILD,
    315 	    x, _rect.top, cx, cy, _parent_window,
    316 	    reinterpret_cast <HMENU>(IDC_PROGRESSBAR),
    317 	    aux->hInstance, NULL);
    318 	SendMessage(_window, PBM_SETRANGE, 0, MAKELPARAM(0, 11));
    319 	SendMessage(_window, PBM_SETSTEP, 1, 0);
    320 	SendMessage(_window, PBM_SETPOS, 0, 0);
    321 
    322 	return IsWindow(_window) ? TRUE : FALSE;
    323 }
    324