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