/* reset content and populate the list */
SendMessage(control_role, CB_RESETCONTENT, 0, 0);
for (i = 0; roles[i].name.m; i++) {
- if (ok_role(i, initrace, initgend, initalign)) {
- if (initgend>=0 && flags.female && roles[i].name.f)
- ind = SendMessage(control_role, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(roles[i].name.f, wbuf, sizeof(wbuf)) );
- else
- ind = SendMessage(control_role, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(roles[i].name.m, wbuf, sizeof(wbuf)) );
-
- SendMessage(control_role, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i );
- if( i==initrole ) {
- SendMessage(control_role, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 );
- valid_opt = 1;
- }
+ if (initgend>=0 && flags.female && roles[i].name.f)
+ ind = SendMessage(control_role, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(roles[i].name.f, wbuf, sizeof(wbuf)) );
+ else
+ ind = SendMessage(control_role, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(roles[i].name.m, wbuf, sizeof(wbuf)) );
+
+ SendMessage(control_role, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i );
+ if( i==initrole ) {
+ SendMessage(control_role, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 );
+ valid_opt = 1;
}
}
(GetNHApp()->bWindowsLocked? MF_CHECKED : MF_UNCHECKED)
);
+ CheckMenuItem(
+ GetMenu(hWnd),
+ IDM_SETTING_AUTOLAYOUT,
+ GetNHApp()->bAutoLayout? MF_CHECKED : MF_UNCHECKED
+ );
+
/* store handle to the mane menu in the application record */
GetNHApp()->hMainWnd = hWnd;
break;
mswin_select_map_mode(iflags.wc_map_mode);
child = GetNHApp()->windowlist[msg_param->wid].win;
- if( child ) mswin_layout_main_window(child);
} break;
}
SIZE msg_size;
POINT map_org;
SIZE map_size;
+ SIZE menu_size;
HWND wnd_status, wnd_msg;
PNHMainWindow data;
msg_size.cx = msg_size.cy = 0;
}
+ /* find all menu windows and calculate the size */
+ menu_size.cx = menu_size.cy = 0;
+ for( i=0; i<MAXWINDOWS; i++ ) {
+ SIZE tmp_size;
+ if( GetNHApp()->windowlist[i].win
+ && !GetNHApp()->windowlist[i].dead
+ && GetNHApp()->windowlist[i].type == NHW_MENU ) {
+ mswin_menu_window_size(GetNHApp()->windowlist[i].win , &tmp_size);
+ menu_size.cx = max(menu_size.cx, tmp_size.cx);
+ menu_size.cy = max(menu_size.cy, tmp_size.cy);
+ }
+ }
+
/* set window positions */
SetRect(&wnd_rect, client_rt.left, client_rt.top, client_rt.right, client_rt.bottom);
switch(iflags.wc_align_status) {
GetNHApp()->rtMsgWindow.right = msg_org.x + msg_size.cx;
GetNHApp()->rtMsgWindow.bottom = msg_org.y + msg_size.cy;
- GetNHApp()->rtMenuWindow.left = map_org.x + map_size.cx*2/3;
- GetNHApp()->rtMenuWindow.top = map_org.y;
- GetNHApp()->rtMenuWindow.right = map_org.x + map_size.cx;
- GetNHApp()->rtMenuWindow.bottom = map_org.y + map_size.cy;
+ /* map_width/4 < menu_width < map_width*2/3 */
+ GetNHApp()->rtMenuWindow.left = GetNHApp()->rtMapWindow.right - min(map_size.cx*2/3, max(map_size.cx/4, menu_size.cx));
+ GetNHApp()->rtMenuWindow.top = GetNHApp()->rtMapWindow.top;
+ GetNHApp()->rtMenuWindow.right = GetNHApp()->rtMapWindow.right;
+ GetNHApp()->rtMenuWindow.bottom = GetNHApp()->rtMapWindow.bottom;
GetNHApp()->rtInvenWindow.left = GetNHApp()->rtMenuWindow.left;
GetNHApp()->rtInvenWindow.top = GetNHApp()->rtMenuWindow.top;
);
}
}
+ if( IsWindow(changed_child) )
+ SetForegroundWindow(changed_child);
}
LRESULT onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
}
case IDM_SETTING_AUTOLAYOUT:
- GetNHApp()->bAutoLayout = TRUE;
+ GetNHApp()->bAutoLayout = !GetNHApp()->bAutoLayout;
mswin_layout_main_window(NULL);
- GetNHApp()->bAutoLayout = FALSE;
+
+ /* Update menu item check-mark */
+ CheckMenuItem(
+ GetMenu(GetNHApp()->hMainWnd),
+ IDM_SETTING_AUTOLAYOUT,
+ GetNHApp()->bAutoLayout? MF_CHECKED : MF_UNCHECKED
+ );
break;
case IDM_SETTING_LOCKWINDOWS:
CheckMenuItem(hMenu, IDM_NHMODE, MF_CHECKED);
else
CheckMenuItem(hMenu, IDM_NHMODE, MF_UNCHECKED);
-
}
void mswin_select_map_mode(int mode)
BOOL counting; /* counting flag */
char prompt[QBUFSZ]; /* menu prompt */
int tab_stop_size[NUMTABS];/* tabstops to align option values */
+ int menu_cx; /* menu width */
} menu;
struct menu_text {
TCHAR* text;
+ SIZE text_box_size;
} text;
};
int result;
case MSNH_MSG_PUTSTR:
{
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam;
- HWND text_view;
+ HWND text_view;
TCHAR wbuf[BUFSZ];
- size_t text_size;
+ size_t text_size;
+ RECT text_rt;
+ HGDIOBJ saveFont;
+ HDC hdc;
if( data->type!=MENU_TYPE_TEXT )
SetMenuType(hWnd, MENU_TYPE_TEXT);
text_view = GetDlgItem(hWnd, IDC_MENU_TEXT);
if( !text_view ) panic("cannot get text view window");
SetWindowText(text_view, data->text.text);
+
+ /* calculate dimensions of the added line of text */
+ hdc = GetDC(text_view);
+ saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE));
+ SetRect(&text_rt, 0, 0, 0, 0);
+ DrawText(hdc, msg_data->text, strlen(msg_data->text), &text_rt, DT_CALCRECT | DT_TOP | DT_LEFT | DT_NOPREFIX | DT_SINGLELINE);
+ data->text.text_box_size.cx = max(text_rt.right - text_rt.left, data->text.text_box_size.cx);
+ data->text.text_box_size.cy += text_rt.bottom - text_rt.top;
+ SelectObject(hdc, saveFont);
+ ReleaseDC(text_view, hdc);
} break;
case MSNH_MSG_STARTMENU:
HDC hDC;
int column;
HFONT saveFont;
+ LONG menuitemwidth = 0;
+ TEXTMETRIC tm;
if( data->type!=MENU_TYPE_MENU ) break;
if( strlen(msg_data->str)==0 ) break;
/* calculate tabstop size */
hDC = GetDC(hWnd);
saveFont = SelectObject(hDC, mswin_get_font(NHW_MENU, msg_data->attr, hDC, FALSE));
+ GetTextMetrics(hDC, &tm);
p1 = data->menu.items[new_item].str;
p = strchr(data->menu.items[new_item].str, '\t');
column = 0;
);
data->menu.tab_stop_size[column] =
max( data->menu.tab_stop_size[column], drawRect.right - drawRect.left );
+
+ menuitemwidth += data->menu.tab_stop_size[column];
+
if (p != NULL) *p = '\t';
else /* last string so, */ break;
+ /* add the separation only when not the last item */
+ /* in the last item, we break out of the loop, in the statement just above */
+ menuitemwidth += TAB_SEPARATION;
+
++column;
p1 = p + 1;
p = strchr(p1, '\t');
SelectObject(hDC, saveFont);
ReleaseDC(hWnd, hDC);
+ /* calculate new menu width */
+ data->menu.menu_cx = max(
+ data->menu.menu_cx,
+ 2*TILE_X + menuitemwidth + (tm.tmAveCharWidth+tm.tmOverhang)*12
+ );
+
/* increment size */
data->menu.size++;
} break;
/* get window coordinates */
GetClientRect(hWnd, &clrt );
-
// OK button
if( data->is_active ) {
GetWindowRect(menu_ok, &rt);
} else {
sz_elem.cy = (clrt.bottom - clrt.top) - 2*MENU_MARGIN;
}
+
+ if( data->type == MENU_TYPE_MENU ) {
+ ListView_SetColumnWidth(
+ GetMenuControl(hWnd),
+ 0,
+ max(clrt.right - clrt.left - GetSystemMetrics(SM_CXVSCROLL), data->menu.menu_cx )
+ );
+ }
+
MoveWindow(GetMenuControl(hWnd), pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE );
}
/*-----------------------------------------------------------------------------*/
RECT client_rt;
GetClientRect(lpdis->hwndItem, &client_rt);
- SetRect( &drawRect, client_rt.left, lpdis->rcItem.top, client_rt.right, lpdis->rcItem.bottom );
+ SetRect( &drawRect,
+ client_rt.left,
+ lpdis->rcItem.top,
+ client_rt.left + ListView_GetColumnWidth(lpdis->hwndItem, 0),
+ lpdis->rcItem.bottom );
DrawFocusRect(lpdis->hDC, &drawRect);
}
/*-----------------------------------------------------------------------------*/
void mswin_menu_window_size (HWND hWnd, LPSIZE sz)
{
- TEXTMETRIC tm;
HWND control;
- HGDIOBJ saveFont;
- HDC hdc;
PNHMenuWindow data;
- int i;
RECT rt, wrt;
int extra_cx;
- GetClientRect(hWnd, &rt);
- sz->cx = rt.right - rt.left;
- sz->cy = rt.bottom - rt.top;
-
- GetWindowRect(hWnd, &wrt);
- extra_cx = (wrt.right-wrt.left) - sz->cx;
-
data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA);
if(data) {
control = GetMenuControl(hWnd);
- hdc = GetDC(control);
- if( data->type==MENU_TYPE_MENU ) {
- /* Calculate the width of the list box. */
- saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE));
- GetTextMetrics(hdc, &tm);
- for(i=0; i<data->menu.size; i++ ) {
- LONG menuitemwidth = 0;
- int column;
- char *p, *p1;
-
- p1 = data->menu.items[i].str;
- p = strchr(data->menu.items[i].str, '\t');
- column = 0;
- for (;;) {
- TCHAR wbuf[BUFSZ];
- RECT tabRect;
- SetRect ( &tabRect, 0, 0, 1, 1 );
- if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */
- DrawText(hdc,
- NH_A2W(p1, wbuf, BUFSZ),
- strlen(p1),
- &tabRect,
- DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE
- );
- /* it probably isn't necessary to recompute the tab width now, but do so
- * just in case, honoring the previously computed value
- */
- menuitemwidth += max(data->menu.tab_stop_size[column],
- tabRect.right - tabRect.left);
- if (p != NULL) *p = '\t';
- else /* last string so, */ break;
- /* add the separation only when not the last item */
- /* in the last item, we break out of the loop, in the statement just above */
- menuitemwidth += TAB_SEPARATION;
- ++column;
- p1 = p + 1;
- p = strchr(p1, '\t');
- }
+ /* get the control size */
+ GetClientRect(control, &rt);
+ sz->cx = rt.right - rt.left;
+ sz->cy = rt.bottom - rt.top;
- sz->cx = max(sz->cx,
- (LONG)(2*TILE_X + menuitemwidth + tm.tmAveCharWidth*12 + tm.tmOverhang));
- }
- SelectObject(hdc, saveFont);
+ /* calculate "extra" space around the control */
+ GetWindowRect(hWnd, &wrt);
+ extra_cx = (wrt.right-wrt.left) - sz->cx;
+
+ if( data->type==MENU_TYPE_MENU ) {
+ sz->cx = max(sz->cx, data->menu.menu_cx + GetSystemMetrics(SM_CXVSCROLL) );
} else {
- /* Calculate the width of the text box. */
- RECT text_rt;
- saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE));
- GetTextMetrics(hdc, &tm);
- SetRect(&text_rt, 0, 0, sz->cx, sz->cy);
- DrawText(hdc, data->text.text, _tcslen(data->text.text), &text_rt, DT_CALCRECT | DT_TOP | DT_LEFT | DT_NOPREFIX);
- sz->cx = max(sz->cx, text_rt.right - text_rt.left + 5*tm.tmAveCharWidth + tm.tmOverhang);
- SelectObject(hdc, saveFont);
+ /* Use the width of the text box */
+ sz->cx = max( sz->cx, data->text.text_box_size.cx + 2*GetSystemMetrics(SM_CXVSCROLL));
}
sz->cx += extra_cx;
-
- ReleaseDC(control, hdc);
+ } else {
+ /* uninitilized window */
+ GetClientRect(hWnd, &rt);
+ sz->cx = rt.right - rt.left;
+ sz->cy = rt.bottom - rt.top;
}
}
/*-----------------------------------------------------------------------------*/