LRESULT CALLBACK TextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HWND control; HDC hdc; PNHTextWindow data; data = (PNHTextWindow)GetWindowLong(hWnd, GWL_USERDATA); switch (message) { case WM_INITDIALOG: /* set text control font */ control = GetDlgItem(hWnd, IDC_TEXT_CONTROL); if( !control ) { panic("cannot get text view window"); } hdc = GetDC(control); SendMessage(control, WM_SETFONT, (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0); ReleaseDC(control, hdc); #if defined(WIN_CE_SMARTPHONE) /* special initialization for SmartPhone dialogs */ NHSPhoneDialogSetup(hWnd, FALSE, GetNHApp()->bFullScreen); #endif /* subclass edit control */ editControlWndProc = (WNDPROC)GetWindowLong(control, GWL_WNDPROC); SetWindowLong(control, GWL_WNDPROC, (LONG)NHTextControlWndProc); if( !program_state.gameover && GetNHApp()->bWrapText ) { DWORD styles; styles = GetWindowLong(control, GWL_STYLE); if( styles ) { SetWindowLong(control, GWL_STYLE, styles & (~WS_HSCROLL)); SetWindowPos(control, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE ); } } SetFocus(control); return FALSE; case WM_MSNH_COMMAND: onMSNHCommand(hWnd, wParam, lParam); break; case WM_SIZE: LayoutText(hWnd); return FALSE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: case IDCANCEL: data->done = 1; return TRUE; } break; case WM_CTLCOLORBTN: case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */ HDC hdcEdit = (HDC) wParam; HWND hwndEdit = (HWND) lParam; if( hwndEdit == GetDlgItem(hWnd, IDC_TEXT_CONTROL) ) { SetBkColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_BG)); SetTextColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_FG)); return (BOOL)mswin_get_brush(NHW_TEXT, MSWIN_COLOR_BG); } } return FALSE; case WM_DESTROY: if( data ) { mswin_free_text_buffer(data->window_text); free(data); SetWindowLong(hWnd, GWL_USERDATA, (LONG)0); } break; } return FALSE; }
LRESULT CALLBACK MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PNHMenuWindow data; CheckInputDialog(hWnd, message, wParam, lParam); data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); switch (message) { case WM_INITDIALOG: { HWND text_control; HDC hDC; text_control = GetDlgItem(hWnd, IDC_MENU_TEXT); data = (PNHMenuWindow)malloc(sizeof(NHMenuWindow)); ZeroMemory(data, sizeof(NHMenuWindow)); data->type = MENU_TYPE_TEXT; data->how = PICK_NONE; data->result = 0; data->done = 0; data->bmpChecked = LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_SEL)); data->bmpCheckedCount = LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_SEL_COUNT)); data->bmpNotChecked = LoadBitmap(GetNHApp()->hApp, MAKEINTRESOURCE(IDB_MENU_UNSEL)); SetWindowLong(hWnd, GWL_USERDATA, (LONG)data); /* subclass edit control */ editControlWndProc = (WNDPROC)GetWindowLong(text_control, GWL_WNDPROC); SetWindowLong(text_control, GWL_WNDPROC, (LONG)NHMenuTextWndProc); /* set text window font */ hDC = GetDC(text_control); SendMessage( text_control, WM_SETFONT, (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hDC, FALSE), (LPARAM)0 ); ReleaseDC(text_control, hDC); #if defined(WIN_CE_SMARTPHONE) /* special initialization for SmartPhone dialogs */ NHSPhoneDialogSetup(hWnd, FALSE, GetNHApp()->bFullScreen); #endif } break; case WM_MSNH_COMMAND: onMSNHCommand(hWnd, wParam, lParam); break; case WM_SIZE: LayoutMenu(hWnd); return FALSE; case WM_COMMAND: { switch (LOWORD(wParam)) { case IDCANCEL: if( data->type == MENU_TYPE_MENU && (data->how==PICK_ONE || data->how==PICK_ANY) && data->menu.counting) { HWND list; int i; /* reset counter if counting is in progress */ list = GetMenuControl(hWnd); i = ListView_GetNextItem(list, -1, LVNI_FOCUSED); if( i>=0 ) { SelectMenuItem(list, data, i, 0); } return FALSE; } else { data->result = -1; data->done = 1; } return FALSE; case IDOK: data->done = 1; data->result = 0; return FALSE; } } break; case WM_NOTIFY: { LPNMHDR lpnmhdr = (LPNMHDR)lParam; switch (LOWORD(wParam)) { case IDC_MENU_LIST: { if( !data || data->type!=MENU_TYPE_MENU ) break; switch(lpnmhdr->code) { case LVN_ITEMACTIVATE: { LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lParam; if(data->how==PICK_ONE) { if( lpnmlv->iItem>=0 && lpnmlv->iItem<data->menu.size && NHMENU_IS_SELECTABLE(data->menu.items[lpnmlv->iItem]) ) { SelectMenuItem( lpnmlv->hdr.hwndFrom, data, lpnmlv->iItem, -1 ); data->done = 1; data->result = 0; return TRUE; } } else if( data->how==PICK_ANY ) { if( lpnmlv->iItem>=0 && lpnmlv->iItem<data->menu.size && NHMENU_IS_SELECTABLE(data->menu.items[lpnmlv->iItem]) ) { SelectMenuItem( lpnmlv->hdr.hwndFrom, data, lpnmlv->iItem, NHMENU_IS_SELECTED(data->menu.items[lpnmlv->iItem])? 0 : -1 ); } } } break; case NM_CLICK: { LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW) lParam; if( lpnmlv->iItem==-1 ) return 0; if( data->how==PICK_ANY ) { SelectMenuItem( lpnmlv->hdr.hwndFrom, data, lpnmlv->iItem, NHMENU_IS_SELECTED(data->menu.items[lpnmlv->iItem])? 0 : -1 ); } } break; case LVN_ITEMCHANGED: { LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lParam; if( lpnmlv->iItem==-1 ) return 0; if( !(lpnmlv->uChanged & LVIF_STATE) ) return 0; /* update item that has the focus */ data->menu.items[lpnmlv->iItem].has_focus = !!(lpnmlv->uNewState & LVIS_FOCUSED); ListView_RedrawItems(lpnmlv->hdr.hwndFrom, lpnmlv->iItem, lpnmlv->iItem); /* update count for single-selection menu (follow the listview selection) */ if( data->how==PICK_ONE ) { if( lpnmlv->uNewState & LVIS_SELECTED ) { SelectMenuItem( lpnmlv->hdr.hwndFrom, data, lpnmlv->iItem, -1 ); } } /* check item focus */ data->menu.items[lpnmlv->iItem].has_focus = !!(lpnmlv->uNewState & LVIS_FOCUSED); ListView_RedrawItems(lpnmlv->hdr.hwndFrom, lpnmlv->iItem, lpnmlv->iItem); } break; case NM_KILLFOCUS: reset_menu_count(lpnmhdr->hwndFrom, data); break; } } break; } } break; case WM_SETFOCUS: if( hWnd!=GetNHApp()->hPopupWnd ) { SetFocus(GetNHApp()->hPopupWnd ); return 0; } break; case WM_MEASUREITEM: if( wParam==IDC_MENU_LIST ) return onMeasureItem(hWnd, wParam, lParam); else return FALSE; case WM_DRAWITEM: if( wParam==IDC_MENU_LIST ) return onDrawItem(hWnd, wParam, lParam); else return FALSE; case WM_CTLCOLORBTN: case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */ HDC hdcEdit = (HDC) wParam; HWND hwndEdit = (HWND) lParam; if( hwndEdit == GetDlgItem(hWnd, IDC_MENU_TEXT) ) { SetBkColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_BG)); SetTextColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_FG)); return (BOOL)mswin_get_brush(NHW_TEXT, MSWIN_COLOR_BG); } } return FALSE; case WM_DESTROY: if( data ) { DeleteObject(data->bmpChecked); DeleteObject(data->bmpCheckedCount); DeleteObject(data->bmpNotChecked); if( data->type == MENU_TYPE_TEXT ) { if( data->text.text ) { mswin_free_text_buffer(data->text.text); data->text.text = NULL; } } free(data); SetWindowLong(hWnd, GWL_USERDATA, (LONG)0); } return TRUE; } return FALSE; }