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