void SendEvent (KVMEventType *evt) { char *event_data = NULL; /* copied from DefaultEventHandler.java */ static int MIDP_KEY_EVENT = 1; static int MIDP_PEN_EVENT = 2; static int MIDP_COMMAND_EVENT = 3; static int MIDP_SYSTEM_EVENT = 4; /* for jsr135's audio building block, -- by hsy */ static int MM_EOM_EVENT = 8; static int PRESSED = 1; static int RELEASED = 2; static int REPEATED = 3; static int DRAGGED = 3; static int TYPED = 4; #ifdef INCLUDE_I18N static int IME = 5; #endif /* translated from LocationEventCodes.java */ #define STATE 4000 #define STATE_AVAILABLE 4001 #define STATE_TEMPORARILY_UNAVAILABLE 4002 #define STATE_OUT_OF_SERVICE 4003 #define ORIENTATION 4100 #define LOCATION 4200 #define ACCURACY 4300 switch (evt->type) { case penDownKVMEvent: if (!generateSoftButtonKeys(evt->screenX,evt->screenY,JAVACALL_PENPRESSED)) javanotify_pen_event(evt->screenX,evt->screenY,JAVACALL_PENPRESSED); break; case penUpKVMEvent: if (!generateSoftButtonKeys(evt->screenX,evt->screenY,JAVACALL_PENRELEASED)) javanotify_pen_event(evt->screenX,evt->screenY,JAVACALL_PENRELEASED); break; case penMoveKVMEvent: javanotify_pen_event(evt->screenX,evt->screenY,JAVACALL_PENDRAGGED); break; case keyDownKVMEvent: #ifdef USE_KEYTYPED_VM_EVENTS /* Regular key events are sent over keyTypedKVMEvent */ if ((evt->chr >= ' ') && (evt->chr <= 127)) { latestKeyTyped = 0; latestKeyDown = evt->chr; break; } #endif if (evt->chr == KEY_USER2) { javanotify_rotation(); } else if ((evt->chr != KEY_END)) { javanotify_key_event(evt->chr, JAVACALL_KEYPRESSED); } else if (isRunningLocal == JAVACALL_FALSE) { javanotify_switch_to_ams(); } else { javanotify_shutdown(); } break; case keyUpKVMEvent: if (evt->chr == KEY_USER2) { // ignore } else if ((evt->chr != KEY_END)) { #if ENABLE_ON_DEVICE_DEBUG /* assert(posInSequence == sizeof(pStartOddKeySequence) - 1) */ if (pStartOddKeySequence[posInSequence] == evt->chr) { posInSequence++; if (posInSequence == sizeof(pStartOddKeySequence) - 1) { posInSequence = 0; javanotify_enable_odd(); break; } } else { posInSequence = 0; } #endif #ifdef USE_KEYTYPED_VM_EVENTS /* Regular key events are sent over keyTypedKVMEvent */ if ((evt->chr >= ' ') && (evt->chr <= 127)) { if (0 == latestKeyTyped) { if (evt->chr == latestKeyDown) { /* Support skin presses - when there is no keytyped * event between key down/up events */ javanotify_key_event(latestKeyDown, JAVACALL_KEYPRESSED); javanotify_key_event(latestKeyDown, JAVACALL_KEYRELEASED); } } else if (evt->chr == latestKeyTyped || evt->chr == latestKeyDown) { javanotify_key_event(latestKeyTyped, JAVACALL_KEYRELEASED); } latestKeyDown = 0; latestKeyTyped = 0; break; } #endif javanotify_key_event(evt->chr, JAVACALL_KEYRELEASED); } break; case keyRepeatKVMEvent: if (evt->chr == KEY_USER2) { // ignore } else if (evt->chr != KEY_END) { #ifdef USE_KEYTYPED_VM_EVENTS /* For compound key presses, like shift + digit, WTK produces repeated * key events for base key only, e.g. for the digit. It is not good, * since, for example for '!' it will produce '1' repeated key event. * It can be fixed in assumption that repeated key event can happen * to previously pressed and not yet released key only */ if ((evt->chr >= ' ') && (evt->chr <= 127)) { if (latestKeyTyped != 0) { javanotify_key_event(latestKeyTyped, JAVACALL_KEYREPEATED); } } else { javanotify_key_event(evt->chr, JAVACALL_KEYREPEATED); } #else javanotify_key_event(evt->chr, JAVACALL_KEYREPEATED); #endif } break; case keyTypedKVMEvent: if (evt->chr == KEY_USER2) { // ignore } else if ((evt->chr != KEY_END)) { #ifdef USE_KEYTYPED_VM_EVENTS /* Multiple key presses are not supported, * non-regular key press means the previous key is released */ if (0 != latestKeyTyped && latestKeyTyped != evt->chr) { javanotify_key_event(latestKeyTyped, JAVACALL_KEYRELEASED); latestKeyTyped = 0; } /* Send regular key events received from the keyboard * using standard MIDP mechanism */ if ((evt->chr >= ' ') && (evt->chr <= 127)) { /* Don't produce multiple press events for held keypad keys, * but do it for other typed chars, since WTK doesn't support * repeated key presses for them */ if (evt->chr != latestKeyTyped || 0 == latestKeyDown) { javanotify_key_event(evt->chr, JAVACALL_KEYPRESSED); latestKeyTyped = evt->chr; } } #else /* Temporary solution, will not work on all cases but provides * a solution for text entry */ if (evt->chr != 8) { javanotify_key_event(evt->chr, JAVACALL_KEYPRESSED); javanotify_key_event(evt->chr, JAVACALL_KEYRELEASED); } #endif } else if (isRunningLocal == JAVACALL_FALSE) { javanotify_switch_to_ams(); } else { javanotify_shutdown(); } break; #ifdef INCLUDE_I18N case imeKVMEvent: { /*StoreKVMEvent(MIDP_KEY_EVENT, 2, IME, instantiateStringFromUnicode(evt->str, evt->len)); midpFree(evt->str); */ break; } #endif case commandKVMEvent: /* StoreKVMEvent(MIDP_COMMAND_EVENT, 1, evt->chr); */ break; case mmEOMEvent: /* StoreKVMEvent(MM_EOM_EVENT, 2, (int)evt->screenX, evt->chr); */ break; case systemKVMEvent: switch (evt->chr) { case VK_SUSPEND_ALL: javanotify_pause(); break; case VK_RESUME_ALL: javanotify_resume(); break; case VK_SHUTDOWN: javanotify_shutdown(); break; #if ENABLE_JSR_179 case STATE_AVAILABLE: HandleLocationProviderStateEvent(JAVACALL_LOCATION_AVAILABLE); break; case STATE_OUT_OF_SERVICE: HandleLocationProviderStateEvent(JAVACALL_LOCATION_OUT_OF_SERVICE); break; case STATE_TEMPORARILY_UNAVAILABLE: HandleLocationProviderStateEvent(JAVACALL_LOCATION_TEMPORARILY_UNAVAILABLE); break; case LOCATION: event_data = ExtractEventData(L"4200"); if (event_data) { ParseLocationData(event_data); } break; case ORIENTATION: event_data = ExtractEventData(L"4100"); if (event_data) ParseOrientationData(event_data); break; case ACCURACY: event_data = ExtractEventData(L"4300"); if (event_data) ParseAccuracyData(event_data); break; #endif #if ENABLE_JSR_75 case FILE_SYSTEM_MOUNTED: javanotify_fileconnection_root_changed(); break; case FILE_SYSTEM_UNMOUNTED: javanotify_fileconnection_root_changed(); break; #endif default: break; } /* switch(evt->chr) */ default: /* do nothing, but continue in loop */ break; } /* switch (evt->type) */
static LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { //check if udp or tcp int level = SOL_SOCKET; int opttarget; int optname; int optsize = sizeof(optname); switch (iMsg) { case WM_CLOSE: /* * Handle the "X" (close window) button by sending the AMS a shutdown * event. */ PostQuitMessage (0); javanotify_shutdown(); return 0; case WM_TIMER: // Stop the timer from repeating the WM_TIMER message. KillTimer(hwnd, wParam); return 0; case WM_NETWORK: #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "Got WM_NETWORK("); fprintf(stderr, "descriptor = %d, ", (int)wParam); fprintf(stderr, "status = %d, ", WSAGETSELECTERROR(lParam)); #endif optname = SO_TYPE; if (0 != getsockopt((SOCKET)wParam, SOL_SOCKET, optname,(char*)&opttarget, &optsize)) { #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "getsocketopt error)\n"); #endif } if(opttarget == SOCK_STREAM) { switch (WSAGETSELECTEVENT(lParam)) { case FD_CONNECT: /* Change this to a write. */ javanotify_socket_event( JAVACALL_EVENT_SOCKET_OPEN_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[TCP] FD_CONNECT)\n"); #endif return 0; case FD_WRITE: javanotify_socket_event( JAVACALL_EVENT_SOCKET_SEND, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); javanotify_socket_event( JAVACALL_EVENT_SERVER_SOCKET_ACCEPT_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[TCP] FD_WRITE)\n"); #endif return 0; case FD_ACCEPT: javanotify_server_socket_event( JAVACALL_EVENT_SERVER_SOCKET_ACCEPT_COMPLETED, (javacall_handle)wParam, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[TCP] FD_ACCEPT, "); #endif case FD_READ: javanotify_socket_event( JAVACALL_EVENT_SOCKET_RECEIVE, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[TCP] FD_READ)\n"); #endif return 0; case FD_CLOSE: javanotify_socket_event( JAVACALL_EVENT_SOCKET_CLOSE_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[TCP] FD_CLOSE)\n"); #endif return 0; default: #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[TCP] unsolicited event %d)\n", WSAGETSELECTEVENT(lParam)); #endif break; }//end switch }//SOCK_STREAM else if (opttarget == SOCK_DGRAM) { switch (WSAGETSELECTEVENT(lParam)) { case FD_WRITE: javanotify_datagram_event( JAVACALL_EVENT_DATAGRAM_SENDTO_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] FD_WRITE)\n"); #endif return 0; case FD_READ: #if ENABLE_JSR_120 if (JAVACALL_OK == try_process_wma_emulator((javacall_handle)wParam)) { return 0; } #endif javanotify_datagram_event( JAVACALL_EVENT_DATAGRAM_RECVFROM_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] FD_READ)\n"); #endif return 0; case FD_CLOSE: #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] FD_CLOSE)\n"); #endif return 0; default: #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] unsolicited event %d)\n", WSAGETSELECTEVENT(lParam)); #endif break; }//end switch }//end UDP return 0; case WM_HOST_RESOLVED: #ifdef ENABLE_TRACE_NETWORKING fprintf(stderr, "Got Windows event WM_HOST_RESOLVED \n"); #endif javanotify_socket_event( JAVACALL_EVENT_NETWORK_GETHOSTBYNAME_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); return 0; } return DefWindowProc (hwnd, iMsg, wParam, lParam); }
static LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { static int penDown = JAVACALL_FALSE; int x, y; int i; PAINTSTRUCT ps; HDC hdc; HANDLE *mutex; int key; //check if udp or tcp int level = SOL_SOCKET; int opttarget; int optname; int optsize = sizeof(optname); switch(iMsg) { #ifdef SKINS_MENU_SUPPORTED case WM_COMMAND: switch(wParam & 0xFFFF) { case EXMENU_ITEM_SHUTDOWN: printf("EXMENU_ITEM_SHUTDOWN ... \n"); javanotify_shutdown(); break; case EXMENU_ITEM_PAUSE: javanotify_pause(); break; case EXMENU_ITEM_RESUME: javanotify_resume(); break; default: return DefWindowProc (hwnd, iMsg, wParam, lParam); } /* end of switch */ return 0; #endif case WM_CREATE: hdc = GetDC(hwnd); CHECK_RETURN(SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT))); GetTextMetrics(hdc, &fixed_tm); CHECK_RETURN(SelectObject(hdc, GetStockObject(SYSTEM_FONT))); GetTextMetrics(hdc, &tm); ReleaseDC(hwnd, hdc); return 0; case WM_PAINT: mutex = (HANDLE*) TlsGetValue(tlsId); WaitForSingleObject(*mutex, INFINITE); hdc = BeginPaint(hwnd, &ps); /* * There are 3 bitmap buffers, putpixel screen buffer, the phone * bitmap and the actual window buffer. Paint the phone bitmap on the * window. LCDUIrefresh has already painted the putpixel buffer on the * LCD screen area of the phone bitmap. * * On a real win32 (or high level window API) device the phone bitmap * would not be needed the code below would just paint the putpixel * buffer the window. */ DrawBitmap(hdc, hPhoneBitmap, 0, 0, SRCCOPY); EndPaint(hwnd, &ps); ReleaseMutex(*mutex); return 0; case WM_CLOSE: /* * Handle the "X" (close window) button by sending the AMS a shutdown * event. */ #ifdef SKINS_MENU_SUPPORTED destroySkinsMenu(); #endif javanotify_shutdown(); PostQuitMessage(0); return 0; case WM_SYSKEYDOWN: case WM_SYSKEYUP: /* The only event of this type that we want MIDP * to handle is the F10 key which for some reason is not * sent in the WM_KEY messages. * if we receive any other key in this message, break. */ if(wParam != VK_F10) { break; } // patch for VK_F10 if (WM_SYSKEYUP == iMsg) { iMsg = WM_KEYUP; } else if (WM_SYSKEYDOWN == iMsg) { iMsg = WM_KEYDOWN; } /* fall through */ case WM_KEYDOWN: { /* Impl note: to send pause and resume notifications */ static int isPaused; if(VK_F5 == wParam) { if(!isPaused) { javanotify_pause(); } else { javanotify_resume(); } isPaused =!isPaused; break; } else if(VK_HOME == wParam) { javanotify_switch_to_ams(); break; } else if(VK_F4 == wParam) { javanotify_select_foreground_app(); break; /* F3 key used for rotation. */ } else if(VK_F3 == wParam) { javanotify_rotation(); } } case WM_KEYUP: key = mapKey(wParam, lParam); switch(key) { case /* MIDP_KEY_INVALID */ 0: return 0; /* case MD_KEY_HOME: if (iMsg == WM_KEYDOWN) { return 0; } pMidpEventResult->type = SELECT_FOREGROUND_EVENT; pSignalResult->waitingFor = AMS_SIGNAL; return 0; */ default: break; } if(iMsg == WM_KEYUP) { javanotify_key_event((javacall_key)key, JAVACALL_KEYRELEASED); } else if(iMsg == WM_KEYDOWN) { if (lParam & 0xf0000000) { javanotify_key_event((javacall_key)key, JAVACALL_KEYREPEATED); } else { javanotify_key_event((javacall_key)key, JAVACALL_KEYPRESSED); } } return 0; case WM_TIMER: // Stop the timer from repeating the WM_TIMER message. KillTimer(hwnd, wParam); return 0; case WM_MOUSEMOVE: case WM_LBUTTONDOWN: case WM_LBUTTONUP: /* Cast lParam to "short" to preserve sign */ x = (short)LOWORD(lParam); y = (short)HIWORD(lParam); /** please uncomment following line if you want to test pen input in win32 emulator. ** with ENABLE_PEN_EVENT_NOTIFICATION defined, you should also modify constants.xml ** in midp workspace in order to pass related tck cases. **/ #define ENABLE_PEN_EVENT_NOTIFICATION 1 #ifdef ENABLE_PEN_EVENT_NOTIFICATION midpScreen_bounds.x = x_offset; midpScreen_bounds.y = y_offset; midpScreen_bounds.width = VRAM.width; midpScreen_bounds.height = (inFullScreenMode? VRAM.height: VRAM.height - TOP_BAR_HEIGHT); if(iMsg == WM_LBUTTONDOWN && INSIDE(x, y, midpScreen_bounds) ) { penAreDragging = JAVACALL_TRUE; SetCapture(hwnd); if (reverse_orientation) { javanotify_pen_event(javacall_lcd_get_screen_width() - y + y_offset, x - x_offset, JAVACALL_PENPRESSED); } else { javanotify_pen_event(x-x_offset, y-y_offset, JAVACALL_PENPRESSED); } return 0; } if(iMsg == WM_LBUTTONUP && (INSIDE(x, y, midpScreen_bounds) || penAreDragging == JAVACALL_TRUE)) { if(penAreDragging == JAVACALL_TRUE) { penAreDragging = JAVACALL_FALSE; ReleaseCapture(); } if (reverse_orientation) { javanotify_pen_event(javacall_lcd_get_screen_width() - y + y_offset, x - x_offset, JAVACALL_PENRELEASED); } else { javanotify_pen_event(x-x_offset, y-y_offset, JAVACALL_PENRELEASED); } return 0; } if(iMsg == WM_MOUSEMOVE) { if(penAreDragging == JAVACALL_TRUE) { if (reverse_orientation) { javanotify_pen_event(javacall_lcd_get_screen_width() - y + y_offset, x - x_offset, JAVACALL_PENDRAGGED); } else { javanotify_pen_event(x-x_offset, y-y_offset, JAVACALL_PENDRAGGED); } } return 0; } #else if(iMsg == WM_MOUSEMOVE) { /* * Don't process mouse move messages that are not over the LCD * screen of the skin. */ return 0; } #endif for(i = 0; i < NUMBEROF(Keys); ++i) { if(!(INSIDE(x, y, Keys[i].bounds))) { continue; } /* Chameleon processes keys on the way down. */ #ifdef SOUND_SUPPORTED if(iMsg == WM_LBUTTONDOWN) { MessageBeep(MB_OK); } #endif switch(Keys[i].button) { case KEY_POWER: if(iMsg == WM_LBUTTONUP) { return 0; } javanotify_shutdown(); return 0; case KEY_END: if(iMsg == WM_LBUTTONUP) { return 0; } /* NEED REVISIT: destroy midlet instead of shutdown? */ javanotify_shutdown(); return 0; default: /* Handle the simulated key events. */ switch(iMsg) { case WM_LBUTTONDOWN: javanotify_key_event((javacall_key)Keys[i].button, JAVACALL_KEYPRESSED); return 0; case WM_LBUTTONUP: javanotify_key_event((javacall_key)Keys[i].button, JAVACALL_KEYRELEASED); return 0; default: break; } /* switch iMsg */ } /* switch key */ } /* for */ return 0; case WM_NETWORK: #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "Got WM_NETWORK("); fprintf(stderr, "descriptor = %d, ", (int)wParam); fprintf(stderr, "status = %d, ", WSAGETSELECTERROR(lParam)); #endif optname = SO_TYPE; if(0 != getsockopt((SOCKET)wParam, SOL_SOCKET, optname,(char*)&opttarget, &optsize)) { #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "getsocketopt error)\n"); #endif } if(opttarget == SOCK_STREAM) { // TCP socket return handleNetworkStreamEvents(wParam,lParam); } else { return handleNetworkDatagramEvents(wParam,lParam); }; break; case WM_HOST_RESOLVED: #ifdef ENABLE_TRACE_NETWORKING fprintf(stderr, "Got Windows event WM_HOST_RESOLVED \n"); #endif javanotify_socket_event( JAVACALL_EVENT_NETWORK_GETHOSTBYNAME_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); return 0; #if 0 /* media */ case WM_DEBUGGER: pSignalResult->waitingFor = VM_DEBUG_SIGNAL; return 0; case WM_MEDIA: pSignalResult->waitingFor = MEDIA_EVENT_SIGNAL; pSignalResult->descriptor = (int)wParam; pSignalResult->pResult = (void*)lParam; return 0; #endif /* media */ default: break; } /* end of external switch */ return DefWindowProc (hwnd, iMsg, wParam, lParam); } /* end of WndProc */