No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hpc / stand / hpcboot / menu / tabwindow.cpp
blobf70fd771e7fe2314aa66fea56ad6c54de27c4a84
1 /* -*-C++-*- $NetBSD: tabwindow.cpp,v 1.5 2005/12/11 12:17:28 christos Exp $ */
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
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.
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.
32 #include <hpcmenu.h>
33 #include <menu/window.h>
34 #include <menu/tabwindow.h>
35 #include <res/resource.h>
38 // TabControl
40 BOOL
41 TabWindowBase::create(LPCREATESTRUCT aux)
43 int cx = _rect.right - _rect.left;
44 int cy = _rect.bottom - _rect.top;
45 _window = CreateWindow(WC_TABCONTROL, L"",
46 WS_CHILD | WS_VISIBLE | WS_TABSTOP |
47 WS_CLIPSIBLINGS | TCS_MULTILINE | TCS_VERTICAL,
48 _rect.left, _rect.top, cx, cy, _parent_window,
49 reinterpret_cast <HMENU>(_id), aux->hInstance,
50 NULL); // this is system window class
52 if (!IsWindow(_window))
53 return FALSE;
55 // set tab image.
56 HIMAGELIST img = ImageList_Create(TABCTRL_TAB_IMAGE_WIDTH,
57 TABCTRL_TAB_IMAGE_HEIGHT,
58 ILC_COLOR, 3, 0);
59 _load_bitmap(img, L"IDI_HPCMENU_MAIN");
60 _load_bitmap(img, L"IDI_HPCMENU_OPTION");
61 _load_bitmap(img, L"IDI_HPCMENU_CONSOLE");
63 TabCtrl_SetPadding(_window, 1, 1);
64 TabCtrl_SetImageList(_window, img);
66 return TRUE;
69 void
70 TabWindowBase::_load_bitmap(HIMAGELIST img, const TCHAR *name)
72 HBITMAP bmp = LoadBitmap(_app._instance, name);
73 ImageList_Add(img, bmp, 0);
74 DeleteObject(bmp);
77 BOOL
78 TabWindowBase::focusManagerHook(WORD vk, UINT flags, HWND prev)
80 int direction = 0;
82 // NB: VK_UP/VK_DOWN move between tabs
83 switch (vk) {
84 case VK_RIGHT:
85 direction = 1; // next
86 break;
88 case VK_LEFT:
89 direction = -1; // prev
90 break;
92 case VK_TAB:
93 if (GetKeyState(VK_SHIFT) & 0x8000) // Shift-Tab
94 direction = -1; // prev
95 else
96 direction = 1; // next
97 break;
100 if (!direction)
101 return FALSE;
103 HWND dst;
105 if (direction > 0) { // next - into the current dialog
106 int tab_id = TabCtrl_GetCurSel(_window);
108 TC_ITEM tc_item;
109 tc_item.mask = TCIF_PARAM;
110 TabCtrl_GetItem(_window, tab_id, &tc_item);
111 TabWindow *tab = reinterpret_cast <TabWindow *>
112 (tc_item.lParam);
114 dst = GetNextDlgTabItem(tab->_window, NULL, FALSE);
115 } else { // prev - to the button in the root
116 dst = prev;
119 SetFocus(dst);
120 return TRUE;
125 // Child of TabControl(Dialog)
127 BOOL
128 TabWindow::create(LPCREATESTRUCT unused)
130 _window = CreateDialogParam
131 (_app._instance, _name, _base._window,
132 reinterpret_cast <DLGPROC>(Window::_dlg_proc),
133 reinterpret_cast <LPARAM>(this));
135 return _window ? TRUE : FALSE;
138 BOOL
139 TabWindow::proc(HWND w, UINT msg, WPARAM wparam, LPARAM lparam)
141 switch(msg) {
142 default:
143 return FALSE;
144 case WM_INITDIALOG:
145 init(w);
146 break;
147 case WM_COMMAND:
148 command(LOWORD(wparam), HIWORD(wparam));
149 break;
151 return TRUE;
154 void
155 TabWindow::init(HWND w)
157 TC_ITEM item;
159 item.mask = TCIF_PARAM | TCIF_IMAGE;
160 item.iImage =(int)_id;
161 item.lParam = reinterpret_cast <LPARAM>(this);
162 // register myself to parent tab-control.
163 _base.insert(_id, item);
164 // fit my dialog size to tab-control window.
165 _base.adjust(_rect);
166 hide();
169 BOOL
170 TabWindow::_is_checked(int id)
172 return SendDlgItemMessage(_window, id, BM_GETCHECK, 0, 0)
173 ? TRUE : FALSE;
176 void
177 TabWindow::_set_check(int id, BOOL onoff)
179 SendDlgItemMessage(_window, id, BM_SETCHECK,
180 onoff ? BST_CHECKED : BST_UNCHECKED, 0);