1 /* -*-C++-*- $NetBSD: tabwindow.cpp,v 1.6 2008/04/28 20:23:20 martin 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 * 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. 30 */ 31 32 #include <hpcmenu.h> 33 #include <menu/window.h> 34 #include <menu/tabwindow.h> 35 #include <res/resource.h> 36 37 // 38 // TabControl 39 // 40 BOOL 41 TabWindowBase::create(LPCREATESTRUCT aux) 42 { 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 51 52 if (!IsWindow(_window)) 53 return FALSE; 54 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"); 62 63 TabCtrl_SetPadding(_window, 1, 1); 64 TabCtrl_SetImageList(_window, img); 65 66 return TRUE; 67 } 68 69 void 70 TabWindowBase::_load_bitmap(HIMAGELIST img, const TCHAR *name) 71 { 72 HBITMAP bmp = LoadBitmap(_app._instance, name); 73 ImageList_Add(img, bmp, 0); 74 DeleteObject(bmp); 75 } 76 77 BOOL 78 TabWindowBase::focusManagerHook(WORD vk, UINT flags, HWND prev) 79 { 80 int direction = 0; 81 82 // NB: VK_UP/VK_DOWN move between tabs 83 switch (vk) { 84 case VK_RIGHT: 85 direction = 1; // next 86 break; 87 88 case VK_LEFT: 89 direction = -1; // prev 90 break; 91 92 case VK_TAB: 93 if (GetKeyState(VK_SHIFT) & 0x8000) // Shift-Tab 94 direction = -1; // prev 95 else 96 direction = 1; // next 97 break; 98 } 99 100 if (!direction) 101 return FALSE; 102 103 HWND dst; 104 105 if (direction > 0) { // next - into the current dialog 106 int tab_id = TabCtrl_GetCurSel(_window); 107 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); 113 114 dst = GetNextDlgTabItem(tab->_window, NULL, FALSE); 115 } else { // prev - to the button in the root 116 dst = prev; 117 } 118 119 SetFocus(dst); 120 return TRUE; 121 } 122 123 124 // 125 // Child of TabControl(Dialog) 126 // 127 BOOL 128 TabWindow::create(LPCREATESTRUCT unused) 129 { 130 _window = CreateDialogParam 131 (_app._instance, _name, _base._window, 132 reinterpret_cast <DLGPROC>(Window::_dlg_proc), 133 reinterpret_cast <LPARAM>(this)); 134 135 return _window ? TRUE : FALSE; 136 } 137 138 BOOL 139 TabWindow::proc(HWND w, UINT msg, WPARAM wparam, LPARAM lparam) 140 { 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; 150 } 151 return TRUE; 152 } 153 154 void 155 TabWindow::init(HWND w) 156 { 157 TC_ITEM item; 158 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(); 167 } 168 169 BOOL 170 TabWindow::_is_checked(int id) 171 { 172 return SendDlgItemMessage(_window, id, BM_GETCHECK, 0, 0) 173 ? TRUE : FALSE; 174 } 175 176 void 177 TabWindow::_set_check(int id, BOOL onoff) 178 { 179 SendDlgItemMessage(_window, id, BM_SETCHECK, 180 onoff ? BST_CHECKED : BST_UNCHECKED, 0); 181 } 182