1 /* -*-C++-*- $NetBSD: tabwindow.cpp,v 1.5 2005/12/11 12:17:28 christos Exp $ */
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
33 #include <menu/window.h>
34 #include <menu/tabwindow.h>
35 #include <res/resource.h>
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
))
56 HIMAGELIST img
= ImageList_Create(TABCTRL_TAB_IMAGE_WIDTH
,
57 TABCTRL_TAB_IMAGE_HEIGHT
,
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
);
70 TabWindowBase::_load_bitmap(HIMAGELIST img
, const TCHAR
*name
)
72 HBITMAP bmp
= LoadBitmap(_app
._instance
, name
);
73 ImageList_Add(img
, bmp
, 0);
78 TabWindowBase::focusManagerHook(WORD vk
, UINT flags
, HWND prev
)
82 // NB: VK_UP/VK_DOWN move between tabs
85 direction
= 1; // next
89 direction
= -1; // prev
93 if (GetKeyState(VK_SHIFT
) & 0x8000) // Shift-Tab
94 direction
= -1; // prev
96 direction
= 1; // next
105 if (direction
> 0) { // next - into the current dialog
106 int tab_id
= TabCtrl_GetCurSel(_window
);
109 tc_item
.mask
= TCIF_PARAM
;
110 TabCtrl_GetItem(_window
, tab_id
, &tc_item
);
111 TabWindow
*tab
= reinterpret_cast <TabWindow
*>
114 dst
= GetNextDlgTabItem(tab
->_window
, NULL
, FALSE
);
115 } else { // prev - to the button in the root
125 // Child of TabControl(Dialog)
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
;
139 TabWindow::proc(HWND w
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
148 command(LOWORD(wparam
), HIWORD(wparam
));
155 TabWindow::init(HWND w
)
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.
170 TabWindow::_is_checked(int id
)
172 return SendDlgItemMessage(_window
, id
, BM_GETCHECK
, 0, 0)
177 TabWindow::_set_check(int id
, BOOL onoff
)
179 SendDlgItemMessage(_window
, id
, BM_SETCHECK
,
180 onoff
? BST_CHECKED
: BST_UNCHECKED
, 0);