1 /* -*-C++-*-	$NetBSD: tabwindow.cpp,v 1.2 2001/05/08 18:51:24 uch 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 //
85 // Child of TabControl(Dialog)
86 //
87 BOOL
88 TabWindow::create(LPCREATESTRUCT unused)
89 {
90 	_window = CreateDialogParam
91 	    (_app._instance, _name, _base._window,
92 		reinterpret_cast <DLGPROC>(Window::_dlg_proc),
93 		reinterpret_cast <LPARAM>(this));
94 
95 	return _window ? TRUE : FALSE;
96 }
97 
98 BOOL
99 TabWindow::proc(HWND w, UINT msg, WPARAM wparam, LPARAM lparam)
100 {
101 	switch(msg) {
102 	default:
103 		return FALSE;
104 	case WM_INITDIALOG:
105 		init(w);
106 		break;
107 	case WM_COMMAND:
108 		command(LOWORD(wparam), HIWORD(wparam));
109 		break;
110 	}
111 	return TRUE;
112 }
113 
114 void
115 TabWindow::init(HWND w)
116 {
117 	TC_ITEM item;
118 
119 	item.mask = TCIF_PARAM | TCIF_IMAGE;
120 	item.iImage =(int)_id;
121 	item.lParam = reinterpret_cast <LPARAM>(this);
122 	// register myself to parent tab-control.
123 	_base.insert(_id, item);
124 	// fit my dialog size to tab-control window.
125 	_base.adjust(_rect);
126 	hide();
127 }
128 
129 BOOL
130 TabWindow::_is_checked(int id)
131 {
132 	return SendDlgItemMessage(_window, id, BM_GETCHECK, 0, 0)
133 	    ? TRUE : FALSE;
134 }
135 
136 void
137 TabWindow::_set_check(int id, BOOL onoff)
138 {
139 	SendDlgItemMessage(_window, id, BM_SETCHECK,
140 	    onoff ? BST_CHECKED : BST_UNCHECKED, 0);
141 }
142