1 /* -*-C++-*- $NetBSD: rootwindow.cpp,v 1.21 2005/12/11 12:17:28 christos Exp $ */
4 * Copyright (c) 2001, 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 #include <menu/window.h>
34 #include <menu/tabwindow.h>
35 #include <menu/rootwindow.h>
36 #include <res/resource.h>
37 #include "../binary/build_number.h"
43 RootWindow::RootWindow(HpcBootApp
&app
)
53 RootWindow::~RootWindow()
58 delete _cancel_button
;
72 RootWindow::create(LPCREATESTRUCT aux
)
75 // Root window's create don't called by Window Procedure.
77 HINSTANCE inst
= _app
._instance
;
78 TCHAR
*wc_name
= reinterpret_cast <TCHAR
*>
79 (LoadString(inst
, IDS_HPCMENU
, 0, 0));
80 wsprintf(app_name
, TEXT("%s Build %d"), wc_name
, HPCBOOT_BUILD_NUMBER
);
82 _window
= CreateWindow(wc_name
, app_name
, WS_VISIBLE
,
83 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
88 HpcMenuInterface
&menu
= HpcMenuInterface::Instance();
89 if (menu
._pref
.auto_boot
> 0)
90 SetTimer(_window
, IDD_TIMER
, menu
._pref
.auto_boot
* 1000, 0);
92 ShowWindow(_window
, SW_SHOW
);
93 UpdateWindow(_window
);
99 RootWindow::proc(HWND w
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
101 LPCREATESTRUCT aux
= reinterpret_cast <LPCREATESTRUCT
>(lparam
);
102 HpcMenuInterface
&menu
= HpcMenuInterface::Instance();
105 default: // message can't handle.
113 case WM_ENTERMENULOOP
:
116 case WM_EXITMENULOOP
:
120 if ((UINT
)LOWORD(wparam
) == WA_INACTIVE
)
127 NMHDR
*notify
= reinterpret_cast <NMHDR
*>(lparam
);
128 // get current selected tab id
129 int tab_id
= TabCtrl_GetCurSel(_base
->_window
);
132 tc_item
.mask
= TCIF_PARAM
;
133 TabCtrl_GetItem(_base
->_window
, tab_id
, &tc_item
);
134 TabWindow
*tab
= reinterpret_cast <TabWindow
*>
136 switch(notify
->code
) {
137 case TCN_SELCHANGING
:
144 NMTCKEYDOWN
*key
= reinterpret_cast
145 <NMTCKEYDOWN
*>(lparam
);
146 return _base
->focusManagerHook(key
->wVKey
, key
->flags
,
147 _cancel_button
->_window
);
159 // inquire current options.
161 if (menu
._pref
.safety_message
) {
162 UINT mb_icon
= menu
._pref
.pause_before_boot
?
163 MB_ICONQUESTION
: MB_ICONWARNING
;
164 if (MessageBox(_window
,
165 TEXT("Data in memory will be lost.\nAre you sure?"),
167 mb_icon
| MB_YESNO
) != IDYES
)
169 UpdateWindow(_window
);
172 SendMessage(_progress_bar
->_window
, PBM_SETPOS
, 0, 0);
173 menu
.print(TEXT("BOOT START\n"));
174 // inquire current options.
176 // save options to `hpcboot.cnf'
178 // start boot sequence.
182 case IDC_PROGRESSBAR
:
184 case IDC_CANCELBUTTON
:
197 RootWindow::SaveFocus() {
198 _saved_focus
= GetFocus();
202 RootWindow::RestoreFocus() {
203 SetFocus(IsWindowEnabled(_saved_focus
) ?
204 _saved_focus
: _boot_button
->_window
);
208 RootWindow::WMPaint(HWND w
, LPCREATESTRUCT aux
)
216 RootWindow::WMCreate(HWND w
, LPCREATESTRUCT aux
)
222 _app
._cmdbar
= CommandBar_Create(aux
->hInstance
, w
, IDC_CMDBAR
);
223 CommandBar_AddAdornments(_app
._cmdbar
, 0, 0);
224 cmdbar_height
= CommandBar_Height(_app
._cmdbar
);
226 _button_height
= cmdbar_height
;
227 _button_width
= BOOT_BUTTON_WIDTH
;
230 if (GetDeviceCaps(hdc
, HORZRES
) > 320)
231 _button_width
+= _button_width
/2;
235 GetClientRect(w
, &rect
);
236 rect
.top
+= cmdbar_height
;
239 _boot_button
= new BootButton(_app
, *this, rect
);
240 _boot_button
->create(aux
);
242 _cancel_button
= new CancelButton(_app
, *this, rect
);
243 _cancel_button
->create(aux
);
245 _progress_bar
= new ProgressBar(_app
, *this, rect
);
246 _progress_bar
->create(aux
);
248 // regsiter myself to menu
249 HpcMenuInterface::Instance()._root
= this;
251 rect
.top
+= _button_height
;
253 _base
= new TabWindowBase(_app
, w
, rect
, IDC_BASE
);
255 // main/option/console dialog.(register to Menu)
256 _main
= _base
->boot(IDC_BASE_MAIN
);
257 _option
= _base
->boot(IDC_BASE_OPTION
);
258 _console
= _base
->boot(IDC_BASE_CONSOLE
);
261 SetFocus(_boot_button
->_window
);
267 RootWindow::disableTimer()
269 KillTimer(_window
, IDD_TIMER
);
273 RootWindow::isDialogMessage(MSG
&msg
)
277 if (_main
&& IsWindowVisible(_main
->_window
))
278 tab_window
= _main
->_window
;
279 else if (_option
&& IsWindowVisible(_option
->_window
))
280 tab_window
= _option
->_window
;
281 else if (_console
&& IsWindowVisible(_console
->_window
))
282 tab_window
= _console
->_window
;
284 if (focusManagerHook(msg
, tab_window
))
287 return IsDialogMessage(tab_window
, &msg
);
291 // XXX !!! XXX !!! XXX !!! XXX !!!
293 // WinCE 2.11 doesn't support keyboard focus traversal for nested
294 // dialogs, so implement poor man focus manager for our root window.
295 // This function handles focus transition from boot/cancel buttons.
296 // Transition from the tab-control is done on WM_NOTIFY/TCN_KEYDOWN
299 // XXX: This is a very smplistic implementation that doesn't handle
300 // <TAB> auto-repeat count in LOWORD(msg.lParam), WS_GROUP, etc...
303 RootWindow::focusManagerHook(MSG
&msg
, HWND tab_window
)
309 if (msg
.message
!= WM_KEYDOWN
)
312 if (msg
.hwnd
== _boot_button
->_window
) {
313 next
= _cancel_button
->_window
;
314 prev
= _base
->_window
;
315 } else if (msg
.hwnd
== _cancel_button
->_window
) {
316 next
= _base
->_window
;
317 prev
= _boot_button
->_window
;
318 } else if (tab_window
== 0) {
321 // last focusable control in the tab_window (XXX: WS_GROUP?)
322 HWND last
= GetNextDlgTabItem(tab_window
, NULL
, TRUE
);
324 !(last
== msg
.hwnd
|| IsChild(last
, msg
.hwnd
)))
326 dlgcode
= SendMessage(last
, WM_GETDLGCODE
, NULL
, (LPARAM
)&msg
);
327 next
= _base
->_window
; // out of the tab window
328 prev
= 0; // let IsDialogMessage handle it
331 #if 0 // XXX: breaks tabbing out of the console window
332 if (dlgcode
& DLGC_WANTALLKEYS
)
335 switch (msg
.wParam
) {
338 if (dlgcode
& DLGC_WANTARROWS
)
345 if (dlgcode
& DLGC_WANTARROWS
)
351 if (dlgcode
& DLGC_WANTTAB
)
353 if (GetKeyState(VK_SHIFT
) & 0x8000) // Shift-Tab
368 RootWindow::progress(const char *msg
)
372 Console::Instance()->print(TEXT("[progress] %S\n"), msg
);
374 SendMessage(_progress_bar
->_window
, PBM_STEPIT
, 0, 0);
378 RootWindow::unprogress()
380 SendMessage(_progress_bar
->_window
, PBM_SETPOS
, 0, 0);
387 BootButton::create(LPCREATESTRUCT aux
)
389 int cx
= _root
._button_width
;
390 int cy
= _root
._button_height
;
392 _window
= CreateWindow(TEXT("BUTTON"), TEXT("Boot"),
393 BS_PUSHBUTTON
| BS_NOTIFY
|
394 WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
,
395 _rect
.left
, _rect
.top
, cx
, cy
, _parent_window
,
396 reinterpret_cast <HMENU
>(IDC_BOOTBUTTON
),
400 return IsWindow(_window
) ? TRUE
: FALSE
;
407 CancelButton::create(LPCREATESTRUCT aux
)
409 int cx
= _root
._button_width
;
410 int cy
= _root
._button_height
;
411 int x
= _rect
.right
- _root
._button_width
;
413 _window
= CreateWindow(TEXT("BUTTON"), TEXT("Cancel"),
414 BS_PUSHBUTTON
| BS_NOTIFY
| WS_TABSTOP
|
415 WS_VISIBLE
| WS_CHILD
,
416 x
, _rect
.top
, cx
, cy
, _parent_window
,
417 reinterpret_cast <HMENU
>(IDC_CANCELBUTTON
),
421 return IsWindow(_window
) ? TRUE
: FALSE
;
428 ProgressBar::create(LPCREATESTRUCT aux
)
430 int cx
= _rect
.right
- _rect
.left
- _root
._button_width
* 2;
431 int cy
= _root
._button_height
;
432 int x
= _rect
.left
+ _root
._button_width
;
433 _window
= CreateWindowEx(WS_EX_CLIENTEDGE
,
434 PROGRESS_CLASS
, TEXT(""),
435 PBS_SMOOTH
| WS_VISIBLE
| WS_CHILD
,
436 x
, _rect
.top
, cx
, cy
, _parent_window
,
437 reinterpret_cast <HMENU
>(IDC_PROGRESSBAR
),
438 aux
->hInstance
, NULL
);
439 SendMessage(_window
, PBM_SETRANGE
, 0, MAKELPARAM(0, 11));
440 SendMessage(_window
, PBM_SETSTEP
, 1, 0);
441 SendMessage(_window
, PBM_SETPOS
, 0, 0);
443 return IsWindow(_window
) ? TRUE
: FALSE
;