static HTMLEventStatus kbBodyCallback(wcCtx* Ctx, wcEL element,HTMLEvent* event, char* param) { Softkey *pSk=0; SoftKeyPad *pMe; pMe = (SoftKeyPad *) wcGetData(Ctx, 0); if (!pMe) return (HTML_EVENT_STATUS_CONTINUE); return pMe->kbBodyCallbackMethod(Ctx,element,event); }
static BOOL WINAPI fake_GetCursorInfo(PCURSORINFO pci) { BOOL ret = orig_GetCursorInfo(pci); if(wcGetConfig()->override_user32) { wcStartServer(); const wcInputData *input = wcGetData(); // todo } return ret; }
static BOOL WINAPI fake_GetKeyboardState(PBYTE lpKeyState) { BOOL ret = orig_GetKeyboardState(lpKeyState); if(wcGetConfig()->override_user32) { wcStartServer(); const wcInputData *input = wcGetData(); for(int i=0; i<256; ++i) { lpKeyState[i] |= (input->key.keys[i] & 0x80); } } return ret; }
void TestDomApi(wcBROW browser, wcDOC doc) { wcCtx _Ctx; wcCtxtInit(&_Ctx, browser, doc); // Test1: - Use dynamic element creation and dom insertion to create a page. // Containing a table. rtp_printf("Test1: - Use dynamic element creation and dom insertion to create a page. Containing a table.\n"); wcEL table = wcElNew(&_Ctx, "table"); wcEL td; wcEL tr = wcElNew(&_Ctx, "tr"); wcELInsertFirst(table,tr); wcElSetId(table, "table0"); wcElSetStyle(table, "border-style:solid;border-thickness:2px;", wcTRUE); td = wcElNew(&_Ctx, "td"); wcELInsertFirst(tr,td); wcElSetId(tr, "row0"); // This crashes when we clone if it is a checkboxk wcElSetInnerHtml(td,"Hello from 0,0"); wcElSetId(td, "col0"); //wcElSetStyle(td, "border-style:solid;border-thickness:2px;"); td = wcElNew(&_Ctx, "td"); wcElSetId(td, "col1"); wcELInsertFirst(tr,td); wcElSetInnerHtml(td,"Hello from 0,1"); //wcElSetStyle(td, "border-style:solid;border-thickness:2px;"); wcDocInsertFirst(&_Ctx, table); wcEL checkboxdiv; checkboxdiv = wcElNew(&_Ctx, "div"); wcElSetInnerHtml(checkboxdiv,"<input id=\"check\" type=\"checkbox\" name=\"checkme\" value=\"Car\" checked=\"checked\" />"); wcDocRefresh(&_Ctx); rtp_printf("Test2: - Find the table cell by walking the dom.\n"); { wcBOOL Error = wcFALSE; wcEL El = wcELFind (&_Ctx, 0, "/table0/row0/col1", &Error); if (El) wcElSetInnerHtml(El,"0,0 again"); } rtp_printf("Test3: - Use the enumeration function to walk the tree and print Id values.\n"); // Garbage collect ascii return buffers when done. // See EnumTestCallback below. { int nfound = 0; wcDocEnumerate(&_Ctx, EnumTestCallback, 0, (void *) &nfound); rtp_printf("Enumeration stest fond this many objects == %d\n", nfound); // print the count we tabulated from the callback. wcCtxtRelease(&_Ctx); // free buffers that ascii strings were returned in. } rtp_printf("Test4: - Use the clone function to clone the table we just made.\n"); // Test4: - Use the clone function to clone the table we just made. // Insert it into our document, give it a new name and move it. // Re enumerate to see what we have // See EnumTestCallback below. wcEL tableClone = wcElClone(table, wcTRUE); if (tableClone) { wcBOOL Error = wcFALSE; int nfound = 0; wcEL El; wcDocInsertLast(&_Ctx, tableClone); wcElSetStyle(tableClone, "position:absolute;left:20px;top:100px;",wcTRUE); wcElSetId(tableClone, "clonetable0"); El = wcELFind (&_Ctx, 0, "/clonetable0/row0/col0", &Error); if (El) wcElSetInnerHtml(El,"0,0 cloned"); wcDocEnumerate(&_Ctx, EnumTestCallback, 0, (void *) &nfound); rtp_printf("Enumeration after clone found this many objects == %d\n", nfound); // print the count we tabulated from the callback. wcCtxtRelease(&_Ctx); // free buffers that ascii strings were returned in. wcDocRefresh(&_Ctx); } rtp_printf("Test5: - Create a button and attach an event handler to it.\n"); // Test5: - Create a button and attach an event handler to it. // The event handler will print out the events presented to it. // To demonstrate use of push and pop events we will over write the the event hendler that must // be clicked to pop the first handler into place. wcEL button = wcElNew(&_Ctx, "input type=button"); { wcBOOL Error = wcFALSE; int nfound = 0; static int whichhandler = 0; wcDocInsertLast(&_Ctx, button); wcElSetInnerHtml(button, "Clickme to toggle event handlers"); wcElSetValue(button, "Clickme"); wcElSetStyle(button, "position:absolute;left:20px;top:150px;",wcTRUE); // cloning of input tag crashes, needs debugging. // wcEL buttonClone = wcElClone(button, wcTRUE); wcEL buttonClone = wcElNew(&_Ctx, "input type=button"); wcDocInsertLast(&_Ctx, buttonClone); wcElSetInnerHtml(buttonClone, "Another butoon, no handler attached"); wcElSetValue(buttonClone, "Clickme"); wcElSetStyle(buttonClone, "position:absolute;left:20px;top:200px;",wcTRUE); wcElSetEventHandler(button, wcTestEventCallback); wcElSetEventHandler(button, ClickMeCallback); // enumerate to show it and its value wcDocEnumerate(&_Ctx, EnumTestCallback, 0, (void *) &nfound); wcCtxtRelease(&_Ctx); // free buffers that ascii strings were returned in. wcDocRefresh(&_Ctx); // wcElSetStyle(button, "position:absolute;left:120px;top:150px;width:100px;height:40px;"); wcDocRefresh(&_Ctx); } // Test6: - Verify push/pop data functioons. rtp_printf("Test6: - Verify element push/pop private data functions. \n"); { int v1 = 1; int v2 = 2; int *p; wcPushData(&_Ctx, button, (void *) &v1); wcPushData(&_Ctx, button, (void *) &v2); p = (int *) wcGetData(&_Ctx, button); if (p) rtp_printf(" wcGetdata test value should be two: %d\n", *p); else rtp_printf(" wcGetdata test failed"); wcPopData(&_Ctx, button); p = (int *) wcGetData(&_Ctx, button); if (p) rtp_printf(" wcGetdata test value should be one: %d\n", *p); else rtp_printf(" wcGetdata test failed"); v1 = 3; v2 = 4; wcPushData(&_Ctx, 0, (void *) &v1); wcPushData(&_Ctx, 0, (void *) &v2); p = (int *) wcGetData(&_Ctx, 0); if (p) rtp_printf(" wcGetdata test value should be four: %d\n", *p); else rtp_printf(" wcGetdata test failed"); wcPopData(&_Ctx, 0); p = (int *) wcGetData(&_Ctx, 0); if (p) rtp_printf(" wcGetdata test value should be three: %d\n", *p); else rtp_printf(" wcGetdata test failed"); } rtp_printf("Test7 and 8: - Verify modal window support. \n"); // Test7: - Create a modal window. Use the body callback event handler to create a button element. // Use the button to trigger a close of the window. // Note: This test also verifies the behavior of wcElGetPosWin, wcElGetPosStyle and wcElSetPosStyle. // The tests center a button on a screen without setting the left and top style attributes. // These test sequences demonstrate the code sequence that handles the HTML_EVENT_WINDOW_REFRESHED event // and calls wcElGetPosWin() to retrieve the coordinates where the elements is displayed and wcElSetPosStyle() to // set the top, left, height, width style attributes to the rendered position. OpenModalDialog("Dismiss the modal dialog to proceed"); // Test8: - Create a window. Combine a message and a dismiss button in the html text. // Give the find button an ID then attach a dismiss button handler to the button using // wcElFind and wcElSetEventHandler. // Call wcWinExecute instead of using the Modal argument to wcWinCreateEX SimpleModalDialog("I am a modal dialog box. Click to dismiss."); rtp_printf("Test9: - Verify window border setting support. \n"); // Test9: - Test window borders. TestWindowBorders(); dotest10: // Test10: - Create two windows each containing two edit controls. // First cycle the focus among the edit controls for 20 seconds. // Then move the windows around the screen wcBOOL Error = wcFALSE; OpenTest10Window(&Test10WindowZero, 100, 100, "Focus test: Window zero. Type. The focus changes every second."); OpenTest10Window(&Test10WindowOne, 325, 175, "Focus test: Window One.Type. The focus changes every second."); Test10Elements[0][0] = wcELFind (&Test10WindowZero, 0, "/0", &Error); Test10Elements[0][1] = wcELFind (&Test10WindowZero, 0, "/1", &Error); Test10Elements[0][2] = wcELFind (&Test10WindowZero, 0, "/2", &Error); Test10Elements[1][0] = wcELFind (&Test10WindowOne, 0, "/0", &Error); Test10Elements[1][1] = wcELFind (&Test10WindowOne, 0, "/1", &Error); Test10Elements[1][2] = wcELFind (&Test10WindowOne, 0, "/2", &Error); wcElSetEventHandler(Test10Elements[0][0], Test10Callback); CycleTest10(); // Note: CycleTest10() calls StartFlyingWindowDemo() when it is finished }
static HTMLEventStatus FlyingWindowBodyCallback(wcCtx* Ctx, wcEL element,HTMLEvent* event, char* param) { /* Close the Browser window when the dismiss button is clicked. */ int CycleTimer = 0; int MaxX,MaxY; struct flyingwindowcontrol *pcontrol; MaxX = 600; // Should call get canvas MaxY = 600; if (event->type == HTML_EVENT_OBJECT_CREATED) { struct flyingwindowcontrol *pcontrol; pcontrol = (struct flyingwindowcontrol *)rtp_malloc(sizeof(struct flyingwindowcontrol)); pcontrol->iteration = 0; pcontrol->xstep = 4; pcontrol->ystep = 2; wcPushData(Ctx, element, (void*) pcontrol); CycleTimer = 1; } else if (event->type == HTML_EVENT_MOUSEDOWN) { // experimental pcontrol = (struct flyingwindowcontrol *) wcGetData(Ctx, element); wcPopData(Ctx, element); rtp_free(pcontrol); wcWinClose(Ctx); StartFlyingWindowDemo(0, 10, WF_SPRITE); return (HTML_EVENT_STATUS_HALT); } else if (event->type == HTML_EVENT_TIMER) { int left,top,width,height; pcontrol = (struct flyingwindowcontrol *) wcGetData(Ctx, element); pcontrol->iteration += 1; if (pcontrol->iteration >= FLYINGWINDOWITERATIONS) { // free private data wcPopData(Ctx, element); rtp_free(pcontrol); // Make a private copy of the stack based context to pass to the Global timer handler wcCtx* KillCtx; KillCtx = (wcCtx*)rtp_malloc(sizeof(*Ctx)); *KillCtx = *Ctx; // Tell the global timer to call our close callback routine wcTimedCallback(FlyingWindowCloseCallback,0, 0, (void *) KillCtx); return (HTML_EVENT_STATUS_CONTINUE); } wcWinGetPos(Ctx, &left, &top, &width, &height); left += pcontrol->xstep; if (left < 0) { left = 0; pcontrol->xstep *= -1; } else if (left+width >= MaxX) { left -= pcontrol->xstep; pcontrol->xstep *= -1; } top += pcontrol->ystep; if (top < 0) { top = 0; pcontrol->ystep *= -1; } else if (top+height >= MaxY) { top -= pcontrol->ystep; pcontrol->ystep *= -1; } wcWinSetPos(Ctx, left, top, width, height); CycleTimer = 1; } if (CycleTimer) { HTMLEvent NewEvent; rtp_memset(&NewEvent, 0 ,sizeof(NewEvent)); NewEvent.type = HTML_EVENT_TIMER; wcTriggerEvent(element, &NewEvent, FLYINGWINDOWPERIOD); } return (HTML_EVENT_STATUS_CONTINUE); }