xref: /netbsd-src/sys/arch/hpc/stand/hpcboot/menu/tabwindow.cpp (revision d48f14661dda8638fee055ba15d35bdfb29b9fa8)
1 /* -*-C++-*-	$NetBSD: tabwindow.cpp,v 1.5 2005/12/11 12:17:28 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by UCHIYAMA Yasushi.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
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.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include <hpcmenu.h>
40 #include <menu/window.h>
41 #include <menu/tabwindow.h>
42 #include <res/resource.h>
43 
44 //
45 // TabControl
46 //
47 BOOL
48 TabWindowBase::create(LPCREATESTRUCT aux)
49 {
50 	int cx = _rect.right - _rect.left;
51 	int cy = _rect.bottom - _rect.top;
52 	_window = CreateWindow(WC_TABCONTROL, L"",
53 	    WS_CHILD | WS_VISIBLE | WS_TABSTOP |
54 	    WS_CLIPSIBLINGS | TCS_MULTILINE | TCS_VERTICAL,
55 	    _rect.left, _rect.top, cx, cy, _parent_window,
56 	    reinterpret_cast <HMENU>(_id), aux->hInstance,
57 	    NULL); // this is system window class
58 
59 	if (!IsWindow(_window))
60 		return FALSE;
61 
62 	// set tab image.
63 	HIMAGELIST img = ImageList_Create(TABCTRL_TAB_IMAGE_WIDTH,
64 	    TABCTRL_TAB_IMAGE_HEIGHT,
65 	    ILC_COLOR, 3, 0);
66 	_load_bitmap(img, L"IDI_HPCMENU_MAIN");
67 	_load_bitmap(img, L"IDI_HPCMENU_OPTION");
68 	_load_bitmap(img, L"IDI_HPCMENU_CONSOLE");
69 
70 	TabCtrl_SetPadding(_window, 1, 1);
71 	TabCtrl_SetImageList(_window, img);
72 
73 	return TRUE;
74 }
75 
76 void
77 TabWindowBase::_load_bitmap(HIMAGELIST img, const TCHAR *name)
78 {
79 	HBITMAP bmp = LoadBitmap(_app._instance, name);
80 	ImageList_Add(img, bmp, 0);
81 	DeleteObject(bmp);
82 }
83 
84 BOOL
85 TabWindowBase::focusManagerHook(WORD vk, UINT flags, HWND prev)
86 {
87 	int direction = 0;
88 
89 	// NB: VK_UP/VK_DOWN move between tabs
90 	switch (vk) {
91 	case VK_RIGHT:
92 		direction = 1;	// next
93 		break;
94 
95 	case VK_LEFT:
96 		direction = -1;	// prev
97 		break;
98 
99 	case VK_TAB:
100 		if (GetKeyState(VK_SHIFT) & 0x8000) // Shift-Tab
101 			direction = -1;	// prev
102 		else
103 			direction = 1; // next
104 		break;
105 	}
106 
107 	if (!direction)
108 		return FALSE;
109 
110 	HWND dst;
111 
112 	if (direction > 0) {	// next - into the current dialog
113 		int tab_id = TabCtrl_GetCurSel(_window);
114 
115 		TC_ITEM tc_item;
116 		tc_item.mask = TCIF_PARAM;
117 		TabCtrl_GetItem(_window, tab_id, &tc_item);
118 		TabWindow *tab = reinterpret_cast <TabWindow *>
119 		    (tc_item.lParam);
120 
121 		dst = GetNextDlgTabItem(tab->_window, NULL, FALSE);
122 	} else {		// prev - to the button in the root
123 		dst = prev;
124 	}
125 
126 	SetFocus(dst);
127 	return TRUE;
128 }
129 
130 
131 //
132 // Child of TabControl(Dialog)
133 //
134 BOOL
135 TabWindow::create(LPCREATESTRUCT unused)
136 {
137 	_window = CreateDialogParam
138 	    (_app._instance, _name, _base._window,
139 		reinterpret_cast <DLGPROC>(Window::_dlg_proc),
140 		reinterpret_cast <LPARAM>(this));
141 
142 	return _window ? TRUE : FALSE;
143 }
144 
145 BOOL
146 TabWindow::proc(HWND w, UINT msg, WPARAM wparam, LPARAM lparam)
147 {
148 	switch(msg) {
149 	default:
150 		return FALSE;
151 	case WM_INITDIALOG:
152 		init(w);
153 		break;
154 	case WM_COMMAND:
155 		command(LOWORD(wparam), HIWORD(wparam));
156 		break;
157 	}
158 	return TRUE;
159 }
160 
161 void
162 TabWindow::init(HWND w)
163 {
164 	TC_ITEM item;
165 
166 	item.mask = TCIF_PARAM | TCIF_IMAGE;
167 	item.iImage =(int)_id;
168 	item.lParam = reinterpret_cast <LPARAM>(this);
169 	// register myself to parent tab-control.
170 	_base.insert(_id, item);
171 	// fit my dialog size to tab-control window.
172 	_base.adjust(_rect);
173 	hide();
174 }
175 
176 BOOL
177 TabWindow::_is_checked(int id)
178 {
179 	return SendDlgItemMessage(_window, id, BM_GETCHECK, 0, 0)
180 	    ? TRUE : FALSE;
181 }
182 
183 void
184 TabWindow::_set_check(int id, BOOL onoff)
185 {
186 	SendDlgItemMessage(_window, id, BM_SETCHECK,
187 	    onoff ? BST_CHECKED : BST_UNCHECKED, 0);
188 }
189