/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by UCHIYAMA Yasushi.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
switch(id) {
default:
break;
case IDC_BASE_MAIN:
menu._main = new MainTabWindow(*this, IDC_BASE_MAIN);
w = menu._main;
break;
case IDC_BASE_OPTION:
menu._option = new OptionTabWindow(*this, IDC_BASE_OPTION);
w = menu._option;
break;
case IDC_BASE_CONSOLE:
menu._console = new ConsoleTabWindow(*this, IDC_BASE_CONSOLE);
w = menu._console;
break;
}
if (w)
w->create(0);
return w;
}
//
// Main window
//
void
MainTabWindow::_insert_item(HWND w, TCHAR *name, int id)
{
int idx = SendDlgItemMessage(w, id, CB_ADDSTRING, 0,
reinterpret_cast <LPARAM>(name));
if (idx != CB_ERR)
SendDlgItemMessage(w, IDC_MAIN_DIR, CB_SETITEMDATA,
idx, _item_idx++);
}
if (_platmap == NULL) {
// can't sort, present in the order of definition
for (i = 0; entry = menu.platform_get(i); i++)
_insert_item(w, entry, IDC_MAIN_PLATFORM);
SendDlgItemMessage(w, IDC_MAIN_PLATFORM, CB_SETCURSEL,
menu.platform_default(), 0);
return;
}
for (i = 0, p = _platmap; i < nids; ++i, ++p) {
p->id = i;
p->name = menu.platform_get(i);
}
if (_filesave) {
if (_logfile == INVALID_HANDLE_VALUE && !_open_log_file()) {
_filesave = FALSE;
_set_check(IDC_CONS_FILESAVE, _filesave);
EnableWindow(_filename_edit, _filesave);
goto display;
}
DWORD cnt;
char c;
for (int i = 0; *buf != TEXT('\0'); buf++) {
c = *buf & 0x7f;
WriteFile(_logfile, &c, 1, &cnt, 0);
}
FlushFileBuffers(_logfile);
return;
}
display:
// count number of '\n'
for (cr = 0, p = buf; p = wcschr(p, TEXT('\n')); cr++, p++)
continue;
// total length of new buffer ('\n' -> "\r\n" + '\0')
size_t sz = (wcslen(buf) + cr + 1) * sizeof(TCHAR);
p = reinterpret_cast <TCHAR *>(malloc(sz));
if (p == NULL)
return;
// convert newlines
TCHAR *d = p;
while (*buf != TEXT('\0')) {
TCHAR c = *buf++;
if (c == TEXT('\n'))
*d++ = TEXT('\r');
*d++ = c;
}
*d = TEXT('\0');
// append the text and scroll
int end = Edit_GetTextLength(_edit);
Edit_SetSel(_edit, end, end);
Edit_ReplaceSel(_edit, p);
Edit_ScrollCaret(_edit);
UpdateWindow(_edit);
free(p);
}
void
ConsoleTabWindow::init(HWND w)
{
HDC hdc = GetDC(0);
int dpix = GetDeviceCaps(hdc, LOGPIXELSX);
int dpiy = GetDeviceCaps(hdc, LOGPIXELSY);
ReleaseDC(0, hdc);
// at this time _window is NULL.
// use argument of window procedure.
TabWindow::init(w);
_edit = GetDlgItem(w, IDC_CONS_EDIT);
MoveWindow(_edit, SCALEX(5), SCALEY(60),
SCALEX(UNSCALEX(_rect.right - _rect.left) - 10),
SCALEY(UNSCALEY(_rect.bottom - _rect.top) - 60), TRUE);
Edit_FmtLines(_edit, TRUE);