Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / hpcmips / stand / pbsdboot / layout.c
blobc2af806a296bbd4732bd4279a82e0a554bc9788e
1 /* $NetBSD: layout.c,v 1.1.1.1 1999/09/16 12:23:30 takemura Exp $ */
3 /*-
4 * Copyright (c) 1999 Shin Takemura.
5 * All rights reserved.
7 * This software is part of the PocketBSD.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the PocketBSD project
20 * and its contributors.
21 * 4. Neither the name of the project nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
38 #include <pbsdboot.h>
39 #include <commctrl.h>
40 #include <res/resource.h>
43 int
44 CreateMainWindow(HINSTANCE hInstance, HWND hWnd, LPCTSTR name, int cmdbar_height)
46 HRSRC res;
47 unsigned char *mem;
48 int i;
49 DLGTEMPLATE dlg;
50 DLGITEMTEMPLATE item;
51 RECT rect;
52 int ratio_x, ratio_y;
54 res = FindResource(hInstance, name, RT_DIALOG);
55 if (res == NULL) {
56 debug_printf(TEXT("error=%d\n"), GetLastError());
58 mem = (unsigned char*)LockResource(LoadResource(NULL, res));
61 * DLGTEMPLATE structure
63 dlg = *(DLGTEMPLATE*)mem;
64 mem += sizeof(DLGTEMPLATE);
66 GetClientRect(hWnd, &rect);
67 rect.top += cmdbar_height; /* get client rect w/o command bar */
68 ratio_x = (rect.right - rect.left) * 100 / dlg.cx;
69 ratio_y = (rect.bottom - rect.top) * 100 / dlg.cy;
72 * menu resource
74 if (*(WORD*)mem == 0xffff) {
75 /* predefined menu */
76 mem += sizeof(WORD);
77 debug_printf(TEXT("Dlg: menu=%04x\n"), *(WORD*)mem);
78 mem += sizeof(WORD);
79 } else
80 if (*(WORD*)mem == 0x0000) {
81 /* no menu */
82 mem += sizeof(WORD);
83 debug_printf(TEXT("Dlg: menu=none\n"));
84 } else {
85 /* menu resource name */
86 debug_printf(TEXT("Dlg: menu=%s\n"), (TCHAR*)mem);
87 while (*(WORD*)mem) { /* zero terminated */
88 mem += sizeof(WORD);
90 mem += sizeof(WORD);
94 * window class
96 if (*(WORD*)mem == 0xffff) {
97 /* predefined class */
98 mem += sizeof(WORD);
99 debug_printf(TEXT("Dlg: class=%04x\n"), *(WORD*)mem);
100 mem += sizeof(WORD);
101 } else
102 if (*(WORD*)mem == 0x0000) {
103 /* default class */
104 mem += sizeof(WORD);
105 debug_printf(TEXT("Dlg: class=none\n"));
106 } else {
107 /* class name */
108 debug_printf(TEXT("Dlg: class=%s\n"), (TCHAR*)mem);
109 while (*(WORD*)mem) { /* zero terminated */
110 mem += sizeof(WORD);
112 mem += sizeof(WORD);
116 * window title
118 debug_printf(TEXT("Dlg: title=%s\n"), (TCHAR*)mem);
119 while (*(WORD*)mem) { /* zero terminated */
120 mem += sizeof(WORD);
122 mem += sizeof(WORD);
124 if (dlg.style & DS_SETFONT) {
125 /* font size */
126 debug_printf(TEXT("Dlg: font size=%d\n"), *(WORD*)mem);
127 mem += sizeof(WORD);
128 /* font name */
129 debug_printf(TEXT("Dlg: font name=%s ("), (TCHAR*)mem);
130 while (*(WORD*)mem) { /* zero terminated */
131 debug_printf(TEXT("%04x"), *(WORD*)mem);
132 mem += sizeof(WORD);
134 debug_printf(TEXT(")\n"));
135 mem += sizeof(WORD);
139 * for each control
141 for (i = 0; i < dlg.cdit; i++) {
142 TCHAR *class_name = NULL;
143 TCHAR *window_text = NULL;
145 /* DWORD alignment */
146 if ((long)mem % sizeof(DWORD)) {
147 mem = (unsigned char*)(((long)mem / sizeof(DWORD) + 1) * sizeof(DWORD));
151 * DLGITEMTEMPLATE structure
153 item = *(DLGITEMTEMPLATE*)mem;
154 mem += sizeof(DLGITEMTEMPLATE);
157 * control class
159 if (*(WORD*)mem == 0xffff) {
160 /* predefined system class */
161 mem += sizeof(WORD);
162 switch (*(WORD*)mem) {
163 case 0x0080: class_name = TEXT("BUTTON"); break;
164 case 0x0081: class_name = TEXT("EDIT"); break;
165 case 0x0082: class_name = TEXT("STATIC"); break;
166 case 0x0083: class_name = TEXT("LISTBOX"); break;
167 case 0x0084: class_name = TEXT("SCROLLBAR"); break;
168 case 0x0085: class_name = TEXT("COMBOBOX"); break;
169 default:
170 debug_printf(TEXT("class=%04x "), *(WORD*)mem);
171 break;
173 mem += sizeof(WORD);
174 } else {
175 /* class name */
176 class_name = (TCHAR*)mem;
177 while (*(WORD*)mem) { /* zero terminated */
178 mem += sizeof(WORD);
180 mem += sizeof(WORD);
184 * window contents
186 if (*(WORD*)mem == 0xffff) {
187 /* resource */
188 mem += sizeof(WORD);
189 debug_printf(TEXT("contents=%04x "), *(WORD*)mem);
190 mem += sizeof(WORD);
191 } else {
192 /* text */
193 window_text = (TCHAR*)mem;
194 while (*(WORD*)mem) { /* zero terminated */
195 mem += sizeof(WORD);
197 mem += sizeof(WORD);
199 if (item.id == 0xffff) {
200 item.id = i + 1;
203 if (class_name) {
204 debug_printf(TEXT("Control: %04x "), item.id);
205 debug_printf(TEXT("class=%s "), class_name);
206 debug_printf(TEXT("contents=%s "),
207 window_text ? window_text : TEXT(""));
209 CreateWindowEx(
210 item.dwExtendedStyle,
211 class_name, // Class
212 window_text, // Title
213 item.style, // Style
214 item.x * ratio_x / 100,
215 item.y * ratio_y / 100 + cmdbar_height,
216 item.cx * ratio_x / 100,
217 item.cy * ratio_y / 100,
218 hWnd, // Parent handle
219 (HMENU)item.id, // Control ID
220 hInstance, // Instance handle
221 NULL); // Creation
224 #if 0
225 /* DWORD alignment */
226 if ((long)mem % sizeof(DWORD)) {
227 //mem = (unsigned char*)(((long)mem / sizeof(DWORD) + 1) * sizeof(DWORD));
229 #endif
232 * creation data
234 debug_printf(TEXT("data=0x%x bytes\n"), *(WORD*)mem);
235 mem += *(WORD*)mem;
236 mem += sizeof(WORD);
239 return (0);