Home | History | Annotate | Line # | Download | only in menu
rootwindow.cpp revision 1.13
      1  1.13  uwe /* -*-C++-*-	$NetBSD: rootwindow.cpp,v 1.13 2004/02/23 05:20:48 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.13  uwe 		case TCN_KEYDOWN: {
    138  1.13  uwe 			NMTCKEYDOWN *key = reinterpret_cast
    139  1.13  uwe 				<NMTCKEYDOWN *>(lparam);
    140  1.13  uwe 			return _base->focusManagerHook(key->wVKey, key->flags,
    141  1.13  uwe 						_cancel_button->_window);
    142  1.13  uwe 		    }
    143   1.1  uch 		}
    144   1.1  uch 	}
    145   1.1  uch 	break;
    146   1.1  uch 	case WM_TIMER:
    147   1.1  uch 		disableTimer();
    148   1.1  uch 		goto boot;
    149   1.1  uch 	case WM_COMMAND:
    150   1.1  uch 		switch(wparam)
    151   1.1  uch 		{
    152   1.1  uch 		case IDC_BOOTBUTTON:
    153   1.1  uch 			// inquire current options.
    154   1.1  uch 			menu.get_options();
    155   1.1  uch 			if (menu._pref.safety_message) {
    156  1.12  uwe 				UINT mb_icon = menu._pref.pause_before_boot ?
    157  1.12  uwe 					MB_ICONQUESTION : MB_ICONWARNING;
    158   1.3  uch 				if (MessageBox(_window,
    159   1.5  uwe 				    TEXT("Data in memory will be lost.\nAre you sure?"),
    160   1.5  uwe 				    TEXT("WARNING"),
    161  1.12  uwe 				    mb_icon | MB_YESNO) != IDYES)
    162   1.1  uch 					break;
    163  1.13  uwe 				UpdateWindow(_window);
    164   1.1  uch 			}
    165   1.1  uch 		boot:
    166   1.2  uch 			SendMessage(_progress_bar->_window, PBM_SETPOS, 0, 0);
    167   1.1  uch 			menu.print(TEXT("BOOT START\n"));
    168   1.1  uch 			// inquire current options.
    169   1.1  uch 			menu.get_options();
    170   1.1  uch 			// save options to `hpcboot.cnf'
    171   1.1  uch 			menu.save();
    172   1.5  uwe 			// start boot sequence.
    173   1.1  uch 			menu.boot();
    174   1.1  uch 			// NOTREACHED
    175   1.1  uch 			break;
    176   1.1  uch 		case IDC_PROGRESSBAR:
    177   1.1  uch 			break;
    178   1.1  uch 		case IDC_CANCELBUTTON:
    179   1.1  uch 			PostQuitMessage(0);
    180   1.1  uch 			break;
    181   1.1  uch 		}
    182   1.1  uch 		break;
    183   1.1  uch 	case WM_DESTROY:
    184   1.1  uch 		PostQuitMessage(0);
    185   1.1  uch 		break;
    186   1.1  uch 	}
    187   1.1  uch 	return TRUE;
    188   1.1  uch }
    189   1.1  uch 
    190   1.1  uch void
    191   1.1  uch RootWindow::WMPaint(HWND w, LPCREATESTRUCT aux)
    192  1.10  uwe {
    193   1.1  uch 	PAINTSTRUCT ps;
    194   1.1  uch 	BeginPaint(w, &ps);
    195   1.1  uch 	EndPaint(w, &ps);
    196   1.1  uch }
    197   1.1  uch 
    198   1.1  uch void
    199   1.1  uch RootWindow::WMCreate(HWND w, LPCREATESTRUCT aux)
    200   1.1  uch {
    201   1.1  uch 	int cmdbar_height;
    202   1.1  uch 
    203   1.1  uch 	_window = w;
    204   1.1  uch 	// Command bar.
    205   1.1  uch 	_app._cmdbar = CommandBar_Create(aux->hInstance, w, IDC_CMDBAR);
    206   1.1  uch 	CommandBar_AddAdornments(_app._cmdbar, 0, 0);
    207   1.1  uch 	cmdbar_height = CommandBar_Height(_app._cmdbar);
    208   1.1  uch 	_button_height = cmdbar_height;
    209  1.10  uwe 
    210   1.1  uch 	RECT rect;
    211   1.1  uch 	GetClientRect(w, &rect);
    212   1.1  uch 	rect.top += cmdbar_height;
    213   1.1  uch 
    214   1.1  uch 	// BOOT button.
    215   1.1  uch 	_boot_button = new BootButton(_app, *this, rect);
    216   1.1  uch 	_boot_button->create(aux);
    217   1.1  uch 	// CANCEL button.
    218   1.1  uch 	_cancel_button = new CancelButton(_app, *this, rect);
    219   1.1  uch 	_cancel_button->create(aux);
    220   1.1  uch 	// Progress bar
    221   1.1  uch 	_progress_bar = new ProgressBar(_app, *this, rect);
    222   1.1  uch 	_progress_bar->create(aux);
    223   1.1  uch 
    224   1.1  uch  	// regsiter myself to menu
    225   1.1  uch 	HpcMenuInterface::Instance()._root = this;
    226   1.1  uch 
    227   1.9  uwe 	rect.top += _button_height;
    228   1.1  uch 	// Tab control.
    229   1.1  uch 	_base =  new TabWindowBase(_app, w, rect, IDC_BASE);
    230   1.1  uch 	_base->create(aux);
    231   1.1  uch 	// main/option/console dialog.(register to Menu)
    232   1.1  uch 	_main = _base->boot(IDC_BASE_MAIN);
    233   1.1  uch 	_option = _base->boot(IDC_BASE_OPTION);
    234   1.1  uch 	_console = _base->boot(IDC_BASE_CONSOLE);
    235  1.10  uwe 
    236   1.1  uch 	_main->show();
    237   1.1  uch 
    238   1.1  uch 	return;
    239   1.1  uch }
    240   1.1  uch 
    241   1.1  uch void
    242   1.1  uch RootWindow::disableTimer()
    243  1.10  uwe {
    244   1.1  uch 	KillTimer(_window, IDD_TIMER);
    245   1.1  uch }
    246   1.1  uch 
    247   1.1  uch BOOL
    248   1.1  uch RootWindow::isDialogMessage(MSG &msg)
    249   1.1  uch {
    250  1.13  uwe 	HWND tab_window;
    251  1.13  uwe 
    252   1.1  uch 	if (_main && IsWindowVisible(_main->_window))
    253  1.13  uwe 		tab_window = _main->_window;
    254  1.13  uwe 	else if (_option && IsWindowVisible(_option->_window))
    255  1.13  uwe 		tab_window = _option->_window;
    256  1.13  uwe 	else if (_console && IsWindowVisible(_console->_window))
    257  1.13  uwe 		tab_window = _console->_window;
    258  1.13  uwe 
    259  1.13  uwe 	if (focusManagerHook(msg, tab_window))
    260  1.13  uwe 		return TRUE;
    261  1.13  uwe 
    262  1.13  uwe 	return IsDialogMessage(tab_window, &msg);
    263  1.13  uwe }
    264  1.13  uwe 
    265  1.13  uwe //
    266  1.13  uwe // WinCE 2.11 doesn't support keyboard focus traversal for nested
    267  1.13  uwe // dialogs, so implement poor man focus manager for our root window.
    268  1.13  uwe // This function handles focus transition from boot/cancel buttons.
    269  1.13  uwe // Transition from the tab-control is done on WM_NOTIFY/TCN_KEYDOWN
    270  1.13  uwe // above.
    271  1.13  uwe //
    272  1.13  uwe // XXX: This is a very smplistic implementation that doesn't handle
    273  1.13  uwe // <TAB> auto-repeat count in LOWORD(msg.lParam).
    274  1.13  uwe //
    275  1.13  uwe BOOL
    276  1.13  uwe RootWindow::focusManagerHook(MSG &msg, HWND tab_window)
    277  1.13  uwe {
    278  1.13  uwe 	HWND next, prev;
    279  1.13  uwe 	HWND dst = 0;
    280  1.13  uwe 
    281  1.13  uwe 	if (msg.message != WM_KEYDOWN)
    282  1.13  uwe 		return FALSE;
    283  1.13  uwe 
    284  1.13  uwe 	if (msg.hwnd == _boot_button->_window) {
    285  1.13  uwe 		next = _cancel_button->_window;
    286  1.13  uwe 		prev = _base->_window;
    287  1.13  uwe 	} else if (msg.hwnd == _cancel_button->_window) {
    288  1.13  uwe 		next = _base->_window;
    289  1.13  uwe 		prev = _boot_button->_window;
    290  1.13  uwe 	} else if (tab_window == 0) {
    291  1.13  uwe 		return FALSE;
    292  1.13  uwe 	} else {
    293  1.13  uwe 		// last focusable control in the tab_window (XXX: WS_GROUP?)
    294  1.13  uwe 		HWND last = GetNextDlgTabItem(tab_window, NULL, TRUE);
    295  1.13  uwe 		if (!last || msg.hwnd != last)
    296  1.13  uwe 			return FALSE;
    297  1.13  uwe 		// XXX: handle DLGC_WANTARROWS &c
    298  1.13  uwe 		next = _base->_window; // out of the tab window
    299  1.13  uwe 		prev = 0;	// let IsDialogMessage handle it
    300  1.13  uwe 	}
    301  1.13  uwe 
    302  1.13  uwe 	switch (msg.wParam) {
    303  1.13  uwe 	case VK_RIGHT:
    304  1.13  uwe 	case VK_DOWN:
    305  1.13  uwe 		dst = next;
    306  1.13  uwe 		break;
    307  1.13  uwe 
    308  1.13  uwe 	case VK_LEFT:
    309  1.13  uwe 	case VK_UP:
    310  1.13  uwe 		dst = prev;
    311  1.13  uwe 		break;
    312  1.13  uwe 
    313  1.13  uwe 	case VK_TAB:
    314  1.13  uwe 		if (GetKeyState(VK_SHIFT) & 0x8000) // Shift-Tab
    315  1.13  uwe 			dst = prev;
    316  1.13  uwe 		else
    317  1.13  uwe 			dst = next;
    318  1.13  uwe 		break;
    319  1.13  uwe 	}
    320  1.13  uwe 
    321  1.13  uwe 	if (dst == 0)
    322  1.13  uwe 		return FALSE;
    323  1.13  uwe 
    324  1.13  uwe 	SetFocus(dst);
    325  1.13  uwe 	return TRUE;
    326   1.1  uch }
    327   1.1  uch 
    328   1.6  uwe void
    329   1.6  uwe RootWindow::progress()
    330   1.6  uwe {
    331   1.7  uwe 	SendMessage(_progress_bar->_window, PBM_STEPIT, 0, 0);
    332   1.6  uwe }
    333   1.6  uwe 
    334   1.6  uwe void
    335   1.6  uwe RootWindow::unprogress()
    336   1.6  uwe {
    337   1.7  uwe 	SendMessage(_progress_bar->_window, PBM_SETPOS, 0, 0);
    338   1.6  uwe }
    339   1.6  uwe 
    340   1.1  uch //
    341   1.1  uch // BOOT button
    342   1.1  uch //
    343   1.1  uch BOOL
    344   1.1  uch BootButton::create(LPCREATESTRUCT aux)
    345   1.1  uch {
    346   1.1  uch 	int cx = BOOT_BUTTON_WIDTH;
    347   1.1  uch 	int cy = _root._button_height;
    348   1.1  uch 
    349  1.11  uwe 	_window = CreateWindow(TEXT("BUTTON"), TEXT("Boot"),
    350   1.3  uch 	    BS_PUSHBUTTON | BS_NOTIFY |
    351   1.3  uch 	    WS_VISIBLE | WS_CHILD | WS_TABSTOP,
    352   1.3  uch 	    _rect.left, _rect.top, cx, cy, _parent_window,
    353   1.3  uch 	    reinterpret_cast <HMENU>(IDC_BOOTBUTTON),
    354   1.3  uch 	    aux->hInstance,
    355   1.3  uch 	    NULL);
    356   1.1  uch 
    357   1.1  uch 	return IsWindow(_window) ? TRUE : FALSE;
    358   1.1  uch }
    359   1.1  uch 
    360   1.1  uch //
    361   1.1  uch // CANCEL button
    362   1.1  uch //
    363   1.1  uch BOOL
    364   1.1  uch CancelButton::create(LPCREATESTRUCT aux)
    365   1.1  uch {
    366   1.1  uch 	int cx = BOOT_BUTTON_WIDTH;
    367   1.1  uch 	int cy = _root._button_height;
    368   1.1  uch 	int x = _rect.right - BOOT_BUTTON_WIDTH;
    369   1.1  uch 
    370  1.11  uwe 	_window = CreateWindow(TEXT("BUTTON"), TEXT("Cancel"),
    371   1.3  uch 	    BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP |
    372   1.3  uch 	    WS_VISIBLE | WS_CHILD,
    373   1.3  uch 	    x, _rect.top, cx, cy, _parent_window,
    374   1.3  uch 	    reinterpret_cast <HMENU>(IDC_CANCELBUTTON),
    375   1.3  uch 	    aux->hInstance,
    376   1.3  uch 	    NULL);
    377  1.13  uwe 
    378   1.1  uch 	return IsWindow(_window) ? TRUE : FALSE;
    379   1.1  uch }
    380   1.1  uch 
    381   1.1  uch //
    382   1.1  uch // PROGRESS BAR
    383   1.1  uch //
    384   1.1  uch BOOL
    385   1.1  uch ProgressBar::create(LPCREATESTRUCT aux)
    386   1.1  uch {
    387   1.9  uwe 	int cx = _rect.right - _rect.left - BOOT_BUTTON_WIDTH * 2;
    388   1.1  uch 	int cy = _root._button_height;
    389   1.1  uch 	int x = _rect.left + BOOT_BUTTON_WIDTH;
    390  1.11  uwe 	_window = CreateWindowEx(WS_EX_CLIENTEDGE,
    391  1.11  uwe 	    PROGRESS_CLASS, TEXT(""),
    392  1.11  uwe 	    PBS_SMOOTH | WS_VISIBLE | WS_CHILD,
    393   1.3  uch 	    x, _rect.top, cx, cy, _parent_window,
    394   1.3  uch 	    reinterpret_cast <HMENU>(IDC_PROGRESSBAR),
    395   1.3  uch 	    aux->hInstance, NULL);
    396   1.9  uwe 	SendMessage(_window, PBM_SETRANGE, 0, MAKELPARAM(0, 11));
    397  1.11  uwe 	SendMessage(_window, PBM_SETSTEP, 1, 0);
    398  1.11  uwe 	SendMessage(_window, PBM_SETPOS, 0, 0);
    399   1.1  uch 
    400   1.1  uch 	return IsWindow(_window) ? TRUE : FALSE;
    401   1.1  uch }
    402