void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { PNHRIPWindow data; static int InRipText = 1; data = (PNHRIPWindow)GetWindowLong(hWnd, GWL_USERDATA); switch( wParam ) { case MSNH_MSG_PUTSTR: { PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam; TCHAR wbuf[BUFSZ]; size_t text_size; if( !data->window_text ) { text_size = strlen(msg_data->text) + 4; data->window_text = (TCHAR*)malloc(text_size*sizeof(data->window_text[0])); ZeroMemory(data->window_text, text_size*sizeof(data->window_text[0])); } else { text_size = _tcslen(data->window_text) + strlen(msg_data->text) + 4; data->window_text = (TCHAR*)realloc(data->window_text, text_size*sizeof(data->window_text[0])); } if( !data->window_text ) break; _tcscat(data->window_text, NH_A2W(msg_data->text, wbuf, BUFSZ)); _tcscat(data->window_text, TEXT("\r\n")); break; } case MSNH_MSG_DIED: { data->rip_text = data->window_text; data->window_text = NULL; break; } } }
// Mesage handler for about box. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { char buf[BUFSZ]; TCHAR wbuf[NHSTR_BUFSIZE]; RECT main_rt, dlg_rt; SIZE dlg_sz; switch (message) { case WM_INITDIALOG: getversionstring(buf); SetDlgItemText(hDlg, IDC_ABOUT_VERSION, NH_A2W(buf, wbuf, NHSTR_BUFSIZE)); SetDlgItemText(hDlg, IDC_ABOUT_COPYRIGHT, NH_A2W(COPYRIGHT_BANNER_A "\n" COPYRIGHT_BANNER_B "\n" COPYRIGHT_BANNER_C "\n" COPYRIGHT_BANNER_D, wbuf, NHSTR_BUFSIZE)); /* center dialog in the main window */ GetWindowRect(GetNHApp()->hMainWnd, &main_rt); GetWindowRect(hDlg, &dlg_rt); dlg_sz.cx = dlg_rt.right - dlg_rt.left; dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; dlg_rt.left = (main_rt.left + main_rt.right - dlg_sz.cx) / 2; dlg_rt.right = dlg_rt.left + dlg_sz.cx; dlg_rt.top = (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2; dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; MoveWindow(hDlg, (main_rt.left + main_rt.right - dlg_sz.cx) / 2, (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2, dlg_sz.cx, dlg_sz.cy, TRUE); return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; } return FALSE; }
void mswin_init_splashfonts(HWND hWnd) { HDC hdc = GetDC(hWnd); LOGFONT lgfnt; ZeroMemory( &lgfnt, sizeof(lgfnt) ); lgfnt.lfHeight = -80; // height of font lgfnt.lfWidth = 0; // average character width lgfnt.lfEscapement = 0; // angle of escapement lgfnt.lfOrientation = 0; // base-line orientation angle lgfnt.lfWeight = FW_BOLD; // font weight lgfnt.lfItalic = FALSE; // italic attribute option lgfnt.lfUnderline = FALSE; // underline attribute option lgfnt.lfStrikeOut = FALSE; // strikeout attribute option lgfnt.lfCharSet = ANSI_CHARSET; // character set identifier lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision lgfnt.lfQuality = DEFAULT_QUALITY; // output quality lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family NH_A2W( "Times New Roman", lgfnt.lfFaceName, LF_FACESIZE); version_splash_font = CreateFontIndirect(&lgfnt); ReleaseDC(hWnd, hdc); }
/* on WM_PAINT */ void onPaint(HWND hWnd) { PNHMapWindow data; PAINTSTRUCT ps; HDC hDC; HDC tileDC; HGDIOBJ saveBmp; RECT paint_rt; int i, j; /* get window data */ data = (PNHMapWindow) GetWindowLong(hWnd, GWL_USERDATA); hDC = BeginPaint(hWnd, &ps); /* calculate paint rectangle */ if (!IsRectEmpty(&ps.rcPaint)) { /* calculate paint rectangle */ paint_rt.left = max(data->xPos + (ps.rcPaint.left - data->map_orig.x) / data->xScrTile, 0); paint_rt.top = max( data->yPos + (ps.rcPaint.top - data->map_orig.y) / data->yScrTile, 0); paint_rt.right = min( data->xPos + (ps.rcPaint.right - data->map_orig.x) / data->xScrTile + 1, COLNO); paint_rt.bottom = min( data->yPos + (ps.rcPaint.bottom - data->map_orig.y) / data->yScrTile + 1, ROWNO); if (data->bAsciiMode || Is_rogue_level(&u.uz)) { /* You enter a VERY primitive world! */ HGDIOBJ oldFont; oldFont = SelectObject(hDC, data->hMapFont); SetBkMode(hDC, TRANSPARENT); /* draw the map */ for (i = paint_rt.left; i < paint_rt.right; i++) for (j = paint_rt.top; j < paint_rt.bottom; j++) if (data->map[i][j] >= 0) { char ch; TCHAR wch; RECT glyph_rect; int color; unsigned special; int mgch; HBRUSH back_brush; COLORREF OldFg; nhcoord2display(data, i, j, &glyph_rect); #if (VERSION_MAJOR < 4) && (VERSION_MINOR < 4) && (PATCHLEVEL < 2) nhglyph2charcolor(data->map[i][j], &ch, &color); OldFg = SetTextColor(hDC, nhcolor_to_RGB(color)); #else /* rely on NetHack core helper routine */ (void) mapglyph(data->map[i][j], &mgch, &color, &special, i, j); ch = (char) mgch; if (((special & MG_PET) && iflags.hilite_pet) || ((special & MG_DETECT) && iflags.use_inverse)) { back_brush = CreateSolidBrush(nhcolor_to_RGB(CLR_GRAY)); FillRect(hDC, &glyph_rect, back_brush); DeleteObject(back_brush); switch (color) { case CLR_GRAY: case CLR_WHITE: OldFg = SetTextColor( hDC, nhcolor_to_RGB(CLR_BLACK)); break; default: OldFg = SetTextColor(hDC, nhcolor_to_RGB(color)); } } else { OldFg = SetTextColor(hDC, nhcolor_to_RGB(color)); } #endif DrawText(hDC, NH_A2W(&ch, &wch, 1), 1, &glyph_rect, DT_CENTER | DT_VCENTER | DT_NOPREFIX); SetTextColor(hDC, OldFg); } SelectObject(hDC, oldFont); } else { /* prepare tiles DC for mapping */ tileDC = CreateCompatibleDC(hDC); saveBmp = SelectObject(tileDC, GetNHApp()->bmpMapTiles); /* draw the map */ for (i = paint_rt.left; i < paint_rt.right; i++) for (j = paint_rt.top; j < paint_rt.bottom; j++) if (data->map[i][j] >= 0) { short ntile; int t_x, t_y; RECT glyph_rect; ntile = glyph2tile[data->map[i][j]]; t_x = (ntile % GetNHApp()->mapTilesPerLine) * GetNHApp()->mapTile_X; t_y = (ntile / GetNHApp()->mapTilesPerLine) * GetNHApp()->mapTile_Y; nhcoord2display(data, i, j, &glyph_rect); StretchBlt(hDC, glyph_rect.left, glyph_rect.top, data->xScrTile, data->yScrTile, tileDC, t_x, t_y, GetNHApp()->mapTile_X, GetNHApp()->mapTile_Y, SRCCOPY); if (glyph_is_pet(data->map[i][j]) && iflags.wc_hilite_pet) { /* apply pet mark transparently over pet image */ HDC hdcPetMark; HBITMAP bmPetMarkOld; /* this is DC for petmark bitmap */ hdcPetMark = CreateCompatibleDC(hDC); bmPetMarkOld = SelectObject( hdcPetMark, GetNHApp()->bmpPetMark); nhapply_image_transparent( hDC, glyph_rect.left, glyph_rect.top, data->xScrTile, data->yScrTile, hdcPetMark, 0, 0, TILE_X, TILE_Y, TILE_BK_COLOR); SelectObject(hdcPetMark, bmPetMarkOld); DeleteDC(hdcPetMark); } } SelectObject(tileDC, saveBmp); DeleteDC(tileDC); } /* draw focus rect */ nhcoord2display(data, data->xCur, data->yCur, &paint_rt); if (data->bAsciiMode) { PatBlt(hDC, paint_rt.left, paint_rt.top, paint_rt.right - paint_rt.left, paint_rt.bottom - paint_rt.top, DSTINVERT); } else { DrawFocusRect(hDC, &paint_rt); } } EndPaint(hWnd, &ps); }
LRESULT CALLBACK StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { RECT rt; PAINTSTRUCT ps; HDC hdc; PNHStatusWindow data; data = (PNHStatusWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA); switch (message) { case WM_MSNH_COMMAND: { switch( wParam ) { case MSNH_MSG_PUTSTR: { PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam; strncpy(data->window_text[data->index], msg_data->text, MAXWINDOWTEXT); strncat(data->window_text[data->index], "\n", MAXWINDOWTEXT-strlen(data->window_text[data->index])); data->index = (data->index+1) % NHSW_LINES; InvalidateRect(hWnd, NULL, TRUE); break; } case MSNH_MSG_CLEAR_WINDOW: data->index = 0; ZeroMemory(data->window_text, sizeof(data->window_text)); InvalidateRect(hWnd, NULL, TRUE); break; } } break; case WM_PAINT: { int i; SIZE sz; HGDIOBJ oldFont; TCHAR wbuf[BUFSZ]; COLORREF OldBg, OldFg; hdc = BeginPaint(hWnd, &ps); GetClientRect(hWnd, &rt); oldFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE)); OldBg = SetBkColor(hdc, status_bg_brush ? status_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_STATUS)); OldFg = SetTextColor(hdc, status_fg_brush ? status_fg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_FG_STATUS)); for(i=0; i<NHSW_LINES; i++ ) { GetTextExtentPoint32(hdc, NH_A2W(data->window_text[i], wbuf, sizeof(wbuf)), strlen(data->window_text[i]), &sz); NH_A2W(data->window_text[i], wbuf, BUFSZ); DrawText(hdc, wbuf, strlen(data->window_text[i]), &rt, DT_LEFT | DT_END_ELLIPSIS); rt.top += sz.cy; } SelectObject(hdc, oldFont); SetTextColor (hdc, OldFg); SetBkColor (hdc, OldBg); EndPaint(hWnd, &ps); } break; case WM_DESTROY: free(data); SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)0); break; case WM_SETFOCUS: SetFocus(GetNHApp()->hMainWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
LRESULT CALLBACK StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { RECT rt; PAINTSTRUCT ps; HDC hdc; PNHStatusWindow data; data = (PNHStatusWindow) GetWindowLong(hWnd, GWL_USERDATA); switch (message) { case WM_MSNH_COMMAND: { switch (wParam) { case MSNH_MSG_PUTSTR: case MSNH_MSG_CLEAR_WINDOW: ZeroMemory(data->window_text, sizeof(data->window_text)); FormatStatusString(data->window_text, data->nhstat_format); break; case MSNH_MSG_CURSOR: { PMSNHMsgCursor msg_data = (PMSNHMsgCursor) lParam; if (msg_data->y == 0) { InvalidateRect(hWnd, NULL, TRUE); } } break; } } break; case WM_PAINT: { HGDIOBJ oldFont; TCHAR wbuf[MAXWINDOWTEXT]; COLORREF OldBg, OldFg; hdc = BeginPaint(hWnd, &ps); GetClientRect(hWnd, &rt); oldFont = SelectObject( hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE)); OldBg = SetBkColor(hdc, mswin_get_color(NHW_STATUS, MSWIN_COLOR_BG)); OldFg = SetTextColor(hdc, mswin_get_color(NHW_STATUS, MSWIN_COLOR_FG)); DrawText(hdc, NH_A2W(data->window_text, wbuf, MAXWINDOWTEXT), strlen(data->window_text), &rt, DT_LEFT | DT_NOPREFIX); SetTextColor(hdc, OldFg); SetBkColor(hdc, OldBg); SelectObject(hdc, oldFont); EndPaint(hWnd, &ps); } break; case WM_DESTROY: free(data); SetWindowLong(hWnd, GWL_USERDATA, (LONG) 0); break; case WM_SETFOCUS: SetFocus(GetNHApp()->hMainWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
/*-------------------------------------------------------------------------*/ void LayoutCmdWindow(HWND hWnd) { RECT clrt; SIZE windowSize; PNHCmdWindow data; int i, j; int x, y; LOGFONT lgfnt; int index; GetClientRect(hWnd, &clrt); if( IsRectEmpty(&clrt) ) return; data = (PNHCmdWindow)GetWindowLong(hWnd, GWL_USERDATA); if( !data->layout_current ) return; /* calculate cell size */ windowSize.cx = clrt.right-clrt.left; windowSize.cy = clrt.bottom-clrt.top; CalculateCellSize(hWnd, &data->cell_size, &windowSize); /* initialize display cells aray */ x = 0; y = 0; for( i=0, index=0; i<nhcmdlayout_rows(data->layout_current); i++ ) { for( j=0; j<nhcmdlayout_columns(data->layout_current); j++, index++ ) { data->cells[index].orig.x = x; data->cells[index].orig.y = y; data->cells[index].type = nhcmdlayout_cell_direct(data->layout_current, index)->type; switch(data->cells[index].type) { case NH_CELL_CTRL: data->cells[index].state = data->is_ctrl? NH_CST_CHECKED : 0; break; case NH_CELL_CAP: data->cells[index].state = data->is_caps? NH_CST_CHECKED : 0; break; case NH_CELL_SHIFT: data->cells[index].state = data->is_shift? NH_CST_CHECKED : 0; break; default: data->cells[index].state = 0; } x += data->cell_size.cx * nhcmdlayout_cell_direct(data->layout_current, index)->mult; } x = 0; y += data->cell_size.cy; } /* create font for display cell text */ for(i=0; i<=NH_CMDPAD_FONT_MAX; i++ ) if( data->font[i] ) DeleteObject(data->font[i]); ZeroMemory( &lgfnt, sizeof(lgfnt) ); lgfnt.lfHeight = data->cell_size.cy; // height of font lgfnt.lfWidth = 0; // average character width lgfnt.lfEscapement = 0; // angle of escapement lgfnt.lfOrientation = 0; // base-line orientation angle lgfnt.lfWeight = FW_NORMAL; // font weight lgfnt.lfItalic = FALSE; // italic attribute option lgfnt.lfUnderline = FALSE; // underline attribute option lgfnt.lfStrikeOut = FALSE; // strikeout attribute option /*JP lgfnt.lfCharSet = ANSI_CHARSET; // character set identifier */ lgfnt.lfCharSet = SHIFTJIS_CHARSET; // character set identifier lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision lgfnt.lfClipPrecision = CLIP_CHARACTER_PRECIS; // clipping precision lgfnt.lfQuality = DEFAULT_QUALITY; // output quality if( iflags.wc_font_message && *iflags.wc_font_message ) { lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family NH_A2W( iflags.wc_font_message, lgfnt.lfFaceName, LF_FACESIZE); } else { lgfnt.lfPitchAndFamily = VARIABLE_PITCH; // pitch and family } data->font[NH_CMDPAD_FONT_NORMAL] = CreateFontIndirect(&lgfnt); InvalidateRect(hWnd, NULL, TRUE); }
/* initialize player selector dialog */ void plselInitDialog(HWND hWnd) { TCHAR wbuf[BUFSZ]; /* set player name */ SetDlgItemText(hWnd, IDC_PLSEL_NAME, NH_A2W(plname, wbuf, sizeof(wbuf))); /* check flags for consistency */ if (flags.initrole >= 0) { if (flags.initrace >= 0 && !validrace(flags.initrole, flags.initrace)) { flags.initrace = ROLE_NONE; } if (flags.initgend >= 0 && !validgend(flags.initrole, flags.initrace, flags.initgend)) { flags.initgend = ROLE_NONE; } if (flags.initalign >= 0 && !validalign(flags.initrole, flags.initrace, flags.initalign)) { flags.initalign = ROLE_NONE; } } /* populate select boxes */ plselAdjustLists(hWnd, -1); /* intialize roles list */ if (flags.initrole < 0 || !ok_role(flags.initrole, ROLE_NONE, ROLE_NONE, ROLE_NONE)) { CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_CHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), FALSE); } else { CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_UNCHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), TRUE); setComboBoxValue(hWnd, IDC_PLSEL_ROLE_LIST, flags.initrole); } /* intialize races list */ if (flags.initrace < 0 || !ok_race(flags.initrole, flags.initrace, ROLE_NONE, ROLE_NONE)) { CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_CHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), FALSE); } else { CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_UNCHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), TRUE); setComboBoxValue(hWnd, IDC_PLSEL_RACE_LIST, flags.initrace); } /* intialize genders list */ if (flags.initgend < 0 || !ok_gend(flags.initrole, flags.initrace, flags.initgend, ROLE_NONE)) { CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_CHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), FALSE); } else { CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_UNCHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), TRUE); setComboBoxValue(hWnd, IDC_PLSEL_GENDER_LIST, flags.initgend); } /* intialize alignments list */ if (flags.initalign < 0 || !ok_align(flags.initrole, flags.initrace, flags.initgend, flags.initalign)) { CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_CHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), FALSE); } else { CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_UNCHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), TRUE); setComboBoxValue(hWnd, IDC_PLSEL_ALIGN_LIST, flags.initalign); } }
void SetMenuListType(HWND hWnd, int how) { PNHMenuWindow data; RECT rt; DWORD dwStyles; char buf[BUFSZ]; TCHAR wbuf[BUFSZ]; int nItem; int i; HWND control; LVCOLUMN lvcol; LRESULT fnt; SIZE wnd_size; data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); if( data->type != MENU_TYPE_MENU ) return; data->how = how; switch(how) { case PICK_NONE: dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD | WS_VSCROLL | WS_HSCROLL | LVS_REPORT | LVS_OWNERDRAWFIXED | LVS_SINGLESEL; break; case PICK_ONE: dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD | WS_VSCROLL | WS_HSCROLL | LVS_REPORT | LVS_OWNERDRAWFIXED | LVS_SINGLESEL; break; case PICK_ANY: dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD | WS_VSCROLL | WS_HSCROLL | LVS_REPORT | LVS_OWNERDRAWFIXED | LVS_SINGLESEL; break; default: panic("how should be one of PICK_NONE, PICK_ONE or PICK_ANY"); }; if( strlen(data->menu.prompt)==0 ) { dwStyles |= LVS_NOCOLUMNHEADER ; } GetWindowRect(GetDlgItem(hWnd, IDC_MENU_LIST), &rt); DestroyWindow(GetDlgItem(hWnd, IDC_MENU_LIST)); control = CreateWindow(WC_LISTVIEW, NULL, dwStyles, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, hWnd, (HMENU)IDC_MENU_LIST, GetNHApp()->hApp, NULL ); if( !control ) panic( "cannot create menu control" ); /* install the hook for the control window procedure */ wndProcListViewOrig = (WNDPROC)GetWindowLong(control, GWL_WNDPROC); SetWindowLong(control, GWL_WNDPROC, (LONG)NHMenuListWndProc); /* set control font */ fnt = SendMessage(hWnd, WM_GETFONT, (WPARAM)0, (LPARAM)0); SendMessage(control, WM_SETFONT, (WPARAM)fnt, (LPARAM)0); /* set control colors */ ListView_SetBkColor(control, mswin_get_color(NHW_MENU, MSWIN_COLOR_BG)); ListView_SetTextBkColor(control, mswin_get_color(NHW_MENU, MSWIN_COLOR_BG)); ListView_SetTextColor(control, mswin_get_color(NHW_MENU, MSWIN_COLOR_FG)); /* add column to the list view */ mswin_menu_window_size(hWnd, &wnd_size); ZeroMemory(&lvcol, sizeof(lvcol)); lvcol.mask = LVCF_WIDTH | LVCF_TEXT; lvcol.cx = max( wnd_size.cx, GetSystemMetrics(SM_CXSCREEN)); lvcol.pszText = NH_A2W(data->menu.prompt, wbuf, BUFSZ); ListView_InsertColumn(control, 0, &lvcol); /* add items to the list view */ for(i=0; i<data->menu.size; i++ ) { LVITEM lvitem; ZeroMemory( &lvitem, sizeof(lvitem) ); sprintf(buf, "%c - %s", max(data->menu.items[i].accelerator, ' '), data->menu.items[i].str ); lvitem.mask = LVIF_PARAM | LVIF_STATE | LVIF_TEXT; lvitem.iItem = i; lvitem.iSubItem = 0; lvitem.state = data->menu.items[i].presel? LVIS_SELECTED : 0; lvitem.pszText = NH_A2W(buf, wbuf, BUFSZ); lvitem.lParam = (LPARAM)&data->menu.items[i]; nItem = SendMessage(control, LB_ADDSTRING, (WPARAM)0, (LPARAM) buf); if( ListView_InsertItem(control, &lvitem)==-1 ) { panic("cannot insert menu item"); } } SetFocus(control); }
void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { PNHMenuWindow data; data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); switch( wParam ) { case MSNH_MSG_PUTSTR: { PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam; HWND text_view; if( data->type!=MENU_TYPE_TEXT ) SetMenuType(hWnd, MENU_TYPE_TEXT); if( !data->text.text ) { data->text.text = mswin_init_text_buffer( program_state.gameover? FALSE : GetNHApp()->bWrapText ); if( !data->text.text ) break; } mswin_add_text(data->text.text, msg_data->attr, msg_data->text); text_view = GetDlgItem(hWnd, IDC_MENU_TEXT); if( !text_view ) panic("cannot get text view window"); mswin_render_text(data->text.text, text_view); } break; case MSNH_MSG_STARTMENU: { int i; if( data->type!=MENU_TYPE_MENU ) SetMenuType(hWnd, MENU_TYPE_MENU); if( data->menu.items ) free(data->menu.items); data->how = PICK_NONE; data->menu.items = NULL; data->menu.size = 0; data->menu.allocated = 0; data->done = 0; data->result = 0; for (i = 0; i < NUMTABS; ++i) data->menu.tab_stop_size[i] = MIN_TABSTOP_SIZE; } break; case MSNH_MSG_ADDMENU: { PMSNHMsgAddMenu msg_data = (PMSNHMsgAddMenu)lParam; char *p, *p1; int new_item; HDC hDC; int column; HFONT saveFont; if( data->type!=MENU_TYPE_MENU ) break; if( strlen(msg_data->str)==0 ) break; if( data->menu.size==data->menu.allocated ) { data->menu.allocated += 10; data->menu.items = (PNHMenuItem)realloc(data->menu.items, data->menu.allocated*sizeof(NHMenuItem)); } new_item = data->menu.size; ZeroMemory( &data->menu.items[new_item], sizeof(data->menu.items[new_item])); data->menu.items[new_item].glyph = msg_data->glyph; data->menu.items[new_item].identifier = *msg_data->identifier; data->menu.items[new_item].accelerator = msg_data->accelerator; data->menu.items[new_item].group_accel = msg_data->group_accel; data->menu.items[new_item].attr = msg_data->attr; parse_menu_str(data->menu.items[new_item].str, msg_data->str, NHMENU_STR_SIZE); data->menu.items[new_item].presel = msg_data->presel; /* calculate tabstop size */ p = strchr(data->menu.items[new_item].str, '\t'); if( p ) { data->menu.items[new_item].has_tab = TRUE; hDC = GetDC(hWnd); saveFont = SelectObject(hDC, mswin_get_font(NHW_MENU, msg_data->attr, hDC, FALSE)); p1 = data->menu.items[new_item].str; column = 0; for (;;) { TCHAR wbuf[BUFSZ]; RECT drawRect; SetRect ( &drawRect, 0, 0, 1, 1 ); if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */ DrawText(hDC, NH_A2W(p1, wbuf, BUFSZ), /*JP strlen(p1), */ -1, &drawRect, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_EXPANDTABS | DT_SINGLELINE ); data->menu.tab_stop_size[column] = max( data->menu.tab_stop_size[column], drawRect.right - drawRect.left ); if (p != NULL) *p = '\t'; else /* last string so, */ break; ++column; p1 = p + 1; p = strchr(p1, '\t'); } SelectObject(hDC, saveFont); ReleaseDC(hWnd, hDC); } else { data->menu.items[new_item].has_tab = FALSE; } /* increment size */ data->menu.size++; } break; case MSNH_MSG_ENDMENU: { PMSNHMsgEndMenu msg_data = (PMSNHMsgEndMenu)lParam; if( msg_data->text ) { strncpy( data->menu.prompt, msg_data->text, sizeof(data->menu.prompt)-1 ); } else { ZeroMemory(data->menu.prompt, sizeof(data->menu.prompt)); } } break; } /* end switch */ }
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), /*JP strlen(p1), */ -1, &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'); } sz->cx = max(sz->cx, (LONG)(2*TILE_X + menuitemwidth + tm.tmAveCharWidth*12 + tm.tmOverhang)); } SelectObject(hdc, saveFont); } else { /* do not change size for text output - the text will be formatted to fit any window */ } sz->cx += extra_cx; ReleaseDC(control, hdc); } }
void getlock() { const char *fq_lock; char tbuf[BUFSZ]; TCHAR wbuf[BUFSZ]; HANDLE f; int fd; int choice; /* regularize(lock); */ /* already done in pcmain */ Sprintf(tbuf, "%s", fqname(lock, LEVELPREFIX, 0)); set_levelfile_name(lock, 0); fq_lock = fqname(lock, LEVELPREFIX, 1); f = CreateFile( NH_A2W(fq_lock, wbuf, BUFSZ), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if( f==INVALID_HANDLE_VALUE ) { if(GetLastError()==ERROR_FILE_NOT_FOUND) goto gotlock; /* no such file */ error("Cannot open %s", fq_lock); } CloseHandle(f); /* prompt user that the game alredy exist */ choice = MessageBox( GetNHApp()->hMainWnd, TEXT("There are files from a game in progress under your name. Recover?"), TEXT("Nethack"), MB_YESNO | MB_DEFBUTTON1 ); switch(choice) { case IDYES: if(recover_savefile()) { goto gotlock; } else { error("Couldn't recover old game."); } break; case IDNO: unlock_file(HLOCK); error("%s", "Cannot start a new game."); break; }; gotlock: fd = creat(fq_lock, FCMASK); if(fd == -1) { error("cannot creat lock file (%s.)", fq_lock); } else { if(write(fd, (char *) &hackpid, sizeof(hackpid)) != sizeof(hackpid)){ error("cannot write lock (%s)", fq_lock); } if(close(fd) == -1) { error("cannot close lock (%s)", fq_lock); } } }
/* adjust role/race/alignment/gender list - filter out invalid combinations changed_sel points to the list where selection occurred (-1 if unknown) */ void plselAdjustLists(HWND hWnd, int changed_sel) { HWND control_role, control_race, control_gender, control_align; int initrole, initrace, initgend, initalign; int i; int ind; int valid_opt; TCHAR wbuf[255]; /* get control handles */ control_role = GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST); control_race = GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST); control_gender = GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST); control_align = GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST); /* get current selections */ ind = SendMessage(control_role, CB_GETCURSEL, 0, 0); initrole = (ind == LB_ERR) ? flags.initrole : SendMessage(control_role, CB_GETITEMDATA, ind, 0); ind = SendMessage(control_race, CB_GETCURSEL, 0, 0); initrace = (ind == LB_ERR) ? flags.initrace : SendMessage(control_race, CB_GETITEMDATA, ind, 0); ind = SendMessage(control_gender, CB_GETCURSEL, 0, 0); initgend = (ind == LB_ERR) ? flags.initgend : SendMessage(control_gender, CB_GETITEMDATA, ind, 0); ind = SendMessage(control_align, CB_GETCURSEL, 0, 0); initalign = (ind == LB_ERR) ? flags.initalign : SendMessage(control_align, CB_GETITEMDATA, ind, 0); /* intialize roles list */ if (changed_sel == -1) { valid_opt = 0; /* 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; } } } /* set selection to the previously selected role if it is still valid */ if (!valid_opt) { initrole = ROLE_NONE; initrace = ROLE_NONE; initgend = ROLE_NONE; initalign = ROLE_NONE; SendMessage(control_role, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); } /* trigger change of the races list */ changed_sel = IDC_PLSEL_ROLE_LIST; } /* intialize races list */ if (changed_sel == IDC_PLSEL_ROLE_LIST) { valid_opt = 0; /* reset content and populate the list */ SendMessage(control_race, CB_RESETCONTENT, 0, 0); for (i = 0; races[i].noun; i++) if (ok_race(initrole, i, ROLE_NONE, ROLE_NONE)) { ind = SendMessage( control_race, CB_ADDSTRING, (WPARAM) 0, (LPARAM) NH_A2W(races[i].noun, wbuf, sizeof(wbuf))); SendMessage(control_race, CB_SETITEMDATA, (WPARAM) ind, (LPARAM) i); if (i == initrace) { SendMessage(control_race, CB_SETCURSEL, (WPARAM) ind, (LPARAM) 0); valid_opt = 1; } } /* set selection to the previously selected race if it is still valid */ if (!valid_opt) { initrace = ROLE_NONE; initgend = ROLE_NONE; initalign = ROLE_NONE; SendMessage(control_race, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); } /* trigger change of the genders list */ changed_sel = IDC_PLSEL_RACE_LIST; } /* intialize genders list */ if (changed_sel == IDC_PLSEL_RACE_LIST) { valid_opt = 0; /* reset content and populate the list */ SendMessage(control_gender, CB_RESETCONTENT, 0, 0); for (i = 0; i < ROLE_GENDERS; i++) if (ok_gend(initrole, initrace, i, ROLE_NONE)) { ind = SendMessage( control_gender, CB_ADDSTRING, (WPARAM) 0, (LPARAM) NH_A2W(genders[i].adj, wbuf, sizeof(wbuf))); SendMessage(control_gender, CB_SETITEMDATA, (WPARAM) ind, (LPARAM) i); if (i == initgend) { SendMessage(control_gender, CB_SETCURSEL, (WPARAM) ind, (LPARAM) 0); valid_opt = 1; } } /* set selection to the previously selected gender if it is still valid */ if (!valid_opt) { initgend = ROLE_NONE; initalign = ROLE_NONE; SendMessage(control_gender, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); } /* trigger change of the alignments list */ changed_sel = IDC_PLSEL_GENDER_LIST; } /* intialize alignments list */ if (changed_sel == IDC_PLSEL_GENDER_LIST) { valid_opt = 0; /* reset content and populate the list */ SendMessage(control_align, CB_RESETCONTENT, 0, 0); for (i = 0; i < ROLE_ALIGNS; i++) if (ok_align(initrole, initrace, initgend, i)) { ind = SendMessage( control_align, CB_ADDSTRING, (WPARAM) 0, (LPARAM) NH_A2W(aligns[i].adj, wbuf, sizeof(wbuf))); SendMessage(control_align, CB_SETITEMDATA, (WPARAM) ind, (LPARAM) i); if (i == initalign) { SendMessage(control_align, CB_SETCURSEL, (WPARAM) ind, (LPARAM) 0); valid_opt = 1; } } /* set selection to the previously selected alignment if it is still valid */ if (!valid_opt) { initalign = ROLE_NONE; SendMessage(control_align, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); } } }
LRESULT CALLBACK GetlinDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { struct getlin_data *data; RECT main_rt, text_rt, dlg_rt, edit_rt; SIZE dlg_sz; TCHAR wbuf[BUFSZ]; HDC hdc; HWND control; HWND hwndMap; #if defined(WIN_CE_POCKETPC) SHInputDialog(hWnd, message, wParam); #endif switch (message) { case WM_INITDIALOG: data = (struct getlin_data *) lParam; SetWindowText(hWnd, NH_A2W(data->question, wbuf, sizeof(wbuf))); SetWindowLong(hWnd, GWL_USERDATA, lParam); /* get title text width */ SetRect(&text_rt, 0, 0, 100, 50); hdc = GetWindowDC(hWnd); DrawText(hdc, wbuf, _tcslen(wbuf), &text_rt, DT_CALCRECT | DT_SINGLELINE | DT_NOPREFIX | DT_LEFT | DT_VCENTER); ReleaseDC(hWnd, hdc); /* center dialog in the main window */ GetWindowRect(hWnd, &dlg_rt); hwndMap = mswin_hwnd_from_winid(WIN_MAP); GetWindowRect(IsWindow(hwndMap) ? hwndMap : GetNHApp()->hMainWnd, &main_rt); dlg_sz.cx = max( dlg_rt.right - dlg_rt.left, min(text_rt.right - text_rt.left + GetSystemMetrics(SM_CXICON), main_rt.right - main_rt.left)); dlg_sz.cy = min(dlg_rt.bottom - dlg_rt.top, main_rt.bottom - main_rt.top); dlg_rt.left = (main_rt.left + main_rt.right - dlg_sz.cx) / 2; dlg_rt.right = dlg_rt.left + dlg_sz.cx; dlg_rt.top = (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2; dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; MoveWindow(hWnd, (main_rt.left + main_rt.right - dlg_sz.cx) / 2, (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2, dlg_sz.cx, dlg_sz.cy, TRUE); /* change layout of controls */ GetClientRect(hWnd, &dlg_rt); control = GetDlgItem(hWnd, IDC_GETLIN_EDIT); GetWindowRect(control, &edit_rt); MoveWindow(control, 0, 0, dlg_rt.right - dlg_rt.left, edit_rt.bottom - edit_rt.top, TRUE); control = GetDlgItem(hWnd, IDOK); GetWindowRect(control, &text_rt); MoveWindow(control, 0, edit_rt.bottom - edit_rt.top, (dlg_rt.right - dlg_rt.left) / 2, text_rt.bottom - text_rt.top, TRUE); control = GetDlgItem(hWnd, IDCANCEL); GetWindowRect(control, &text_rt); MoveWindow(control, (dlg_rt.right - dlg_rt.left) / 2, edit_rt.bottom - edit_rt.top, (dlg_rt.right - dlg_rt.left) / 2, text_rt.bottom - text_rt.top, TRUE); #if defined(WIN_CE_SMARTPHONE) NHSPhoneDialogSetup(hWnd, IDC_SPHONE_DIALOGBAR, TRUE, FALSE); #endif /* set focus to the edit control */ SetFocus(GetDlgItem(hWnd, IDC_GETLIN_EDIT)); /* tell windows that we've set the focus */ return FALSE; break; case WM_COMMAND: { TCHAR wbuf[BUFSZ]; switch (LOWORD(wParam)) { /* OK button was pressed */ case IDOK: data = (struct getlin_data *) GetWindowLong(hWnd, GWL_USERDATA); SendDlgItemMessage(hWnd, IDC_GETLIN_EDIT, WM_GETTEXT, (WPARAM) sizeof(wbuf), (LPARAM) wbuf); NH_W2A(wbuf, data->result, data->result_size); /* Fall through. */ /* cancel button was pressed */ case IDCANCEL: EndDialog(hWnd, wParam); return TRUE; } } break; #if defined(WIN_CE_SMARTPHONE) case WM_HOTKEY: if (VK_TBACK == HIWORD(lParam)) { SHSendBackToFocusWindow(message, wParam, lParam); } break; #endif } /* end switch (message) */ return FALSE; }
void mswin_map_stretch(HWND hWnd, LPSIZE lpsz, BOOL redraw) { PNHMapWindow data; RECT client_rt; SCROLLINFO si; SIZE wnd_size; LOGFONT lgfnt; /* check arguments */ if (!IsWindow(hWnd) || !lpsz || lpsz->cx <= 0 || lpsz->cy <= 0) return; /* calculate window size */ GetClientRect(hWnd, &client_rt); wnd_size.cx = client_rt.right - client_rt.left; wnd_size.cy = client_rt.bottom - client_rt.top; /* set new screen tile size */ data = (PNHMapWindow) GetWindowLong(hWnd, GWL_USERDATA); data->xScrTile = max(1, (data->bFitToScreenMode ? wnd_size.cx : lpsz->cx) / COLNO); data->yScrTile = max(1, (data->bFitToScreenMode ? wnd_size.cy : lpsz->cy) / ROWNO); /* set map origin point */ data->map_orig.x = max(0, client_rt.left + (wnd_size.cx - data->xScrTile * COLNO) / 2); data->map_orig.y = max(0, client_rt.top + (wnd_size.cy - data->yScrTile * ROWNO) / 2); data->map_orig.x -= data->map_orig.x % data->xScrTile; data->map_orig.y -= data->map_orig.y % data->yScrTile; /* adjust horizontal scroll bar */ if (data->bFitToScreenMode) data->xPageSize = COLNO + 1; /* disable scroll bar */ else data->xPageSize = wnd_size.cx / data->xScrTile; if (data->xPageSize >= COLNO) { data->xPos = 0; GetNHApp()->bNoHScroll = TRUE; } else { GetNHApp()->bNoHScroll = FALSE; data->xPos = max( 0, min(COLNO - data->xPageSize + 1, u.ux - data->xPageSize / 2)); } if (!GetNHApp()->bHideScrollBars) { si.cbSize = sizeof(si); si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; si.nMin = 0; si.nMax = COLNO; si.nPage = data->xPageSize; si.nPos = data->xPos; SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); } /* adjust vertical scroll bar */ if (data->bFitToScreenMode) data->yPageSize = ROWNO + 1; /* disable scroll bar */ else data->yPageSize = wnd_size.cy / data->yScrTile; if (data->yPageSize >= ROWNO) { data->yPos = 0; GetNHApp()->bNoVScroll = TRUE; } else { GetNHApp()->bNoVScroll = FALSE; data->yPos = max( 0, min(ROWNO - data->yPageSize + 1, u.uy - data->yPageSize / 2)); } if (!GetNHApp()->bHideScrollBars) { si.cbSize = sizeof(si); si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; si.nMin = 0; si.nMax = ROWNO; si.nPage = data->yPageSize; si.nPos = data->yPos; SetScrollInfo(hWnd, SB_VERT, &si, TRUE); } /* create font */ if (data->hMapFont) DeleteObject(data->hMapFont); ZeroMemory(&lgfnt, sizeof(lgfnt)); lgfnt.lfHeight = -data->yScrTile; // height of font lgfnt.lfWidth = -data->xScrTile; // average character width lgfnt.lfEscapement = 0; // angle of escapement lgfnt.lfOrientation = 0; // base-line orientation angle lgfnt.lfWeight = FW_NORMAL; // font weight lgfnt.lfItalic = FALSE; // italic attribute option lgfnt.lfUnderline = FALSE; // underline attribute option lgfnt.lfStrikeOut = FALSE; // strikeout attribute option lgfnt.lfCharSet = mswin_charset(); // character set identifier lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision lgfnt.lfQuality = DEFAULT_QUALITY; // output quality if (iflags.wc_font_map && *iflags.wc_font_map) { lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family NH_A2W(iflags.wc_font_map, lgfnt.lfFaceName, LF_FACESIZE); } else { lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family _tcsncpy(lgfnt.lfFaceName, NHMAP_FONT_NAME, LF_FACESIZE); } data->hMapFont = CreateFontIndirect(&lgfnt); mswin_cliparound(data->xCur, data->yCur); if (redraw) InvalidateRect(hWnd, NULL, TRUE); }
/*-------------------------------------------------------------------------*/ void onPaint(HWND hWnd) { PNHCmdWindow data; PAINTSTRUCT ps; HDC hDC; int x, y; TCHAR wbuf[BUFSZ]; HGDIOBJ saveFont; BITMAP bm; int cell_index; /* get window data */ data = (PNHCmdWindow)GetWindowLong(hWnd, GWL_USERDATA); hDC = BeginPaint(hWnd, &ps); if( !IsRectEmpty(&ps.rcPaint) ) { HGDIOBJ oldBr; HBRUSH hbrPattern; COLORREF OldBg, OldFg; HPEN hPen; HGDIOBJ hOldPen; saveFont = SelectObject(hDC, data->font[NH_CMDPAD_FONT_NORMAL]); OldBg = SetBkColor(hDC, mswin_get_color(NHW_KEYPAD, MSWIN_COLOR_BG)); OldFg = SetTextColor(hDC, mswin_get_color(NHW_KEYPAD, MSWIN_COLOR_FG)); GetObject(data->images, sizeof(BITMAP), (LPVOID)&bm); hbrPattern = CreatePatternBrush(data->images); hPen = CreatePen(PS_SOLID, 1, mswin_get_color(NHW_KEYPAD, MSWIN_COLOR_FG)); for( x=0, cell_index = 0; x<nhcmdlayout_rows(data->layout_current); x++ ) for( y=0; y<nhcmdlayout_columns(data->layout_current); y++, cell_index++ ) { RECT cell_rt; POINT pt[5]; PNHCmdPadCell p_cell_data; p_cell_data = nhcmdlayout_cell_direct(data->layout_current, cell_index); /* calculate the cell rectangle */ cell_rt.left = data->cells[cell_index].orig.x; cell_rt.top = data->cells[cell_index].orig.y; cell_rt.right = data->cells[cell_index].orig.x + data->cell_size.cx*p_cell_data->mult; cell_rt.bottom = data->cells[cell_index].orig.y + data->cell_size.cy; /* draw border */ hOldPen = SelectObject(hDC, hPen); pt[0].x = cell_rt.left; pt[0].y = cell_rt.top; pt[1].x = cell_rt.right; pt[1].y = cell_rt.top; pt[2].x = cell_rt.right; pt[2].y = cell_rt.bottom; pt[3].x = cell_rt.left; pt[3].y = cell_rt.bottom; pt[4].x = cell_rt.left; pt[4].y = cell_rt.top; Polyline(hDC, pt, 5); SelectObject(hDC, hOldPen); /* calculate clipping rectangle for the text */ cell_rt.left++; cell_rt.top ++; cell_rt.right--; cell_rt.bottom--; /* draw the cell text */ if( p_cell_data->image<=0 ) { SelectObject(hDC, data->font[ -p_cell_data->image ]); DrawText(hDC, NH_A2W(p_cell_data->text, wbuf, BUFSZ), /*JP strlen(p_cell_data->text), */ -1, &cell_rt, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX ); } else { /* draw bitmap */ int bmOffset; RECT bitmap_rt; bmOffset = (p_cell_data->image - 1)*bm.bmHeight; bitmap_rt.left = ((cell_rt.left+cell_rt.right) - min(bm.bmHeight, (cell_rt.right-cell_rt.left)))/2; bitmap_rt.top = ((cell_rt.bottom+cell_rt.top) - min(bm.bmHeight, (cell_rt.bottom-cell_rt.top)))/2; bitmap_rt.right = bitmap_rt.left + min(bm.bmHeight, (cell_rt.right-cell_rt.left)); bitmap_rt.bottom = bitmap_rt.top + min(bm.bmHeight, (cell_rt.bottom-cell_rt.top)); SetBrushOrgEx(hDC, bitmap_rt.left-bmOffset, bitmap_rt.top, NULL); oldBr = SelectObject(hDC, hbrPattern); PatBlt( hDC, bitmap_rt.left, bitmap_rt.top, bitmap_rt.right-bitmap_rt.left, bitmap_rt.bottom-bitmap_rt.top, PATCOPY); SelectObject(hDC, oldBr); } /* invert the cell if it is selected */ if( data->cells[cell_index].state == NH_CST_CHECKED ) { IntersectRect( &cell_rt, &cell_rt, &ps.rcPaint); PatBlt( hDC, cell_rt.left, cell_rt.top, cell_rt.right - cell_rt.left, cell_rt.bottom - cell_rt.top, DSTINVERT ); } } SetTextColor(hDC, OldFg); SetBkColor(hDC, OldBg); SelectObject(hDC, saveFont); DeleteObject(hbrPattern); DeleteObject(hPen); } EndPaint(hWnd, &ps); }
/* create font based on window type, charater attributes and window device context */ HGDIOBJ mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace) { HFONT fnt = NULL; LOGFONT lgfnt; int font_size; int font_index; static BOOL once = FALSE; if( !once ) { once = TRUE; atexit(font_table_cleanup); } ZeroMemory( &lgfnt, sizeof(lgfnt) ); /* try find font in the table */ for(font_index=0; font_index<font_table_size; font_index++) if(NHFONT_CODE(win_type, attr)==font_table[font_index].code) break; if( !replace && font_index<font_table_size ) return font_table[font_index].hFont; switch(win_type) { case NHW_STATUS: lgfnt.lfHeight = -iflags.wc_fontsiz_status*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font lgfnt.lfWidth = 0; // average character width lgfnt.lfEscapement = 0; // angle of escapement lgfnt.lfOrientation = 0; // base-line orientation angle lgfnt.lfWeight = FW_BOLD; // font weight lgfnt.lfItalic = FALSE; // italic attribute option lgfnt.lfUnderline = FALSE; // underline attribute option lgfnt.lfStrikeOut = FALSE; // strikeout attribute option lgfnt.lfCharSet = mswin_charset(); // character set identifier lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision lgfnt.lfQuality = DEFAULT_QUALITY; // output quality if( iflags.wc_font_status && *iflags.wc_font_status ) { lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family NH_A2W( iflags.wc_font_status, lgfnt.lfFaceName, LF_FACESIZE); } else { lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family } break; case NHW_MENU: lgfnt.lfHeight = -iflags.wc_fontsiz_menu*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font lgfnt.lfWidth = 0; // average character width lgfnt.lfEscapement = 0; // angle of escapement lgfnt.lfOrientation = 0; // base-line orientation angle lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option lgfnt.lfUnderline = (attr==ATR_ULINE || attr==ATR_INVERSE)? TRUE : FALSE; // underline attribute option lgfnt.lfStrikeOut = FALSE; // strikeout attribute option lgfnt.lfCharSet = mswin_charset(); // character set identifier lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision lgfnt.lfQuality = DEFAULT_QUALITY; // output quality if( iflags.wc_font_menu && *iflags.wc_font_menu ) { lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family NH_A2W( iflags.wc_font_menu, lgfnt.lfFaceName, LF_FACESIZE); } else { lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family } break; case NHW_MESSAGE: font_size = (attr==ATR_INVERSE)? iflags.wc_fontsiz_message+1 : iflags.wc_fontsiz_message; lgfnt.lfHeight = -font_size*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font lgfnt.lfWidth = 0; // average character width lgfnt.lfEscapement = 0; // angle of escapement lgfnt.lfOrientation = 0; // base-line orientation angle lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option lgfnt.lfUnderline = (attr==ATR_ULINE)? TRUE : FALSE; // underline attribute option lgfnt.lfStrikeOut = FALSE; // strikeout attribute option lgfnt.lfCharSet = mswin_charset(); // character set identifier lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision lgfnt.lfQuality = DEFAULT_QUALITY; // output quality if( iflags.wc_font_message && *iflags.wc_font_message ) { lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family NH_A2W( iflags.wc_font_message, lgfnt.lfFaceName, LF_FACESIZE); } else { lgfnt.lfPitchAndFamily = VARIABLE_PITCH; // pitch and family } break; case NHW_TEXT: lgfnt.lfHeight = -iflags.wc_fontsiz_text*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font lgfnt.lfWidth = 0; // average character width lgfnt.lfEscapement = 0; // angle of escapement lgfnt.lfOrientation = 0; // base-line orientation angle lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option lgfnt.lfUnderline = (attr==ATR_ULINE)? TRUE : FALSE; // underline attribute option lgfnt.lfStrikeOut = FALSE; // strikeout attribute option lgfnt.lfCharSet = mswin_charset(); // character set identifier lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision lgfnt.lfQuality = DEFAULT_QUALITY; // output quality if( iflags.wc_font_text && *iflags.wc_font_text ) { lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family NH_A2W( iflags.wc_font_text, lgfnt.lfFaceName, LF_FACESIZE); } else { lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family } break; } fnt = CreateFontIndirect(&lgfnt); /* add font to the table */ if( font_index==font_table_size ) { if( font_table_size>=MAXFONTS ) panic( "font table overflow!" ); font_table_size++; } else { DeleteObject(font_table[font_index].hFont); } font_table[font_index].code = NHFONT_CODE(win_type, attr); font_table[font_index].hFont = fnt; return fnt; }
LRESULT CALLBACK ExtCmdDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { struct extcmd_data *data; RECT main_rt, dlg_rt; SIZE dlg_sz; int i; const char *ptr; TCHAR wbuf[255]; switch (message) { case WM_INITDIALOG: data = (struct extcmd_data *) lParam; SetWindowLong(hWnd, GWL_USERDATA, lParam); /* center dialog in the main window */ GetWindowRect(GetNHApp()->hMainWnd, &main_rt); GetWindowRect(hWnd, &dlg_rt); dlg_sz.cx = dlg_rt.right - dlg_rt.left; dlg_sz.cy = dlg_rt.bottom - dlg_rt.top; dlg_rt.left = (main_rt.left + main_rt.right - dlg_sz.cx) / 2; dlg_rt.right = dlg_rt.left + dlg_sz.cx; dlg_rt.top = (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2; dlg_rt.bottom = dlg_rt.top + dlg_sz.cy; MoveWindow(hWnd, (main_rt.left + main_rt.right - dlg_sz.cx) / 2, (main_rt.top + main_rt.bottom - dlg_sz.cy) / 2, dlg_sz.cx, dlg_sz.cy, TRUE); /* fill combobox with extended commands */ for (i = 0; (ptr = extcmdlist[i].ef_txt); i++) { SendDlgItemMessage(hWnd, IDC_EXTCMD_LIST, LB_ADDSTRING, (WPARAM) 0, (LPARAM) NH_A2W(ptr, wbuf, sizeof(wbuf))); } #if defined(WIN_CE_SMARTPHONE) NHSPhoneDialogSetup(hWnd, IDC_SPHONE_DIALOGBAR, FALSE, FALSE); GetClientRect(hWnd, &dlg_rt); MoveWindow(GetDlgItem(hWnd, IDC_EXTCMD_LIST), dlg_rt.left, dlg_rt.top, dlg_rt.right - dlg_rt.left, dlg_rt.bottom - dlg_rt.top, TRUE); #endif /* set focus to the list control */ SetFocus(GetDlgItem(hWnd, IDC_EXTCMD_LIST)); /* tell windows we set the focus */ return FALSE; break; case WM_COMMAND: data = (struct extcmd_data *) GetWindowLong(hWnd, GWL_USERDATA); switch (LOWORD(wParam)) { /* OK button ws clicked */ case IDOK: *data->selection = SendDlgItemMessage( hWnd, IDC_EXTCMD_LIST, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); if (*data->selection == LB_ERR) *data->selection = -1; /* Fall through. */ /* CANCEL button ws clicked */ case IDCANCEL: EndDialog(hWnd, wParam); return TRUE; /* list control events */ case IDC_EXTCMD_LIST: switch (HIWORD(wParam)) { case LBN_DBLCLK: /* double click within the list wParam The low-order word is the list box identifier. The high-order word is the notification message. lParam Handle to the list box */ *data->selection = SendMessage((HWND) lParam, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); if (*data->selection == LB_ERR) *data->selection = -1; EndDialog(hWnd, IDOK); return TRUE; } break; } } return FALSE; }
LRESULT onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) { LPDRAWITEMSTRUCT lpdis; PNHMenuItem item; PNHMenuWindow data; TEXTMETRIC tm; HGDIOBJ saveFont; HDC tileDC; short ntile; int t_x, t_y; int x, y; TCHAR wbuf[BUFSZ]; RECT drawRect; COLORREF OldBg, OldFg, NewBg; char *p, *p1; int column; lpdis = (LPDRAWITEMSTRUCT) lParam; /* If there are no list box items, skip this message. */ if (lpdis->itemID == -1) return FALSE; data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); item = &data->menu.items[lpdis->itemID]; tileDC = CreateCompatibleDC(lpdis->hDC); saveFont = SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, item->attr, lpdis->hDC, FALSE)); NewBg = mswin_get_color(NHW_MENU, MSWIN_COLOR_BG); OldBg = SetBkColor(lpdis->hDC, NewBg); OldFg = SetTextColor(lpdis->hDC, mswin_get_color(NHW_MENU, MSWIN_COLOR_FG)); GetTextMetrics(lpdis->hDC, &tm); x = lpdis->rcItem.left + 1; /* print check mark if it is a "selectable" menu */ if( data->how!=PICK_NONE ) { if( NHMENU_IS_SELECTABLE(*item) ) { HGDIOBJ saveBrush; HBRUSH hbrCheckMark; char buf[2]; switch(item->count) { case -1: hbrCheckMark = CreatePatternBrush(data->bmpChecked); break; case 0: hbrCheckMark = CreatePatternBrush(data->bmpNotChecked); break; default: hbrCheckMark = CreatePatternBrush(data->bmpCheckedCount); break; } y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2; SetBrushOrgEx(lpdis->hDC, x, y, NULL); saveBrush = SelectObject(lpdis->hDC, hbrCheckMark); PatBlt(lpdis->hDC, x, y, TILE_X, TILE_Y, PATCOPY); SelectObject(lpdis->hDC, saveBrush); DeleteObject(hbrCheckMark); x += TILE_X + 5; if(item->accelerator!=0) { buf[0] = item->accelerator; buf[1] = '\x0'; SetRect( &drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, lpdis->rcItem.bottom ); /*JP DrawText(lpdis->hDC, NH_A2W(buf, wbuf, 2), 1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); */ DrawText(lpdis->hDC, NH_A2W(buf, wbuf, 2), -1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); } x += tm.tmAveCharWidth + tm.tmOverhang + 5; } else { x += TILE_X + tm.tmAveCharWidth + tm.tmOverhang + 10; } } /* print glyph if present */ if( item->glyph != NO_GLYPH ) { HGDIOBJ saveBmp; saveBmp = SelectObject(tileDC, GetNHApp()->bmpTiles); ntile = glyph2tile[ item->glyph ]; t_x = (ntile % TILES_PER_LINE)*TILE_X; t_y = (ntile / TILES_PER_LINE)*TILE_Y; y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2; nhapply_image_transparent( lpdis->hDC, x, y, TILE_X, TILE_Y, tileDC, t_x, t_y, TILE_X, TILE_Y, TILE_BK_COLOR ); SelectObject(tileDC, saveBmp); } x += TILE_X + 5; /* draw item text */ if( item->has_tab ) { p1 = item->str; p = strchr(item->str, '\t'); column = 0; SetRect( &drawRect, x, lpdis->rcItem.top, min(x + data->menu.tab_stop_size[0], lpdis->rcItem.right), lpdis->rcItem.bottom ); for (;;) { TCHAR wbuf[BUFSZ]; if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */ DrawText(lpdis->hDC, NH_A2W(p1, wbuf, BUFSZ), /*JP strlen(p1), */ -1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE ); if (p != NULL) *p = '\t'; else /* last string so, */ break; p1 = p + 1; p = strchr(p1, '\t'); drawRect.left = drawRect.right + TAB_SEPARATION; ++column; drawRect.right = min (drawRect.left + data->menu.tab_stop_size[column], lpdis->rcItem.right); } } else { TCHAR wbuf[BUFSZ]; SetRect( &drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, lpdis->rcItem.bottom); DrawText(lpdis->hDC, NH_A2W(item->str, wbuf, BUFSZ), /*JP strlen(item->str), */ -1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE ); } /* draw focused item */ if( item->has_focus ) { RECT client_rt; HBRUSH bkBrush; GetClientRect(lpdis->hwndItem, &client_rt); if( NHMENU_IS_SELECTABLE(*item) && data->menu.items[lpdis->itemID].count>0 && item->glyph != NO_GLYPH ) { if( data->menu.items[lpdis->itemID].count==-1 ) { _stprintf(wbuf, TEXT("Count: All") ); } else { _stprintf(wbuf, TEXT("Count: %d"), data->menu.items[lpdis->itemID].count ); } SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, ATR_BLINK, lpdis->hDC, FALSE)); /* calculate text rectangle */ SetRect( &drawRect, client_rt.left, lpdis->rcItem.top, client_rt.right, lpdis->rcItem.bottom ); /*JP DrawText(lpdis->hDC, wbuf, _tcslen(wbuf), &drawRect, */ DrawText(lpdis->hDC, wbuf, -1, &drawRect, DT_CALCRECT | DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX ); /* erase text rectangle */ drawRect.left = max(client_rt.left+1, client_rt.right - (drawRect.right - drawRect.left) - 10); drawRect.right = client_rt.right-1; drawRect.top = lpdis->rcItem.top; drawRect.bottom = lpdis->rcItem.bottom; bkBrush = CreateSolidBrush( GetBkColor(lpdis->hDC) ); FillRect(lpdis->hDC, &drawRect, bkBrush ); DeleteObject( bkBrush ); /* draw text */ /*JP DrawText(lpdis->hDC, wbuf, _tcslen(wbuf), &drawRect, */ DrawText(lpdis->hDC, wbuf, -1, &drawRect, DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX ); } /* draw focus rect */ SetRect( &drawRect, client_rt.left, lpdis->rcItem.top, client_rt.right, lpdis->rcItem.bottom ); DrawFocusRect(lpdis->hDC, &drawRect); } SetTextColor (lpdis->hDC, OldFg); SetBkColor (lpdis->hDC, OldBg); SelectObject(lpdis->hDC, saveFont); DeleteDC(tileDC); return TRUE; }