AString ADVBPatterns::GetPatternDefinitionsJSON() { AString str; uint_t i, j, nfields; const FIELD *fields = ADVBProg::GetFields(nfields); str.printf("\"patterndefs\":"); str.printf("{\"fields\":["); for (i = 0; i < nfields; i++) { const FIELD& field = fields[i]; if (i) str.printf(","); str.printf("{\"name\":\"%s\"", JSONFormat(field.name).str()); str.printf(",\"desc\":\"%s\"", JSONFormat(field.desc).str()); str.printf(",\"type\":%u", field.type); str.printf(",\"assignable\":%s", field.assignable ? "true" : "false"); str.printf(",\"operators\":["); bool flag = false; for (j = 0; j < NUMBEROF(operators); j++) { const OPERATOR& oper = operators[j]; if ((field.assignable == oper.assign) && (oper.fieldtypes & (1U << field.type))) { if (flag) str.printf(","); str.printf("%u", j); flag = true; } } str.printf("]}"); } str.printf("]"); str.printf(",\"fieldnames\":{"); for (i = 0; i < nfields; i++) { const FIELD& field = fields[i]; if (i) str.printf(","); str.printf("\"%s\":%u", JSONFormat(field.name).str(), i); } str.printf("}"); str.printf(",\"operators\":["); for (j = 0; j < NUMBEROF(operators); j++) { const OPERATOR& oper = operators[j]; if (j) str.printf(","); str.printf("{\"text\":\"%s\"", JSONFormat(oper.str).str()); str.printf(",\"desc\":\"%s\"", JSONFormat(oper.desc).str()); str.printf(",\"opcode\":%u", (uint_t)oper.opcode); str.printf(",\"assign\":%s}", oper.assign ? "true" : "false"); } str.printf("]"); str.printf(",\"orflags\":["); for (j = 0; j < 2; j++) { if (j) str.printf(","); str.printf("{\"text\":\"%s\"", JSONFormat(j ? "or" : "and").str()); str.printf(",\"desc\":\"%s\"", JSONFormat(j ? "Or the next term" : "And the next term").str()); str.printf(",\"value\":%u}", j); } str.printf("]}"); return str; }
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 */