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