MCPcopy Create free account
hub / github.com/NetHack/NetHack / onMSNHCommand

Function onMSNHCommand

win/win32/mhmenu.c:532–725  ·  view source on GitHub ↗

-----------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

530}
531/*-----------------------------------------------------------------------------*/
532void
533onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
534{
535 PNHMenuWindow data;
536
537 data = (PNHMenuWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
538 switch (wParam) {
539 case MSNH_MSG_PUTSTR: {
540 PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam;
541 HWND text_view;
542 TCHAR wbuf[BUFSZ];
543 size_t text_size;
544 RECT text_rt;
545 HGDIOBJ saveFont;
546 HDC hdc;
547 TCHAR *was;
548
549 if (data->type != MENU_TYPE_TEXT)
550 SetMenuType(hWnd, MENU_TYPE_TEXT);
551
552 if (!data->menui.text.text) {
553 text_size = strlen(msg_data->text) + 4;
554 data->menui.text.text =
555 (TCHAR *) malloc(text_size * sizeof(data->menui.text.text[0]));
556 if (data->menui.text.text)
557 ZeroMemory(data->menui.text.text,
558 text_size * sizeof(data->menui.text.text[0]));
559 } else {
560 was = data->menui.text.text;
561
562 text_size = _tcslen(data->menui.text.text) + strlen(msg_data->text) + 4;
563 data->menui.text.text = (TCHAR *) realloc(
564 data->menui.text.text, text_size * sizeof(data->menui.text.text[0]));
565 if (!data->menui.text.text)
566 free(was); /* this is not a good situation, but not a leak either */
567 }
568 if (!data->menui.text.text)
569 break;
570
571 _tcscat(data->menui.text.text, NH_A2W(msg_data->text, wbuf, BUFSZ));
572 _tcscat(data->menui.text.text, TEXT("\r\n"));
573
574 text_view = GetDlgItem(hWnd, IDC_MENU_TEXT);
575 if (!text_view)
576 panic("cannot get text view window");
577 SetWindowText(text_view, data->menui.text.text);
578
579 /* calculate dimensions of the added line of text */
580 hdc = GetDC(text_view);
581 cached_font * font = mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE);
582 saveFont = SelectObject(hdc, font->hFont);
583 SetRect(&text_rt, 0, 0, 0, 0);
584 DrawTextA(hdc, msg_data->text, strlen(msg_data->text), &text_rt,
585 DT_CALCRECT | DT_TOP | DT_LEFT | DT_NOPREFIX
586 | DT_SINGLELINE);
587 data->menui.text.text_box_size.cx =
588 max(text_rt.right - text_rt.left, data->menui.text.text_box_size.cx);
589 data->menui.text.text_box_size.cy += text_rt.bottom - text_rt.top;

Callers 1

MenuWndProcFunction · 0.70

Calls 5

strNsubstFunction · 0.85
SetMenuTypeFunction · 0.70
mswin_get_fontFunction · 0.70
GetMenuControlFunction · 0.70
panicFunction · 0.50

Tested by

no test coverage detected