Home | History | Annotate | Line # | Download | only in menu
rootwindow.cpp revision 1.11
      1  1.11  uwe /* -*-C++-*-	$NetBSD: rootwindow.cpp,v 1.11 2003/12/25 03:19:53 uwe 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.10  uwe 
     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.5  uwe 				    TEXT("Data in memory will be lost.\nAre you sure?"),
    152   1.5  uwe 				    TEXT("WARNING"),
    153   1.5  uwe 				    MB_ICONQUESTION | MB_YESNO) != IDYES)
    154   1.1  uch 					break;
    155   1.8  uwe 				UpdateWindow(w);
    156   1.1  uch 			}
    157   1.1  uch 		boot:
    158   1.2  uch 			SendMessage(_progress_bar->_window, PBM_SETPOS, 0, 0);
    159   1.1  uch 			menu.print(TEXT("BOOT START\n"));
    160   1.1  uch 			// inquire current options.
    161   1.1  uch 			menu.get_options();
    162   1.1  uch 			// save options to `hpcboot.cnf'
    163   1.1  uch 			menu.save();
    164   1.5  uwe 			// start boot sequence.
    165   1.1  uch 			menu.boot();
    166   1.1  uch 			// NOTREACHED
    167   1.1  uch 			break;
    168   1.1  uch 		case IDC_PROGRESSBAR:
    169   1.1  uch 			break;
    170   1.1  uch 		case IDC_CANCELBUTTON:
    171   1.1  uch 			PostQuitMessage(0);
    172   1.1  uch 			break;
    173   1.1  uch 		}
    174   1.1  uch 		break;
    175   1.1  uch 	case WM_DESTROY:
    176   1.1  uch 		PostQuitMessage(0);
    177   1.1  uch 		break;
    178   1.1  uch 	}
    179   1.1  uch 	return TRUE;
    180   1.1  uch }
    181   1.1  uch 
    182   1.1  uch void
    183   1.1  uch RootWindow::WMPaint(HWND w, LPCREATESTRUCT aux)
    184  1.10  uwe {
    185   1.1  uch 	PAINTSTRUCT ps;
    186   1.1  uch 	BeginPaint(w, &ps);
    187   1.1  uch 	EndPaint(w, &ps);
    188   1.1  uch }
    189   1.1  uch 
    190   1.1  uch void
    191   1.1  uch RootWindow::WMCreate(HWND w, LPCREATESTRUCT aux)
    192   1.1  uch {
    193   1.1  uch 	int cmdbar_height;
    194   1.1  uch 
    195   1.1  uch 	_window = w;
    196   1.1  uch 	// Command bar.
    197   1.1  uch 	_app._cmdbar = CommandBar_Create(aux->hInstance, w, IDC_CMDBAR);
    198   1.1  uch 	CommandBar_AddAdornments(_app._cmdbar, 0, 0);
    199   1.1  uch 	cmdbar_height = CommandBar_Height(_app._cmdbar);
    200   1.1  uch 	_button_height = cmdbar_height;
    201  1.10  uwe 
    202   1.1  uch 	RECT rect;
    203   1.1  uch 	GetClientRect(w, &rect);
    204   1.1  uch 	rect.top += cmdbar_height;
    205   1.1  uch 
    206   1.1  uch 	// BOOT button.
    207   1.1  uch 	_boot_button = new BootButton(_app, *this, rect);
    208   1.1  uch 	_boot_button->create(aux);
    209   1.1  uch 	// CANCEL button.
    210   1.1  uch 	_cancel_button = new CancelButton(_app, *this, rect);
    211   1.1  uch 	_cancel_button->create(aux);
    212   1.1  uch 	// Progress bar
    213   1.1  uch 	_progress_bar = new ProgressBar(_app, *this, rect);
    214   1.1  uch 	_progress_bar->create(aux);
    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.9  uwe 	rect.top += _button_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.10  uwe 
    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.10  uwe {
    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.6  uwe void
    252   1.6  uwe RootWindow::progress()
    253   1.6  uwe {
    254   1.7  uwe 	SendMessage(_progress_bar->_window, PBM_STEPIT, 0, 0);
    255   1.6  uwe }
    256   1.6  uwe 
    257   1.6  uwe void
    258   1.6  uwe RootWindow::unprogress()
    259   1.6  uwe {
    260   1.7  uwe 	SendMessage(_progress_bar->_window, PBM_SETPOS, 0, 0);
    261   1.6  uwe }
    262   1.6  uwe 
    263   1.1  uch //
    264   1.1  uch // BOOT button
    265   1.1  uch //
    266   1.1  uch BOOL
    267   1.1  uch BootButton::create(LPCREATESTRUCT aux)
    268   1.1  uch {
    269   1.1  uch 	int cx = BOOT_BUTTON_WIDTH;
    270   1.1  uch 	int cy = _root._button_height;
    271   1.1  uch 
    272  1.11  uwe 	_window = CreateWindow(TEXT("BUTTON"), TEXT("Boot"),
    273   1.3  uch 	    BS_PUSHBUTTON | BS_NOTIFY |
    274   1.3  uch 	    WS_VISIBLE | WS_CHILD | WS_TABSTOP,
    275   1.3  uch 	    _rect.left, _rect.top, cx, cy, _parent_window,
    276   1.3  uch 	    reinterpret_cast <HMENU>(IDC_BOOTBUTTON),
    277   1.3  uch 	    aux->hInstance,
    278   1.3  uch 	    NULL);
    279   1.1  uch 
    280   1.1  uch 	return IsWindow(_window) ? TRUE : FALSE;
    281   1.1  uch }
    282   1.1  uch 
    283   1.1  uch //
    284   1.1  uch // CANCEL button
    285   1.1  uch //
    286   1.1  uch BOOL
    287   1.1  uch CancelButton::create(LPCREATESTRUCT aux)
    288   1.1  uch {
    289   1.1  uch 	int cx = BOOT_BUTTON_WIDTH;
    290   1.1  uch 	int cy = _root._button_height;
    291   1.1  uch 	int x = _rect.right - BOOT_BUTTON_WIDTH;
    292   1.1  uch 
    293  1.11  uwe 	_window = CreateWindow(TEXT("BUTTON"), TEXT("Cancel"),
    294   1.3  uch 	    BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP |
    295   1.3  uch 	    WS_VISIBLE | WS_CHILD,
    296   1.3  uch 	    x, _rect.top, cx, cy, _parent_window,
    297   1.3  uch 	    reinterpret_cast <HMENU>(IDC_CANCELBUTTON),
    298   1.3  uch 	    aux->hInstance,
    299   1.3  uch 	    NULL);
    300   1.1  uch 	return IsWindow(_window) ? TRUE : FALSE;
    301   1.1  uch }
    302   1.1  uch 
    303   1.1  uch //
    304   1.1  uch // PROGRESS BAR
    305   1.1  uch //
    306   1.1  uch BOOL
    307   1.1  uch ProgressBar::create(LPCREATESTRUCT aux)
    308   1.1  uch {
    309   1.9  uwe 	int cx = _rect.right - _rect.left - BOOT_BUTTON_WIDTH * 2;
    310   1.1  uch 	int cy = _root._button_height;
    311   1.1  uch 	int x = _rect.left + BOOT_BUTTON_WIDTH;
    312  1.11  uwe 	_window = CreateWindowEx(WS_EX_CLIENTEDGE,
    313  1.11  uwe 	    PROGRESS_CLASS, TEXT(""),
    314  1.11  uwe 	    PBS_SMOOTH | WS_VISIBLE | WS_CHILD,
    315   1.3  uch 	    x, _rect.top, cx, cy, _parent_window,
    316   1.3  uch 	    reinterpret_cast <HMENU>(IDC_PROGRESSBAR),
    317   1.3  uch 	    aux->hInstance, NULL);
    318   1.9  uwe 	SendMessage(_window, PBM_SETRANGE, 0, MAKELPARAM(0, 11));
    319  1.11  uwe 	SendMessage(_window, PBM_SETSTEP, 1, 0);
    320  1.11  uwe 	SendMessage(_window, PBM_SETPOS, 0, 0);
    321   1.1  uch 
    322   1.1  uch 	return IsWindow(_window) ? TRUE : FALSE;
    323   1.1  uch }
    324