rootwindow.cpp revision 1.1 1 1.1 uch /* -*-C++-*- $NetBSD: rootwindow.cpp,v 1.1 2001/02/09 18:35:01 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.1 uch
45 1.1 uch //
46 1.1 uch // root window
47 1.1 uch //
48 1.1 uch RootWindow::RootWindow(HpcBootApp &app)
49 1.1 uch : Window(app)
50 1.1 uch {
51 1.1 uch _boot_button = 0;
52 1.1 uch _base = 0;
53 1.1 uch _main = 0;
54 1.1 uch _option = 0;
55 1.1 uch _console = 0;
56 1.1 uch }
57 1.1 uch
58 1.1 uch RootWindow::~RootWindow()
59 1.1 uch {
60 1.1 uch if (_boot_button)
61 1.1 uch delete _boot_button;
62 1.1 uch if (_cancel_button)
63 1.1 uch delete _cancel_button;
64 1.1 uch if (_progress_bar)
65 1.1 uch delete _progress_bar;
66 1.1 uch if (_main)
67 1.1 uch delete _main;
68 1.1 uch if (_option)
69 1.1 uch delete _option;
70 1.1 uch if (_console)
71 1.1 uch delete _console;
72 1.1 uch if (_base)
73 1.1 uch delete _base;
74 1.1 uch }
75 1.1 uch
76 1.1 uch BOOL
77 1.1 uch RootWindow::create(LPCREATESTRUCT aux)
78 1.1 uch {
79 1.1 uch // Root window's create don't called by Window Procedure.
80 1.1 uch // so aux is NULL
81 1.1 uch HINSTANCE inst = _app._instance;
82 1.1 uch TCHAR *wc_name = reinterpret_cast <TCHAR *>
83 1.1 uch (LoadString(inst, IDS_HPCMENU, 0, 0));
84 1.1 uch
85 1.1 uch _window = CreateWindow(wc_name, wc_name, WS_VISIBLE,
86 1.1 uch CW_USEDEFAULT, CW_USEDEFAULT,
87 1.1 uch CW_USEDEFAULT, CW_USEDEFAULT,
88 1.1 uch 0, 0, inst, this);
89 1.1 uch if (!_window)
90 1.1 uch return FALSE;
91 1.1 uch
92 1.1 uch HpcMenuInterface &menu = HpcMenuInterface::Instance();
93 1.1 uch if (menu._pref.auto_boot > 0)
94 1.1 uch SetTimer(_window, IDD_TIMER, menu._pref.auto_boot * 1000, 0);
95 1.1 uch
96 1.1 uch ShowWindow(_window, SW_SHOW);
97 1.1 uch UpdateWindow(_window);
98 1.1 uch
99 1.1 uch return TRUE;
100 1.1 uch }
101 1.1 uch
102 1.1 uch BOOL
103 1.1 uch RootWindow::proc(HWND w, UINT msg, WPARAM wparam, LPARAM lparam)
104 1.1 uch {
105 1.1 uch LPCREATESTRUCT aux = reinterpret_cast <LPCREATESTRUCT>(lparam);
106 1.1 uch HpcMenuInterface &menu = HpcMenuInterface::Instance();
107 1.1 uch
108 1.1 uch switch(msg) {
109 1.1 uch default: // message can't handle.
110 1.1 uch return FALSE;
111 1.1 uch case WM_CREATE:
112 1.1 uch WMCreate(w, aux);
113 1.1 uch break;
114 1.1 uch case WM_PAINT:
115 1.1 uch WMPaint(w, aux);
116 1.1 uch break;
117 1.1 uch case WM_NOTIFY:
118 1.1 uch {
119 1.1 uch NMHDR *notify = reinterpret_cast <NMHDR *>(lparam);
120 1.1 uch // get current selected tab id
121 1.1 uch int tab_id = TabCtrl_GetCurSel(_base->_window);
122 1.1 uch // get context
123 1.1 uch TC_ITEM tc_item;
124 1.1 uch tc_item.mask = TCIF_PARAM;
125 1.1 uch TabCtrl_GetItem(_base->_window, tab_id, &tc_item);
126 1.1 uch TabWindow *tab = reinterpret_cast <TabWindow *>
127 1.1 uch (tc_item.lParam);
128 1.1 uch switch(notify->code) {
129 1.1 uch case TCN_SELCHANGING:
130 1.1 uch tab->hide();
131 1.1 uch break;
132 1.1 uch case TCN_SELCHANGE:
133 1.1 uch tab->show();
134 1.1 uch break;
135 1.1 uch }
136 1.1 uch }
137 1.1 uch break;
138 1.1 uch case WM_TIMER:
139 1.1 uch disableTimer();
140 1.1 uch goto boot;
141 1.1 uch case WM_COMMAND:
142 1.1 uch switch(wparam)
143 1.1 uch {
144 1.1 uch case IDC_BOOTBUTTON:
145 1.1 uch // inquire current options.
146 1.1 uch menu.get_options();
147 1.1 uch if (menu._pref.safety_message) {
148 1.1 uch if (MessageBox
149 1.1 uch (_window,
150 1.1 uch TEXT("Data in memory will be lost.\n Are you sure?"),
151 1.1 uch TEXT("WARNING"), MB_YESNO) != IDYES)
152 1.1 uch break;
153 1.1 uch }
154 1.1 uch boot:
155 1.1 uch menu.print(TEXT("BOOT START\n"));
156 1.1 uch // inquire current options.
157 1.1 uch menu.get_options();
158 1.1 uch // save options to `hpcboot.cnf'
159 1.1 uch menu.save();
160 1.1 uch // atart boot sequence.
161 1.1 uch menu.boot();
162 1.1 uch // NOTREACHED
163 1.1 uch break;
164 1.1 uch case IDC_PROGRESSBAR:
165 1.1 uch break;
166 1.1 uch case IDC_CANCELBUTTON:
167 1.1 uch PostQuitMessage(0);
168 1.1 uch break;
169 1.1 uch }
170 1.1 uch break;
171 1.1 uch case WM_DESTROY:
172 1.1 uch PostQuitMessage(0);
173 1.1 uch break;
174 1.1 uch }
175 1.1 uch return TRUE;
176 1.1 uch }
177 1.1 uch
178 1.1 uch void
179 1.1 uch RootWindow::WMPaint(HWND w, LPCREATESTRUCT aux)
180 1.1 uch {
181 1.1 uch PAINTSTRUCT ps;
182 1.1 uch BeginPaint(w, &ps);
183 1.1 uch EndPaint(w, &ps);
184 1.1 uch }
185 1.1 uch
186 1.1 uch void
187 1.1 uch RootWindow::WMCreate(HWND w, LPCREATESTRUCT aux)
188 1.1 uch {
189 1.1 uch int cmdbar_height;
190 1.1 uch
191 1.1 uch _window = w;
192 1.1 uch // Command bar.
193 1.1 uch _app._cmdbar = CommandBar_Create(aux->hInstance, w, IDC_CMDBAR);
194 1.1 uch CommandBar_AddAdornments(_app._cmdbar, 0, 0);
195 1.1 uch cmdbar_height = CommandBar_Height(_app._cmdbar);
196 1.1 uch _button_height = cmdbar_height;
197 1.1 uch
198 1.1 uch RECT rect;
199 1.1 uch GetClientRect(w, &rect);
200 1.1 uch rect.top += cmdbar_height;
201 1.1 uch
202 1.1 uch // BOOT button.
203 1.1 uch _boot_button = new BootButton(_app, *this, rect);
204 1.1 uch _boot_button->create(aux);
205 1.1 uch // CANCEL button.
206 1.1 uch _cancel_button = new CancelButton(_app, *this, rect);
207 1.1 uch _cancel_button->create(aux);
208 1.1 uch // Progress bar
209 1.1 uch _progress_bar = new ProgressBar(_app, *this, rect);
210 1.1 uch _progress_bar->create(aux);
211 1.1 uch SendMessage(_progress_bar->_window, PBM_SETPOS, 0, 0);
212 1.1 uch
213 1.1 uch // regsiter myself to menu
214 1.1 uch HpcMenuInterface::Instance()._root = this;
215 1.1 uch
216 1.1 uch rect.top += cmdbar_height;
217 1.1 uch // Tab control.
218 1.1 uch _base = new TabWindowBase(_app, w, rect, IDC_BASE);
219 1.1 uch _base->create(aux);
220 1.1 uch // main/option/console dialog.(register to Menu)
221 1.1 uch _main = _base->boot(IDC_BASE_MAIN);
222 1.1 uch _option = _base->boot(IDC_BASE_OPTION);
223 1.1 uch _console = _base->boot(IDC_BASE_CONSOLE);
224 1.1 uch
225 1.1 uch _main->show();
226 1.1 uch
227 1.1 uch return;
228 1.1 uch }
229 1.1 uch
230 1.1 uch void
231 1.1 uch RootWindow::disableTimer()
232 1.1 uch {
233 1.1 uch KillTimer(_window, IDD_TIMER);
234 1.1 uch }
235 1.1 uch
236 1.1 uch BOOL
237 1.1 uch RootWindow::isDialogMessage(MSG &msg)
238 1.1 uch {
239 1.1 uch if (_main && IsWindowVisible(_main->_window))
240 1.1 uch return IsDialogMessage(_main->_window, &msg);
241 1.1 uch if (_option && IsWindowVisible(_option->_window))
242 1.1 uch return IsDialogMessage(_option->_window, &msg);
243 1.1 uch if (_console && IsWindowVisible(_console->_window))
244 1.1 uch return IsDialogMessage(_console->_window, &msg);
245 1.1 uch return FALSE;
246 1.1 uch }
247 1.1 uch
248 1.1 uch //
249 1.1 uch // BOOT button
250 1.1 uch //
251 1.1 uch BOOL
252 1.1 uch BootButton::create(LPCREATESTRUCT aux)
253 1.1 uch {
254 1.1 uch int cx = BOOT_BUTTON_WIDTH;
255 1.1 uch int cy = _root._button_height;
256 1.1 uch
257 1.1 uch _window = CreateWindow(TEXT("BUTTON"), TEXT("BOOT"),
258 1.1 uch BS_PUSHBUTTON | BS_NOTIFY |
259 1.1 uch WS_VISIBLE | WS_CHILD | WS_TABSTOP,
260 1.1 uch _rect.left, _rect.top, cx, cy, _parent_window,
261 1.1 uch reinterpret_cast <HMENU>(IDC_BOOTBUTTON),
262 1.1 uch aux->hInstance,
263 1.1 uch NULL);
264 1.1 uch
265 1.1 uch return IsWindow(_window) ? TRUE : FALSE;
266 1.1 uch }
267 1.1 uch
268 1.1 uch //
269 1.1 uch // CANCEL button
270 1.1 uch //
271 1.1 uch BOOL
272 1.1 uch CancelButton::create(LPCREATESTRUCT aux)
273 1.1 uch {
274 1.1 uch int cx = BOOT_BUTTON_WIDTH;
275 1.1 uch int cy = _root._button_height;
276 1.1 uch int x = _rect.right - BOOT_BUTTON_WIDTH;
277 1.1 uch
278 1.1 uch _window = CreateWindow(TEXT("BUTTON"), TEXT("CANCEL"),
279 1.1 uch BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP |
280 1.1 uch WS_VISIBLE | WS_CHILD,
281 1.1 uch x, _rect.top, cx, cy, _parent_window,
282 1.1 uch reinterpret_cast <HMENU>(IDC_CANCELBUTTON),
283 1.1 uch aux->hInstance,
284 1.1 uch NULL);
285 1.1 uch return IsWindow(_window) ? TRUE : FALSE;
286 1.1 uch }
287 1.1 uch
288 1.1 uch //
289 1.1 uch // PROGRESS BAR
290 1.1 uch //
291 1.1 uch BOOL
292 1.1 uch ProgressBar::create(LPCREATESTRUCT aux)
293 1.1 uch {
294 1.1 uch int cx = _rect.right - _rect.left
295 1.1 uch - TABCTRL_TAB_WIDTH - BOOT_BUTTON_WIDTH * 2;
296 1.1 uch int cy = _root._button_height;
297 1.1 uch int x = _rect.left + BOOT_BUTTON_WIDTH;
298 1.1 uch _window = CreateWindow(PROGRESS_CLASS, TEXT(""),
299 1.1 uch WS_VISIBLE | WS_CHILD,
300 1.1 uch x, _rect.top, cx, cy, _parent_window,
301 1.1 uch reinterpret_cast <HMENU>(IDC_PROGRESSBAR),
302 1.1 uch aux->hInstance, NULL);
303 1.1 uch SendMessage(_window, PBM_SETRANGE, 0, MAKELPARAM(0, 12));
304 1.1 uch SendMessage(_window, PBM_SETSTEP, 1, 0);
305 1.1 uch
306 1.1 uch return IsWindow(_window) ? TRUE : FALSE;
307 1.1 uch }
308