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